npm-pkg-hook 1.0.1 → 1.0.2

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.
Files changed (46) hide show
  1. package/.babelrc +13 -13
  2. package/.eslintrc.json +107 -107
  3. package/.github/pull_request_template.md +18 -0
  4. package/.github/workflows/pepeline.yaml +30 -0
  5. package/README.md +1 -1
  6. package/jsconfig.json +27 -27
  7. package/next.config.js +128 -128
  8. package/package.json +10 -2
  9. package/src/cookies/index.ts +3 -3
  10. package/src/hooks/index.js +19 -15
  11. package/src/hooks/useAcumulateDate/index.js +15 -15
  12. package/src/hooks/useAnimationText/index.jsx +29 -29
  13. package/src/hooks/useCategoryStore/index.js +7 -7
  14. package/src/hooks/useCategoryStore/queries.js +16 -16
  15. package/src/hooks/useCheckbox/index.js +114 -0
  16. package/src/hooks/useClients/index.js +13 -0
  17. package/src/hooks/useClients/queries.js +118 -0
  18. package/src/hooks/useDrag/index.js +56 -56
  19. package/src/hooks/useEvent/index.js +33 -33
  20. package/src/hooks/useFetchJson/index.js +24 -24
  21. package/src/hooks/useFetchMoreInteractions/index.jsx +34 -34
  22. package/src/hooks/useFormTools/index.js +70 -70
  23. package/src/hooks/useFullScreenMode/index.js +65 -65
  24. package/src/hooks/useGetCategorieStore/index.js +20 -20
  25. package/src/hooks/useGetCategorieStore/queries.js +77 -77
  26. package/src/hooks/useGetProductsFood/index.js +46 -0
  27. package/src/hooks/useGetProductsFood/queriesStore.js +766 -0
  28. package/src/hooks/useHover/index.js +28 -28
  29. package/src/hooks/useInnerHtml/index.js +37 -37
  30. package/src/hooks/useIntersection/index.js +30 -30
  31. package/src/hooks/useKeypress/index.js +27 -27
  32. package/src/hooks/useLocalSorage/index.js +35 -35
  33. package/src/hooks/useLocationNavigate/index.js +54 -54
  34. package/src/hooks/useMobile/index.js +38 -0
  35. package/src/hooks/useRestaurant/index.js +19 -19
  36. package/src/hooks/useRestaurant/queries.js +69 -69
  37. package/src/hooks/useSales/index.js +489 -0
  38. package/src/hooks/useSales/queries.js +230 -0
  39. package/src/hooks/useSetState/index.js +24 -24
  40. package/src/hooks/useStore/index.js +18 -0
  41. package/src/hooks/useStore/queries.js +136 -0
  42. package/src/hooks/useTimeAgo/useTimeAgo.js +39 -39
  43. package/src/hooks/useUpdateCart/index.js +124 -123
  44. package/src/hooks/useUser/index.js +3 -3
  45. package/src/hooks/useWindowSize/index.js +37 -37
  46. package/src/utils/index.js +54 -27
@@ -1,15 +1,19 @@
1
- export * from './useLocationNavigate'
2
- export * from './useUser'
3
- export * from './useTimeAgo/useTimeAgo'
4
- export * from './useEvent'
5
- export * from './useFetchJson'
6
- export * from './useRestaurant'
7
- export * from './useFormTools/index'
8
- export * from './useDrag'
9
- export * from './useHover'
10
- export * from './useKeypress'
11
- export * from './useLocalSorage'
12
- export * from './useUpdateCart'
13
- export * from './useSetState'
14
- export * from './useGetCategorieStore'
15
- export * from './useCategoryStore'
1
+ export * from './useCategoryStore'
2
+ export * from './useCheckbox'
3
+ export * from './useDrag'
4
+ export * from './useEvent'
5
+ export * from './useFetchJson'
6
+ export * from './useFormTools/index'
7
+ export * from './useGetCategorieStore'
8
+ export * from './useHover'
9
+ export * from './useKeypress'
10
+ export * from './useLocalSorage'
11
+ export * from './useLocationNavigate'
12
+ export * from './useMobile'
13
+ export * from './useRestaurant'
14
+ export * from './useSales'
15
+ export * from './useSetState'
16
+ export * from './useTimeAgo/useTimeAgo'
17
+ export * from './useUpdateCart'
18
+ export * from './useUser'
19
+ export * from './useClients'
@@ -1,16 +1,16 @@
1
-
2
- const data = [
3
- { x: '2021-10-17T14:38:45.540Z', y: 2 }
4
- ]
5
- export const get_date_parts = (iso_string) => {
6
- const [year, month, day, hr, min, sec] = iso_string.split(/\D/g)
7
- return { year, month, day, hr, min, sec }
8
- }
9
- function group_by_year(arr) {
10
- let total = arr.reduce((a, b) => {
11
- const { day } = get_date_parts(b.x)
12
- return a + parseInt(day)
13
- }, 0)
14
- return total
15
- }
1
+
2
+ const data = [
3
+ { x: '2021-10-17T14:38:45.540Z', y: 2 }
4
+ ]
5
+ export const get_date_parts = (iso_string) => {
6
+ const [year, month, day, hr, min, sec] = iso_string.split(/\D/g)
7
+ return { year, month, day, hr, min, sec }
8
+ }
9
+ function group_by_year(arr) {
10
+ let total = arr.reduce((a, b) => {
11
+ const { day } = get_date_parts(b.x)
12
+ return a + parseInt(day)
13
+ }, 0)
14
+ return total
15
+ }
16
16
  const result = group_by_year(data)
