npm-pkg-hook 1.4.5 → 1.4.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/.eslintrc.js CHANGED
@@ -1,38 +1,38 @@
1
- module.exports = {
2
- settings: {
3
- react: {
4
- version: 'detect'
5
- }
6
- },
7
- env: {
8
- browser: true,
9
- es2021: true,
10
- node: true
11
- },
12
- extends: [
13
- 'standard',
14
- 'plugin:react/recommended'
15
- ],
16
- overrides: [
17
- {
18
- env: {
19
- node: true
20
- },
21
- files: [
22
- '.eslintrc.{js,cjs}'
23
- ],
24
- parserOptions: {
25
- sourceType: 'script'
26
- }
27
- }
28
- ],
29
- parserOptions: {
30
- ecmaVersion: 'latest',
31
- sourceType: 'module'
32
- },
33
- plugins: [
34
- 'react'
35
- ],
36
- rules: {
37
- }
38
- }
1
+ module.exports = {
2
+ settings: {
3
+ react: {
4
+ version: 'detect'
5
+ }
6
+ },
7
+ env: {
8
+ browser: true,
9
+ es2021: true,
10
+ node: true
11
+ },
12
+ extends: [
13
+ 'standard',
14
+ 'plugin:react/recommended'
15
+ ],
16
+ overrides: [
17
+ {
18
+ env: {
19
+ node: true
20
+ },
21
+ files: [
22
+ '.eslintrc.{js,cjs}'
23
+ ],
24
+ parserOptions: {
25
+ sourceType: 'script'
26
+ }
27
+ }
28
+ ],
29
+ parserOptions: {
30
+ ecmaVersion: 'latest',
31
+ sourceType: 'module'
32
+ },
33
+ plugins: [
34
+ 'react'
35
+ ],
36
+ rules: {
37
+ }
38
+ }
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.4.5"
46
+ "version": "1.4.7"
47
47
  }
@@ -12,12 +12,15 @@ export * from './useScheduleData'
12
12
  export * from './useOrders'
13
13
  export * from './usePushNotifications'
14
14
  export * from './useLocationManager'
15
+ export * from './useQueryLocationsMap'
16
+ export * from './useGetAllLocationUser'
15
17
  export * from './useFingerprintjs'
16
18
  export * from './useCountries'
17
19
  export * from './useDessertWithPrice'
18
20
  export * from './generateStoreURL'
19
21
  export * from './useCreateStorePendingToRegister'
20
22
  export * from './useDepartments'
23
+ export * from './useSaveLocation'
21
24
  export * from './useRoads'
22
25
  export * from './useCities'
23
26
  export * from './useEditCategory'
