propro-utils 1.5.97 → 1.5.99
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/package.json
CHANGED
|
@@ -3,19 +3,19 @@
|
|
|
3
3
|
* This module provides functions for setting and clearing authentication cookies.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
const { URL } = require(
|
|
6
|
+
const { URL } = require("url");
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Safely stringify an object, handling circular references
|
|
10
10
|
* @param {Object} obj - The object to stringify
|
|
11
11
|
* @return {string} A JSON string representation of the object
|
|
12
12
|
*/
|
|
13
|
-
const safeStringify = obj => {
|
|
13
|
+
const safeStringify = (obj) => {
|
|
14
14
|
const seen = new WeakSet();
|
|
15
15
|
return JSON.stringify(obj, (key, value) => {
|
|
16
|
-
if (typeof value ===
|
|
16
|
+
if (typeof value === "object" && value !== null) {
|
|
17
17
|
if (seen.has(value)) {
|
|
18
|
-
return
|
|
18
|
+
return "[Circular]";
|
|
19
19
|
}
|
|
20
20
|
seen.add(value);
|
|
21
21
|
}
|
|
@@ -28,7 +28,7 @@ const safeStringify = obj => {
|
|
|
28
28
|
* @param {Object} user - The user object to sanitize
|
|
29
29
|
* @return {Object} A sanitized version of the user object
|
|
30
30
|
*/
|
|
31
|
-
const sanitizeUser = user => {
|
|
31
|
+
const sanitizeUser = (user) => {
|
|
32
32
|
const sanitized = { ...user };
|
|
33
33
|
|
|
34
34
|
delete sanitized.password;
|
|
@@ -61,10 +61,10 @@ const sanitizeUser = user => {
|
|
|
61
61
|
* @param {Object} details - Cookie details
|
|
62
62
|
* @returns {Promise} Promise that resolves when cookie is set
|
|
63
63
|
*/
|
|
64
|
-
const setChromeExtensionCookie = details => {
|
|
64
|
+
const setChromeExtensionCookie = (details) => {
|
|
65
65
|
return new Promise((resolve, reject) => {
|
|
66
66
|
try {
|
|
67
|
-
chrome.cookies.set(details, cookie => {
|
|
67
|
+
chrome.cookies.set(details, (cookie) => {
|
|
68
68
|
if (chrome.runtime.lastError) {
|
|
69
69
|
reject(chrome.runtime.lastError);
|
|
70
70
|
} else {
|
|
@@ -83,13 +83,13 @@ const setChromeExtensionCookie = details => {
|
|
|
83
83
|
*/
|
|
84
84
|
const setAuthCookies = async (res, tokens, account, user, appUrl) => {
|
|
85
85
|
if (!tokens?.refresh?.token || !tokens?.access?.token) {
|
|
86
|
-
throw new Error(
|
|
86
|
+
throw new Error("Invalid tokens object");
|
|
87
87
|
}
|
|
88
88
|
if (!account) {
|
|
89
|
-
throw new Error(
|
|
89
|
+
throw new Error("Invalid account object");
|
|
90
90
|
}
|
|
91
91
|
if (!user) {
|
|
92
|
-
throw new Error(
|
|
92
|
+
throw new Error("Invalid user object");
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
const currentDateTime = new Date();
|
|
@@ -102,34 +102,34 @@ const setAuthCookies = async (res, tokens, account, user, appUrl) => {
|
|
|
102
102
|
let domain;
|
|
103
103
|
try {
|
|
104
104
|
domain = appUrl ? new URL(appUrl).hostname : undefined;
|
|
105
|
-
if (domain?.includes(
|
|
106
|
-
domain =
|
|
105
|
+
if (domain?.includes("mapmap.app")) {
|
|
106
|
+
domain = ".mapmap.app";
|
|
107
107
|
}
|
|
108
|
-
if (domain?.includes(
|
|
108
|
+
if (domain?.includes("localhost")) {
|
|
109
109
|
domain = undefined;
|
|
110
110
|
}
|
|
111
|
-
if (domain?.includes(
|
|
112
|
-
domain =
|
|
111
|
+
if (domain?.includes("propro.so")) {
|
|
112
|
+
domain = ".propro.so";
|
|
113
113
|
}
|
|
114
114
|
} catch (error) {
|
|
115
|
-
console.error(
|
|
115
|
+
console.error("Invalid appUrl:", { error, appUrl });
|
|
116
116
|
domain = undefined;
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
const commonAttributes = {
|
|
120
120
|
secure: true,
|
|
121
|
-
sameSite:
|
|
121
|
+
sameSite: "None",
|
|
122
122
|
domain,
|
|
123
|
-
path:
|
|
123
|
+
path: "/",
|
|
124
124
|
};
|
|
125
125
|
|
|
126
126
|
const httpOnlyCookies = {
|
|
127
|
-
|
|
127
|
+
"x-refresh-token": {
|
|
128
128
|
value: tokens.refresh.token,
|
|
129
129
|
maxAge: refreshMaxAge,
|
|
130
130
|
httpOnly: true,
|
|
131
131
|
},
|
|
132
|
-
|
|
132
|
+
"x-access-token": {
|
|
133
133
|
value: tokens.access.token,
|
|
134
134
|
maxAge: accessMaxAge,
|
|
135
135
|
httpOnly: true,
|
|
@@ -150,7 +150,7 @@ const setAuthCookies = async (res, tokens, account, user, appUrl) => {
|
|
|
150
150
|
maxAge: refreshMaxAge,
|
|
151
151
|
},
|
|
152
152
|
has_account_token: {
|
|
153
|
-
value: JSON.stringify({ value:
|
|
153
|
+
value: JSON.stringify({ value: "true", expires: accessMaxAge }),
|
|
154
154
|
maxAge: accessMaxAge,
|
|
155
155
|
},
|
|
156
156
|
};
|
|
@@ -170,21 +170,21 @@ const setAuthCookies = async (res, tokens, account, user, appUrl) => {
|
|
|
170
170
|
...regularCookies,
|
|
171
171
|
}).map(([name, config]) => {
|
|
172
172
|
return setChromeExtensionCookie({
|
|
173
|
-
url: `https://${domain ||
|
|
173
|
+
url: `https://${domain || "propro.so"}`,
|
|
174
174
|
name,
|
|
175
175
|
value: config.value,
|
|
176
176
|
secure: true,
|
|
177
177
|
httpOnly: !!config.httpOnly,
|
|
178
|
-
sameSite:
|
|
179
|
-
path:
|
|
178
|
+
sameSite: "no_restriction",
|
|
179
|
+
path: "/",
|
|
180
180
|
expirationDate: Math.floor((Date.now() + config.maxAge) / 1000),
|
|
181
|
-
domain: domain?.startsWith(
|
|
181
|
+
domain: domain?.startsWith(".") ? domain : `.${domain || "propro.so"}`,
|
|
182
182
|
});
|
|
183
183
|
});
|
|
184
184
|
|
|
185
185
|
await Promise.allSettled(extensionCookiePromises);
|
|
186
186
|
|
|
187
|
-
console.log(
|
|
187
|
+
console.log("Auth cookies set successfully", {
|
|
188
188
|
domain,
|
|
189
189
|
sameSite: commonAttributes.sameSite,
|
|
190
190
|
cookieNames: [
|
|
@@ -193,11 +193,11 @@ const setAuthCookies = async (res, tokens, account, user, appUrl) => {
|
|
|
193
193
|
],
|
|
194
194
|
});
|
|
195
195
|
} catch (error) {
|
|
196
|
-
console.error(
|
|
196
|
+
console.error("Error setting cookies:", {
|
|
197
197
|
error: error.message,
|
|
198
198
|
stack: error.stack,
|
|
199
199
|
});
|
|
200
|
-
throw new Error(
|
|
200
|
+
throw new Error("Failed to set authentication cookies");
|
|
201
201
|
}
|
|
202
202
|
};
|
|
203
203
|
|
|
@@ -208,44 +208,44 @@ const clearAuthCookies = async (res, appUrl) => {
|
|
|
208
208
|
let domain;
|
|
209
209
|
try {
|
|
210
210
|
domain = appUrl ? new URL(appUrl).hostname : undefined;
|
|
211
|
-
if (domain?.includes(
|
|
212
|
-
domain =
|
|
211
|
+
if (domain?.includes("mapmap.app")) {
|
|
212
|
+
domain = ".mapmap.app";
|
|
213
213
|
}
|
|
214
|
-
if (domain?.includes(
|
|
214
|
+
if (domain?.includes("localhost")) {
|
|
215
215
|
domain = undefined;
|
|
216
216
|
}
|
|
217
217
|
} catch (error) {
|
|
218
|
-
console.error(
|
|
218
|
+
console.error("Invalid appUrl:", error);
|
|
219
219
|
domain = undefined;
|
|
220
220
|
}
|
|
221
221
|
|
|
222
222
|
const commonAttributes = {
|
|
223
223
|
secure: true,
|
|
224
|
-
sameSite:
|
|
224
|
+
sameSite: "None",
|
|
225
225
|
domain,
|
|
226
|
-
path:
|
|
226
|
+
path: "/",
|
|
227
227
|
};
|
|
228
228
|
|
|
229
229
|
const cookieNames = [
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
230
|
+
"x-refresh-token",
|
|
231
|
+
"x-access-token",
|
|
232
|
+
"user",
|
|
233
|
+
"account",
|
|
234
|
+
"has_account_token",
|
|
235
235
|
];
|
|
236
236
|
|
|
237
237
|
// Clear web cookies
|
|
238
|
-
cookieNames.forEach(cookieName => {
|
|
238
|
+
cookieNames.forEach((cookieName) => {
|
|
239
239
|
res.clearCookie(cookieName, commonAttributes);
|
|
240
240
|
});
|
|
241
241
|
|
|
242
242
|
try {
|
|
243
243
|
const extensionClearPromises = cookieNames.map(
|
|
244
|
-
name =>
|
|
245
|
-
new Promise(resolve => {
|
|
244
|
+
(name) =>
|
|
245
|
+
new Promise((resolve) => {
|
|
246
246
|
chrome.cookies.remove(
|
|
247
247
|
{
|
|
248
|
-
url: `https://${domain ||
|
|
248
|
+
url: `https://${domain || "mapmap.app"}`,
|
|
249
249
|
name,
|
|
250
250
|
},
|
|
251
251
|
resolve
|
|
@@ -258,7 +258,7 @@ const clearAuthCookies = async (res, appUrl) => {
|
|
|
258
258
|
// Not in extension context, ignore
|
|
259
259
|
}
|
|
260
260
|
|
|
261
|
-
console.log(
|
|
261
|
+
console.log("Auth cookies cleared successfully", {
|
|
262
262
|
domain,
|
|
263
263
|
cookieNames,
|
|
264
264
|
sameSite: commonAttributes.sameSite,
|