propro-utils 1.7.42 → 1.7.44

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.
@@ -37,18 +37,15 @@ const ServiceManager = require('../utils/serviceManager');
37
37
  const authValidation = (requiredPermissions = []) => {
38
38
  return async (req, res, next) => {
39
39
  try {
40
- console.log("AUTH VALIDATION: 1", req.cookies);
41
40
  const accessToken =
42
41
  req.cookies?.['x-access-token'] ||
43
42
  req.headers.authorization?.split(' ')[1];
44
43
 
45
- console.log("AUTH VALIDATION: 2", accessToken);
46
44
  if (!accessToken) {
47
45
  return res.status(403).json({ error: 'Access token is required' });
48
46
  }
49
47
 
50
48
  const fetchPermission = async () => {
51
- console.log("AUTH VALIDATION: fetchPermission()");
52
49
  const response = await axios.post(
53
50
  `${process.env.AUTH_URL}/api/v1/auth/validateToken`,
54
51
  {
@@ -58,43 +55,32 @@ const authValidation = (requiredPermissions = []) => {
58
55
  );
59
56
  return response.data;
60
57
  };
61
- console.log("AUTH VALIDATION: 3");
62
58
  const redisClient = await ServiceManager.getService('RedisClient');
63
- console.log("AUTH VALIDATION: 4");
64
59
  const cacheKey = `account:permissions:${accessToken}`;
65
- console.log("AUTH VALIDATION: 5");
66
60
  const { accountId, validPermissions } = await getOrSetCache(
67
61
  redisClient,
68
62
  cacheKey,
69
63
  fetchPermission,
70
64
  1800
71
65
  );
72
- console.log("AUTH VALIDATION: 6", validPermissions);
73
66
 
74
67
  if (!validPermissions) {
75
68
  return res.status(403).json({ error: 'Invalid permissions' });
76
69
  }
77
70
 
78
- console.log("AUTH VALIDATION: 7", req.account);
79
-
80
71
  req.account = accountId;
81
72
 
82
73
  let user = null;
83
74
  try {
84
- console.log("AUTH VALIDATION: 8");
85
75
  user = await checkIfUserExists(accountId);
86
- console.log("AUTH VALIDATION: 9", user);
87
76
  if (!user) throw new Error('User not found');
88
77
  } catch (error) {
89
- console.log("AUTH VALIDATION: ERROR 1", error);
90
78
  return res.status(403).json({error: error?.message || 'User not found'});
91
79
  }
92
80
 
93
81
  req.user = user.id;
94
- console.log("AUTH VALIDATION: 10", req.user);
95
82
  next();
96
83
  } catch (error) {
97
- console.log("AUTH VALIDATION: ERROR 2", error);
98
84
  if (error.response && error.response.status) {
99
85
  next(new Error(error.response.data.message));
100
86
  }
@@ -180,7 +180,8 @@ const checkIfUserExists = async accountId => {
180
180
  console.log("ACCOUNT INFO: 1");
181
181
 
182
182
  try {
183
- const schemaResults = await Promise.all([
183
+ /*
184
+ const schemaResults = await Promise.all([
184
185
  ServiceManager.getService("UserSchema"),
185
186
  ServiceManager.getService("UserStyleSchema"),
186
187
  ServiceManager.getService("FolderSchema"),
@@ -192,6 +193,31 @@ const checkIfUserExists = async accountId => {
192
193
  const [userSchema, userStyleSchema, folderSchema, themeSchema] =
193
194
  schemaResults;
194
195
 
196
+ */
197
+ const userSchema = await ServiceManager.getService("UserSchema");
198
+
199
+ console.log("ACCOUNT INFO: 2", userSchema);
200
+
201
+ const userStyleSchema = await ServiceManager.getService("UserStyleSchema");
202
+
203
+ console.log("ACCOUNT INFO: 3", userStyleSchema);
204
+
205
+ const folderSchema = await ServiceManager.getService("FolderSchema");
206
+
207
+ console.log("ACCOUNT INFO: 4", folderSchema);
208
+
209
+ const themeSchema = await ServiceManager.getService("ThemeSchema");
210
+
211
+ console.log("ACCOUNT INFO: 5", themeSchema);
212
+
213
+ const schemaResults = [
214
+ userSchema,
215
+ userStyleSchema,
216
+ folderSchema,
217
+ themeSchema,
218
+ ];
219
+
220
+
195
221
  if (!userSchema) {
196
222
  throw new Error("UserSchema service not available");
197
223
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "propro-utils",
3
- "version": "1.7.42",
3
+ "version": "1.7.44",
4
4
  "description": "Auth middleware for propro-auth",
5
5
  "main": "src/index.js",
6
6
  "private": false,
@@ -31,15 +31,19 @@ class ServiceManager {
31
31
  }
32
32
 
33
33
  getService(name) {
34
+ console.log("GET SERVICE ", {name, service: this.services[name], servicePromise: this.servicePromises[name]});
35
+
34
36
  if (this.services[name]) {
35
37
  return this.services[name];
36
38
  }
37
39
 
38
40
  if (!this.servicePromises[name]) {
39
41
  this.servicePromises[name] = {};
42
+ console.log("GET SERVICE - Promise assignment");
40
43
  this.servicePromises[name].promise = new Promise(resolve => {
41
44
  this.servicePromises[name].resolve = resolve;
42
45
  });
46
+ console.log("GET SERVICE - Promise assignment over", this.servicePromises[name]);
43
47
  }
44
48
 
45
49
  return this.servicePromises[name].promise;