npm-pkg-hook 1.3.4 → 1.3.5

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
@@ -43,5 +43,5 @@
43
43
  "rm": "rm -rf node_modules package-lock.json && npm i",
44
44
  "test": "echo \"Error: no test specified\" && exit 1"
45
45
  },
46
- "version": "1.3.4"
46
+ "version": "1.3.5"
47
47
  }
@@ -14,28 +14,36 @@ const ENCRYPTION_KEY = generateEncryptionKey(
14
14
  const IV_LENGTH = 16 // Para AES, este siempre debe ser 16
15
15
 
16
16
  export const encryptSession = (text) => {
17
- const iv = crypto.randomBytes(IV_LENGTH)
18
- const cipher = crypto.createCipheriv(
19
- 'aes-256-cbc',
20
- Buffer.from(ENCRYPTION_KEY),
21
- iv
22
- )
23
- let encrypted = cipher.update(text)
24
- encrypted = Buffer.concat([encrypted, cipher.final()])
25
- return iv.toString('hex') + ':' + encrypted.toString('hex')
17
+ try {
18
+ const iv = crypto.randomBytes(IV_LENGTH)
19
+ const cipher = crypto.createCipheriv(
20
+ 'aes-256-cbc',
21
+ Buffer.from(ENCRYPTION_KEY),
22
+ iv
23
+ )
24
+ let encrypted = cipher.update(text)
25
+ encrypted = Buffer.concat([encrypted, cipher.final()])
26
+ return iv.toString('hex') + ':' + encrypted.toString('hex')
27
+ } catch (error) {
28
+ return null
29
+ }
26
30
  }
27
31
 
28
32
  export const decryptSession = (text) => {
29
- if (!text) return
30
- const textParts = text.split(':')
31
- const iv = Buffer.from(textParts.shift(), 'hex')
32
- const encryptedText = Buffer.from(textParts.join(':'), 'hex')
33
- const decipher = crypto.createDecipheriv(
34
- 'aes-256-cbc',
35
- Buffer.from(ENCRYPTION_KEY),
36
- iv
37
- )
38
- let decrypted = decipher.update(encryptedText)
39
- decrypted = Buffer.concat([decrypted, decipher.final()])
40
- return decrypted.toString()
33
+ try {
34
+ if (!text) return
35
+ const textParts = text.split(':')
36
+ const iv = Buffer.from(textParts.shift(), 'hex')
37
+ const encryptedText = Buffer.from(textParts.join(':'), 'hex')
38
+ const decipher = crypto.createDecipheriv(
39
+ 'aes-256-cbc',
40
+ Buffer.from(ENCRYPTION_KEY),
41
+ iv
42
+ )
43
+ let decrypted = decipher.update(encryptedText)
44
+ decrypted = Buffer.concat([decrypted, decipher.final()])
45
+ return decrypted.toString()
46
+ } catch (error) {
47
+ return null
48
+ }
41
49
  }
@@ -6,7 +6,7 @@ export const useGetStoreCookie = () => {
6
6
 
7
7
  useEffect(() => {
8
8
  const getCookieValue = () => {
9
- const cookieValue = Cookies.get('vp.store');
9
+ const cookieValue = Cookies.get(process.env.SESSION_NAME);
10
10
  console.log('Cookie Value:', cookieValue);
11
11
 
12
12
  if (cookieValue) {
@@ -24,7 +24,7 @@ export const useLogout = ({ setAlertBox = () => { } } = {}) => {
24
24
  localStorage.removeItem('latitude')
25
25
  localStorage.removeItem('userlogin')
26
26
  localStorage.removeItem('restaurant')
27
- Cookies.remove('vp.store')
27
+ Cookies.remove(process.env.SESSION_NAME)
28
28
  Cookies.remove('app.cart.sales')
29
29
  Cookies.remove('restaurant')
30
30
  client?.clearStore()
@@ -2,26 +2,35 @@ import { Cookies } from '../../cookies';
2
2
  import { getCurrentDomain } from '../../utils';
3
3
 
4
4
  export const useSetSession = () => {
5
- const domain = getCurrentDomain()
6
-
7
5
  const handleSession = async (props) => {
8
6
  try {
9
- const { cookie } = props;
10
- if (!Array.isArray(cookie)) {
7
+ const { cookies } = props;
8
+ let domain = getCurrentDomain();
9
+
10
+ // Si estás en entorno local, usa 'localhost' como dominio
11
+ if (domain === 'localhost') {
12
+ domain = undefined; // Esto permitirá la cookie en 'localhost'
13
+ }
14
+
15
+ if (!Array.isArray(cookies)) {
11
16
  throw new Error('Input cookies should be an array.');
12
17
  }
13
18
 
14
- for (const { name, value } of cookie) {
19
+ for (const { name, value, domain: incomingDomain } of cookies) {
15
20
  if (value) {
16
21
  const expirationTime = new Date();
17
- expirationTime.setTime(expirationTime.getTime() + 8 * 60 * 60 * 1000)
22
+ expirationTime.setTime(expirationTime.getTime() + 8 * 60 * 60 * 1000);
23
+
24
+ const formattedDomain = incomingDomain || domain;
25
+
18
26
  await Cookies.set(name, value, {
19
- domain,
27
+ domain: formattedDomain,
20
28
  path: '/',
21
- secure: process.env.NODE_ENV === 'production',
22
- sameSite: process.env.NODE_ENV === 'production' ? 'none' : 'lax', // Configura 'none' en producción
29
+ secure: process.env.NODE_ENV === 'production',
30
+ sameSite: process.env.NODE_ENV === 'production' ? 'none' : 'lax',
23
31
  expires: expirationTime
24
32
  });
33
+
25
34
  }
26
35
  }
27
36