@makana-cl/portal-internal-client 1.2.3
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/README.md +404 -0
- package/dist/client/apollo-client.d.ts +25 -0
- package/dist/client/apollo-client.d.ts.map +1 -0
- package/dist/client/apollo-client.js +93 -0
- package/dist/client/apollo-client.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.esm.js/client/apollo-client.d.ts +25 -0
- package/dist/index.esm.js/client/apollo-client.d.ts.map +1 -0
- package/dist/index.esm.js/client/apollo-client.js +90 -0
- package/dist/index.esm.js/client/apollo-client.js.map +1 -0
- package/dist/index.esm.js/index.d.ts +22 -0
- package/dist/index.esm.js/index.d.ts.map +1 -0
- package/dist/index.esm.js/index.esm.js.tmp/client/apollo-client.d.ts +25 -0
- package/dist/index.esm.js/index.esm.js.tmp/client/apollo-client.d.ts.map +1 -0
- package/dist/index.esm.js/index.esm.js.tmp/client/apollo-client.js +90 -0
- package/dist/index.esm.js/index.esm.js.tmp/client/apollo-client.js.map +1 -0
- package/dist/index.esm.js/index.esm.js.tmp/index.d.ts +22 -0
- package/dist/index.esm.js/index.esm.js.tmp/index.d.ts.map +1 -0
- package/dist/index.esm.js/index.esm.js.tmp/index.js +21 -0
- package/dist/index.esm.js/index.esm.js.tmp/index.js.map +1 -0
- package/dist/index.esm.js/index.esm.js.tmp/queries/businesses.d.ts +37 -0
- package/dist/index.esm.js/index.esm.js.tmp/queries/businesses.d.ts.map +1 -0
- package/dist/index.esm.js/index.esm.js.tmp/queries/businesses.js +82 -0
- package/dist/index.esm.js/index.esm.js.tmp/queries/businesses.js.map +1 -0
- package/dist/index.esm.js/index.esm.js.tmp/queries/index.d.ts +5 -0
- package/dist/index.esm.js/index.esm.js.tmp/queries/index.d.ts.map +1 -0
- package/dist/index.esm.js/index.esm.js.tmp/queries/index.js +5 -0
- package/dist/index.esm.js/index.esm.js.tmp/queries/index.js.map +1 -0
- package/dist/index.esm.js/index.esm.js.tmp/queries/searchBusinesses.d.ts +64 -0
- package/dist/index.esm.js/index.esm.js.tmp/queries/searchBusinesses.d.ts.map +1 -0
- package/dist/index.esm.js/index.esm.js.tmp/queries/searchBusinesses.js +97 -0
- package/dist/index.esm.js/index.esm.js.tmp/queries/searchBusinesses.js.map +1 -0
- package/dist/index.esm.js/index.esm.js.tmp/queries/users.d.ts +51 -0
- package/dist/index.esm.js/index.esm.js.tmp/queries/users.d.ts.map +1 -0
- package/dist/index.esm.js/index.esm.js.tmp/queries/users.js +138 -0
- package/dist/index.esm.js/index.esm.js.tmp/queries/users.js.map +1 -0
- package/dist/index.esm.js/index.esm.js.tmp/queries/usersLight.d.ts +63 -0
- package/dist/index.esm.js/index.esm.js.tmp/queries/usersLight.d.ts.map +1 -0
- package/dist/index.esm.js/index.esm.js.tmp/queries/usersLight.js +90 -0
- package/dist/index.esm.js/index.esm.js.tmp/queries/usersLight.js.map +1 -0
- package/dist/index.esm.js/index.esm.js.tmp/types/business.d.ts +20 -0
- package/dist/index.esm.js/index.esm.js.tmp/types/business.d.ts.map +1 -0
- package/dist/index.esm.js/index.esm.js.tmp/types/business.js +2 -0
- package/dist/index.esm.js/index.esm.js.tmp/types/business.js.map +1 -0
- package/dist/index.esm.js/index.esm.js.tmp/types/common.d.ts +45 -0
- package/dist/index.esm.js/index.esm.js.tmp/types/common.d.ts.map +1 -0
- package/dist/index.esm.js/index.esm.js.tmp/types/common.js +2 -0
- package/dist/index.esm.js/index.esm.js.tmp/types/common.js.map +1 -0
- package/dist/index.esm.js/index.esm.js.tmp/types/department.d.ts +6 -0
- package/dist/index.esm.js/index.esm.js.tmp/types/department.d.ts.map +1 -0
- package/dist/index.esm.js/index.esm.js.tmp/types/department.js +2 -0
- package/dist/index.esm.js/index.esm.js.tmp/types/department.js.map +1 -0
- package/dist/index.esm.js/index.esm.js.tmp/types/group.d.ts +9 -0
- package/dist/index.esm.js/index.esm.js.tmp/types/group.d.ts.map +1 -0
- package/dist/index.esm.js/index.esm.js.tmp/types/group.js +2 -0
- package/dist/index.esm.js/index.esm.js.tmp/types/group.js.map +1 -0
- package/dist/index.esm.js/index.esm.js.tmp/types/index.d.ts +6 -0
- package/dist/index.esm.js/index.esm.js.tmp/types/index.d.ts.map +1 -0
- package/dist/index.esm.js/index.esm.js.tmp/types/index.js +6 -0
- package/dist/index.esm.js/index.esm.js.tmp/types/index.js.map +1 -0
- package/dist/index.esm.js/index.esm.js.tmp/types/user.d.ts +61 -0
- package/dist/index.esm.js/index.esm.js.tmp/types/user.d.ts.map +1 -0
- package/dist/index.esm.js/index.esm.js.tmp/types/user.js +7 -0
- package/dist/index.esm.js/index.esm.js.tmp/types/user.js.map +1 -0
- package/dist/index.esm.js/index.js +21 -0
- package/dist/index.esm.js/index.js.map +1 -0
- package/dist/index.esm.js/queries/businesses.d.ts +37 -0
- package/dist/index.esm.js/queries/businesses.d.ts.map +1 -0
- package/dist/index.esm.js/queries/businesses.js +82 -0
- package/dist/index.esm.js/queries/businesses.js.map +1 -0
- package/dist/index.esm.js/queries/index.d.ts +5 -0
- package/dist/index.esm.js/queries/index.d.ts.map +1 -0
- package/dist/index.esm.js/queries/index.js +5 -0
- package/dist/index.esm.js/queries/index.js.map +1 -0
- package/dist/index.esm.js/queries/searchBusinesses.d.ts +64 -0
- package/dist/index.esm.js/queries/searchBusinesses.d.ts.map +1 -0
- package/dist/index.esm.js/queries/searchBusinesses.js +97 -0
- package/dist/index.esm.js/queries/searchBusinesses.js.map +1 -0
- package/dist/index.esm.js/queries/users.d.ts +51 -0
- package/dist/index.esm.js/queries/users.d.ts.map +1 -0
- package/dist/index.esm.js/queries/users.js +138 -0
- package/dist/index.esm.js/queries/users.js.map +1 -0
- package/dist/index.esm.js/queries/usersLight.d.ts +63 -0
- package/dist/index.esm.js/queries/usersLight.d.ts.map +1 -0
- package/dist/index.esm.js/queries/usersLight.js +90 -0
- package/dist/index.esm.js/queries/usersLight.js.map +1 -0
- package/dist/index.esm.js/types/business.d.ts +20 -0
- package/dist/index.esm.js/types/business.d.ts.map +1 -0
- package/dist/index.esm.js/types/business.js +2 -0
- package/dist/index.esm.js/types/business.js.map +1 -0
- package/dist/index.esm.js/types/common.d.ts +45 -0
- package/dist/index.esm.js/types/common.d.ts.map +1 -0
- package/dist/index.esm.js/types/common.js +2 -0
- package/dist/index.esm.js/types/common.js.map +1 -0
- package/dist/index.esm.js/types/department.d.ts +6 -0
- package/dist/index.esm.js/types/department.d.ts.map +1 -0
- package/dist/index.esm.js/types/department.js +2 -0
- package/dist/index.esm.js/types/department.js.map +1 -0
- package/dist/index.esm.js/types/group.d.ts +9 -0
- package/dist/index.esm.js/types/group.d.ts.map +1 -0
- package/dist/index.esm.js/types/group.js +2 -0
- package/dist/index.esm.js/types/group.js.map +1 -0
- package/dist/index.esm.js/types/index.d.ts +6 -0
- package/dist/index.esm.js/types/index.d.ts.map +1 -0
- package/dist/index.esm.js/types/index.js +6 -0
- package/dist/index.esm.js/types/index.js.map +1 -0
- package/dist/index.esm.js/types/user.d.ts +61 -0
- package/dist/index.esm.js/types/user.d.ts.map +1 -0
- package/dist/index.esm.js/types/user.js +7 -0
- package/dist/index.esm.js/types/user.js.map +1 -0
- package/dist/index.js +47 -0
- package/dist/index.js.map +1 -0
- package/dist/queries/businesses.d.ts +37 -0
- package/dist/queries/businesses.d.ts.map +1 -0
- package/dist/queries/businesses.js +86 -0
- package/dist/queries/businesses.js.map +1 -0
- package/dist/queries/index.d.ts +5 -0
- package/dist/queries/index.d.ts.map +1 -0
- package/dist/queries/index.js +21 -0
- package/dist/queries/index.js.map +1 -0
- package/dist/queries/searchBusinesses.d.ts +64 -0
- package/dist/queries/searchBusinesses.d.ts.map +1 -0
- package/dist/queries/searchBusinesses.js +101 -0
- package/dist/queries/searchBusinesses.js.map +1 -0
- package/dist/queries/users.d.ts +51 -0
- package/dist/queries/users.d.ts.map +1 -0
- package/dist/queries/users.js +142 -0
- package/dist/queries/users.js.map +1 -0
- package/dist/queries/usersLight.d.ts +63 -0
- package/dist/queries/usersLight.d.ts.map +1 -0
- package/dist/queries/usersLight.js +94 -0
- package/dist/queries/usersLight.js.map +1 -0
- package/dist/types/business.d.ts +20 -0
- package/dist/types/business.d.ts.map +1 -0
- package/dist/types/business.js +3 -0
- package/dist/types/business.js.map +1 -0
- package/dist/types/common.d.ts +45 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/common.js +3 -0
- package/dist/types/common.js.map +1 -0
- package/dist/types/department.d.ts +6 -0
- package/dist/types/department.d.ts.map +1 -0
- package/dist/types/department.js +3 -0
- package/dist/types/department.js.map +1 -0
- package/dist/types/group.d.ts +9 -0
- package/dist/types/group.d.ts.map +1 -0
- package/dist/types/group.js +3 -0
- package/dist/types/group.js.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +22 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/user.d.ts +61 -0
- package/dist/types/user.d.ts.map +1 -0
- package/dist/types/user.js +10 -0
- package/dist/types/user.js.map +1 -0
- package/package.json +50 -0
package/README.md
ADDED
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
# @makana-cl/portal-internal-client
|
|
2
|
+
|
|
3
|
+
GraphQL client library for Makana Portal internal applications. Provides React hooks and Apollo Client setup for querying the Makana GraphQL API.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- ✅ Pre-configured Apollo Client with JWT authentication
|
|
8
|
+
- ✅ React hooks for Users, Businesses, and searchBusinesses queries
|
|
9
|
+
- ✅ Full TypeScript support with type definitions
|
|
10
|
+
- ✅ Error handling and caching configured
|
|
11
|
+
- ✅ Easy to integrate into any React application
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
### Prerequisites
|
|
16
|
+
|
|
17
|
+
- Node.js 18+ and npm
|
|
18
|
+
- React 18+
|
|
19
|
+
- A valid JWT token for Makana API authentication
|
|
20
|
+
|
|
21
|
+
### Install from GitHub Packages
|
|
22
|
+
|
|
23
|
+
1. **Configure npm to use GitHub Packages**
|
|
24
|
+
|
|
25
|
+
Create or edit `~/.npmrc` (or `.npmrc` in your project root) and add:
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
@makana-cl:registry=https://npm.pkg.github.com
|
|
29
|
+
//npm.pkg.github.com/:_authToken=YOUR_GITHUB_TOKEN
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
To create a GitHub Personal Access Token:
|
|
33
|
+
- Go to GitHub Settings → Developer settings → Personal access tokens → Tokens (classic)
|
|
34
|
+
- Generate a new token with `read:packages` scope
|
|
35
|
+
- Use this token in your `.npmrc` file
|
|
36
|
+
|
|
37
|
+
2. **Install the package**
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npm install @makana-cl/portal-internal-client
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Or with yarn:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
yarn add @makana-cl/portal-internal-client
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Quick Start
|
|
50
|
+
|
|
51
|
+
### 1. Set up Apollo Client Provider
|
|
52
|
+
|
|
53
|
+
In your main App component or root file:
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
import React from 'react';
|
|
57
|
+
import { ApolloProvider } from '@apollo/client';
|
|
58
|
+
import { createMakanaClient } from '@makana-cl/portal-internal-client';
|
|
59
|
+
|
|
60
|
+
// Create the Apollo Client instance
|
|
61
|
+
const client = createMakanaClient({
|
|
62
|
+
apiUrl: 'https://api.makana.cl/graphql', // Your Makana API URL
|
|
63
|
+
getToken: () => {
|
|
64
|
+
// Return your JWT token from wherever you store it
|
|
65
|
+
return localStorage.getItem('jwt_token');
|
|
66
|
+
// Or from a state management library:
|
|
67
|
+
// return store.getState().auth.token;
|
|
68
|
+
},
|
|
69
|
+
onError: (error) => {
|
|
70
|
+
// Optional: Handle errors globally
|
|
71
|
+
console.error('GraphQL Error:', error);
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
function App() {
|
|
76
|
+
return (
|
|
77
|
+
<ApolloProvider client={client}>
|
|
78
|
+
{/* Your app components */}
|
|
79
|
+
</ApolloProvider>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export default App;
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### 2. Use Query Hooks in Components
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
import React from 'react';
|
|
90
|
+
import { useGetUsers, useGetBusinesses, useSearchBusinesses } from '@makana-cl/portal-internal-client';
|
|
91
|
+
|
|
92
|
+
function UsersList() {
|
|
93
|
+
const { users, loading, error, refetch } = useGetUsers({
|
|
94
|
+
filters: { businessId: '123' },
|
|
95
|
+
first: 10,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
if (loading) return <div>Loading...</div>;
|
|
99
|
+
if (error) return <div>Error: {error.message}</div>;
|
|
100
|
+
|
|
101
|
+
return (
|
|
102
|
+
<div>
|
|
103
|
+
<h2>Users ({users.length})</h2>
|
|
104
|
+
<ul>
|
|
105
|
+
{users.map((user) => (
|
|
106
|
+
<li key={user.id}>
|
|
107
|
+
{user.firstName} {user.lastName} - {user.email}
|
|
108
|
+
</li>
|
|
109
|
+
))}
|
|
110
|
+
</ul>
|
|
111
|
+
<button onClick={() => refetch()}>Refresh</button>
|
|
112
|
+
</div>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function BusinessesList() {
|
|
117
|
+
const { businesses, loading, error } = useGetBusinesses({
|
|
118
|
+
filters: { groupId: '456' },
|
|
119
|
+
first: 20,
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
if (loading) return <div>Loading...</div>;
|
|
123
|
+
if (error) return <div>Error: {error.message}</div>;
|
|
124
|
+
|
|
125
|
+
return (
|
|
126
|
+
<div>
|
|
127
|
+
<h2>Businesses</h2>
|
|
128
|
+
<ul>
|
|
129
|
+
{businesses.map((business) => (
|
|
130
|
+
<li key={business.id}>{business.name}</li>
|
|
131
|
+
))}
|
|
132
|
+
</ul>
|
|
133
|
+
</div>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function BusinessSearch() {
|
|
138
|
+
const [searchTerm, setSearchTerm] = React.useState('');
|
|
139
|
+
|
|
140
|
+
const { businesses, totalBusinesses, loading, error } = useSearchBusinesses({
|
|
141
|
+
searchTerm,
|
|
142
|
+
sort: { sortBy: 'name', sortOrder: 'ASC' },
|
|
143
|
+
page: 0,
|
|
144
|
+
pageSize: 25,
|
|
145
|
+
fromDate: '2024-01-01',
|
|
146
|
+
toDate: '2024-12-31',
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
return (
|
|
150
|
+
<div>
|
|
151
|
+
<input
|
|
152
|
+
type="text"
|
|
153
|
+
value={searchTerm}
|
|
154
|
+
onChange={(e) => setSearchTerm(e.target.value)}
|
|
155
|
+
placeholder="Search businesses..."
|
|
156
|
+
/>
|
|
157
|
+
{loading && <div>Loading...</div>}
|
|
158
|
+
{error && <div>Error: {error.message}</div>}
|
|
159
|
+
<p>Found {totalBusinesses} businesses</p>
|
|
160
|
+
<ul>
|
|
161
|
+
{businesses.map((business) => (
|
|
162
|
+
<li key={business.id}>
|
|
163
|
+
{business.name} - {business.totalUsers} users
|
|
164
|
+
</li>
|
|
165
|
+
))}
|
|
166
|
+
</ul>
|
|
167
|
+
</div>
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## API Reference
|
|
173
|
+
|
|
174
|
+
### `createMakanaClient(config)`
|
|
175
|
+
|
|
176
|
+
Creates a configured Apollo Client instance.
|
|
177
|
+
|
|
178
|
+
**Parameters:**
|
|
179
|
+
- `config.apiUrl` (string, required): The GraphQL API endpoint URL
|
|
180
|
+
- `config.getToken` (function, required): Function that returns the JWT token
|
|
181
|
+
- `config.onError` (function, optional): Global error handler callback
|
|
182
|
+
|
|
183
|
+
**Returns:** Configured Apollo Client instance
|
|
184
|
+
|
|
185
|
+
### `useGetUsers(variables?, options?)`
|
|
186
|
+
|
|
187
|
+
React hook to fetch users.
|
|
188
|
+
|
|
189
|
+
**Parameters:**
|
|
190
|
+
- `variables` (object, optional):
|
|
191
|
+
- `filters` (FilterInput): Filter users by business, department, etc.
|
|
192
|
+
- `sort` (SortInput): Sort order
|
|
193
|
+
- `first` (number): Number of items to fetch
|
|
194
|
+
- `after` (string): Cursor for pagination
|
|
195
|
+
- `includeInactive` (boolean): Include inactive users
|
|
196
|
+
- `skip` (boolean): Skip the query
|
|
197
|
+
|
|
198
|
+
**Returns:**
|
|
199
|
+
- `users`: Array of user objects
|
|
200
|
+
- `totalCount`: Total number of users
|
|
201
|
+
- `pageInfo`: Pagination information
|
|
202
|
+
- `loading`: Loading state
|
|
203
|
+
- `error`: Error object if any
|
|
204
|
+
- `refetch`: Function to refetch data
|
|
205
|
+
- `fetchMore`: Function for pagination
|
|
206
|
+
|
|
207
|
+
### `useGetBusinesses(variables?, options?)`
|
|
208
|
+
|
|
209
|
+
React hook to fetch businesses.
|
|
210
|
+
|
|
211
|
+
**Parameters:**
|
|
212
|
+
- `variables` (object, optional):
|
|
213
|
+
- `filters` (FilterInput): Filter businesses
|
|
214
|
+
- `first` (number): Number of items to fetch
|
|
215
|
+
- `after` (string): Cursor for pagination
|
|
216
|
+
|
|
217
|
+
**Returns:** Same structure as `useGetUsers`
|
|
218
|
+
|
|
219
|
+
### `useSearchBusinesses(variables?, options?)`
|
|
220
|
+
|
|
221
|
+
React hook to search businesses with advanced filtering.
|
|
222
|
+
|
|
223
|
+
**Parameters:**
|
|
224
|
+
- `variables` (object, optional):
|
|
225
|
+
- `searchTerm` (string): Search term for business name
|
|
226
|
+
- `sort` (SortInput): Sort configuration
|
|
227
|
+
- `page` (number): Page number (0-indexed)
|
|
228
|
+
- `pageSize` (number): Items per page
|
|
229
|
+
- `fromDate` (string): Start date filter (YYYY-MM-DD)
|
|
230
|
+
- `toDate` (string): End date filter (YYYY-MM-DD)
|
|
231
|
+
- `skip` (boolean): Skip the query
|
|
232
|
+
|
|
233
|
+
**Returns:**
|
|
234
|
+
- `businesses`: Array of business objects
|
|
235
|
+
- `totalCount`: Count of businesses in current page
|
|
236
|
+
- `totalBusinesses`: Total count before search term filter
|
|
237
|
+
- `pageInfo`: Pagination information
|
|
238
|
+
- `loading`, `error`, `refetch`, `fetchMore`: Standard query properties
|
|
239
|
+
|
|
240
|
+
## TypeScript Types
|
|
241
|
+
|
|
242
|
+
All types are exported from the package:
|
|
243
|
+
|
|
244
|
+
```typescript
|
|
245
|
+
import type {
|
|
246
|
+
User,
|
|
247
|
+
Business,
|
|
248
|
+
Group,
|
|
249
|
+
Department,
|
|
250
|
+
FilterInput,
|
|
251
|
+
SortInput,
|
|
252
|
+
Connection,
|
|
253
|
+
PageInfo,
|
|
254
|
+
} from '@makana-cl/portal-internal-client';
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
## Development
|
|
258
|
+
|
|
259
|
+
### Building the Package
|
|
260
|
+
|
|
261
|
+
```bash
|
|
262
|
+
npm run build
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
This compiles TypeScript to JavaScript in the `dist/` directory.
|
|
266
|
+
|
|
267
|
+
### Type Checking
|
|
268
|
+
|
|
269
|
+
```bash
|
|
270
|
+
npm run type-check
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
## Deployment to GitHub Packages
|
|
274
|
+
|
|
275
|
+
### Prerequisites
|
|
276
|
+
|
|
277
|
+
1. GitHub repository: `makana-cl/makana-portal-internal-client`
|
|
278
|
+
2. GitHub Personal Access Token with `write:packages` scope
|
|
279
|
+
3. GitHub Actions enabled for the repository
|
|
280
|
+
|
|
281
|
+
### Automatic Deployment (Recommended)
|
|
282
|
+
|
|
283
|
+
The package is automatically published to GitHub Packages when you:
|
|
284
|
+
|
|
285
|
+
1. **Push a new tag** that follows semantic versioning (e.g., `v1.0.0`)
|
|
286
|
+
|
|
287
|
+
```bash
|
|
288
|
+
git tag v1.0.0
|
|
289
|
+
git push origin v1.0.0
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
2. **GitHub Actions will automatically:**
|
|
293
|
+
- Build the package
|
|
294
|
+
- Publish to GitHub Packages
|
|
295
|
+
- Make it available for installation
|
|
296
|
+
|
|
297
|
+
### Manual Deployment
|
|
298
|
+
|
|
299
|
+
If you need to publish manually:
|
|
300
|
+
|
|
301
|
+
1. **Build the package:**
|
|
302
|
+
```bash
|
|
303
|
+
npm run build
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
2. **Configure npm for GitHub Packages:**
|
|
307
|
+
```bash
|
|
308
|
+
npm config set @makana-cl:registry https://npm.pkg.github.com
|
|
309
|
+
npm config set //npm.pkg.github.com/:_authToken YOUR_GITHUB_TOKEN
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
3. **Publish:**
|
|
313
|
+
```bash
|
|
314
|
+
npm publish
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
### Versioning
|
|
318
|
+
|
|
319
|
+
Follow [Semantic Versioning](https://semver.org/):
|
|
320
|
+
- **MAJOR** (1.0.0): Breaking changes
|
|
321
|
+
- **MINOR** (0.1.0): New features, backward compatible
|
|
322
|
+
- **PATCH** (0.0.1): Bug fixes, backward compatible
|
|
323
|
+
|
|
324
|
+
Update version in `package.json` before publishing:
|
|
325
|
+
|
|
326
|
+
```bash
|
|
327
|
+
npm version patch # 1.0.0 -> 1.0.1
|
|
328
|
+
npm version minor # 1.0.0 -> 1.1.0
|
|
329
|
+
npm version major # 1.0.0 -> 2.0.0
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
## Installing in Other Projects
|
|
333
|
+
|
|
334
|
+
### Step 1: Configure npm for GitHub Packages
|
|
335
|
+
|
|
336
|
+
In the project where you want to install the package, create or edit `.npmrc`:
|
|
337
|
+
|
|
338
|
+
```
|
|
339
|
+
@makana-cl:registry=https://npm.pkg.github.com
|
|
340
|
+
//npm.pkg.github.com/:_authToken=YOUR_GITHUB_TOKEN
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
**Important:** Add `.npmrc` to `.gitignore` to avoid committing your token!
|
|
344
|
+
|
|
345
|
+
### Step 2: Install the Package
|
|
346
|
+
|
|
347
|
+
```bash
|
|
348
|
+
npm install @makana-cl/portal-internal-client
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
Or specify a version:
|
|
352
|
+
|
|
353
|
+
```bash
|
|
354
|
+
npm install @makana-cl/portal-internal-client@1.0.0
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
### Step 3: Use in Your Code
|
|
358
|
+
|
|
359
|
+
```typescript
|
|
360
|
+
import { createMakanaClient, useGetUsers } from '@makana-cl/portal-internal-client';
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
## Troubleshooting
|
|
364
|
+
|
|
365
|
+
### Authentication Errors
|
|
366
|
+
|
|
367
|
+
If you get authentication errors:
|
|
368
|
+
|
|
369
|
+
1. Verify your GitHub token has `read:packages` scope
|
|
370
|
+
2. Check that `.npmrc` is configured correctly
|
|
371
|
+
3. Ensure the token is not expired
|
|
372
|
+
|
|
373
|
+
### Package Not Found
|
|
374
|
+
|
|
375
|
+
If npm can't find the package:
|
|
376
|
+
|
|
377
|
+
1. Verify the package name: `@makana-cl/portal-internal-client`
|
|
378
|
+
2. Check that the package has been published (check GitHub Packages)
|
|
379
|
+
3. Ensure your `.npmrc` points to the correct registry
|
|
380
|
+
|
|
381
|
+
### TypeScript Errors
|
|
382
|
+
|
|
383
|
+
If you get TypeScript errors:
|
|
384
|
+
|
|
385
|
+
1. Ensure you have `@apollo/client` and `react` installed as peer dependencies
|
|
386
|
+
2. Check that your TypeScript version is compatible (5.3+)
|
|
387
|
+
3. Try deleting `node_modules` and reinstalling
|
|
388
|
+
|
|
389
|
+
## Contributing
|
|
390
|
+
|
|
391
|
+
1. Make changes in the `src/` directory
|
|
392
|
+
2. Build and test locally: `npm run build`
|
|
393
|
+
3. Update version in `package.json`
|
|
394
|
+
4. Create a new tag: `git tag v1.0.1`
|
|
395
|
+
5. Push tag: `git push origin v1.0.1`
|
|
396
|
+
6. GitHub Actions will automatically publish
|
|
397
|
+
|
|
398
|
+
## License
|
|
399
|
+
|
|
400
|
+
UNLICENSED - Internal use only
|
|
401
|
+
|
|
402
|
+
## Support
|
|
403
|
+
|
|
404
|
+
For issues or questions, contact the Makana development team.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ApolloClient } from '@apollo/client';
|
|
2
|
+
export interface MakanaClientConfig {
|
|
3
|
+
apiUrl: string;
|
|
4
|
+
getToken: () => string | null | Promise<string | null>;
|
|
5
|
+
onError?: (error: Error) => void;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Creates a configured Apollo Client instance for Makana GraphQL API
|
|
9
|
+
*
|
|
10
|
+
* @param config - Configuration object
|
|
11
|
+
* @param config.apiUrl - The GraphQL API endpoint URL (e.g., 'https://api.makana.cl/graphql')
|
|
12
|
+
* @param config.getToken - Function that returns the JWT token for authentication
|
|
13
|
+
* @param config.onError - Optional error handler callback
|
|
14
|
+
* @returns Configured Apollo Client instance
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const client = createMakanaClient({
|
|
19
|
+
* apiUrl: 'https://api.makana.cl/graphql',
|
|
20
|
+
* getToken: () => localStorage.getItem('jwt_token')
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function createMakanaClient(config: MakanaClientConfig): ApolloClient<any>;
|
|
25
|
+
//# sourceMappingURL=apollo-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apollo-client.d.ts","sourceRoot":"","sources":["../../src/client/apollo-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAuC,MAAM,gBAAgB,CAAC;AAInF,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACvD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,kBAAkB,GAAG,YAAY,CAAC,GAAG,CAAC,CA2EhF"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createMakanaClient = createMakanaClient;
|
|
4
|
+
const client_1 = require("@apollo/client");
|
|
5
|
+
const context_1 = require("@apollo/client/link/context");
|
|
6
|
+
const error_1 = require("@apollo/client/link/error");
|
|
7
|
+
/**
|
|
8
|
+
* Creates a configured Apollo Client instance for Makana GraphQL API
|
|
9
|
+
*
|
|
10
|
+
* @param config - Configuration object
|
|
11
|
+
* @param config.apiUrl - The GraphQL API endpoint URL (e.g., 'https://api.makana.cl/graphql')
|
|
12
|
+
* @param config.getToken - Function that returns the JWT token for authentication
|
|
13
|
+
* @param config.onError - Optional error handler callback
|
|
14
|
+
* @returns Configured Apollo Client instance
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const client = createMakanaClient({
|
|
19
|
+
* apiUrl: 'https://api.makana.cl/graphql',
|
|
20
|
+
* getToken: () => localStorage.getItem('jwt_token')
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
function createMakanaClient(config) {
|
|
25
|
+
const httpLink = (0, client_1.createHttpLink)({
|
|
26
|
+
uri: config.apiUrl,
|
|
27
|
+
});
|
|
28
|
+
const authLink = (0, context_1.setContext)(async (_, { headers }) => {
|
|
29
|
+
const token = await config.getToken();
|
|
30
|
+
return {
|
|
31
|
+
headers: {
|
|
32
|
+
...headers,
|
|
33
|
+
authorization: token ? `Bearer ${token}` : '',
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
const errorLink = (0, error_1.onError)(({ graphQLErrors, networkError, operation, forward }) => {
|
|
38
|
+
if (graphQLErrors) {
|
|
39
|
+
graphQLErrors.forEach(({ message, locations, path }) => {
|
|
40
|
+
console.error(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`);
|
|
41
|
+
if (config.onError) {
|
|
42
|
+
config.onError(new Error(message));
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
if (networkError) {
|
|
47
|
+
console.error(`[Network error]: ${networkError}`);
|
|
48
|
+
if (config.onError) {
|
|
49
|
+
config.onError(networkError);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
return new client_1.ApolloClient({
|
|
54
|
+
link: (0, client_1.from)([errorLink, authLink, httpLink]),
|
|
55
|
+
cache: new client_1.InMemoryCache({
|
|
56
|
+
typePolicies: {
|
|
57
|
+
Query: {
|
|
58
|
+
fields: {
|
|
59
|
+
fetchUsers: {
|
|
60
|
+
keyArgs: ['filters', 'sort'],
|
|
61
|
+
merge(existing, incoming) {
|
|
62
|
+
return incoming;
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
fetchBusinesses: {
|
|
66
|
+
keyArgs: ['filters'],
|
|
67
|
+
merge(existing, incoming) {
|
|
68
|
+
return incoming;
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
searchBusinesses: {
|
|
72
|
+
keyArgs: ['searchTerm', 'sort', 'fromDate', 'toDate'],
|
|
73
|
+
merge(existing, incoming) {
|
|
74
|
+
return incoming;
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
}),
|
|
81
|
+
defaultOptions: {
|
|
82
|
+
watchQuery: {
|
|
83
|
+
fetchPolicy: 'cache-first',
|
|
84
|
+
errorPolicy: 'all',
|
|
85
|
+
},
|
|
86
|
+
query: {
|
|
87
|
+
fetchPolicy: 'cache-first',
|
|
88
|
+
errorPolicy: 'all',
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=apollo-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apollo-client.js","sourceRoot":"","sources":["../../src/client/apollo-client.ts"],"names":[],"mappings":";;AA2BA,gDA2EC;AAtGD,2CAAmF;AACnF,yDAAyD;AACzD,qDAAoD;AAQpD;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,kBAAkB,CAAC,MAA0B;IAC3D,MAAM,QAAQ,GAAG,IAAA,uBAAc,EAAC;QAC9B,GAAG,EAAE,MAAM,CAAC,MAAM;KACnB,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,IAAA,oBAAU,EAAC,KAAK,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;QACnD,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,QAAQ,EAAE,CAAC;QAEtC,OAAO;YACL,OAAO,EAAE;gBACP,GAAG,OAAO;gBACV,aAAa,EAAE,KAAK,CAAC,CAAC,CAAC,UAAU,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE;aAC9C;SACF,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,IAAA,eAAO,EAAC,CAAC,EAAE,aAAa,EAAE,YAAY,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE,EAAE;QAChF,IAAI,aAAa,EAAE,CAAC;YAClB,aAAa,CAAC,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE;gBACrD,OAAO,CAAC,KAAK,CACX,6BAA6B,OAAO,eAAe,SAAS,WAAW,IAAI,EA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L,WAAW,EAAE,aAAa;gBAC1B,WAAW,EAAE,KAAK;aACnB;SACF;KACF,CAAC,CAAC;AACL,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @makana-cl/portal-internal-client
|
|
3
|
+
*
|
|
4
|
+
* GraphQL client library for Makana Portal internal applications.
|
|
5
|
+
* Provides React hooks and Apollo Client setup for querying Makana GraphQL API.
|
|
6
|
+
*/
|
|
7
|
+
export { createMakanaClient } from './client/apollo-client';
|
|
8
|
+
export type { MakanaClientConfig } from './client/apollo-client';
|
|
9
|
+
export { useGetUsers } from './queries/users';
|
|
10
|
+
export type { FetchUsersVariables, FetchUsersResponse } from './queries/users';
|
|
11
|
+
export { useGetUsersLight } from './queries/usersLight';
|
|
12
|
+
export type { FetchUsersLightVariables, FetchUsersLightResponse, UserLightNode } from './queries/usersLight';
|
|
13
|
+
export { useGetBusinesses } from './queries/businesses';
|
|
14
|
+
export type { FetchBusinessesResponse } from './queries/businesses';
|
|
15
|
+
export { useSearchBusinesses } from './queries/searchBusinesses';
|
|
16
|
+
export type { SearchBusinessesVariables, SearchBusinessesResponse } from './queries/searchBusinesses';
|
|
17
|
+
export { GET_USERS } from './queries/users';
|
|
18
|
+
export { GET_USERS_LIGHT } from './queries/usersLight';
|
|
19
|
+
export { GET_BUSINESSES } from './queries/businesses';
|
|
20
|
+
export { SEARCH_BUSINESSES } from './queries/searchBusinesses';
|
|
21
|
+
export * from './types';
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,YAAY,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAGjE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,YAAY,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAE/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,YAAY,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE7G,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,YAAY,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAEpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,YAAY,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAGtG,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAG/D,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ApolloClient } from '@apollo/client';
|
|
2
|
+
export interface MakanaClientConfig {
|
|
3
|
+
apiUrl: string;
|
|
4
|
+
getToken: () => string | null | Promise<string | null>;
|
|
5
|
+
onError?: (error: Error) => void;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Creates a configured Apollo Client instance for Makana GraphQL API
|
|
9
|
+
*
|
|
10
|
+
* @param config - Configuration object
|
|
11
|
+
* @param config.apiUrl - The GraphQL API endpoint URL (e.g., 'https://api.makana.cl/graphql')
|
|
12
|
+
* @param config.getToken - Function that returns the JWT token for authentication
|
|
13
|
+
* @param config.onError - Optional error handler callback
|
|
14
|
+
* @returns Configured Apollo Client instance
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const client = createMakanaClient({
|
|
19
|
+
* apiUrl: 'https://api.makana.cl/graphql',
|
|
20
|
+
* getToken: () => localStorage.getItem('jwt_token')
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function createMakanaClient(config: MakanaClientConfig): ApolloClient<any>;
|
|
25
|
+
//# sourceMappingURL=apollo-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apollo-client.d.ts","sourceRoot":"","sources":["../../../src/client/apollo-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAuC,MAAM,gBAAgB,CAAC;AAInF,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACvD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,kBAAkB,GAAG,YAAY,CAAC,GAAG,CAAC,CA2EhF"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { ApolloClient, InMemoryCache, createHttpLink, from } from '@apollo/client';
|
|
2
|
+
import { setContext } from '@apollo/client/link/context';
|
|
3
|
+
import { onError } from '@apollo/client/link/error';
|
|
4
|
+
/**
|
|
5
|
+
* Creates a configured Apollo Client instance for Makana GraphQL API
|
|
6
|
+
*
|
|
7
|
+
* @param config - Configuration object
|
|
8
|
+
* @param config.apiUrl - The GraphQL API endpoint URL (e.g., 'https://api.makana.cl/graphql')
|
|
9
|
+
* @param config.getToken - Function that returns the JWT token for authentication
|
|
10
|
+
* @param config.onError - Optional error handler callback
|
|
11
|
+
* @returns Configured Apollo Client instance
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const client = createMakanaClient({
|
|
16
|
+
* apiUrl: 'https://api.makana.cl/graphql',
|
|
17
|
+
* getToken: () => localStorage.getItem('jwt_token')
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export function createMakanaClient(config) {
|
|
22
|
+
const httpLink = createHttpLink({
|
|
23
|
+
uri: config.apiUrl,
|
|
24
|
+
});
|
|
25
|
+
const authLink = setContext(async (_, { headers }) => {
|
|
26
|
+
const token = await config.getToken();
|
|
27
|
+
return {
|
|
28
|
+
headers: {
|
|
29
|
+
...headers,
|
|
30
|
+
authorization: token ? `Bearer ${token}` : '',
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
const errorLink = onError(({ graphQLErrors, networkError, operation, forward }) => {
|
|
35
|
+
if (graphQLErrors) {
|
|
36
|
+
graphQLErrors.forEach(({ message, locations, path }) => {
|
|
37
|
+
console.error(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`);
|
|
38
|
+
if (config.onError) {
|
|
39
|
+
config.onError(new Error(message));
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
if (networkError) {
|
|
44
|
+
console.error(`[Network error]: ${networkError}`);
|
|
45
|
+
if (config.onError) {
|
|
46
|
+
config.onError(networkError);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
return new ApolloClient({
|
|
51
|
+
link: from([errorLink, authLink, httpLink]),
|
|
52
|
+
cache: new InMemoryCache({
|
|
53
|
+
typePolicies: {
|
|
54
|
+
Query: {
|
|
55
|
+
fields: {
|
|
56
|
+
fetchUsers: {
|
|
57
|
+
keyArgs: ['filters', 'sort'],
|
|
58
|
+
merge(existing, incoming) {
|
|
59
|
+
return incoming;
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
fetchBusinesses: {
|
|
63
|
+
keyArgs: ['filters'],
|
|
64
|
+
merge(existing, incoming) {
|
|
65
|
+
return incoming;
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
searchBusinesses: {
|
|
69
|
+
keyArgs: ['searchTerm', 'sort', 'fromDate', 'toDate'],
|
|
70
|
+
merge(existing, incoming) {
|
|
71
|
+
return incoming;
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
}),
|
|
78
|
+
defaultOptions: {
|
|
79
|
+
watchQuery: {
|
|
80
|
+
fetchPolicy: 'cache-first',
|
|
81
|
+
errorPolicy: 'all',
|
|
82
|
+
},
|
|
83
|
+
query: {
|
|
84
|
+
fetchPolicy: 'cache-first',
|
|
85
|
+
errorPolicy: 'all',
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=apollo-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apollo-client.js","sourceRoot":"","sources":["../../../src/client/apollo-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACnF,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAQpD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAA0B;IAC3D,MAAM,QAAQ,GAAG,cAAc,CAAC;QAC9B,GAAG,EAAE,MAAM,CAAC,MAAM;KACnB,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,UAAU,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;QACnD,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,QAAQ,EAAE,CAAC;QAEtC,OAAO;YACL,OAAO,EAAE;gBACP,GAAG,OAAO;gBACV,aAAa,EAAE,KAAK,CAAC,CAAC,CAAC,UAAU,KAAK,EAAE,CAAC,CAAC,CAAC,E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