npm-pkg-hook 1.4.8 → 1.5.0

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
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "recommendations": [
3
+ "github.copilot",
4
+ "github.copilot-nightly"
5
+ ]
6
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "cSpell.words": [
3
+ "Anauthorized",
4
+ "deepmerge",
5
+ "Eliminado",
6
+ "Pedido"
7
+ ]
8
+ }
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.8"
46
+ "version": "1.5.0"
47
47
  }
@@ -59,4 +59,4 @@ export const getCategoriesWithProduct = (
59
59
  }).filter(Boolean)
60
60
 
61
61
  return findProduct
62
- }
62
+ }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Get the start timestamp for the current day.
3
+ * @returns {string} The start timestamp for the current day.
4
+ */
5
+ export const getStartOfDayTimestamp = () => {
6
+ const start = new Date()
7
+ start.setHours(0, 0, 0, 0)
8
+ return start.toISOString()
9
+ }
10
+
11
+ /**
12
+ * Get the end timestamp for the current day.
13
+ * @returns {string} The end timestamp for the current day.
14
+ */
15
+ export const getEndOfDayTimestamp = () => {
16
+ const end = new Date()
17
+ end.setHours(23, 59, 59, 999)
18
+ return end.toISOString()
19
+ }
20
+
21
+ /**
22
+ * Get start and end timestamps for the current day.
23
+ * @returns {Object} An object containing start and end timestamps.
24
+ */
25
+ export const getTodayTimestamps = () => {
26
+ return {
27
+ startTimestamp: getStartOfDayTimestamp(),
28
+ endTimestamp: getEndOfDayTimestamp()
29
+ }
30
+ }
31
+
32
+ /**
33
+ * Get start timestamp for a specific number of days ago.
34
+ * @param {number} daysAgo - The number of days ago.
35
+ * @returns {string} The start timestamp for the specified number of days ago.
36
+ */
37
+ export const getStartTimestampDaysAgo = (daysAgo) => {
38
+ if (isNaN(daysAgo) || daysAgo < 0) {
39
+ throw new Error('Invalid input. Provide a valid number of days.')
40
+ }
41
+
42
+ const start = new Date()
43
+ start.setDate(start.getDate() - daysAgo)
44
+ start.setHours(0, 0, 0, 0)
45
+
46
+ return start.toISOString()
47
+ }
48
+
49
+ export function convertDateFormat ({ dateString, start }) {
50
+ const parsedDate = new Date(dateString)
51
+ const year = parsedDate.getFullYear()
52
+ const month = `0${parsedDate.getMonth() + 1}`.slice(-2)
53
+ const day = `0${parsedDate.getDate()}`.slice(-2)
54
+
55
+ if (start) {
56
+ // Inicio del día (00:00:00)
57
+ return `${year}-${month}-${day}T00:00:00.000Z`
58
+ } else {
59
+ // Final del día (23:59:59.999)
60
+ const endOfDay = new Date(parsedDate)
61
+ endOfDay.setHours(23, 59, 59, 999)
62
+ return endOfDay.toISOString()
63
+ }
64
+ }
@@ -46,6 +46,7 @@ export * from './useDrag'
46
46
  export * from './useEvent'
47
47
  export * from './useFetchJson'
48
48
  export * from './useFormatDate'
49
+ export * from './getTodayTimestamps'
49
50
  export * from './useFormatNumberPhone'
50
51
  export * from './useFormTools/index'
51
52
  export * from './useHover'
@@ -7,4 +7,4 @@ mutation deleteOneItem($cState: Int, $ShoppingCard: ID) {
7
7
  message
8
8
  }
9
9
  }
10
- `
10
+ `
@@ -1,2 +1,2 @@
1
1
  export * from './useCart'
2
- export * from './useGetCart'
2
+ export * from './useGetCart'
@@ -2,7 +2,7 @@ import { filterKeyObject } from '../../../../utils'
2
2
 
3
3
  const filters = ['__typename']
4
4
 