@@ -0,0 +1,12 @@
1
+ import { useQuery } from '@apollo/client'
2
+ import { GET_ALL_LOCATIONS } from './queries'
3
+
4
+ /**
5
+ * useGetAllLocationUser
6
+ * @returns {any}
7
+ */
8
+ export const useGetAllLocationUser = () => {
9
+ const { data, loading } = useQuery(GET_ALL_LOCATIONS)
10
+
11
+ return [data, { loading }]
12
+ }
@@ -0,0 +1,44 @@
1
+ import { gql } from '@apollo/client';
2
+
3
+ export const GET_ALL_LOCATIONS = gql`
4
+
5
+ query getUserLocations {
6
+ getUserLocations {
7
+ locationId
8
+ # id
9
+ cId
10
+ dId
11
+ ctId
12
+ uLatitud
13
+ uLongitude
14
+ uLocationKnow
15
+ uPiso
16
+ DatCre
17
+ DatMod
18
+ pais {
19
+ cId
20
+ cName
21
+ cCalCod
22
+ cState
23
+ cDatCre
24
+ cDatMod
25
+ }
26
+ city {
27
+ ctId
28
+ dId
29
+ cName
30
+ cState
31
+ cDatCre
32
+ cDatMod
33
+ }
34
+ department {
35
+ dId
36
+ cId
37
+ dName
38
+ dState
39
+ dDatCre
40
+ dDatMod
41
+ }
42
+ }
43
+ }
44
+ `
@@ -12,33 +12,43 @@ export const useLogout = ({ setAlertBox = () => { } } = {}) => {
12
12
  const onClickLogout = async () => {
13
13
  try {
14
14
  setLoading(true)
15
+
15
16
  // Logout from the server
16
17
  const logoutResponse = await window.fetch(`${process.env.URL_BASE}/api/auth/logout/`, {})
17
- if (!logoutResponse.ok) return
18
- await window
19
- .fetch(`${process.env.URL_BASE}/api/auth/logout/`, {})
20
- .then(res => {
21
- if (res) {
22
- Cookies.remove(process.env.SESSION_NAME)
23
- Cookies.remove(process.env.LOCAL_SALES_STORE)
24
- Cookies.remove('restaurant')
25
- Cookies.remove('usuario')
26
- Cookies.remove('session')
27
- client?.clearStore()
28
- setLoading(false)
29
- console.log('Borrado todo')
30
- }
31
- })
32
- signOutAuth({ redirect: true, callbackUrl: '/' })
33
- .catch(() => {
34
- setError(true)
35
- setAlertBox({ message: 'Ocurrió un error al cerrar session' })
36
- })
18
+
19
+ if (!logoutResponse.ok) {
20
+ setLoading(false)
21
+ // Manejar el caso en que la solicitud no es exitosa, por ejemplo, mostrar un mensaje de error
22
+ return
23
+ }
24
+
25
+ const response = await logoutResponse.json() // Espera la resolución de la promesa de respuesta y obtén los datos JSON
26
+ const { status } = response || {}
27
+ console.log('Intentando borrar cookies...')
28
+ console.log('Cookies antes de borrar:', Cookies.get())
29
+ if (status === 200) {
30
+ if (Cookies.get(process.env.SESSION_NAME)) {
31
+ Cookies.remove(process.env.SESSION_NAME, { path: '/' })
32
+ console.log('Cookie de sesión eliminada')
33
+ }
34
+ Cookies.remove(process.env.LOCAL_SALES_STORE)
35
+ Cookies.remove('restaurant')
36
+ Cookies.remove('usuario')
37
+ Cookies.remove('session')
38
+ client?.clearStore()
39
+ setLoading(false)
40
+ console.log('Borrado todo')
41
+ signOutAuth({ redirect: true, callbackUrl: '/' })
42
+ .catch(() => {
43
+ setError(true)
44
+ setAlertBox({ message: 'Ocurrió un error al cerrar session' })
45
+ })
46
+ }
37
47
  setLoading(false)
38
48
  } catch (error) {
39
49
  setLoading(false)
40
50
  setError(true)
41
- setAlertBox({ message: 'Ocurrió un error al cerrar session' })
51
+ setAlertBox({ message: 'Ocurrió un error al cerrar sesión' })
42
52
  }
43
53
  }
44
54
 
@@ -0,0 +1,19 @@
1
+ import { useLazyQuery } from '@apollo/client'
2
+ import { GET_ONE_COUNTRY, GET_ONE_DEPARTMENT, GET_ONE_CITY } from './queries'
3
+
4
+ const useGetOneCountry = () => {
5
+ const [getOneCountry, { data: dataCountry }] = useLazyQuery(GET_ONE_COUNTRY)
6
+ return { getOneCountry, dataCountry }
7
+ }
8
+
9
+ const useGetOneDepartment = () => {
10
+ const [getOneDepartment, { data: dataDepartment }] = useLazyQuery(GET_ONE_DEPARTMENT)
11
+ return { getOneDepartment, dataDepartment }
12
+ }
13
+
14
+ const useGetOneCity = () => {
15
+ const [getOneCities, { data: dataGetOneCity }] = useLazyQuery(GET_ONE_CITY)
16
+ return { getOneCities, dataGetOneCity }
17
+ }
18
+
19
+ export { useGetOneCountry, useGetOneDepartment, useGetOneCity }
@@ -0,0 +1,40 @@
1
+ import { gql } from '@apollo/client'
2
+
3
+ export const GET_ONE_COUNTRY = gql`
4
+ query getOneCountry($cId: ID){
5
+ getOneCountry(cId: $cId) {
6
+ cId
7
+ cName
8
+ cName
9
+ cDatCre
10
+ cCalCod
11
+ cState
12
+ cDatMod
13
+
14
+ }
15
+ }
16
+ `
17
+ export const GET_ONE_DEPARTMENT = gql`
18
+ query getOneDepartment($dId: ID){
19
+ getOneDepartment(dId: $dId) {
20
+ dId
21
+ cId
22
+ dName
23
+ dState
24
+ dDatCre
25
+ dDatMod
26
+ }
27
+ }
28
+ `
29
+ export const GET_ONE_CITY = gql`
30
+ query getOneCities($ctId: ID){
31
+ getOneCities(ctId: $ctId) {
32
+ ctId
33
+ dId
34
+ cName
35
+ cState
36
+ cDatCre
37
+ cDatMod
38
+ }
39
+ }
40
+ `
@@ -0,0 +1,16 @@
1
+ import { useMutation } from '@apollo/client'
2
+ import { SAVE_LOCATION_USER } from './queries'
3
+
4
+ export const useSaveLocation = () => {
5
+ const [updateUserLocations, { loading, error, data }] =
6
+ useMutation(SAVE_LOCATION_USER)
7
+
8
+ return [
9
+ updateUserLocations,
10
+ {
11
+ loading,
12
+ error,
13
+ data
14
+ }
15
+ ]
16
+ }
@@ -0,0 +1,19 @@
1
+ import { gql } from '@apollo/client'
2
+
3
+ export const SAVE_LOCATION_USER = gql`
4
+ mutation updateUserLocations($input: InputUserLocation) {
5
+ updateUserLocations(input: $input) {
6
+ locationId
7
+ id
8
+ cId
9
+ dId
10
+ ctId
11
+ uLatitud
12
+ uLongitude
13
+ uLocationKnow
14
+ uPiso
15
+ DatCre
16
+ DatMod
17
+ }
18
+ }
19
+ `
@@ -1,27 +1,27 @@
1
- import { Cookies } from '../../cookies';
2
- import { getCurrentDomain } from '../../utils';
1
+ import { Cookies } from '../../cookies'
2
+ import { getCurrentDomain } from '../../utils'
3
3
 
4
4
  export const useSetSession = () => {
5
5
  const handleSession = async (props) => {
6
6
  try {
7
- const { cookies } = props;
8
- let domain = getCurrentDomain();
7
+ const { cookies } = props
8
+ let domain = getCurrentDomain()
9
9
 
10
10
  // Si estás en entorno local, usa 'localhost' como dominio
11
11
  if (domain === 'localhost') {
12
- domain = undefined; // Esto permitirá la cookie en 'localhost'
12
+ domain = undefined // Esto permitirá la cookie en 'localhost'
13
13
  }
14
14
 
15
15
  if (!Array.isArray(cookies)) {
16
- throw new Error('Input cookies should be an array.');
16
+ throw new Error('Input cookies should be an array.')
17
17
  }
18
18
 
19
19
  for (const { name, value, domain: incomingDomain } of cookies) {
20
20
  if (value) {
21
- const expirationTime = new Date();
22
- expirationTime.setTime(expirationTime.getTime() + 8 * 60 * 60 * 1000);
21
+ const expirationTime = new Date()
22
+ expirationTime.setTime(expirationTime.getTime() + 8 * 60 * 60 * 1000)
23
23
 
24
- const formattedDomain = incomingDomain || domain;
24
+ const formattedDomain = incomingDomain || domain
25
25
 
26
26
  await Cookies.set(name, value, {
27
27
  domain: formattedDomain,
@@ -29,17 +29,16 @@ export const useSetSession = () => {
29
29
  secure: process.env.NODE_ENV === 'production',
30
30
  sameSite: process.env.NODE_ENV === 'production' ? 'none' : 'lax',
31
31
  expires: expirationTime
32
- });
33
-
32
+ })
34
33
  }
35
34
  }
36
35
 
37
- console.log('Cookies guardadas correctamente.');
36
+ console.log('Cookies guardadas correctamente.')
38
37
  } catch (error) {
39
- console.error('Error al guardar las cookies:', error);
40
- throw new Error('Error al guardar las cookies.');
38
+ console.error('Error al guardar las cookies:', error)
39
+ throw new Error('Error al guardar las cookies.')
41
40
  }
42
- };
41
+ }
43
42
 
