webs-sdk 0.11.6 → 0.11.7
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/libraries/auth.js +658 -658
- package/dist/libraries/user.d.ts +1 -7
- package/dist/libraries/user.d.ts.map +1 -1
- package/dist/libraries/user.js +6 -13
- package/dist/libraries/user.js.map +1 -1
- package/package.json +1 -1
package/dist/libraries/auth.js
CHANGED
|
@@ -1,659 +1,659 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.AuthManager = void 0;
|
|
18
|
-
const config_1 = __importDefault(require("../config"));
|
|
19
|
-
const storage_1 = __importDefault(require("./storage"));
|
|
20
|
-
const index_1 = __importDefault(require("../index"));
|
|
21
|
-
class AuthManager {
|
|
22
|
-
constructor() {
|
|
23
|
-
this.backendBaseUrl = config_1.default.backendBaseUrl;
|
|
24
|
-
this.storage = new storage_1.default();
|
|
25
|
-
this.init();
|
|
26
|
-
}
|
|
27
|
-
async init() {
|
|
28
|
-
console.debug("AuthManager init");
|
|
29
|
-
}
|
|
30
|
-
async auto_login(cfg_sessionid, websiteData, requestUrl) {
|
|
31
|
-
var _a, _b, _c, _d;
|
|
32
|
-
console.log('AuthManager auto-login with session and website', cfg_sessionid, websiteData === null || websiteData === void 0 ? void 0 : websiteData.web_id);
|
|
33
|
-
const authResult = await this._fetchAutoLogin(cfg_sessionid, websiteData === null || websiteData === void 0 ? void 0 : websiteData.web_id);
|
|
34
|
-
const cookies = [];
|
|
35
|
-
const baseUrl = requestUrl.replace(/[?&]cfg_sessionid=[^&]*/g, '');
|
|
36
|
-
if ((authResult === null || authResult === void 0 ? void 0 : authResult.status) === 'success') {
|
|
37
|
-
console.log('✅ Auto-login successful, preparing cookies');
|
|
38
|
-
const isRecentSession = this.isSessionRecent(cfg_sessionid);
|
|
39
|
-
const hasNoSubscription = !((_b = (_a = authResult.data) === null || _a === void 0 ? void 0 : _a.subscription_data) === null || _b === void 0 ? void 0 : _b.subscription_active);
|
|
40
|
-
if (isRecentSession && hasNoSubscription) {
|
|
41
|
-
authResult.data.wip = true;
|
|
42
|
-
console.log('✅ Session is recent and has no subscription - setting wip=true');
|
|
43
|
-
}
|
|
44
|
-
const userSessionData = {
|
|
45
|
-
user: Object.assign(Object.assign({}, (authResult.data || {})), { metadata: ((_c = authResult.data) === null || _c === void 0 ? void 0 : _c.metadata) || null, subscription_data: ((_d = authResult.data) === null || _d === void 0 ? void 0 : _d.subscription_data) || null }),
|
|
46
|
-
token: authResult.session_id || `session_${Date.now()}`,
|
|
47
|
-
isAuthenticated: true
|
|
48
|
-
};
|
|
49
|
-
cookies.push({
|
|
50
|
-
name: 'autoLoginFlag',
|
|
51
|
-
value: JSON.stringify(userSessionData),
|
|
52
|
-
options: {
|
|
53
|
-
path: '/',
|
|
54
|
-
maxAge: 10,
|
|
55
|
-
sameSite: 'lax',
|
|
56
|
-
secure: process.env.NODE_ENV === 'production',
|
|
57
|
-
httpOnly: false
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
return {
|
|
61
|
-
status: 'success',
|
|
62
|
-
redirectUrl: baseUrl,
|
|
63
|
-
cookies: cookies
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
console.log('❌ Auto-login failed:', authResult);
|
|
68
|
-
return {
|
|
69
|
-
status: 'error',
|
|
70
|
-
redirectUrl: baseUrl,
|
|
71
|
-
cookies: cookies,
|
|
72
|
-
errorKey: authResult === null || authResult === void 0 ? void 0 : authResult.errorKey,
|
|
73
|
-
error: authResult === null || authResult === void 0 ? void 0 : authResult.error
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
async _fetchAutoLogin(cfg_sessionid, website_id) {
|
|
78
|
-
var _a, _b, _c, _d;
|
|
79
|
-
console.debug("AuthManager _fetchAutoLogin called with cfg_sessionid:", cfg_sessionid);
|
|
80
|
-
if (!cfg_sessionid) {
|
|
81
|
-
console.warn("cfg_sessionid es requerido");
|
|
82
|
-
return {
|
|
83
|
-
status: 'error',
|
|
84
|
-
errorKey: 'invalidData',
|
|
85
|
-
error: 'Required fields: cfg_sessionid'
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
if (!website_id) {
|
|
89
|
-
console.warn("website_id es requerido");
|
|
90
|
-
return {
|
|
91
|
-
status: 'error',
|
|
92
|
-
errorKey: 'invalidData',
|
|
93
|
-
error: 'Required fields: website_id'
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
const thankyouMetadata = await this.getThankyouPageMetadata(cfg_sessionid);
|
|
97
|
-
if (thankyouMetadata.status === "error") {
|
|
98
|
-
return {
|
|
99
|
-
status: 'error',
|
|
100
|
-
errorKey: thankyouMetadata.errorKey,
|
|
101
|
-
error: thankyouMetadata.error
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
const authParams = {
|
|
105
|
-
login: (_b = (_a = thankyouMetadata.data) === null || _a === void 0 ? void 0 : _a.user) === null || _b === void 0 ? void 0 : _b.login,
|
|
106
|
-
password: (_d = (_c = thankyouMetadata.data) === null || _c === void 0 ? void 0 : _c.user) === null || _d === void 0 ? void 0 : _d.password,
|
|
107
|
-
websiteid: website_id
|
|
108
|
-
};
|
|
109
|
-
const authResult = await this.authUser(authParams);
|
|
110
|
-
if (authResult.status === "success") {
|
|
111
|
-
this.onAuthSuccess(authResult);
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
this.onAuthFailure(authResult.error || "Unknown error in authentication");
|
|
115
|
-
}
|
|
116
|
-
return authResult;
|
|
117
|
-
}
|
|
118
|
-
async getThankyouPageMetadata(cfg_sessionid) {
|
|
119
|
-
var _a, _b, _c, _d, _e;
|
|
120
|
-
console.log("AuthManager getThankyouPageMetadata called with cfg_sessionid:", cfg_sessionid);
|
|
121
|
-
try {
|
|
122
|
-
const result = await index_1.default.Networking.request(`${this.backendBaseUrl}/auth/get-thankyoupage-metadata`, { cfg_sessionid });
|
|
123
|
-
console.log("getThankyouPageMetadata response:", JSON.stringify(result, null, 2));
|
|
124
|
-
if (!((_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.user)) {
|
|
125
|
-
if (((_c = (_b = result === null || result === void 0 ? void 0 : result.data) === null || _b === void 0 ? void 0 : _b.error) === null || _c === void 0 ? void 0 : _c.code) && ((_e = (_d = result === null || result === void 0 ? void 0 : result.data) === null || _d === void 0 ? void 0 : _d.error) === null || _e === void 0 ? void 0 : _e.desc)) {
|
|
126
|
-
return {
|
|
127
|
-
status: 'error',
|
|
128
|
-
errorKey: result.data.error.code,
|
|
129
|
-
error: result.data.error.desc
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
return {
|
|
133
|
-
status: 'error',
|
|
134
|
-
errorKey: 'no-user-data',
|
|
135
|
-
error: 'No user data found in server response'
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
return {
|
|
139
|
-
status: 'success',
|
|
140
|
-
data: result.data
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
catch (error) {
|
|
144
|
-
return {
|
|
145
|
-
status: 'error',
|
|
146
|
-
errorKey: 'serverError',
|
|
147
|
-
error: "Server communication error"
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
async authUser(authParams) {
|
|
152
|
-
var _a, _b, _c;
|
|
153
|
-
console.log("AuthManager authUser called with params:", Object.assign(Object.assign({}, authParams), { password: '***' }));
|
|
154
|
-
const { login, password, websiteid } = authParams;
|
|
155
|
-
if (!login || !password || !websiteid) {
|
|
156
|
-
return {
|
|
157
|
-
status: 'error',
|
|
158
|
-
errorKey: 'invalidData',
|
|
159
|
-
error: 'Required fields: login, password and websiteid'
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
try {
|
|
163
|
-
const apiData = await index_1.default.Networking.request(`${this.backendBaseUrl}/auth/auth-user`, authParams);
|
|
164
|
-
console.log('🔍 Auth API Response RAW:', JSON.stringify(apiData, null, 2));
|
|
165
|
-
if (((_a = apiData === null || apiData === void 0 ? void 0 : apiData.data) === null || _a === void 0 ? void 0 : _a.success) === 1 || ((_b = apiData === null || apiData === void 0 ? void 0 : apiData.data) === null || _b === void 0 ? void 0 : _b.success) === '1') {
|
|
166
|
-
const response = Object.assign({ status: 'success' }, apiData);
|
|
167
|
-
return response;
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
const error = ((_c = apiData === null || apiData === void 0 ? void 0 : apiData.data) === null || _c === void 0 ? void 0 : _c.error) || 'authentication error';
|
|
171
|
-
let errorKey = 'authFailed';
|
|
172
|
-
if (error) {
|
|
173
|
-
switch (error.reason) {
|
|
174
|
-
case 'user-not-found':
|
|
175
|
-
errorKey = 'userNotFound';
|
|
176
|
-
break;
|
|
177
|
-
case 'invalid-credentials':
|
|
178
|
-
errorKey = 'invalidCredentials';
|
|
179
|
-
break;
|
|
180
|
-
case 'account-disabled':
|
|
181
|
-
errorKey = 'accountDisabled';
|
|
182
|
-
break;
|
|
183
|
-
case 'user-not-active':
|
|
184
|
-
errorKey = 'userNotActive';
|
|
185
|
-
break;
|
|
186
|
-
default:
|
|
187
|
-
errorKey = 'authFailed';
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
return {
|
|
191
|
-
status: 'error',
|
|
192
|
-
errorKey: errorKey,
|
|
193
|
-
error: (error === null || error === void 0 ? void 0 : error.reason_extended) || (error === null || error === void 0 ? void 0 : error.reason) || 'Authentication error',
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
catch (apiError) {
|
|
198
|
-
console.error('Error:', apiError);
|
|
199
|
-
return {
|
|
200
|
-
status: 'error',
|
|
201
|
-
errorKey: 'serverError',
|
|
202
|
-
error: 'Server communication error'
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
async authOnlyUser(authOnlyUserParams) {
|
|
207
|
-
var _a, _b, _c;
|
|
208
|
-
console.log("AuthManager authOnlyUser called with params:", Object.assign({}, authOnlyUserParams));
|
|
209
|
-
const { login, websiteid, login_only_user } = authOnlyUserParams;
|
|
210
|
-
if (!login || !websiteid) {
|
|
211
|
-
return {
|
|
212
|
-
status: 'error',
|
|
213
|
-
errorKey: 'invalidData',
|
|
214
|
-
error: 'Required fields: login and websiteid'
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
try {
|
|
218
|
-
const apiData = await index_1.default.Networking.request(`${this.backendBaseUrl}/auth/auth-only-user`, authOnlyUserParams);
|
|
219
|
-
console.log('🔍 Auth API Response RAW:', JSON.stringify(apiData, null, 2));
|
|
220
|
-
if (((_a = apiData === null || apiData === void 0 ? void 0 : apiData.data) === null || _a === void 0 ? void 0 : _a.success) === 1 || ((_b = apiData === null || apiData === void 0 ? void 0 : apiData.data) === null || _b === void 0 ? void 0 : _b.success) === '1') {
|
|
221
|
-
const response = Object.assign({ status: 'success' }, apiData);
|
|
222
|
-
return response;
|
|
223
|
-
}
|
|
224
|
-
else {
|
|
225
|
-
const error = ((_c = apiData === null || apiData === void 0 ? void 0 : apiData.data) === null || _c === void 0 ? void 0 : _c.error) || 'authentication error';
|
|
226
|
-
let errorKey = 'authFailed';
|
|
227
|
-
if (error) {
|
|
228
|
-
switch (error.reason) {
|
|
229
|
-
case 'user-not-found':
|
|
230
|
-
errorKey = 'userNotFound';
|
|
231
|
-
break;
|
|
232
|
-
case 'invalid-credentials':
|
|
233
|
-
errorKey = 'invalidCredentials';
|
|
234
|
-
break;
|
|
235
|
-
case 'account-disabled':
|
|
236
|
-
errorKey = 'accountDisabled';
|
|
237
|
-
break;
|
|
238
|
-
case 'user-not-active':
|
|
239
|
-
errorKey = 'userNotActive';
|
|
240
|
-
break;
|
|
241
|
-
default:
|
|
242
|
-
errorKey = 'authFailed';
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
return {
|
|
246
|
-
status: 'error',
|
|
247
|
-
errorKey: errorKey,
|
|
248
|
-
error: (error === null || error === void 0 ? void 0 : error.reason_extended) || (error === null || error === void 0 ? void 0 : error.reason) || 'Authentication error',
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
catch (apiError) {
|
|
253
|
-
console.error('Error:', apiError);
|
|
254
|
-
return {
|
|
255
|
-
status: 'error',
|
|
256
|
-
errorKey: 'serverError',
|
|
257
|
-
error: 'Server communication error'
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
async createUser(createUserParams) {
|
|
262
|
-
var _a, _b;
|
|
263
|
-
console.log("AuthManager createUser called with params:", Object.assign(Object.assign({}, createUserParams), { password: '***' }));
|
|
264
|
-
const { login, password, websiteid } = createUserParams;
|
|
265
|
-
if (!login || !password || !websiteid) {
|
|
266
|
-
return {
|
|
267
|
-
status: 'error',
|
|
268
|
-
errorKey: 'invalidData',
|
|
269
|
-
error: 'Required fields: login, password and websiteid'
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
try {
|
|
273
|
-
const apiData = await index_1.default.Networking.request(`${this.backendBaseUrl}/auth/create-user`, createUserParams);
|
|
274
|
-
console.log('📡 API Response PARSED JSON:', JSON.stringify(apiData, null, 2));
|
|
275
|
-
if (((_a = apiData === null || apiData === void 0 ? void 0 : apiData.data) === null || _a === void 0 ? void 0 : _a.success) === 1 || ((_b = apiData === null || apiData === void 0 ? void 0 : apiData.data) === null || _b === void 0 ? void 0 : _b.success) === '1') {
|
|
276
|
-
console.log('✅ Cuenta creada exitosamente');
|
|
277
|
-
const response = Object.assign({ status: 'success' }, apiData);
|
|
278
|
-
return response;
|
|
279
|
-
}
|
|
280
|
-
else if ((apiData === null || apiData === void 0 ? void 0 : apiData.code) === 112) {
|
|
281
|
-
console.log('❌ Usuario ya existe');
|
|
282
|
-
const response = {
|
|
283
|
-
status: 'error',
|
|
284
|
-
errorKey: 'userAlreadyExists',
|
|
285
|
-
error: apiData.msg || 'User already exists'
|
|
286
|
-
};
|
|
287
|
-
return response;
|
|
288
|
-
}
|
|
289
|
-
else {
|
|
290
|
-
console.log('❌ La cuenta NO se creó exitosamente');
|
|
291
|
-
console.log('❌ apiData.success value:', apiData.success, 'type:', typeof apiData.success);
|
|
292
|
-
console.log('❌ Full apiData:', JSON.stringify(apiData, null, 2));
|
|
293
|
-
const response = {
|
|
294
|
-
status: 'error',
|
|
295
|
-
errorKey: 'signupFailed',
|
|
296
|
-
error: (apiData === null || apiData === void 0 ? void 0 : apiData.msg) || 'User creation failed'
|
|
297
|
-
};
|
|
298
|
-
return response;
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
catch (apiError) {
|
|
302
|
-
console.error('Error:', apiError);
|
|
303
|
-
return {
|
|
304
|
-
status: 'error',
|
|
305
|
-
errorKey: 'serverError',
|
|
306
|
-
error: 'Server communication error'
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
async uploadProfilePhoto(uploadProfilePhotoParams) {
|
|
311
|
-
var _a;
|
|
312
|
-
console.log("AuthManager uploadProfilePhoto called with params:", Object.assign(Object.assign({}, uploadProfilePhotoParams), { password: '***' }));
|
|
313
|
-
const { login, password, websiteid, resource } = uploadProfilePhotoParams;
|
|
314
|
-
if (!login || !websiteid || !resource) {
|
|
315
|
-
return {
|
|
316
|
-
status: 'error',
|
|
317
|
-
errorKey: 'invalidData',
|
|
318
|
-
error: 'Required fields: resource (file), login, and websiteid'
|
|
319
|
-
};
|
|
320
|
-
}
|
|
321
|
-
const allowedTypes = ['image/jpeg', 'image/jpg', 'image/png', 'image/webp'];
|
|
322
|
-
if (!allowedTypes.includes(resource.type)) {
|
|
323
|
-
return {
|
|
324
|
-
status: 'error',
|
|
325
|
-
errorKey: 'invalidFormat',
|
|
326
|
-
error: 'Invalid file type. Allowed: JPG, JPEG, PNG, WEBP'
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
const maxSize = 5 * 1024 * 1024;
|
|
330
|
-
if (resource.size > maxSize) {
|
|
331
|
-
return {
|
|
332
|
-
status: 'error',
|
|
333
|
-
errorKey: 'fileTooLarge',
|
|
334
|
-
error: 'File too large. Maximum size: 5MB'
|
|
335
|
-
};
|
|
336
|
-
}
|
|
337
|
-
try {
|
|
338
|
-
const apiFormData = new FormData();
|
|
339
|
-
apiFormData.append('resource', resource);
|
|
340
|
-
apiFormData.append('login', login);
|
|
341
|
-
if (password) {
|
|
342
|
-
apiFormData.append('password', password);
|
|
343
|
-
}
|
|
344
|
-
apiFormData.append('websiteid', websiteid);
|
|
345
|
-
console.log('Uploading profile photo for login:', login);
|
|
346
|
-
console.log('Password provided:', password ? '***' : 'NO');
|
|
347
|
-
console.log('WebsiteID:', websiteid);
|
|
348
|
-
const apiResponse = await fetch(`${this.backendBaseUrl}/auth/upload-profile-photo`, {
|
|
349
|
-
method: 'POST',
|
|
350
|
-
body: apiFormData
|
|
351
|
-
});
|
|
352
|
-
if (!apiResponse.ok) {
|
|
353
|
-
throw new Error(`Error en la API externa: ${apiResponse.status}`);
|
|
354
|
-
}
|
|
355
|
-
let apiData;
|
|
356
|
-
try {
|
|
357
|
-
apiData = await apiResponse.json();
|
|
358
|
-
console.log('📡 API Response PARSED JSON:', JSON.stringify(apiData, null, 2));
|
|
359
|
-
}
|
|
360
|
-
catch (parseError) {
|
|
361
|
-
console.error('❌ Error parsing JSON response:', parseError);
|
|
362
|
-
throw new Error('Invalid JSON response from external API');
|
|
363
|
-
}
|
|
364
|
-
console.log('📡 API Response PARSED JSON:', JSON.stringify(apiData, null, 2));
|
|
365
|
-
if (((_a = apiData === null || apiData === void 0 ? void 0 : apiData.data) === null || _a === void 0 ? void 0 : _a.profile_photo) != null) {
|
|
366
|
-
const profilePhotoUrl = apiData.data.profile_photo;
|
|
367
|
-
const response = {
|
|
368
|
-
status: 'success',
|
|
369
|
-
profile_photo: profilePhotoUrl,
|
|
370
|
-
message: 'Profile photo updated successfully',
|
|
371
|
-
metadata: {
|
|
372
|
-
profile_photo: profilePhotoUrl
|
|
373
|
-
}
|
|
374
|
-
};
|
|
375
|
-
return response;
|
|
376
|
-
}
|
|
377
|
-
else {
|
|
378
|
-
return {
|
|
379
|
-
status: 'error',
|
|
380
|
-
errorKey: 'uploadFailed',
|
|
381
|
-
error: (apiData === null || apiData === void 0 ? void 0 : apiData.error) || 'Failed to upload profile photo'
|
|
382
|
-
};
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
catch (apiError) {
|
|
386
|
-
console.error('Error:', apiError);
|
|
387
|
-
return {
|
|
388
|
-
status: 'error',
|
|
389
|
-
errorKey: 'serverError',
|
|
390
|
-
error: 'Server communication error'
|
|
391
|
-
};
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
async setUserMetadata(SetUserMetadataParams) {
|
|
395
|
-
var _a, _b;
|
|
396
|
-
console.log("AuthManager setUserMetadata called with params:", Object.assign(Object.assign({}, SetUserMetadataParams), { password: SetUserMetadataParams.password ? '***' : undefined }));
|
|
397
|
-
const { login, password, websiteid } = SetUserMetadataParams, metadata = __rest(SetUserMetadataParams, ["login", "password", "websiteid"]);
|
|
398
|
-
if (!login || !websiteid) {
|
|
399
|
-
return {
|
|
400
|
-
status: 'error',
|
|
401
|
-
errorKey: 'invalidData',
|
|
402
|
-
error: 'Se requieren los campos login y websiteid'
|
|
403
|
-
};
|
|
404
|
-
}
|
|
405
|
-
try {
|
|
406
|
-
const requestParams = Object.assign({ login,
|
|
407
|
-
websiteid }, metadata);
|
|
408
|
-
if (password) {
|
|
409
|
-
requestParams.password = password;
|
|
410
|
-
}
|
|
411
|
-
const apiData = await index_1.default.Networking.request(`${this.backendBaseUrl}/auth/set-user-metadata`, requestParams);
|
|
412
|
-
console.log('📡 API Response PARSED JSON:', JSON.stringify(apiData, null, 2));
|
|
413
|
-
if (((_a = apiData === null || apiData === void 0 ? void 0 : apiData.data) === null || _a === void 0 ? void 0 : _a.success) === 1 || ((_b = apiData === null || apiData === void 0 ? void 0 : apiData.data) === null || _b === void 0 ? void 0 : _b.success) === '1') {
|
|
414
|
-
return Object.assign({ status: 'success' }, apiData);
|
|
415
|
-
}
|
|
416
|
-
else {
|
|
417
|
-
let errorKey = 'unsubscribeFailed';
|
|
418
|
-
let errorReason = 'Unsubscribe error';
|
|
419
|
-
if (apiData === null || apiData === void 0 ? void 0 : apiData.code) {
|
|
420
|
-
errorKey = apiData.code;
|
|
421
|
-
}
|
|
422
|
-
if (apiData === null || apiData === void 0 ? void 0 : apiData.msg) {
|
|
423
|
-
errorReason = apiData.msg;
|
|
424
|
-
}
|
|
425
|
-
return {
|
|
426
|
-
status: 'error',
|
|
427
|
-
errorKey: errorKey,
|
|
428
|
-
error: errorReason
|
|
429
|
-
};
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
catch (error) {
|
|
433
|
-
console.error('❌ Error in setUserMetadata:', error);
|
|
434
|
-
return {
|
|
435
|
-
status: 'error',
|
|
436
|
-
errorKey: 'serverError',
|
|
437
|
-
error: 'Server communication error'
|
|
438
|
-
};
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
onAuthSuccess(authResult) {
|
|
442
|
-
console.log("✅ User authenticated successfully");
|
|
443
|
-
}
|
|
444
|
-
onAuthFailure(error) {
|
|
445
|
-
console.error("❌ User authentication failed: ", error);
|
|
446
|
-
}
|
|
447
|
-
async unsubscribeUser(unsubscribeParams) {
|
|
448
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
449
|
-
console.log("AuthManager unsubscribeUser called with params:", Object.assign({}, unsubscribeParams));
|
|
450
|
-
const { user_id, callback_url, org } = unsubscribeParams;
|
|
451
|
-
if (!user_id) {
|
|
452
|
-
return {
|
|
453
|
-
status: 'error',
|
|
454
|
-
errorKey: 'invalidData',
|
|
455
|
-
error: 'Required fields: user_id'
|
|
456
|
-
};
|
|
457
|
-
}
|
|
458
|
-
try {
|
|
459
|
-
const apiData = await index_1.default.Networking.request(`${this.backendBaseUrl}/auth/unsubscribe-user`, unsubscribeParams);
|
|
460
|
-
console.log('🔍 Unsubscribe API Response RAW:', JSON.stringify(apiData, null, 2));
|
|
461
|
-
if (((_a = apiData === null || apiData === void 0 ? void 0 : apiData.data) === null || _a === void 0 ? void 0 : _a.success) === 1 || ((_b = apiData === null || apiData === void 0 ? void 0 : apiData.data) === null || _b === void 0 ? void 0 : _b.success) === '1' || ((_c = apiData === null || apiData === void 0 ? void 0 : apiData.data) === null || _c === void 0 ? void 0 : _c.success) === true) {
|
|
462
|
-
return Object.assign({ status: 'success', data: apiData }, apiData);
|
|
463
|
-
}
|
|
464
|
-
else {
|
|
465
|
-
let errorKey = 'unsubscribeFailed';
|
|
466
|
-
let errorReason = 'Unsubscribe error';
|
|
467
|
-
if ((_e = (_d = apiData === null || apiData === void 0 ? void 0 : apiData.data) === null || _d === void 0 ? void 0 : _d.error) === null || _e === void 0 ? void 0 : _e.id) {
|
|
468
|
-
errorKey = apiData.data.error.id;
|
|
469
|
-
}
|
|
470
|
-
else if ((_g = (_f = apiData === null || apiData === void 0 ? void 0 : apiData.data) === null || _f === void 0 ? void 0 : _f.error) === null || _g === void 0 ? void 0 : _g.code) {
|
|
471
|
-
errorKey = apiData.data.error.code;
|
|
472
|
-
}
|
|
473
|
-
else if (apiData === null || apiData === void 0 ? void 0 : apiData.code) {
|
|
474
|
-
errorKey = apiData.code;
|
|
475
|
-
}
|
|
476
|
-
if ((_j = (_h = apiData === null || apiData === void 0 ? void 0 : apiData.data) === null || _h === void 0 ? void 0 : _h.error) === null || _j === void 0 ? void 0 : _j.reason) {
|
|
477
|
-
errorReason = apiData.data.error.reason;
|
|
478
|
-
}
|
|
479
|
-
else if (apiData === null || apiData === void 0 ? void 0 : apiData.msg) {
|
|
480
|
-
errorReason = apiData.msg;
|
|
481
|
-
}
|
|
482
|
-
return {
|
|
483
|
-
status: 'error',
|
|
484
|
-
errorKey: errorKey,
|
|
485
|
-
error: errorReason
|
|
486
|
-
};
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
catch (apiError) {
|
|
490
|
-
console.error('Error:', apiError);
|
|
491
|
-
return {
|
|
492
|
-
status: 'error',
|
|
493
|
-
errorKey: 'serverError',
|
|
494
|
-
error: 'Server communication error'
|
|
495
|
-
};
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
async changePassword(changePasswordParams) {
|
|
499
|
-
console.log("AuthManager changePassword called with params:", Object.assign(Object.assign({}, changePasswordParams), { new_pass: '***', repeat_new_pass: '***' }));
|
|
500
|
-
const { login, websiteid, new_pass, repeat_new_pass } = changePasswordParams;
|
|
501
|
-
if (!login) {
|
|
502
|
-
return {
|
|
503
|
-
status: 'error',
|
|
504
|
-
errorKey: 'invalidData',
|
|
505
|
-
error: 'Required fields: login'
|
|
506
|
-
};
|
|
507
|
-
}
|
|
508
|
-
if (!websiteid) {
|
|
509
|
-
return {
|
|
510
|
-
status: 'error',
|
|
511
|
-
errorKey: 'invalidData',
|
|
512
|
-
error: 'Required fields: login'
|
|
513
|
-
};
|
|
514
|
-
}
|
|
515
|
-
if (!new_pass || new_pass.length < 8) {
|
|
516
|
-
return {
|
|
517
|
-
status: 'error',
|
|
518
|
-
errorKey: 'invalidData',
|
|
519
|
-
error: 'Required fields: new_pass (at least 8 characters)'
|
|
520
|
-
};
|
|
521
|
-
}
|
|
522
|
-
if (!repeat_new_pass || repeat_new_pass.length < 8) {
|
|
523
|
-
return {
|
|
524
|
-
status: 'error',
|
|
525
|
-
errorKey: 'invalidData',
|
|
526
|
-
error: 'Required fields: repeat_new_pass (at least 8 characters)'
|
|
527
|
-
};
|
|
528
|
-
}
|
|
529
|
-
try {
|
|
530
|
-
const apiData = await index_1.default.Networking.request(`${this.backendBaseUrl}/auth/change-pass`, changePasswordParams);
|
|
531
|
-
console.log('🔍 Change Password API Response RAW:', JSON.stringify(apiData, null, 2));
|
|
532
|
-
if ((apiData === null || apiData === void 0 ? void 0 : apiData.success) === 1 || (apiData === null || apiData === void 0 ? void 0 : apiData.success) === '1' || (apiData === null || apiData === void 0 ? void 0 : apiData.success) === true) {
|
|
533
|
-
return Object.assign({ status: 'success' }, apiData);
|
|
534
|
-
}
|
|
535
|
-
else {
|
|
536
|
-
let errorKey = 'changePasswordFailed';
|
|
537
|
-
let errorReason = 'Change password error';
|
|
538
|
-
return {
|
|
539
|
-
status: 'error',
|
|
540
|
-
errorKey: errorKey,
|
|
541
|
-
error: errorReason
|
|
542
|
-
};
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
catch (apiError) {
|
|
546
|
-
console.error('Error:', apiError);
|
|
547
|
-
return {
|
|
548
|
-
status: 'error',
|
|
549
|
-
errorKey: 'serverError',
|
|
550
|
-
error: 'Server communication error'
|
|
551
|
-
};
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
async changeCredentials(changeCredentialsParams) {
|
|
555
|
-
console.log("AuthManager changeCredentials called with params:", Object.assign(Object.assign({}, changeCredentialsParams), { password: '***', new_pass: '***', repeat_new_pass: '***' }));
|
|
556
|
-
const { websiteid, login, password, new_login, new_pass, repeat_new_pass } = changeCredentialsParams;
|
|
557
|
-
if (!websiteid) {
|
|
558
|
-
return {
|
|
559
|
-
status: 'error',
|
|
560
|
-
errorKey: 'invalidData',
|
|
561
|
-
error: 'Required fields: websiteid'
|
|
562
|
-
};
|
|
563
|
-
}
|
|
564
|
-
if (!login) {
|
|
565
|
-
return {
|
|
566
|
-
status: 'error',
|
|
567
|
-
errorKey: 'invalidData',
|
|
568
|
-
error: 'Required fields: login'
|
|
569
|
-
};
|
|
570
|
-
}
|
|
571
|
-
if (!password) {
|
|
572
|
-
return {
|
|
573
|
-
status: 'error',
|
|
574
|
-
errorKey: 'invalidData',
|
|
575
|
-
error: 'Required fields: password'
|
|
576
|
-
};
|
|
577
|
-
}
|
|
578
|
-
if (!new_login) {
|
|
579
|
-
return {
|
|
580
|
-
status: 'error',
|
|
581
|
-
errorKey: 'invalidData',
|
|
582
|
-
error: 'Required fields: new_login'
|
|
583
|
-
};
|
|
584
|
-
}
|
|
585
|
-
if (!new_pass) {
|
|
586
|
-
return {
|
|
587
|
-
status: 'error',
|
|
588
|
-
errorKey: 'invalidData',
|
|
589
|
-
error: 'Required fields: new_pass'
|
|
590
|
-
};
|
|
591
|
-
}
|
|
592
|
-
if (!repeat_new_pass) {
|
|
593
|
-
return {
|
|
594
|
-
status: 'error',
|
|
595
|
-
errorKey: 'invalidData',
|
|
596
|
-
error: 'Required fields: repeat_new_pass'
|
|
597
|
-
};
|
|
598
|
-
}
|
|
599
|
-
try {
|
|
600
|
-
const apiData = await index_1.default.Networking.request(`${this.backendBaseUrl}/auth/change-credentials`, changeCredentialsParams);
|
|
601
|
-
console.log('🔍 Change Password API Response RAW:', JSON.stringify(apiData, null, 2));
|
|
602
|
-
if ((apiData === null || apiData === void 0 ? void 0 : apiData.success) === 1 || (apiData === null || apiData === void 0 ? void 0 : apiData.success) === '1' || (apiData === null || apiData === void 0 ? void 0 : apiData.success) === true) {
|
|
603
|
-
return Object.assign({ status: 'success' }, apiData);
|
|
604
|
-
}
|
|
605
|
-
else {
|
|
606
|
-
let errorKey = 'changeCredentialsFailed';
|
|
607
|
-
let errorReason = (apiData === null || apiData === void 0 ? void 0 : apiData.msg) || 'Change credentials error';
|
|
608
|
-
return {
|
|
609
|
-
status: 'error',
|
|
610
|
-
errorKey: errorKey,
|
|
611
|
-
error: errorReason
|
|
612
|
-
};
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
catch (apiError) {
|
|
616
|
-
console.error('Error:', apiError);
|
|
617
|
-
return {
|
|
618
|
-
status: 'error',
|
|
619
|
-
errorKey: 'serverError',
|
|
620
|
-
error: 'Server communication error'
|
|
621
|
-
};
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
hasActiveSession() {
|
|
625
|
-
const token = this.storage.get(config_1.default.storage.tokenKey);
|
|
626
|
-
return !!token;
|
|
627
|
-
}
|
|
628
|
-
isSessionRecent(cfg_sessionid) {
|
|
629
|
-
try {
|
|
630
|
-
if (!cfg_sessionid || cfg_sessionid.length < 14) {
|
|
631
|
-
console.warn('Invalid cfg_sessionid format for date parsing');
|
|
632
|
-
return false;
|
|
633
|
-
}
|
|
634
|
-
const dateStr = cfg_sessionid.substring(0, 14);
|
|
635
|
-
const year = parseInt(dateStr.substring(0, 4));
|
|
636
|
-
const month = parseInt(dateStr.substring(4, 6)) - 1;
|
|
637
|
-
const day = parseInt(dateStr.substring(6, 8));
|
|
638
|
-
const hour = parseInt(dateStr.substring(8, 10));
|
|
639
|
-
const minute = parseInt(dateStr.substring(10, 12));
|
|
640
|
-
const second = parseInt(dateStr.substring(12, 14));
|
|
641
|
-
const sessionDate = new Date(year, month, day, hour, minute, second);
|
|
642
|
-
const now = new Date();
|
|
643
|
-
const diffMs = now.getTime() - sessionDate.getTime();
|
|
644
|
-
const oneHourMs = 60 * 60 * 1000;
|
|
645
|
-
console.log(`Session date: ${sessionDate.toISOString()}, Current: ${now.toISOString()}, Diff: ${diffMs}ms`);
|
|
646
|
-
return diffMs < oneHourMs && diffMs >= 0;
|
|
647
|
-
}
|
|
648
|
-
catch (error) {
|
|
649
|
-
console.error('Error parsing session date:', error);
|
|
650
|
-
return false;
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
logout() {
|
|
654
|
-
console.log("Sesión cerrada");
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
exports.AuthManager = AuthManager;
|
|
658
|
-
exports.default = AuthManager;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.AuthManager = void 0;
|
|
18
|
+
const config_1 = __importDefault(require("../config"));
|
|
19
|
+
const storage_1 = __importDefault(require("./storage"));
|
|
20
|
+
const index_1 = __importDefault(require("../index"));
|
|
21
|
+
class AuthManager {
|
|
22
|
+
constructor() {
|
|
23
|
+
this.backendBaseUrl = config_1.default.backendBaseUrl;
|
|
24
|
+
this.storage = new storage_1.default();
|
|
25
|
+
this.init();
|
|
26
|
+
}
|
|
27
|
+
async init() {
|
|
28
|
+
console.debug("AuthManager init");
|
|
29
|
+
}
|
|
30
|
+
async auto_login(cfg_sessionid, websiteData, requestUrl) {
|
|
31
|
+
var _a, _b, _c, _d;
|
|
32
|
+
console.log('AuthManager auto-login with session and website', cfg_sessionid, websiteData === null || websiteData === void 0 ? void 0 : websiteData.web_id);
|
|
33
|
+
const authResult = await this._fetchAutoLogin(cfg_sessionid, websiteData === null || websiteData === void 0 ? void 0 : websiteData.web_id);
|
|
34
|
+
const cookies = [];
|
|
35
|
+
const baseUrl = requestUrl.replace(/[?&]cfg_sessionid=[^&]*/g, '');
|
|
36
|
+
if ((authResult === null || authResult === void 0 ? void 0 : authResult.status) === 'success') {
|
|
37
|
+
console.log('✅ Auto-login successful, preparing cookies');
|
|
38
|
+
const isRecentSession = this.isSessionRecent(cfg_sessionid);
|
|
39
|
+
const hasNoSubscription = !((_b = (_a = authResult.data) === null || _a === void 0 ? void 0 : _a.subscription_data) === null || _b === void 0 ? void 0 : _b.subscription_active);
|
|
40
|
+
if (isRecentSession && hasNoSubscription) {
|
|
41
|
+
authResult.data.wip = true;
|
|
42
|
+
console.log('✅ Session is recent and has no subscription - setting wip=true');
|
|
43
|
+
}
|
|
44
|
+
const userSessionData = {
|
|
45
|
+
user: Object.assign(Object.assign({}, (authResult.data || {})), { metadata: ((_c = authResult.data) === null || _c === void 0 ? void 0 : _c.metadata) || null, subscription_data: ((_d = authResult.data) === null || _d === void 0 ? void 0 : _d.subscription_data) || null }),
|
|
46
|
+
token: authResult.session_id || `session_${Date.now()}`,
|
|
47
|
+
isAuthenticated: true
|
|
48
|
+
};
|
|
49
|
+
cookies.push({
|
|
50
|
+
name: 'autoLoginFlag',
|
|
51
|
+
value: JSON.stringify(userSessionData),
|
|
52
|
+
options: {
|
|
53
|
+
path: '/',
|
|
54
|
+
maxAge: 10,
|
|
55
|
+
sameSite: 'lax',
|
|
56
|
+
secure: process.env.NODE_ENV === 'production',
|
|
57
|
+
httpOnly: false
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
return {
|
|
61
|
+
status: 'success',
|
|
62
|
+
redirectUrl: baseUrl,
|
|
63
|
+
cookies: cookies
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
console.log('❌ Auto-login failed:', authResult);
|
|
68
|
+
return {
|
|
69
|
+
status: 'error',
|
|
70
|
+
redirectUrl: baseUrl,
|
|
71
|
+
cookies: cookies,
|
|
72
|
+
errorKey: authResult === null || authResult === void 0 ? void 0 : authResult.errorKey,
|
|
73
|
+
error: authResult === null || authResult === void 0 ? void 0 : authResult.error
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async _fetchAutoLogin(cfg_sessionid, website_id) {
|
|
78
|
+
var _a, _b, _c, _d;
|
|
79
|
+
console.debug("AuthManager _fetchAutoLogin called with cfg_sessionid:", cfg_sessionid);
|
|
80
|
+
if (!cfg_sessionid) {
|
|
81
|
+
console.warn("cfg_sessionid es requerido");
|
|
82
|
+
return {
|
|
83
|
+
status: 'error',
|
|
84
|
+
errorKey: 'invalidData',
|
|
85
|
+
error: 'Required fields: cfg_sessionid'
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
if (!website_id) {
|
|
89
|
+
console.warn("website_id es requerido");
|
|
90
|
+
return {
|
|
91
|
+
status: 'error',
|
|
92
|
+
errorKey: 'invalidData',
|
|
93
|
+
error: 'Required fields: website_id'
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
const thankyouMetadata = await this.getThankyouPageMetadata(cfg_sessionid);
|
|
97
|
+
if (thankyouMetadata.status === "error") {
|
|
98
|
+
return {
|
|
99
|
+
status: 'error',
|
|
100
|
+
errorKey: thankyouMetadata.errorKey,
|
|
101
|
+
error: thankyouMetadata.error
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
const authParams = {
|
|
105
|
+
login: (_b = (_a = thankyouMetadata.data) === null || _a === void 0 ? void 0 : _a.user) === null || _b === void 0 ? void 0 : _b.login,
|
|
106
|
+
password: (_d = (_c = thankyouMetadata.data) === null || _c === void 0 ? void 0 : _c.user) === null || _d === void 0 ? void 0 : _d.password,
|
|
107
|
+
websiteid: website_id
|
|
108
|
+
};
|
|
109
|
+
const authResult = await this.authUser(authParams);
|
|
110
|
+
if (authResult.status === "success") {
|
|
111
|
+
this.onAuthSuccess(authResult);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
this.onAuthFailure(authResult.error || "Unknown error in authentication");
|
|
115
|
+
}
|
|
116
|
+
return authResult;
|
|
117
|
+
}
|
|
118
|
+
async getThankyouPageMetadata(cfg_sessionid) {
|
|
119
|
+
var _a, _b, _c, _d, _e;
|
|
120
|
+
console.log("AuthManager getThankyouPageMetadata called with cfg_sessionid:", cfg_sessionid);
|
|
121
|
+
try {
|
|
122
|
+
const result = await index_1.default.Networking.request(`${this.backendBaseUrl}/auth/get-thankyoupage-metadata`, { cfg_sessionid });
|
|
123
|
+
console.log("getThankyouPageMetadata response:", JSON.stringify(result, null, 2));
|
|
124
|
+
if (!((_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.user)) {
|
|
125
|
+
if (((_c = (_b = result === null || result === void 0 ? void 0 : result.data) === null || _b === void 0 ? void 0 : _b.error) === null || _c === void 0 ? void 0 : _c.code) && ((_e = (_d = result === null || result === void 0 ? void 0 : result.data) === null || _d === void 0 ? void 0 : _d.error) === null || _e === void 0 ? void 0 : _e.desc)) {
|
|
126
|
+
return {
|
|
127
|
+
status: 'error',
|
|
128
|
+
errorKey: result.data.error.code,
|
|
129
|
+
error: result.data.error.desc
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
status: 'error',
|
|
134
|
+
errorKey: 'no-user-data',
|
|
135
|
+
error: 'No user data found in server response'
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
status: 'success',
|
|
140
|
+
data: result.data
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
return {
|
|
145
|
+
status: 'error',
|
|
146
|
+
errorKey: 'serverError',
|
|
147
|
+
error: "Server communication error"
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
async authUser(authParams) {
|
|
152
|
+
var _a, _b, _c;
|
|
153
|
+
console.log("AuthManager authUser called with params:", Object.assign(Object.assign({}, authParams), { password: '***' }));
|
|
154
|
+
const { login, password, websiteid } = authParams;
|
|
155
|
+
if (!login || !password || !websiteid) {
|
|
156
|
+
return {
|
|
157
|
+
status: 'error',
|
|
158
|
+
errorKey: 'invalidData',
|
|
159
|
+
error: 'Required fields: login, password and websiteid'
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
try {
|
|
163
|
+
const apiData = await index_1.default.Networking.request(`${this.backendBaseUrl}/auth/auth-user`, authParams);
|
|
164
|
+
console.log('🔍 Auth API Response RAW:', JSON.stringify(apiData, null, 2));
|
|
165
|
+
if (((_a = apiData === null || apiData === void 0 ? void 0 : apiData.data) === null || _a === void 0 ? void 0 : _a.success) === 1 || ((_b = apiData === null || apiData === void 0 ? void 0 : apiData.data) === null || _b === void 0 ? void 0 : _b.success) === '1') {
|
|
166
|
+
const response = Object.assign({ status: 'success' }, apiData);
|
|
167
|
+
return response;
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
const error = ((_c = apiData === null || apiData === void 0 ? void 0 : apiData.data) === null || _c === void 0 ? void 0 : _c.error) || 'authentication error';
|
|
171
|
+
let errorKey = 'authFailed';
|
|
172
|
+
if (error) {
|
|
173
|
+
switch (error.reason) {
|
|
174
|
+
case 'user-not-found':
|
|
175
|
+
errorKey = 'userNotFound';
|
|
176
|
+
break;
|
|
177
|
+
case 'invalid-credentials':
|
|
178
|
+
errorKey = 'invalidCredentials';
|
|
179
|
+
break;
|
|
180
|
+
case 'account-disabled':
|
|
181
|
+
errorKey = 'accountDisabled';
|
|
182
|
+
break;
|
|
183
|
+
case 'user-not-active':
|
|
184
|
+
errorKey = 'userNotActive';
|
|
185
|
+
break;
|
|
186
|
+
default:
|
|
187
|
+
errorKey = 'authFailed';
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return {
|
|
191
|
+
status: 'error',
|
|
192
|
+
errorKey: errorKey,
|
|
193
|
+
error: (error === null || error === void 0 ? void 0 : error.reason_extended) || (error === null || error === void 0 ? void 0 : error.reason) || 'Authentication error',
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
catch (apiError) {
|
|
198
|
+
console.error('Error:', apiError);
|
|
199
|
+
return {
|
|
200
|
+
status: 'error',
|
|
201
|
+
errorKey: 'serverError',
|
|
202
|
+
error: 'Server communication error'
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
async authOnlyUser(authOnlyUserParams) {
|
|
207
|
+
var _a, _b, _c;
|
|
208
|
+
console.log("AuthManager authOnlyUser called with params:", Object.assign({}, authOnlyUserParams));
|
|
209
|
+
const { login, websiteid, login_only_user } = authOnlyUserParams;
|
|
210
|
+
if (!login || !websiteid) {
|
|
211
|
+
return {
|
|
212
|
+
status: 'error',
|
|
213
|
+
errorKey: 'invalidData',
|
|
214
|
+
error: 'Required fields: login and websiteid'
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
try {
|
|
218
|
+
const apiData = await index_1.default.Networking.request(`${this.backendBaseUrl}/auth/auth-only-user`, authOnlyUserParams);
|
|
219
|
+
console.log('🔍 Auth API Response RAW:', JSON.stringify(apiData, null, 2));
|
|
220
|
+
if (((_a = apiData === null || apiData === void 0 ? void 0 : apiData.data) === null || _a === void 0 ? void 0 : _a.success) === 1 || ((_b = apiData === null || apiData === void 0 ? void 0 : apiData.data) === null || _b === void 0 ? void 0 : _b.success) === '1') {
|
|
221
|
+
const response = Object.assign({ status: 'success' }, apiData);
|
|
222
|
+
return response;
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
const error = ((_c = apiData === null || apiData === void 0 ? void 0 : apiData.data) === null || _c === void 0 ? void 0 : _c.error) || 'authentication error';
|
|
226
|
+
let errorKey = 'authFailed';
|
|
227
|
+
if (error) {
|
|
228
|
+
switch (error.reason) {
|
|
229
|
+
case 'user-not-found':
|
|
230
|
+
errorKey = 'userNotFound';
|
|
231
|
+
break;
|
|
232
|
+
case 'invalid-credentials':
|
|
233
|
+
errorKey = 'invalidCredentials';
|
|
234
|
+
break;
|
|
235
|
+
case 'account-disabled':
|
|
236
|
+
errorKey = 'accountDisabled';
|
|
237
|
+
break;
|
|
238
|
+
case 'user-not-active':
|
|
239
|
+
errorKey = 'userNotActive';
|
|
240
|
+
break;
|
|
241
|
+
default:
|
|
242
|
+
errorKey = 'authFailed';
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return {
|
|
246
|
+
status: 'error',
|
|
247
|
+
errorKey: errorKey,
|
|
248
|
+
error: (error === null || error === void 0 ? void 0 : error.reason_extended) || (error === null || error === void 0 ? void 0 : error.reason) || 'Authentication error',
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
catch (apiError) {
|
|
253
|
+
console.error('Error:', apiError);
|
|
254
|
+
return {
|
|
255
|
+
status: 'error',
|
|
256
|
+
errorKey: 'serverError',
|
|
257
|
+
error: 'Server communication error'
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
async createUser(createUserParams) {
|
|
262
|
+
var _a, _b;
|
|
263
|
+
console.log("AuthManager createUser called with params:", Object.assign(Object.assign({}, createUserParams), { password: '***' }));
|
|
264
|
+
const { login, password, websiteid } = createUserParams;
|
|
265
|
+
if (!login || !password || !websiteid) {
|
|
266
|
+
return {
|
|
267
|
+
status: 'error',
|
|
268
|
+
errorKey: 'invalidData',
|
|
269
|
+
error: 'Required fields: login, password and websiteid'
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
try {
|
|
273
|
+
const apiData = await index_1.default.Networking.request(`${this.backendBaseUrl}/auth/create-user`, createUserParams);
|
|
274
|
+
console.log('📡 API Response PARSED JSON:', JSON.stringify(apiData, null, 2));
|
|
275
|
+
if (((_a = apiData === null || apiData === void 0 ? void 0 : apiData.data) === null || _a === void 0 ? void 0 : _a.success) === 1 || ((_b = apiData === null || apiData === void 0 ? void 0 : apiData.data) === null || _b === void 0 ? void 0 : _b.success) === '1') {
|
|
276
|
+
console.log('✅ Cuenta creada exitosamente');
|
|
277
|
+
const response = Object.assign({ status: 'success' }, apiData);
|
|
278
|
+
return response;
|
|
279
|
+
}
|
|
280
|
+
else if ((apiData === null || apiData === void 0 ? void 0 : apiData.code) === 112) {
|
|
281
|
+
console.log('❌ Usuario ya existe');
|
|
282
|
+
const response = {
|
|
283
|
+
status: 'error',
|
|
284
|
+
errorKey: 'userAlreadyExists',
|
|
285
|
+
error: apiData.msg || 'User already exists'
|
|
286
|
+
};
|
|
287
|
+
return response;
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
console.log('❌ La cuenta NO se creó exitosamente');
|
|
291
|
+
console.log('❌ apiData.success value:', apiData.success, 'type:', typeof apiData.success);
|
|
292
|
+
console.log('❌ Full apiData:', JSON.stringify(apiData, null, 2));
|
|
293
|
+
const response = {
|
|
294
|
+
status: 'error',
|
|
295
|
+
errorKey: 'signupFailed',
|
|
296
|
+
error: (apiData === null || apiData === void 0 ? void 0 : apiData.msg) || 'User creation failed'
|
|
297
|
+
};
|
|
298
|
+
return response;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
catch (apiError) {
|
|
302
|
+
console.error('Error:', apiError);
|
|
303
|
+
return {
|
|
304
|
+
status: 'error',
|
|
305
|
+
errorKey: 'serverError',
|
|
306
|
+
error: 'Server communication error'
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
async uploadProfilePhoto(uploadProfilePhotoParams) {
|
|
311
|
+
var _a;
|
|
312
|
+
console.log("AuthManager uploadProfilePhoto called with params:", Object.assign(Object.assign({}, uploadProfilePhotoParams), { password: '***' }));
|
|
313
|
+
const { login, password, websiteid, resource } = uploadProfilePhotoParams;
|
|
314
|
+
if (!login || !websiteid || !resource) {
|
|
315
|
+
return {
|
|
316
|
+
status: 'error',
|
|
317
|
+
errorKey: 'invalidData',
|
|
318
|
+
error: 'Required fields: resource (file), login, and websiteid'
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
const allowedTypes = ['image/jpeg', 'image/jpg', 'image/png', 'image/webp'];
|
|
322
|
+
if (!allowedTypes.includes(resource.type)) {
|
|
323
|
+
return {
|
|
324
|
+
status: 'error',
|
|
325
|
+
errorKey: 'invalidFormat',
|
|
326
|
+
error: 'Invalid file type. Allowed: JPG, JPEG, PNG, WEBP'
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
const maxSize = 5 * 1024 * 1024;
|
|
330
|
+
if (resource.size > maxSize) {
|
|
331
|
+
return {
|
|
332
|
+
status: 'error',
|
|
333
|
+
errorKey: 'fileTooLarge',
|
|
334
|
+
error: 'File too large. Maximum size: 5MB'
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
try {
|
|
338
|
+
const apiFormData = new FormData();
|
|
339
|
+
apiFormData.append('resource', resource);
|
|
340
|
+
apiFormData.append('login', login);
|
|
341
|
+
if (password) {
|
|
342
|
+
apiFormData.append('password', password);
|
|
343
|
+
}
|
|
344
|
+
apiFormData.append('websiteid', websiteid);
|
|
345
|
+
console.log('Uploading profile photo for login:', login);
|
|
346
|
+
console.log('Password provided:', password ? '***' : 'NO');
|
|
347
|
+
console.log('WebsiteID:', websiteid);
|
|
348
|
+
const apiResponse = await fetch(`${this.backendBaseUrl}/auth/upload-profile-photo`, {
|
|
349
|
+
method: 'POST',
|
|
350
|
+
body: apiFormData
|
|
351
|
+
});
|
|
352
|
+
if (!apiResponse.ok) {
|
|
353
|
+
throw new Error(`Error en la API externa: ${apiResponse.status}`);
|
|
354
|
+
}
|
|
355
|
+
let apiData;
|
|
356
|
+
try {
|
|
357
|
+
apiData = await apiResponse.json();
|
|
358
|
+
console.log('📡 API Response PARSED JSON:', JSON.stringify(apiData, null, 2));
|
|
359
|
+
}
|
|
360
|
+
catch (parseError) {
|
|
361
|
+
console.error('❌ Error parsing JSON response:', parseError);
|
|
362
|
+
throw new Error('Invalid JSON response from external API');
|
|
363
|
+
}
|
|
364
|
+
console.log('📡 API Response PARSED JSON:', JSON.stringify(apiData, null, 2));
|
|
365
|
+
if (((_a = apiData === null || apiData === void 0 ? void 0 : apiData.data) === null || _a === void 0 ? void 0 : _a.profile_photo) != null) {
|
|
366
|
+
const profilePhotoUrl = apiData.data.profile_photo;
|
|
367
|
+
const response = {
|
|
368
|
+
status: 'success',
|
|
369
|
+
profile_photo: profilePhotoUrl,
|
|
370
|
+
message: 'Profile photo updated successfully',
|
|
371
|
+
metadata: {
|
|
372
|
+
profile_photo: profilePhotoUrl
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
return response;
|
|
376
|
+
}
|
|
377
|
+
else {
|
|
378
|
+
return {
|
|
379
|
+
status: 'error',
|
|
380
|
+
errorKey: 'uploadFailed',
|
|
381
|
+
error: (apiData === null || apiData === void 0 ? void 0 : apiData.error) || 'Failed to upload profile photo'
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
catch (apiError) {
|
|
386
|
+
console.error('Error:', apiError);
|
|
387
|
+
return {
|
|
388
|
+
status: 'error',
|
|
389
|
+
errorKey: 'serverError',
|
|
390
|
+
error: 'Server communication error'
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
async setUserMetadata(SetUserMetadataParams) {
|
|
395
|
+
var _a, _b;
|
|
396
|
+
console.log("AuthManager setUserMetadata called with params:", Object.assign(Object.assign({}, SetUserMetadataParams), { password: SetUserMetadataParams.password ? '***' : undefined }));
|
|
397
|
+
const { login, password, websiteid } = SetUserMetadataParams, metadata = __rest(SetUserMetadataParams, ["login", "password", "websiteid"]);
|
|
398
|
+
if (!login || !websiteid) {
|
|
399
|
+
return {
|
|
400
|
+
status: 'error',
|
|
401
|
+
errorKey: 'invalidData',
|
|
402
|
+
error: 'Se requieren los campos login y websiteid'
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
try {
|
|
406
|
+
const requestParams = Object.assign({ login,
|
|
407
|
+
websiteid }, metadata);
|
|
408
|
+
if (password) {
|
|
409
|
+
requestParams.password = password;
|
|
410
|
+
}
|
|
411
|
+
const apiData = await index_1.default.Networking.request(`${this.backendBaseUrl}/auth/set-user-metadata`, requestParams);
|
|
412
|
+
console.log('📡 API Response PARSED JSON:', JSON.stringify(apiData, null, 2));
|
|
413
|
+
if (((_a = apiData === null || apiData === void 0 ? void 0 : apiData.data) === null || _a === void 0 ? void 0 : _a.success) === 1 || ((_b = apiData === null || apiData === void 0 ? void 0 : apiData.data) === null || _b === void 0 ? void 0 : _b.success) === '1') {
|
|
414
|
+
return Object.assign({ status: 'success' }, apiData);
|
|
415
|
+
}
|
|
416
|
+
else {
|
|
417
|
+
let errorKey = 'unsubscribeFailed';
|
|
418
|
+
let errorReason = 'Unsubscribe error';
|
|
419
|
+
if (apiData === null || apiData === void 0 ? void 0 : apiData.code) {
|
|
420
|
+
errorKey = apiData.code;
|
|
421
|
+
}
|
|
422
|
+
if (apiData === null || apiData === void 0 ? void 0 : apiData.msg) {
|
|
423
|
+
errorReason = apiData.msg;
|
|
424
|
+
}
|
|
425
|
+
return {
|
|
426
|
+
status: 'error',
|
|
427
|
+
errorKey: errorKey,
|
|
428
|
+
error: errorReason
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
catch (error) {
|
|
433
|
+
console.error('❌ Error in setUserMetadata:', error);
|
|
434
|
+
return {
|
|
435
|
+
status: 'error',
|
|
436
|
+
errorKey: 'serverError',
|
|
437
|
+
error: 'Server communication error'
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
onAuthSuccess(authResult) {
|
|
442
|
+
console.log("✅ User authenticated successfully");
|
|
443
|
+
}
|
|
444
|
+
onAuthFailure(error) {
|
|
445
|
+
console.error("❌ User authentication failed: ", error);
|
|
446
|
+
}
|
|
447
|
+
async unsubscribeUser(unsubscribeParams) {
|
|
448
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
449
|
+
console.log("AuthManager unsubscribeUser called with params:", Object.assign({}, unsubscribeParams));
|
|
450
|
+
const { user_id, callback_url, org } = unsubscribeParams;
|
|
451
|
+
if (!user_id) {
|
|
452
|
+
return {
|
|
453
|
+
status: 'error',
|
|
454
|
+
errorKey: 'invalidData',
|
|
455
|
+
error: 'Required fields: user_id'
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
try {
|
|
459
|
+
const apiData = await index_1.default.Networking.request(`${this.backendBaseUrl}/auth/unsubscribe-user`, unsubscribeParams);
|
|
460
|
+
console.log('🔍 Unsubscribe API Response RAW:', JSON.stringify(apiData, null, 2));
|
|
461
|
+
if (((_a = apiData === null || apiData === void 0 ? void 0 : apiData.data) === null || _a === void 0 ? void 0 : _a.success) === 1 || ((_b = apiData === null || apiData === void 0 ? void 0 : apiData.data) === null || _b === void 0 ? void 0 : _b.success) === '1' || ((_c = apiData === null || apiData === void 0 ? void 0 : apiData.data) === null || _c === void 0 ? void 0 : _c.success) === true) {
|
|
462
|
+
return Object.assign({ status: 'success', data: apiData }, apiData);
|
|
463
|
+
}
|
|
464
|
+
else {
|
|
465
|
+
let errorKey = 'unsubscribeFailed';
|
|
466
|
+
let errorReason = 'Unsubscribe error';
|
|
467
|
+
if ((_e = (_d = apiData === null || apiData === void 0 ? void 0 : apiData.data) === null || _d === void 0 ? void 0 : _d.error) === null || _e === void 0 ? void 0 : _e.id) {
|
|
468
|
+
errorKey = apiData.data.error.id;
|
|
469
|
+
}
|
|
470
|
+
else if ((_g = (_f = apiData === null || apiData === void 0 ? void 0 : apiData.data) === null || _f === void 0 ? void 0 : _f.error) === null || _g === void 0 ? void 0 : _g.code) {
|
|
471
|
+
errorKey = apiData.data.error.code;
|
|
472
|
+
}
|
|
473
|
+
else if (apiData === null || apiData === void 0 ? void 0 : apiData.code) {
|
|
474
|
+
errorKey = apiData.code;
|
|
475
|
+
}
|
|
476
|
+
if ((_j = (_h = apiData === null || apiData === void 0 ? void 0 : apiData.data) === null || _h === void 0 ? void 0 : _h.error) === null || _j === void 0 ? void 0 : _j.reason) {
|
|
477
|
+
errorReason = apiData.data.error.reason;
|
|
478
|
+
}
|
|
479
|
+
else if (apiData === null || apiData === void 0 ? void 0 : apiData.msg) {
|
|
480
|
+
errorReason = apiData.msg;
|
|
481
|
+
}
|
|
482
|
+
return {
|
|
483
|
+
status: 'error',
|
|
484
|
+
errorKey: errorKey,
|
|
485
|
+
error: errorReason
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
catch (apiError) {
|
|
490
|
+
console.error('Error:', apiError);
|
|
491
|
+
return {
|
|
492
|
+
status: 'error',
|
|
493
|
+
errorKey: 'serverError',
|
|
494
|
+
error: 'Server communication error'
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
async changePassword(changePasswordParams) {
|
|
499
|
+
console.log("AuthManager changePassword called with params:", Object.assign(Object.assign({}, changePasswordParams), { new_pass: '***', repeat_new_pass: '***' }));
|
|
500
|
+
const { login, websiteid, new_pass, repeat_new_pass } = changePasswordParams;
|
|
501
|
+
if (!login) {
|
|
502
|
+
return {
|
|
503
|
+
status: 'error',
|
|
504
|
+
errorKey: 'invalidData',
|
|
505
|
+
error: 'Required fields: login'
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
if (!websiteid) {
|
|
509
|
+
return {
|
|
510
|
+
status: 'error',
|
|
511
|
+
errorKey: 'invalidData',
|
|
512
|
+
error: 'Required fields: login'
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
if (!new_pass || new_pass.length < 8) {
|
|
516
|
+
return {
|
|
517
|
+
status: 'error',
|
|
518
|
+
errorKey: 'invalidData',
|
|
519
|
+
error: 'Required fields: new_pass (at least 8 characters)'
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
if (!repeat_new_pass || repeat_new_pass.length < 8) {
|
|
523
|
+
return {
|
|
524
|
+
status: 'error',
|
|
525
|
+
errorKey: 'invalidData',
|
|
526
|
+
error: 'Required fields: repeat_new_pass (at least 8 characters)'
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
try {
|
|
530
|
+
const apiData = await index_1.default.Networking.request(`${this.backendBaseUrl}/auth/change-pass`, changePasswordParams);
|
|
531
|
+
console.log('🔍 Change Password API Response RAW:', JSON.stringify(apiData, null, 2));
|
|
532
|
+
if ((apiData === null || apiData === void 0 ? void 0 : apiData.success) === 1 || (apiData === null || apiData === void 0 ? void 0 : apiData.success) === '1' || (apiData === null || apiData === void 0 ? void 0 : apiData.success) === true) {
|
|
533
|
+
return Object.assign({ status: 'success' }, apiData);
|
|
534
|
+
}
|
|
535
|
+
else {
|
|
536
|
+
let errorKey = 'changePasswordFailed';
|
|
537
|
+
let errorReason = 'Change password error';
|
|
538
|
+
return {
|
|
539
|
+
status: 'error',
|
|
540
|
+
errorKey: errorKey,
|
|
541
|
+
error: errorReason
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
catch (apiError) {
|
|
546
|
+
console.error('Error:', apiError);
|
|
547
|
+
return {
|
|
548
|
+
status: 'error',
|
|
549
|
+
errorKey: 'serverError',
|
|
550
|
+
error: 'Server communication error'
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
async changeCredentials(changeCredentialsParams) {
|
|
555
|
+
console.log("AuthManager changeCredentials called with params:", Object.assign(Object.assign({}, changeCredentialsParams), { password: '***', new_pass: '***', repeat_new_pass: '***' }));
|
|
556
|
+
const { websiteid, login, password, new_login, new_pass, repeat_new_pass } = changeCredentialsParams;
|
|
557
|
+
if (!websiteid) {
|
|
558
|
+
return {
|
|
559
|
+
status: 'error',
|
|
560
|
+
errorKey: 'invalidData',
|
|
561
|
+
error: 'Required fields: websiteid'
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
if (!login) {
|
|
565
|
+
return {
|
|
566
|
+
status: 'error',
|
|
567
|
+
errorKey: 'invalidData',
|
|
568
|
+
error: 'Required fields: login'
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
if (!password) {
|
|
572
|
+
return {
|
|
573
|
+
status: 'error',
|
|
574
|
+
errorKey: 'invalidData',
|
|
575
|
+
error: 'Required fields: password'
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
if (!new_login) {
|
|
579
|
+
return {
|
|
580
|
+
status: 'error',
|
|
581
|
+
errorKey: 'invalidData',
|
|
582
|
+
error: 'Required fields: new_login'
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
if (!new_pass) {
|
|
586
|
+
return {
|
|
587
|
+
status: 'error',
|
|
588
|
+
errorKey: 'invalidData',
|
|
589
|
+
error: 'Required fields: new_pass'
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
if (!repeat_new_pass) {
|
|
593
|
+
return {
|
|
594
|
+
status: 'error',
|
|
595
|
+
errorKey: 'invalidData',
|
|
596
|
+
error: 'Required fields: repeat_new_pass'
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
try {
|
|
600
|
+
const apiData = await index_1.default.Networking.request(`${this.backendBaseUrl}/auth/change-credentials`, changeCredentialsParams);
|
|
601
|
+
console.log('🔍 Change Password API Response RAW:', JSON.stringify(apiData, null, 2));
|
|
602
|
+
if ((apiData === null || apiData === void 0 ? void 0 : apiData.success) === 1 || (apiData === null || apiData === void 0 ? void 0 : apiData.success) === '1' || (apiData === null || apiData === void 0 ? void 0 : apiData.success) === true) {
|
|
603
|
+
return Object.assign({ status: 'success' }, apiData);
|
|
604
|
+
}
|
|
605
|
+
else {
|
|
606
|
+
let errorKey = 'changeCredentialsFailed';
|
|
607
|
+
let errorReason = (apiData === null || apiData === void 0 ? void 0 : apiData.msg) || 'Change credentials error';
|
|
608
|
+
return {
|
|
609
|
+
status: 'error',
|
|
610
|
+
errorKey: errorKey,
|
|
611
|
+
error: errorReason
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
catch (apiError) {
|
|
616
|
+
console.error('Error:', apiError);
|
|
617
|
+
return {
|
|
618
|
+
status: 'error',
|
|
619
|
+
errorKey: 'serverError',
|
|
620
|
+
error: 'Server communication error'
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
hasActiveSession() {
|
|
625
|
+
const token = this.storage.get(config_1.default.storage.tokenKey);
|
|
626
|
+
return !!token;
|
|
627
|
+
}
|
|
628
|
+
isSessionRecent(cfg_sessionid) {
|
|
629
|
+
try {
|
|
630
|
+
if (!cfg_sessionid || cfg_sessionid.length < 14) {
|
|
631
|
+
console.warn('Invalid cfg_sessionid format for date parsing');
|
|
632
|
+
return false;
|
|
633
|
+
}
|
|
634
|
+
const dateStr = cfg_sessionid.substring(0, 14);
|
|
635
|
+
const year = parseInt(dateStr.substring(0, 4));
|
|
636
|
+
const month = parseInt(dateStr.substring(4, 6)) - 1;
|
|
637
|
+
const day = parseInt(dateStr.substring(6, 8));
|
|
638
|
+
const hour = parseInt(dateStr.substring(8, 10));
|
|
639
|
+
const minute = parseInt(dateStr.substring(10, 12));
|
|
640
|
+
const second = parseInt(dateStr.substring(12, 14));
|
|
641
|
+
const sessionDate = new Date(year, month, day, hour, minute, second);
|
|
642
|
+
const now = new Date();
|
|
643
|
+
const diffMs = now.getTime() - sessionDate.getTime();
|
|
644
|
+
const oneHourMs = 60 * 60 * 1000;
|
|
645
|
+
console.log(`Session date: ${sessionDate.toISOString()}, Current: ${now.toISOString()}, Diff: ${diffMs}ms`);
|
|
646
|
+
return diffMs < oneHourMs && diffMs >= 0;
|
|
647
|
+
}
|
|
648
|
+
catch (error) {
|
|
649
|
+
console.error('Error parsing session date:', error);
|
|
650
|
+
return false;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
logout() {
|
|
654
|
+
console.log("Sesión cerrada");
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
exports.AuthManager = AuthManager;
|
|
658
|
+
exports.default = AuthManager;
|
|
659
659
|
//# sourceMappingURL=auth.js.map
|