5
- export const filterDataOptional = (dataOptional) => {
5
+ export const filterDataOptional = (dataOptional) => {
6
6
  if (!Array.isArray(dataOptional)) {
7
7
  throw new Error('Input data is not an array')
8
8
  }
@@ -72,4 +72,4 @@ export const filterExtra = (dataExtra) => {
72
72
  } catch (error) {
73
73
  return []
74
74
  }
75
- }
75
+ }
@@ -52,4 +52,4 @@ query getCatProductsWithProductClient($search: String, $min: Int, $max: Int, $ge
52
52
 
53
53
  }
54
54
  }
55
- `
55
+ `
@@ -75,4 +75,4 @@ getOneCatStore(catStore: $catStore){
75
75
  }
76
76
  }
77
77
  }
78
- `
78
+ `
@@ -11,30 +11,29 @@ export const useChartData = ({ year }) => {
11
11
  const [asFilter, setFilter] = useState(false)
12
12
  const [newResult, setNewResult] = useState([])
13
13
  const result = []
14
- data?.getAllSalesStore?.length > 0 && data?.getAllSalesStore.reduce(function (res, value) {
15
- // Creamos la posición del array para cada mes
16
- const mes = new Date(value.pDatCre).getMonth()
17
- const Year = new Date(value.pDatCre).getFullYear()
18
- if (!res[mes]) {
19
- res[mes] = { Mes: mes, Year }
20
- // Inicializamos a 0 el valor de cada key
21
- Object.keys(value).forEach((key) => {
22
- if (key !== 'pDatCre') {
23
- res[mes][key] = 0
24
- }
25
- })
14
+ const sumByMonth = {}
26
15
 
27
- result.push(res[mes])
28
- }
29
- // Sumamos el valor de cada clave dentro de un bucle
30
- Object.keys(value).forEach(function (key) {
31
- if (key !== 'pDatCre') {
32
- res[mes].totalProductsPrice += value.totalProductsPrice
16
+ data?.getAllSalesStore?.forEach(function (value) {
17
+ const month = new Date(value.pDatCre).getMonth()
18
+ const year = new Date(value.pDatCre).getFullYear()
19
+ const key = `${month}-${year}`
20
+
21
+ if (!sumByMonth[key]) {
22
+ sumByMonth[key] = {
23
+ Mes: month,
24
+ Year: year,
25
+ totalProductsPrice: 0
33
26
  }
34
- })
35
- return res
36
- }, {})
37
27
 
28
+ result.push(sumByMonth[key])
29
+ }
30
+
31
+ sumByMonth[key].totalProductsPrice += value.totalProductsPrice
32
+ })
33
+
34
+ console.log(result)
35
+
36
+ console.log(data?.getAllSalesStore)
38
37
  const allMonths = Array.from({ length: 12 }, (_, i) => { return i })
39
38
  const missingMonths = allMonths.filter(month => { return !result.some(data => { return data.Mes === month }) })
40
39
 
@@ -89,6 +88,7 @@ export const useChartData = ({ year }) => {
89
88
  }
90
89
  ]
91
90
  }
91
+ console.log(result)
92
92
  const options = {
93
93
  interaction: {
94
94
  mode: 'index',
@@ -44,4 +44,4 @@ query getFavorite{
44
44
  }
45
45
  }
46
46
  }
47
- `
47
+ `
@@ -22,4 +22,4 @@ export const fetchJson = async (...args) => {
22
22
  }
23
23
  throw error
24
24
  }
25
- }
25
+ }
@@ -15,4 +15,4 @@ getOneRating(idStore: $idStore){
15
15
  updateAt
16
16
  }
17
17
  }