44
- return [handleSession];
45
- };
43
+ return [handleSession]
44
+ }
@@ -4,27 +4,26 @@ import { GET_ONE_STORE, GET_ONE_STORE_BY_ID } from './queries' // Reemplaza con
4
4
  import { errorHandler } from '../../config/client'
5
5
  import { useLogout } from '../useLogout'
6
6
  export const useStore = ({ isClient = false, idStore = '' } = {}) => {
7
-
8
- const client = useApolloClient();
9
- const [onClickLogout, { loading: load }] = useLogout();
7
+ const client = useApolloClient()
8
+ const [onClickLogout, { loading: load }] = useLogout()
10
9
 
11
10
  // Variables para almacenar los datos del store
12
- const [store, setStore] = useState({});
13
- const [loading, setLoading] = useState(false);
14
- const [error, setError] = useState(null);
11
+ const [store, setStore] = useState({})
12
+ const [loading, setLoading] = useState(false)
13
+ const [error, setError] = useState(null)
15
14
 
16
15
  // Intentar leer los datos de la caché
17
- const cachedData = client.readQuery({ query: GET_ONE_STORE });
16
+ const cachedData = client.readQuery({ query: GET_ONE_STORE })
18
17
 
19
18
  useEffect(() => {
20
19
  if (cachedData) {
21
20
  const array = store ? Object.keys(store) : []
22
21
  // Comprobar si los datos de la caché ya están establecidos en el estado
23
- if (!store || Array.isArray(array) && array?.length === 0) {
24
- setStore(cachedData.getStore);
22
+ if ((!store || Array.isArray(array)) && array?.length === 0) {
23
+ setStore(cachedData.getStore)
25
24
  }
26
25
  }
27
- }, [cachedData, store]);
26
+ }, [cachedData, store])
28
27
 