@@ -1,30 +1,30 @@
1
- import React, { useEffect, useState, useRef } from 'react'
2
-
3
- const fullText =
4
- ' this is full text it\'ll be animated again! Writing a really huge senetence here so that I can see the animation happen. I know it\'s fast but that\'s how it goes.'
5
-
6
- const useAnimatedText = textMessage => {
7
- const fullTextRef = useRef(textMessage)
8
- const [text, setText] = useState('')
9
- const [index, setIndex] = useState(0)
10
- useEffect(() => {
11
- if (index < fullText.length) {
12
- window.requestAnimationFrame(() => {
13
- // eslint-disable-next-line
14
- setText(text => text + fullTextRef.current[index]);
15
- setIndex(() => {return index + 1})
16
- })
17
- }
18
- }, [index])
19
- useEffect(() => {
20
- fullText.current = textMessage
21
- }, [textMessage])
22
-
23
- return text
24
- }
25
-
26
- export default function TextHook() {
27
- const text = useAnimatedText(fullText)
28
-
29
- return <span>{text} </span>
1
+ import React, { useEffect, useState, useRef } from 'react'
2
+
3
+ const fullText =
4
+ ' this is full text it\'ll be animated again! Writing a really huge senetence here so that I can see the animation happen. I know it\'s fast but that\'s how it goes.'
5
+
6
+ const useAnimatedText = textMessage => {
7
+ const fullTextRef = useRef(textMessage)
8
+ const [text, setText] = useState('')
9
+ const [index, setIndex] = useState(0)
10
+ useEffect(() => {
11
+ if (index < fullText.length) {
12
+ window.requestAnimationFrame(() => {
13
+ // eslint-disable-next-line
14
+ setText(text => text + fullTextRef.current[index]);
15
+ setIndex(() => {return index + 1})
16
+ })
17
+ }
18
+ }, [index])
19
+ useEffect(() => {
20
+ fullText.current = textMessage
21
+ }, [textMessage])
22
+
23
+ return text
24
+ }
25
+
26
+ export default function TextHook() {
27
+ const text = useAnimatedText(fullText)
28
+
29
+ return <span>{text} </span>
30
30
  }
@@ -1,7 +1,7 @@
1
- import { useQuery } from '@apollo/client'
2
- import { GET_ALL_CAT_STORE } from './queries'
3
-
4
- export const useCategoryStore = () => {
5
- const { data } = useQuery(GET_ALL_CAT_STORE)
6
- return [data]
7
- }
1
+ import { useQuery } from '@apollo/client'
2
+ import { GET_ALL_CAT_STORE } from './queries'
3
+
4
+ export const useCategoryStore = () => {
5
+ const { data } = useQuery(GET_ALL_CAT_STORE)
6
+ return [data]
7
+ }
@@ -1,16 +1,16 @@
1
- import { gql } from '@apollo/client'
2
-
3
- export const GET_ALL_CAT_STORE = gql`
4
- query getAllCatStore{
5
- getAllCatStore{
6
- catStore
7
- idUser
8
- cPathImage
9
- cName
10
- cState
11
- cDatCre
12
- cDatMod
13
- csDescription
14
- }
15
- }
16
- `
1
+ import { gql } from '@apollo/client'
2
+
3
+ export const GET_ALL_CAT_STORE = gql`
4
+ query getAllCatStore{
5
+ getAllCatStore{
6
+ catStore
7
+ idUser
8
+ cPathImage
9
+ cName
10
+ cState
11
+ cDatCre
12
+ cDatMod
13
+ csDescription
14
+ }
15
+ }
16
+ `
@@ -0,0 +1,114 @@
1
+ import { useCallback, useState } from 'react'
2
+
3
+ /**
4
+ * Hook for managing multiple checkbox states
5
+ *
6
+ * @param {Array<String | Number>} elem - list of all elem
7
+ * @param {Array<String | Number>} selectedIds - list of selected elem (optional)
8
+ *
9
+ * @returns {Object}
10
+ * - checkboxStates (state object),
11
+ * - numSelectedItems (number),
12
+ * - handleChangeCheck (callback),
13
+ * - toggleAll (callback),
14
+ * - selectAll (callback),
15
+ * - clearAll (callback)
16
+ */
17
+
18
+ export const useCheckboxState = (elem, selectedIds = [], disabledIds = []) => {
19
+ const numTotalItems = elem?.length
20
+ const [checkedItems, setCheckedItems] = useState(new Set(selectedIds))
21
+ const [disabledItems, setDisabledItems] = useState(new Set(disabledIds))
22
+
23
+ const handleChangeCheck = useCallback((event, id) => {
24
+ const target = event.target
25
+ setCheckedItems(prevState => {
26
+ const newState = new Set(prevState)
27
+ if (target.checked) {
28
+ newState.add(id)
29
+ } else {
30
+ newState.delete(id)
31
+ }
32
+ return newState
33
+ })
34
+ }, [])
35
+
36
+ const setAll = useCallback(
37
+ isChecked => {
38
+ setCheckedItems(prevState => {
39
+ const newState = new Set(prevState)
40
+ for (const id of elem) {
41
+ if (disabledItems.has(id)) {
42
+ continue
43
+ }
44
+ if (isChecked) {
45
+ newState.add(id)
46
+ } else {
47
+ newState.delete(id)
48
+ }
49
+ }
50
+ return newState
51
+ })
52
+ },
53
+ [elem, disabledItems]
54
+ )
55
+
56
+ const selectAll = useCallback(() => {
57
+ if (checkedItems.size === numTotalItems) {
58
+ return
59
+ }
60
+ setAll(true)
61
+ }, [checkedItems, numTotalItems, setAll])
62
+
63
+ const clearAll = useCallback(() => {
64
+ if (checkedItems.size === 0) {
65
+ return
66
+ }
67
+ setAll(false)
68
+ }, [checkedItems, setAll])
69
+
70
+ const toggleAll = useCallback(() => {
71
+ const numDisabledAndChecked = [...disabledItems].reduce((count, id) => {
72
+ if (checkedItems.has(id)) {
73
+ return count + 1
74
+ }
75
+ return count
76
+ }, 0)
77
+ if (checkedItems.size - numDisabledAndChecked === 0) {
78
+ selectAll()
79
+ } else {
80
+ clearAll()
81
+ }
82
+ }, [checkedItems, disabledItems, selectAll, clearAll])
83
+
84
+ const enableCheckboxes = useCallback((...elem) => {
85
+ setDisabledItems(prevState => {
86
+ const newState = new Set(prevState)
87
+ for (const id of elem) {
88
+ newState.delete(id)
89
+ }
90
+ return newState
91
+ })
92
+ }, [])
93
+
94
+ const disableCheckboxes = useCallback((...elem) => {
95
+ setDisabledItems(prevState => {
96
+ const newState = new Set(prevState)
97
+ for (const id of elem) {
98
+ newState.add(id)
99
+ }
100
+ return newState
101
+ })
102
+ }, [])
103
+
104
+ return {
105
+ checkedItems,
106
+ disabledItems,
107
+ handleChangeCheck,
108
+ toggleAll,
109
+ selectAll,
110
+ clearAll,
111
+ enableCheckboxes,
112
+ disableCheckboxes
113
+ }
114
+ }
@@ -0,0 +1,13 @@
1
+ import { useQuery } from '@apollo/client'
2
+ import { useEffect, useState } from 'react'
3
+ import { GET_ALL_CLIENTS } from './queries'
4
+
5
+ export const useGetClients = () => {
6
+ const [clientes, setClients] = useState([])
7
+ const { loading, error } = useQuery(GET_ALL_CLIENTS, {
8
+ onCompleted: (data) => {
9
+ setClients(data)
10
+ }
11
+ })
12
+ return [clientes?.getAllClients, { loading, error }]
13
+ }
@@ -0,0 +1,118 @@
1
+ import { gql } from '@apollo/client'
2
+
3
+ export const CREATE_CLIENTS = gql`
4
+ mutation createClients ($input: IClients) {
5
+ createClients(input: $input) {
6
+ cliId
7
+ idStore
8
+ idUser
9
+ clState
10
+ ClientAddress
11
+ clientNumber
12
+ ccClient
13
+ gender
14
+ clientLastName
15
+ clientName
16
+ createAt
17
+ updateAt
18
+ }
19
+ }
20
+ `
21
+ export const DELETE_ONE_CLIENTS = gql`
22
+ mutation deleteClient($cliId: ID, $clState: Int!) {
23
+ deleteClient(cliId: $cliId, clState: $clState) {
24
+ success
25
+ message
26
+ }
27
+ }
28
+ `
29
+ export const GET_ALL_CLIENTS = gql`
30
+ query getAllClients($idStore: ID, $cId: ID, $dId: ID, $ctId: ID, $search: String, $min: Int, $max: Int, $fromDate: DateTime, $toDate: DateTime ) {
31
+ getAllClients(idStore: $idStore, cId: $cId, dId: $dId, ctId: $ctId, search: $search, min: $min, max: $max, fromDate: $fromDate, toDate: $toDate) {
32
+ cliId
33
+ idStore
34
+ gender
35
+ # idUser
36
+ clState
37
+ clientNumber
38
+ ccClient
39
+ clientLastName
40
+ clientName
41
+ ClientAddress
42
+ createAt
43
+ updateAt
44
+
45
+ }
46
+ }
47
+ `
48
+ export const GET_ONE_CLIENT = gql`
49
+ query getOneClients($cliId: ID) {
50
+ getOneClients(cliId: $cliId) {
51
+ cliId
52
+ idStore
53
+ idUser
54
+ clState
55
+ clientNumber
56
+ ClientAddress
57
+ gender
58
+ ccClient
59
+ clientLastName
60
+ clientName
61
+ createAt
62
+ updateAt
63
+
64
+ }
65
+ }
66
+ `
67
+
68
+ export const CREATE_SHOPPING_CARD = gql`
69
+ mutation registerShoppingCard($input: IShoppingCard, $idSubArray: IID_SUB_ITEMS){
70
+ registerShoppingCard(input: $input, idSubArray: $idSubArray){
71
+ ShoppingCard
72
+ id
73
+ pId
74
+ subProductsId
75
+ ShoppingCardRefCode
76
+ uuid
77
+ discountCardProduct
78
+ idUser
79
+ cName
80
+ idStore
81
+ cState
82
+ cDatCre
83
+ cDatMod
84
+ csDescription
85
+ cantProducts
86
+ comments
87
+ # idSubArray
88
+ }
89
+ }
90
+ `
91
+ export const CREATE_SHOPPING_CARD_TO_USER_STORE = gql`
92
+ mutation registerSalesStore($input: [IShoppingCard], $id: ID, $idStore: ID, $pCodeRef: String, $change: String, $valueDelivery: Float, $payMethodPState: Int, $pickUp: Int, $totalProductsPrice: Float, $idSubArray: IID_SUB_ITEMS){
93
+ registerSalesStore(input: $input, id: $id, idStore: $idStore, pCodeRef: $pCodeRef, change: $change, valueDelivery: $valueDelivery, payMethodPState: $payMethodPState, pickUp: $pickUp, totalProductsPrice: $totalProductsPrice, idSubArray: $idSubArray){
94
+ ShoppingCard {
95
+ ShoppingCard
96
+ id
97
+ pId
98
+ subProductsId
99
+ ShoppingCardRefCode
100
+ uuid
101
+ discountCardProduct
102
+ idUser
103
+ cName
104
+ idStore
105
+ cState
106
+ cDatCre
107
+ cDatMod
108
+ csDescription
109
+ cantProducts
110
+ comments
111
+ }
112
+ Response {
113
+ success
114
+ message
115
+ }
116
+ }
117
+ }
118
+ `
@@ -1,57 +1,57 @@
1
- import { useEffect } from 'react'
2
-
3
- export function useDrag2(ref) {
4
- useEffect(() => {
5
- const target = ref.current
6
- if (!target) return
7
- const previousOffset = { x: 0, y: 0 }
8
- let originMouseX
9
- let originMouseY
10
- function onMousemove(e) {
11
- const { pageX, pageY } = e
12
- const x = pageX - originMouseX + previousOffset.x
13
- const y = pageY - originMouseY + previousOffset.y
14
- target.style.transform = `translate(${ x }px, ${ y }px)`
15
- }
16
- function onMouseup(e) {
17
- previousOffset.x += e.pageX - originMouseX
18
- previousOffset.y += e.pageY - originMouseY
19
- window.removeEventListener('mousemove', onMousemove)
20
- window.removeEventListener('mouseup', onMouseup)
21
- }
22
- function onMousedown(e) {
23
- originMouseX = e.pageX
24
- originMouseY = e.pageY
25
- window.addEventListener('mousemove', onMousemove)
26
- window.addEventListener('mouseup', onMouseup)
27
- }
28
- target.addEventListener('mousedown', onMousedown)
29
- return () => {
30
- target?.removeEventListener('mousedown', onMousedown)
31
- window?.removeEventListener('mouseup', onMouseup)
32
- window?.removeEventListener('mousemove', onMousemove)
33
- }
34
- }, [ref])
35
- }
36
- import { useState } from 'react'
37
-
38
- export const useDrag = (x, y) => {
39
- const [move, setMove] = useState(false)
40
- const [moveTo, setMoveTo] = useState([x, y])
41
- const moveIcon = e => {
42
- const xcoord = moveTo[0] + e.movementX
43
- const ycoord = moveTo[1] + e.movementY
44
- setMoveTo([xcoord, ycoord])
45
- }
46
- const handleMove = e => {
47
- move && moveIcon(e)
48
- }
49
- const handelDown = () => {
50
- setMove(true)
51
- }
52
- const handelUp = () => {
53
- setMove(false)
54
- }
55
-
56
- return { move, moveTo, handelDown, handelUp, handleMove }
1
+ import { useEffect } from 'react'
2
+
3
+ export function useDrag2(ref) {
4
+ useEffect(() => {
5
+ const target = ref.current
6
+ if (!target) return
7
+ const previousOffset = { x: 0, y: 0 }
8
+ let originMouseX
9
+ let originMouseY
10
+ function onMousemove(e) {
11
+ const { pageX, pageY } = e
12
+ const x = pageX - originMouseX + previousOffset.x
13
+ const y = pageY - originMouseY + previousOffset.y
14
+ target.style.transform = `translate(${ x }px, ${ y }px)`
15
+ }
16
+ function onMouseup(e) {
17
+ previousOffset.x += e.pageX - originMouseX
18
+ previousOffset.y += e.pageY - originMouseY
19
+ window.removeEventListener('mousemove', onMousemove)
20
+ window.removeEventListener('mouseup', onMouseup)
21
+ }
22
+ function onMousedown(e) {
23
+ originMouseX = e.pageX
24
+ originMouseY = e.pageY
25
+ window.addEventListener('mousemove', onMousemove)
26
+ window.addEventListener('mouseup', onMouseup)
27
+ }
28
+ target.addEventListener('mousedown', onMousedown)
29
+ return () => {
30
+ target?.removeEventListener('mousedown', onMousedown)
31
+ window?.removeEventListener('mouseup', onMouseup)
32
+ window?.removeEventListener('mousemove', onMousemove)
33
+ }
34
+ }, [ref])
35
+ }
36
+ import { useState } from 'react'
37
+
38
+ export const useDrag = (x, y) => {
39
+ const [move, setMove] = useState(false)
40
+ const [moveTo, setMoveTo] = useState([x, y])
41
+ const moveIcon = e => {
42
+ const xcoord = moveTo[0] + e.movementX
43
+ const ycoord = moveTo[1] + e.movementY
44
+ setMoveTo([xcoord, ycoord])
45
+ }
46
+ const handleMove = e => {
47
+ move && moveIcon(e)
48
+ }
49
+ const handelDown = () => {
50
+ setMove(true)
51
+ }
52
+ const handelUp = () => {
53
+ setMove(false)
54
+ }
55
+
56
+ return { move, moveTo, handelDown, handelUp, handleMove }
57
57
  }
@@ -1,33 +1,33 @@
1
- import { useEffect } from 'react';
2
- export const on = ({ eventType, callBack }) => {
3
- document.addEventListener(eventType, callBack);
4
- };
5
- export const off = ({ eventType, callBack }) => {
6
- document.removeEventListener(eventType, callBack);
7
- };
8
- export const once = ({ eventType, callBack }) => {
9
- const handleEventOnce = (event) => {
10
- callBack(event);
11
- off({ eventType, callBack: handleEventOnce });
12
- };
13
- on({ eventType, callBack: handleEventOnce });
14
- };
15
- export const trigger = ({ eventType, data }) => {
16
- const event = new CustomEvent(eventType, { detail: data });
17
- document.dispatchEvent(event);
18
- };
19
- //This function is used to subscribe components an any event
20
- export const useEvents = ({ eventType, callBack }) => {
21
- useEffect(() => {
22
- on({ eventType, callBack: callBack });
23
- return () => {
24
- off({ eventType, callBack: callBack });
25
- };
26
- }, [eventType, callBack]);
27
- };
28
- // This function create and dispatch event
29
- export const useTrigerEvent = () => {
30
- return {
31
- trigger
32
- };
33
- };
1
+ import { useEffect } from 'react';
2
+ export const on = ({ eventType, callBack }) => {
3
+ document.addEventListener(eventType, callBack);
4
+ };
5
+ export const off = ({ eventType, callBack }) => {
6
+ document.removeEventListener(eventType, callBack);
7
+ };
8
+ export const once = ({ eventType, callBack }) => {
9
+ const handleEventOnce = (event) => {
10
+ callBack(event);
11
+ off({ eventType, callBack: handleEventOnce });
12
+ };
13
+ on({ eventType, callBack: handleEventOnce });
14
+ };
15
+ export const trigger = ({ eventType, data }) => {
16
+ const event = new CustomEvent(eventType, { detail: data });
17
+ document.dispatchEvent(event);
18
+ };
19
+ //This function is used to subscribe components an any event
20
+ export const useEvents = ({ eventType, callBack }) => {
21
+ useEffect(() => {
22
+ on({ eventType, callBack: callBack });
23
+ return () => {
24
+ off({ eventType, callBack: callBack });
25
+ };
26
+ }, [eventType, callBack]);
27
+ };
28
+ // This function create and dispatch event
29
+ export const useTrigerEvent = () => {
30
+ return {
31
+ trigger
32
+ };
33
+ };
@@ -1,25 +1,25 @@
1
- /**
2
- * It fetches a json response, and if the response is not ok, it throws an error with the response and
3
- * the data
4
- * @param args - The arguments to pass to fetch.
5
- */
6
- export const fetchJson = async (...args) => {
7
- try {
8
- const response = await fetch(...args)
9
- // if the server replies, there's always some data in json
10
- // if there's a network error, it will throw at the previous line
11
- const data = await response.json()
12
- if (response.ok) {
13
- return data
14
- }
15
- const error = new Error(response.statusText)
16
- error.response = response
17
- error.data = data
18
- throw error
19
- } catch (error) {
20
- if (!error.data) {
21
- error.data = { message: error.message }
22
- }
23
- throw error
24
- }
1
+ /**
2
+ * It fetches a json response, and if the response is not ok, it throws an error with the response and
3
+ * the data
4
+ * @param args - The arguments to pass to fetch.
5
+ */
6
+ export const fetchJson = async (...args) => {
7
+ try {
8
+ const response = await fetch(...args)
9
+ // if the server replies, there's always some data in json
10
+ // if there's a network error, it will throw at the previous line
11
+ const data = await response.json()
12
+ if (response.ok) {
13
+ return data
14
+ }
15
+ const error = new Error(response.statusText)
16
+ error.response = response
17
+ error.data = data
18
+ throw error
19
+ } catch (error) {
20
+ if (!error.data) {
21
+ error.data = { message: error.message }
22
+ }
23
+ throw error
24
+ }
25
25
  }