18
- `
18
+ `
@@ -1,15 +1,15 @@
1
- export default (d, s, id, jsSrc, cb, onError) => {
2
- const element = d.getElementsByTagName(s)[0]
3
- const fjs = element
4
- let js = element
5
- js = d.createElement(s)
6
- js.id = id
7
- js.src = jsSrc
8
- if (fjs && fjs.parentNode) {
9
- fjs.parentNode.insertBefore(js, fjs)
10
- } else {
11
- d.head.appendChild(js)
12
- }
13
- js.onerror = onError
14
- js.onload = cb
15
- }
1
+ export default (d, s, id, jsSrc, cb, onError) => {
2
+ const element = d.getElementsByTagName(s)[0]
3
+ const fjs = element
4
+ let js = element
5
+ js = d.createElement(s)
6
+ js.id = id
7
+ js.src = jsSrc
8
+ if (fjs && fjs.parentNode) {
9
+ fjs.parentNode.insertBefore(js, fjs)
10
+ } else {
11
+ d.head.appendChild(js)
12
+ }
13
+ js.onerror = onError
14
+ js.onload = cb
15
+ }
@@ -1,7 +1,7 @@
1
- export default (d, id) => {
2
- const element = d.getElementById(id)
3
-
4
- if (element) {
5
- element.parentNode.removeChild(element)
6
- }
7
- }
1
+ export default (d, id) => {
2
+ const element = d.getElementById(id)
3
+
4
+ if (element) {
5
+ element.parentNode.removeChild(element)
6
+ }
7
+ }
@@ -25,4 +25,4 @@ export const useKeyPress = (targetKey) => {
25
25
  }, [targetKey])
26
26
 
27
27
  return keyPressed
28
- }
28
+ }
@@ -2,19 +2,43 @@ import { useApolloClient } from '@apollo/client'
2
2
  import { useState } from 'react'
3
3
  import { Cookies } from '../../cookies/index'
4
4
  import { signOutAuth } from './helpers'
5
+ import { getCurrentDomain } from '../../utils'
5
6
  export { signOutAuth } from './helpers'
6
7
 
