webs-sdk 0.10.1 → 0.10.2
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/andromeda.js +192 -192
- package/dist/libraries/auth.js +512 -512
- package/dist/libraries/content.js +24 -24
- package/dist/libraries/user.d.ts +1 -0
- package/dist/libraries/user.d.ts.map +1 -1
- package/dist/libraries/user.js +24 -0
- package/dist/libraries/user.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,193 +1,193 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Andromeda = void 0;
|
|
7
|
-
const index_1 = __importDefault(require("../index"));
|
|
8
|
-
const config_1 = __importDefault(require("../config"));
|
|
9
|
-
class Andromeda {
|
|
10
|
-
constructor() {
|
|
11
|
-
this.backendBaseUrl = config_1.default.backendBaseUrl;
|
|
12
|
-
this.init();
|
|
13
|
-
}
|
|
14
|
-
async init() {
|
|
15
|
-
console.debug("Andromeda init");
|
|
16
|
-
}
|
|
17
|
-
async getWebsiteMetadatabyHostname(hostname, existingCookie) {
|
|
18
|
-
var _a;
|
|
19
|
-
console.debug("Andromeda getWebsiteMetadatabyHostname called with hostname:", hostname);
|
|
20
|
-
if (existingCookie) {
|
|
21
|
-
try {
|
|
22
|
-
const websiteDataFromCookie = JSON.parse(decodeURIComponent(existingCookie));
|
|
23
|
-
console.log('🎯 WebsiteData leído desde cookie existente:', websiteDataFromCookie === null || websiteDataFromCookie === void 0 ? void 0 : websiteDataFromCookie.web_id);
|
|
24
|
-
if ((websiteDataFromCookie === null || websiteDataFromCookie === void 0 ? void 0 : websiteDataFromCookie.hostname) === hostname) {
|
|
25
|
-
return {
|
|
26
|
-
status: 'success',
|
|
27
|
-
websiteData: websiteDataFromCookie,
|
|
28
|
-
cookies: []
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
console.log('⚠️ Hostname mismatch en websiteDataFlag cookie [', websiteDataFromCookie === null || websiteDataFromCookie === void 0 ? void 0 : websiteDataFromCookie.hostname, ' vs ', hostname, '], obteniendo nuevo websiteData desde WebSDK');
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
catch (error) {
|
|
36
|
-
console.error('❌ Error parsing websiteData desde cookie:', error);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
console.log('🔄 Cookie websiteDataFlag no existe, obteniendo websiteData desde backend');
|
|
40
|
-
const websiteDataResult = await this._fetchWebsiteMetadatabyHostname(hostname);
|
|
41
|
-
if (!websiteDataResult) {
|
|
42
|
-
return {
|
|
43
|
-
status: 'error',
|
|
44
|
-
errorKey: 'server-error',
|
|
45
|
-
error: 'No response from backend'
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
const cookies = [];
|
|
49
|
-
if (websiteDataResult.status === 'success' && ((_a = websiteDataResult.data) === null || _a === void 0 ? void 0 : _a.web_id)) {
|
|
50
|
-
const websiteData = websiteDataResult.data;
|
|
51
|
-
websiteData.hostname = hostname;
|
|
52
|
-
console.log('✅ WebsiteData obtenido desde backend, creando cookie');
|
|
53
|
-
cookies.push({
|
|
54
|
-
name: 'websiteDataFlag',
|
|
55
|
-
value: JSON.stringify(websiteData),
|
|
56
|
-
options: {
|
|
57
|
-
path: '/',
|
|
58
|
-
maxAge: 60 * 60,
|
|
59
|
-
sameSite: 'lax',
|
|
60
|
-
secure: process.env.NODE_ENV === 'production',
|
|
61
|
-
httpOnly: false
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
return {
|
|
65
|
-
status: 'success',
|
|
66
|
-
websiteData: websiteData,
|
|
67
|
-
cookies: cookies
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
console.log('❌ No se pudo obtener websiteData válido desde backend');
|
|
72
|
-
if (existingCookie) {
|
|
73
|
-
console.log('🗑️ Limpiando cookie websiteDataFlag existente');
|
|
74
|
-
cookies.push({
|
|
75
|
-
name: 'websiteDataFlag',
|
|
76
|
-
value: '',
|
|
77
|
-
options: {
|
|
78
|
-
path: '/',
|
|
79
|
-
maxAge: 0,
|
|
80
|
-
sameSite: 'lax',
|
|
81
|
-
secure: false,
|
|
82
|
-
httpOnly: false,
|
|
83
|
-
expires: new Date(0)
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
return {
|
|
88
|
-
status: 'error',
|
|
89
|
-
errorKey: websiteDataResult.errorKey,
|
|
90
|
-
error: websiteDataResult.error,
|
|
91
|
-
cookies: cookies
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
async _fetchWebsiteMetadatabyHostname(hostname) {
|
|
96
|
-
var _a, _b, _c, _d, _e;
|
|
97
|
-
console.debug("Andromeda _fetchWebsiteMetadatabyHostname called with hostname:", hostname);
|
|
98
|
-
if (!hostname) {
|
|
99
|
-
console.warn("hostname es requerido");
|
|
100
|
-
return {
|
|
101
|
-
status: 'error',
|
|
102
|
-
errorKey: 'invalidData',
|
|
103
|
-
error: 'Required fields: hostname'
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
try {
|
|
107
|
-
const formData = new URLSearchParams();
|
|
108
|
-
formData.append('hostname', hostname);
|
|
109
|
-
console.log("baseurl: ", this.backendBaseUrl);
|
|
110
|
-
const result = await index_1.default.Networking.request(`${this.backendBaseUrl}/auth/get-website-metadata-by-hostname`, { hostname });
|
|
111
|
-
console.log("_fetchWebsiteMetadatabyHostname response:", JSON.stringify(result, null, 2));
|
|
112
|
-
if (!((_a = result.data) === null || _a === void 0 ? void 0 : _a.web_id)) {
|
|
113
|
-
if (((_c = (_b = result.data) === null || _b === void 0 ? void 0 : _b.error) === null || _c === void 0 ? void 0 : _c.code) && ((_e = (_d = result.data) === null || _d === void 0 ? void 0 : _d.error) === null || _e === void 0 ? void 0 : _e.desc)) {
|
|
114
|
-
return {
|
|
115
|
-
status: 'error',
|
|
116
|
-
errorKey: result.data.error.code,
|
|
117
|
-
error: result.data.error.desc
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
return {
|
|
121
|
-
status: 'error',
|
|
122
|
-
errorKey: 'no-website-data',
|
|
123
|
-
error: 'No website data found in server response'
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
return {
|
|
127
|
-
status: 'success',
|
|
128
|
-
data: result.data
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
catch (error) {
|
|
132
|
-
return {
|
|
133
|
-
status: 'error',
|
|
134
|
-
errorKey: 'server-error',
|
|
135
|
-
error: "Server communication error"
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
async getWebsiteConfig(webId, merchantId) {
|
|
140
|
-
var _a, _b, _c, _d, _e, _f;
|
|
141
|
-
console.debug("Andromeda getWebsiteConfig called with webId:", webId, "and merchantId:", merchantId);
|
|
142
|
-
if (!webId) {
|
|
143
|
-
console.warn("webId es requerido");
|
|
144
|
-
return {
|
|
145
|
-
status: 'error',
|
|
146
|
-
errorKey: 'invalidData',
|
|
147
|
-
error: 'Required fields: webId'
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
try {
|
|
151
|
-
const apiData = await index_1.default.Networking.request(`${this.backendBaseUrl}/config/get`, { web_id: webId, merchant_id: merchantId });
|
|
152
|
-
console.log("getWebsiteConfig response:", JSON.stringify(apiData, null, 2));
|
|
153
|
-
if (!apiData.data) {
|
|
154
|
-
let errorKey = 'no-website-config';
|
|
155
|
-
let errorReason = 'No website config found in server response';
|
|
156
|
-
if ((_b = (_a = apiData === null || apiData === void 0 ? void 0 : apiData.data) === null || _a === void 0 ? void 0 : _a.error) === null || _b === void 0 ? void 0 : _b.id) {
|
|
157
|
-
errorKey = apiData.data.error.id;
|
|
158
|
-
}
|
|
159
|
-
else if ((_d = (_c = apiData === null || apiData === void 0 ? void 0 : apiData.data) === null || _c === void 0 ? void 0 : _c.error) === null || _d === void 0 ? void 0 : _d.code) {
|
|
160
|
-
errorKey = apiData.data.error.code;
|
|
161
|
-
}
|
|
162
|
-
else if (apiData === null || apiData === void 0 ? void 0 : apiData.code) {
|
|
163
|
-
errorKey = apiData.code;
|
|
164
|
-
}
|
|
165
|
-
if ((_f = (_e = apiData === null || apiData === void 0 ? void 0 : apiData.data) === null || _e === void 0 ? void 0 : _e.error) === null || _f === void 0 ? void 0 : _f.reason) {
|
|
166
|
-
errorReason = apiData.data.error.reason;
|
|
167
|
-
}
|
|
168
|
-
else if (apiData === null || apiData === void 0 ? void 0 : apiData.msg) {
|
|
169
|
-
errorReason = apiData.msg;
|
|
170
|
-
}
|
|
171
|
-
return {
|
|
172
|
-
status: 'error',
|
|
173
|
-
errorKey: errorKey,
|
|
174
|
-
error: errorReason
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
return {
|
|
178
|
-
status: 'success',
|
|
179
|
-
data: apiData.data
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
catch (error) {
|
|
183
|
-
return {
|
|
184
|
-
status: 'error',
|
|
185
|
-
errorKey: 'server-error',
|
|
186
|
-
error: "Server communication error"
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
exports.Andromeda = Andromeda;
|
|
192
|
-
exports.default = Andromeda;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Andromeda = void 0;
|
|
7
|
+
const index_1 = __importDefault(require("../index"));
|
|
8
|
+
const config_1 = __importDefault(require("../config"));
|
|
9
|
+
class Andromeda {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.backendBaseUrl = config_1.default.backendBaseUrl;
|
|
12
|
+
this.init();
|
|
13
|
+
}
|
|
14
|
+
async init() {
|
|
15
|
+
console.debug("Andromeda init");
|
|
16
|
+
}
|
|
17
|
+
async getWebsiteMetadatabyHostname(hostname, existingCookie) {
|
|
18
|
+
var _a;
|
|
19
|
+
console.debug("Andromeda getWebsiteMetadatabyHostname called with hostname:", hostname);
|
|
20
|
+
if (existingCookie) {
|
|
21
|
+
try {
|
|
22
|
+
const websiteDataFromCookie = JSON.parse(decodeURIComponent(existingCookie));
|
|
23
|
+
console.log('🎯 WebsiteData leído desde cookie existente:', websiteDataFromCookie === null || websiteDataFromCookie === void 0 ? void 0 : websiteDataFromCookie.web_id);
|
|
24
|
+
if ((websiteDataFromCookie === null || websiteDataFromCookie === void 0 ? void 0 : websiteDataFromCookie.hostname) === hostname) {
|
|
25
|
+
return {
|
|
26
|
+
status: 'success',
|
|
27
|
+
websiteData: websiteDataFromCookie,
|
|
28
|
+
cookies: []
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
console.log('⚠️ Hostname mismatch en websiteDataFlag cookie [', websiteDataFromCookie === null || websiteDataFromCookie === void 0 ? void 0 : websiteDataFromCookie.hostname, ' vs ', hostname, '], obteniendo nuevo websiteData desde WebSDK');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
console.error('❌ Error parsing websiteData desde cookie:', error);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
console.log('🔄 Cookie websiteDataFlag no existe, obteniendo websiteData desde backend');
|
|
40
|
+
const websiteDataResult = await this._fetchWebsiteMetadatabyHostname(hostname);
|
|
41
|
+
if (!websiteDataResult) {
|
|
42
|
+
return {
|
|
43
|
+
status: 'error',
|
|
44
|
+
errorKey: 'server-error',
|
|
45
|
+
error: 'No response from backend'
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const cookies = [];
|
|
49
|
+
if (websiteDataResult.status === 'success' && ((_a = websiteDataResult.data) === null || _a === void 0 ? void 0 : _a.web_id)) {
|
|
50
|
+
const websiteData = websiteDataResult.data;
|
|
51
|
+
websiteData.hostname = hostname;
|
|
52
|
+
console.log('✅ WebsiteData obtenido desde backend, creando cookie');
|
|
53
|
+
cookies.push({
|
|
54
|
+
name: 'websiteDataFlag',
|
|
55
|
+
value: JSON.stringify(websiteData),
|
|
56
|
+
options: {
|
|
57
|
+
path: '/',
|
|
58
|
+
maxAge: 60 * 60,
|
|
59
|
+
sameSite: 'lax',
|
|
60
|
+
secure: process.env.NODE_ENV === 'production',
|
|
61
|
+
httpOnly: false
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
return {
|
|
65
|
+
status: 'success',
|
|
66
|
+
websiteData: websiteData,
|
|
67
|
+
cookies: cookies
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
console.log('❌ No se pudo obtener websiteData válido desde backend');
|
|
72
|
+
if (existingCookie) {
|
|
73
|
+
console.log('🗑️ Limpiando cookie websiteDataFlag existente');
|
|
74
|
+
cookies.push({
|
|
75
|
+
name: 'websiteDataFlag',
|
|
76
|
+
value: '',
|
|
77
|
+
options: {
|
|
78
|
+
path: '/',
|
|
79
|
+
maxAge: 0,
|
|
80
|
+
sameSite: 'lax',
|
|
81
|
+
secure: false,
|
|
82
|
+
httpOnly: false,
|
|
83
|
+
expires: new Date(0)
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
status: 'error',
|
|
89
|
+
errorKey: websiteDataResult.errorKey,
|
|
90
|
+
error: websiteDataResult.error,
|
|
91
|
+
cookies: cookies
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async _fetchWebsiteMetadatabyHostname(hostname) {
|
|
96
|
+
var _a, _b, _c, _d, _e;
|
|
97
|
+
console.debug("Andromeda _fetchWebsiteMetadatabyHostname called with hostname:", hostname);
|
|
98
|
+
if (!hostname) {
|
|
99
|
+
console.warn("hostname es requerido");
|
|
100
|
+
return {
|
|
101
|
+
status: 'error',
|
|
102
|
+
errorKey: 'invalidData',
|
|
103
|
+
error: 'Required fields: hostname'
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
try {
|
|
107
|
+
const formData = new URLSearchParams();
|
|
108
|
+
formData.append('hostname', hostname);
|
|
109
|
+
console.log("baseurl: ", this.backendBaseUrl);
|
|
110
|
+
const result = await index_1.default.Networking.request(`${this.backendBaseUrl}/auth/get-website-metadata-by-hostname`, { hostname });
|
|
111
|
+
console.log("_fetchWebsiteMetadatabyHostname response:", JSON.stringify(result, null, 2));
|
|
112
|
+
if (!((_a = result.data) === null || _a === void 0 ? void 0 : _a.web_id)) {
|
|
113
|
+
if (((_c = (_b = result.data) === null || _b === void 0 ? void 0 : _b.error) === null || _c === void 0 ? void 0 : _c.code) && ((_e = (_d = result.data) === null || _d === void 0 ? void 0 : _d.error) === null || _e === void 0 ? void 0 : _e.desc)) {
|
|
114
|
+
return {
|
|
115
|
+
status: 'error',
|
|
116
|
+
errorKey: result.data.error.code,
|
|
117
|
+
error: result.data.error.desc
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
status: 'error',
|
|
122
|
+
errorKey: 'no-website-data',
|
|
123
|
+
error: 'No website data found in server response'
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
status: 'success',
|
|
128
|
+
data: result.data
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
return {
|
|
133
|
+
status: 'error',
|
|
134
|
+
errorKey: 'server-error',
|
|
135
|
+
error: "Server communication error"
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
async getWebsiteConfig(webId, merchantId) {
|
|
140
|
+
var _a, _b, _c, _d, _e, _f;
|
|
141
|
+
console.debug("Andromeda getWebsiteConfig called with webId:", webId, "and merchantId:", merchantId);
|
|
142
|
+
if (!webId) {
|
|
143
|
+
console.warn("webId es requerido");
|
|
144
|
+
return {
|
|
145
|
+
status: 'error',
|
|
146
|
+
errorKey: 'invalidData',
|
|
147
|
+
error: 'Required fields: webId'
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
try {
|
|
151
|
+
const apiData = await index_1.default.Networking.request(`${this.backendBaseUrl}/config/get`, { web_id: webId, merchant_id: merchantId });
|
|
152
|
+
console.log("getWebsiteConfig response:", JSON.stringify(apiData, null, 2));
|
|
153
|
+
if (!apiData.data) {
|
|
154
|
+
let errorKey = 'no-website-config';
|
|
155
|
+
let errorReason = 'No website config found in server response';
|
|
156
|
+
if ((_b = (_a = apiData === null || apiData === void 0 ? void 0 : apiData.data) === null || _a === void 0 ? void 0 : _a.error) === null || _b === void 0 ? void 0 : _b.id) {
|
|
157
|
+
errorKey = apiData.data.error.id;
|
|
158
|
+
}
|
|
159
|
+
else if ((_d = (_c = apiData === null || apiData === void 0 ? void 0 : apiData.data) === null || _c === void 0 ? void 0 : _c.error) === null || _d === void 0 ? void 0 : _d.code) {
|
|
160
|
+
errorKey = apiData.data.error.code;
|
|
161
|
+
}
|
|
162
|
+
else if (apiData === null || apiData === void 0 ? void 0 : apiData.code) {
|
|
163
|
+
errorKey = apiData.code;
|
|
164
|
+
}
|
|
165
|
+
if ((_f = (_e = apiData === null || apiData === void 0 ? void 0 : apiData.data) === null || _e === void 0 ? void 0 : _e.error) === null || _f === void 0 ? void 0 : _f.reason) {
|
|
166
|
+
errorReason = apiData.data.error.reason;
|
|
167
|
+
}
|
|
168
|
+
else if (apiData === null || apiData === void 0 ? void 0 : apiData.msg) {
|
|
169
|
+
errorReason = apiData.msg;
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
status: 'error',
|
|
173
|
+
errorKey: errorKey,
|
|
174
|
+
error: errorReason
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
status: 'success',
|
|
179
|
+
data: apiData.data
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
return {
|
|
184
|
+
status: 'error',
|
|
185
|
+
errorKey: 'server-error',
|
|
186
|
+
error: "Server communication error"
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
exports.Andromeda = Andromeda;
|
|
192
|
+
exports.default = Andromeda;
|
|
193
193
|
//# sourceMappingURL=andromeda.js.map
|