29
28
  if (isClient && !!idStore) {
30
29
  const { data, refetch, loading: loadingClient, error: errorStoreClient } = useQuery(GET_ONE_STORE_BY_ID, {
@@ -32,39 +31,39 @@ export const useStore = ({ isClient = false, idStore = '' } = {}) => {
32
31
  variables: {
33
32
  idStore
34
33
  }
35
- });
34
+ })
36
35
 
37
- const dataOneStoreClient = !loadingClient ? data?.getOneStore : {};
36
+ const dataOneStoreClient = !loadingClient ? data?.getOneStore : {}
38
37
 
39
38
  return [dataOneStoreClient, {
40
39
  refetch,
41
40
  loading: loadingClient,
42
41
  error: errorStoreClient
43
- }];
42
+ }]
44
43
  } else {
45
- const { loading: loadingServer, error: errorServer } = useQuery(GET_ONE_STORE, {
44
+ const { loading: loadingServer } = useQuery(GET_ONE_STORE, {
46
45
  skip: isClient && !idStore,
47
46
  variables: {
48
47
  idStore
49
48
  },
50
49
  fetchPolicy: 'cache-first',
51
50
  onCompleted: (data) => {
52
- const { getStore } = data || {};
53
- setStore(getStore);
54
- setLoading(false);
51
+ const { getStore } = data || {}
52
+ setStore(getStore)
53
+ setLoading(false)
55
54
  },
56
55
  onError: (err) => {
57
56
  if (err.networkError && err.networkError.result) {
58
- const response = errorHandler(err.networkError.result);
57
+ const response = errorHandler(err.networkError.result)
59
58
  if (response) {
60
- onClickLogout();
59
+ onClickLogout()
61
60
  }
62
61
  }
63
- setError(err);
64
- setLoading(false);
62
+ setError(err)
63
+ setLoading(false)
65
64
  }
66
- });
65
+ })
67
66
 
68
- return [store, { loading: load || loadingServer || loading, error }];
67
+ return [store, { loading: load || loadingServer || loading, error }]
69
68
  }
70
- };
69
+ }