7
- export const useLogout = ({ setAlertBox = () => { } } = {}) => {
8
+ export const useLogout = ({ setAlertBox = () => {} } = {}) => {
8
9
  const [loading, setLoading] = useState(false)
9
10
  const [error, setError] = useState(false)
10
11
  const client = useApolloClient()
11
12
 
13
+ const eliminarCookie = async (nombreCookie) => {
14
+ try {
15
+ let domain = getCurrentDomain()
16
+
17
+ // Si estás en entorno local, usa 'localhost' como dominio
18
+ if (domain === 'localhost') {
19
+ domain = undefined // Esto permitirá la cookie en 'localhost'
20
+ }
21
+
22
+ const expirationTime = new Date()
23
+ expirationTime.setTime(expirationTime.getTime() - 1000) // Establece una fecha de expiración en el pasado
24
+
25
+ const formattedDomain = domain || getCurrentDomain()
26
+
27
+ await Cookies.remove(nombreCookie, { domain: formattedDomain, path: '/', secure: process.env.NODE_ENV === 'production' })
28
+
29
+ console.log('Cookie eliminada correctamente.')
30
+ } catch (error) {
31
+ console.error('Error al eliminar la cookie:', error)
32
+ throw new Error('Error al eliminar la cookie. ')
33
+ }
34
+ }
35
+
12
36
  const onClickLogout = async () => {
13
37
  try {
14
38
  setLoading(true)
15
39
 
16
40
  // Logout from the server
17
- const logoutResponse = await window.fetch(`${process.env.URL_BASE}/api/auth/logout/`, {
41
+ const logoutResponse = await fetch(`${process.env.URL_BASE}/api/auth/logout/`, {
18
42
  method: 'POST',
19
43
  headers: {
20
44
  'Content-Type': 'application/json'
@@ -24,33 +48,31 @@ export const useLogout = ({ setAlertBox = () => { } } = {}) => {
24
48
 
25
49
  if (!logoutResponse.ok) {
26
50
  setLoading(false)
27
- // Manejar el caso en que la solicitud no es exitosa, por ejemplo, mostrar un mensaje de error
51
+ // Handle unsuccessful logout request, e.g., show an error message
28
52
  return
29
53
  }
30
54
 
31
- const response = await logoutResponse.json() // Espera la resolución de la promesa de respuesta y obtén los datos JSON
55
+ const response = await logoutResponse.json()
32
56
  const { status } = response || {}
33
57
  console.log('Intentando borrar cookies...')
34
- console.log('Cookies antes de borrar:', Cookies.get())
35
- if (status === 200) {
36
- if (Cookies.get(process.env.SESSION_NAME)) {
37
- Cookies.remove(process.env.SESSION_NAME, { path: '/' })
38
- console.log('Cookie de sesión eliminada')
39
- }
40
- Cookies.remove(process.env.LOCAL_SALES_STORE)
41
- Cookies.remove('restaurant')
42
- Cookies.remove('usuario')
43
- Cookies.remove('session')
44
- client?.clearStore()
45
- setLoading(false)
46
- console.log('Borrado todo')
47
- signOutAuth({ redirect: true, callbackUrl: '/' })
48
- .catch(() => {
49
- setError(true)
50
- setAlertBox({ message: 'Ocurrió un error al cerrar session' })
51
- })
52
- }
58
+
59
+ // Eliminar la cookie process.env.SESSION_NAME
60
+ await eliminarCookie(process.env.SESSION_NAME)
61
+ Cookies.remove(process.env.LOCAL_SALES_STORE)
62
+ Cookies.remove('restaurant')
63
+ Cookies.remove('usuario')
64
+ Cookies.remove('session')
65
+
66
+ // Clear Apollo Client cache
67
+ client?.clearStore()
68
+
53
69
  setLoading(false)
70
+ console.log('Cookies eliminadas y sesión cerrada con éxito')
71
+ signOutAuth({ redirect: true, callbackUrl: '/' })
72
+ .catch(() => {
73
+ setError(true)
74
+ setAlertBox({ message: 'Ocurrió un error al cerrar sesión' })
75
+ })
54
76
  } catch (error) {
55
77
  setLoading(false)
56
78
  setError(true)
@@ -2,4 +2,4 @@ export const useOrderClient = () => {
2
2
  return {
3
3
 
4
4
  }
5
- }
5
+ }
@@ -325,4 +325,4 @@ query getAllOrdersFromStore(
325
325
  }
326
326
 
327
327
 
328
- `
328
+ `
@@ -30,15 +30,15 @@ export const useReport = ({
30
30
  variables: {
31
31
  fromDate,
32
32
  toDate
33
- },
34
- skip: !data || data?.getAllSalesStore?.length === 0 // Skip if main query hasn't loaded or has no data
33
+ }
35
34
  })
36
-
35
+ console.log(fromDate,
36
+ toDate)
37
37
  const totalSales = totalSalesData?.getAllSalesStoreTotal ?? {}
38
38
 
39
39
  return {
40
40
  getAllSalesStore: lazyQuery ? getAllSalesStore : () => { }, // Return function only if in lazy mode
41
- data: lazyQuery ? data || lazyDataSales : data, // Use data from lazy query if available
41
+ data: lazyQuery ? lazyDataSales : data, // Use data from lazy query if available
42
42
  loading: lazyQuery ? lazyLoading || loading : loading,
43
43
  totalSales: totalSales.TOTAL || 0,
44
44
  restaurant: totalSales.restaurant || 0,
@@ -1,7 +1,7 @@
1
1
  import { gql } from '@apollo/client'
2
2
 
3
3
  export const GET_ALL_SALES = gql`
4
- query getAllSalesStore($idStore: ID,$search: String, $min: Int, $max: Int $fromDate: DateTime, $toDate: DateTime ) {
4
+ query getAllSalesStore($idStore: ID,$search: String, $min: Int, $max: Int $fromDate: String, $toDate: String ) {
5
5
  getAllSalesStore(idStore: $idStore, search: $search, min: $min, max: $max, toDate: $toDate, fromDate: $fromDate) {
6
6
  totalProductsPrice
7
7
  channel
@@ -12,7 +12,7 @@ query getAllSalesStore($idStore: ID,$search: String, $min: Int, $max: Int $fromD
12
12
  `
13
13
 
14
14
  export const GET_ALL_TOTAL_SALES = gql`
15
- query getAllSalesStoreTotal($idStore: ID,$search: String, $min: Int, $max: Int $fromDate: DateTime, $toDate: DateTime ) {
15
+ query getAllSalesStoreTotal($idStore: ID,$search: String, $min: Int, $max: Int $fromDate: String, $toDate: String) {
16
16
  getAllSalesStoreTotal(idStore: $idStore, search: $search, min: $min, max: $max, toDate: $toDate, fromDate: $fromDate) {
17
17
  restaurant
18
18
  delivery
@@ -120,4 +120,4 @@ query getOneSalesStore($pCodeRef: String) {
120
120
  }
121
121
  }
122
122
  }
123
- `
123
+ `
@@ -77,4 +77,4 @@ query getAllStoreInStore($search: String, $min: Int, $max: Int){
77
77
  }
78
78
 
79
79
  }
80
- `
80
+ `
@@ -54,10 +54,10 @@ const initializer = (initialValue = initialState) => {
54
54
  }
55
55
 
56
56
  export const useSales = ({
57
- disabled,
58
- sendNotification,
57
+ disabled = false,
59
58
  router,
60
- setAlertBox
59
+ sendNotification = () => { return },
60
+ setAlertBox = () => { return }
61
61
  }) => {
62
62
  const domain = getCurrentDomain()
63
63
  const [loadingSale, setLoadingSale] = useState(false)
@@ -330,14 +330,6 @@ export const useSales = ({
330
330
  case 'DECREMENT':
331
331
  return {
332
332
  ...state
333
- // counter: state.counter - 1,
334
- // PRODUCT: state?.PRODUCT?.map((items) => {
335
- // return items.pId === action.id ? {
336
- // ...items,
337
- // ProQuantity: items.ProQuantity - 1,
338
- // // ProPrice: ((productExist.ProQuantity + 1) * OurProduct?.ProPrice),
339
- // } : items
340
- // })
341
333
  }
342
334
  case 'PAYMENT_METHOD_TRANSACTION':
343
335
  return {
@@ -826,6 +818,7 @@ export const useSales = ({
826
818
  const totalProductsPrice = totalProductPrice
827
819
  const client = useApolloClient()
828
820
  const { getOnePedidoStore } = useGetSale()
821
+
829
822
  const handleSubmit = () => {
830
823
  if (errors?.change || errors?.valueDelivery) {
831
824
  return sendNotification({
@@ -837,7 +830,7 @@ export const useSales = ({
837
830
  setLoadingSale(true)
838
831
  const code = RandomCode(10)
839
832
  setCode(code)
840
- function convertirAEntero (cadena) {
833
+ function convertInteger (cadena) {
841
834
  if (typeof cadena === 'string') {
842
835
  const numeroEntero = parseInt(cadena?.replace('.', ''))
843
836
  return numeroEntero
@@ -849,12 +842,12 @@ export const useSales = ({
849
842
  input: finalArrayProduct || [],
850
843
  id: values?.cliId,
851
844
  pCodeRef: code,
852
- change: convertirAEntero(values.change),
853
- valueDelivery: convertirAEntero(values.valueDelivery),
845
+ change: convertInteger(values.change),
846
+ valueDelivery: convertInteger(values.valueDelivery),
854
847
  payMethodPState: data.payMethodPState,
855
848
  pickUp: 1,
856
849
  discount: discount.discount || 0,
857
- totalProductsPrice: convertirAEntero(totalProductsPrice) || 0
850
+ totalProductsPrice: convertInteger(totalProductsPrice) || 0
858
851
  }
859
852
  })
860
853
  .then((responseRegisterR) => {
@@ -6,8 +6,8 @@ export const GET_ALL_SALES = gql`
6
6
  $search: String
7
7
  $min: Int
8
8
  $max: Int
9
- $fromDate: DateTime
10
- $toDate: DateTime
9
+ $fromDate: String
10
+ $toDate: String
11
11
  ) {
12
12
  getAllSalesStore(
13
13
  idStore: $idStore
@@ -275,6 +275,7 @@ export const GET_ONE_SALE = gql`
275
275
  getAllShoppingCard {
276
276
  ShoppingCard
277
277
  cantProducts
278
+ priceProduct
278
279
  refCodePid
279
280
  subProductsId
280
281
  comments
@@ -416,6 +417,7 @@ query getAllPedidoStoreFinal($idStore: ID, $search: String, $min: Int, $max: Int
416
417
  pDatMod
417
418
  getAllShoppingCard {
418
419
  ShoppingCard
420
+ priceProduct
419
421
  comments
420
422
  cantProducts
421
423
  pId