@bluecopa/react 0.1.3 → 0.1.4
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 +530 -125
- package/dist/{COOQDZLH-Ddkg5gQi.js → COOQDZLH-vTaS9Cbn.js} +2 -2
- package/dist/{MU7WGUJF-Cztn6X5s.js → MU7WGUJF-S8eWbvlS.js} +2 -2
- package/dist/{VREWMQAW-MNJLwgkh.js → VREWMQAW-Cr9gkBCt.js} +1 -1
- package/dist/hooks/useDataset.d.ts +4 -0
- package/dist/hooks/useDataset.d.ts.map +1 -1
- package/dist/hooks/useGetFileUrlByFileId.d.ts +12 -0
- package/dist/hooks/useGetFileUrlByFileId.d.ts.map +1 -0
- package/dist/hooks/useGetPublishedWorkbookById.d.ts +11 -0
- package/dist/hooks/useGetPublishedWorkbookById.d.ts.map +1 -0
- package/dist/hooks/useGetTableById.d.ts +10 -0
- package/dist/hooks/useGetTableById.d.ts.map +1 -0
- package/dist/hooks/useGetWorkbooksByType.d.ts +10 -0
- package/dist/hooks/useGetWorkbooksByType.d.ts.map +1 -0
- package/dist/hooks/useGetWorkflowInstanceStatusById.d.ts +11 -0
- package/dist/hooks/useGetWorkflowInstanceStatusById.d.ts.map +1 -0
- package/dist/hooks/useGetWorksheets.d.ts +10 -0
- package/dist/hooks/useGetWorksheets.d.ts.map +1 -0
- package/dist/hooks/useGetWorksheetsByType.d.ts +10 -0
- package/dist/hooks/useGetWorksheetsByType.d.ts.map +1 -0
- package/dist/hooks/useInputTable.d.ts +4 -0
- package/dist/hooks/useInputTable.d.ts.map +1 -1
- package/dist/hooks/useTriggerHttpWorkflow.d.ts +11 -0
- package/dist/hooks/useTriggerHttpWorkflow.d.ts.map +1 -0
- package/dist/hooks/useTriggerWorkflow.d.ts +11 -0
- package/dist/hooks/useTriggerWorkflow.d.ts.map +1 -0
- package/dist/hooks/useWorkbook.d.ts +8 -0
- package/dist/hooks/useWorkbook.d.ts.map +1 -0
- package/dist/hooks/useWorkflow.d.ts +7 -0
- package/dist/hooks/useWorkflow.d.ts.map +1 -0
- package/dist/hooks/useWorksheet.d.ts +8 -0
- package/dist/hooks/useWorksheet.d.ts.map +1 -0
- package/dist/{index-4pvStUsJ.js → index-BBZbg2TO.js} +4329 -4237
- package/dist/index.es.js +9 -7
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,183 +1,583 @@
|
|
|
1
|
-
# @bluecopa/
|
|
2
|
-
|
|
3
|
-
A
|
|
1
|
+
# @bluecopa/react [](https://www.npmjs.com/package/@bluecopa/react) [](https://github.com/bluecopa/blui/blob/main/packages/react/LICENSE)
|
|
2
|
+
|
|
3
|
+
## A Comprehensive React Query Integration for Bluecopa
|
|
4
|
+
|
|
5
|
+
A React library providing opinionated custom hooks for TanStack React Query integration with Bluecopa core API. This package enables efficient data fetching, caching, and synchronization with the Bluecopa platform while maintaining type safety and developer experience.
|
|
6
|
+
|
|
7
|
+
## Table of Contents
|
|
8
|
+
|
|
9
|
+
1. [Features](#features)
|
|
10
|
+
2. [Installation](#installation)
|
|
11
|
+
3. [Usage](#usage)
|
|
12
|
+
- [Query Provider Setup](#query-provider-setup)
|
|
13
|
+
- [Boilerplate Integration](#boilerplate-integration)
|
|
14
|
+
- [Hook Examples](#hook-examples)
|
|
15
|
+
4. [API Documentation](#api-documentation)
|
|
16
|
+
- [`useUser`](#useuser)
|
|
17
|
+
- [`useDataset`](#usedataset)
|
|
18
|
+
- [`useDatasetSample`](#usedatasetsample)
|
|
19
|
+
- [`useMetric`](#usemetric)
|
|
20
|
+
- [`useInputTable`](#useinputtable)
|
|
21
|
+
- [`useGetFileUrlByFileId`](#usegetfileurlbyfileid)
|
|
22
|
+
- [`useGetPublishedWorkbookById`](#usegetpublishedworkbookbyid)
|
|
23
|
+
- [`useGetTableById`](#usegettablebyid)
|
|
24
|
+
- [`useGetWorkbooksByType`](#usegetworkbooksbytype)
|
|
25
|
+
- [`useGetWorkflowInstanceStatusById`](#usegetworkflowinstancestatusbyid)
|
|
26
|
+
- [`useGetWorksheets`](#usegetworksheets)
|
|
27
|
+
- [`useGetWorksheetsByType`](#usegetworksheetsbytype)
|
|
28
|
+
- [`useRunDefinition`](#userundefinition)
|
|
29
|
+
- [`useRunPublishedDefinition`](#userunpublisheddefinition)
|
|
30
|
+
- [`useRunSampleDefinition`](#userunsampledefinition)
|
|
31
|
+
- [`useTriggerHttpWorkflow`](#usetriggerhttpworkflow)
|
|
32
|
+
- [`useTriggerWorkflow`](#usetriggerworkflow)
|
|
33
|
+
- [`useWorkbook`](#useworkbook)
|
|
34
|
+
- [`useWorkflow`](#useworkflow)
|
|
35
|
+
- [`useWorksheet`](#useworksheet)
|
|
36
|
+
5. [Configuration](#configuration)
|
|
37
|
+
6. [TypeScript Support](#typescript-support)
|
|
38
|
+
7. [Development](#development)
|
|
39
|
+
8. [Contributing](#contributing)
|
|
40
|
+
9. [License](#license)
|
|
41
|
+
|
|
42
|
+
## Features
|
|
43
|
+
|
|
44
|
+
- ✅ First-class TypeScript support with strict type definitions
|
|
45
|
+
- 🔁 Seamless integration with TanStack React Query (v5+)
|
|
46
|
+
- 🛡 Comprehensive error handling patterns
|
|
47
|
+
- ⚙ Optimized default query configuration
|
|
48
|
+
- 📦 Re-exports of core TanStack React Query utilities
|
|
49
|
+
- 📊 Sample data preview capabilities
|
|
50
|
+
- 🧩 Customizable query parameters (limit, caching, retries)
|
|
4
51
|
|
|
5
52
|
## Installation
|
|
6
53
|
|
|
7
54
|
```bash
|
|
8
|
-
npm install @bluecopa/
|
|
55
|
+
npm install @bluecopa/react
|
|
56
|
+
# or with pnpm
|
|
57
|
+
pnpm add @bluecopa/react
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Peer Dependencies
|
|
61
|
+
|
|
62
|
+
This package requires the following in your application:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
npm install react@^18.0.0 react-dom@^18.0.0
|
|
9
66
|
```
|
|
10
67
|
|
|
11
68
|
## Usage
|
|
12
69
|
|
|
13
|
-
###
|
|
70
|
+
### Query Provider Setup
|
|
14
71
|
|
|
15
|
-
Wrap your
|
|
72
|
+
Wrap your application with the React Query provider:
|
|
16
73
|
|
|
17
74
|
```tsx
|
|
18
|
-
import
|
|
19
|
-
import { BlueCopaQueryProvider } from '@bluecopa/reactjs';
|
|
20
|
-
import { ApiClient } from '@bluecopa/core';
|
|
75
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
21
76
|
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
77
|
+
const queryClient = new QueryClient({
|
|
78
|
+
defaultOptions: {
|
|
79
|
+
queries: {
|
|
80
|
+
staleTime: 60 * 1000, // 1 minute
|
|
81
|
+
refetchOnWindowFocus: false,
|
|
82
|
+
},
|
|
83
|
+
},
|
|
25
84
|
});
|
|
26
85
|
|
|
27
86
|
function App() {
|
|
28
87
|
return (
|
|
29
|
-
<
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
defaultCacheTime: 10 * 60 * 1000, // 10 minutes
|
|
34
|
-
enableDevtools: true,
|
|
35
|
-
}}
|
|
36
|
-
>
|
|
37
|
-
<YourAppComponents />
|
|
38
|
-
</BlueCopaQueryProvider>
|
|
88
|
+
<QueryClientProvider client={queryClient}>
|
|
89
|
+
<YourApp />
|
|
90
|
+
<ReactQueryDevtools initialIsOpen={false} />
|
|
91
|
+
</QueryClientProvider>
|
|
39
92
|
);
|
|
40
93
|
}
|
|
41
94
|
```
|
|
42
95
|
|
|
43
|
-
###
|
|
96
|
+
### Boilerplate Integration
|
|
97
|
+
|
|
98
|
+
For projects using the Bluecopa React boilerplate, use the pre-configured `QueryProvider` component that handles API configuration automatically:
|
|
44
99
|
|
|
45
100
|
```tsx
|
|
46
|
-
|
|
47
|
-
import {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
101
|
+
// src/providers/query-provider.tsx
|
|
102
|
+
import { ReactQueryDevtools, reactQuery, copaSetConfig } from "@bluecopa/react";
|
|
103
|
+
import { useEffect, useState } from "react";
|
|
104
|
+
|
|
105
|
+
const { QueryClient, QueryClientProvider } = reactQuery;
|
|
106
|
+
|
|
107
|
+
export default function QueryProvider({ children }: { children: React.ReactNode }) {
|
|
108
|
+
const [queryClient] = useState(() => new QueryClient({
|
|
109
|
+
defaultOptions: {
|
|
110
|
+
queries: {
|
|
111
|
+
staleTime: 60 * 1000, // 1 minute
|
|
112
|
+
refetchOnWindowFocus: false,
|
|
113
|
+
},
|
|
54
114
|
},
|
|
55
|
-
|
|
56
|
-
|
|
115
|
+
}));
|
|
116
|
+
|
|
117
|
+
useEffect(() => {
|
|
118
|
+
let copaUser: any = {};
|
|
119
|
+
try {
|
|
120
|
+
const copaToken = import.meta.env.VITE_BLUECOPA_API_TOKEN
|
|
121
|
+
? atob(import.meta.env.VITE_BLUECOPA_API_TOKEN)
|
|
122
|
+
: "{}";
|
|
123
|
+
|
|
124
|
+
copaUser = JSON.parse(copaToken);
|
|
125
|
+
} catch (error) {
|
|
126
|
+
console.warn("Failed to parse VITE_BLUECOPA_API_TOKEN:", error);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
copaSetConfig({
|
|
130
|
+
apiBaseUrl: import.meta.env.VITE_BLUECOPA_API_URL || "https://develop.bluecopa.com/api/v1",
|
|
131
|
+
workspaceId: import.meta.env.VITE_BLUECOPA_WORKSPACE_ID || "",
|
|
132
|
+
accessToken: copaUser?.accessToken || "",
|
|
133
|
+
});
|
|
134
|
+
}, []);
|
|
57
135
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
136
|
+
return (
|
|
137
|
+
<QueryClientProvider client={queryClient}>
|
|
138
|
+
{children}
|
|
139
|
+
<ReactQueryDevtools initialIsOpen={false} />
|
|
140
|
+
</QueryClientProvider>
|
|
141
|
+
);
|
|
62
142
|
}
|
|
63
143
|
```
|
|
64
144
|
|
|
65
|
-
|
|
145
|
+
**Required Environment Variables:**
|
|
66
146
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
147
|
+
| Variable | Description | Example |
|
|
148
|
+
|----------|-------------|---------|
|
|
149
|
+
| `VITE_BLUECOPA_API_URL` | Base URL for Bluecopa API | `https://api.bluecopa.com` |
|
|
150
|
+
| `VITE_BLUECOPA_WORKSPACE_ID` | Your workspace identifier | `my-workspace-123` |
|
|
151
|
+
| `VITE_BLUECOPA_API_TOKEN` | Base64-encoded JSON string containing `accessToken` | `eyJhY2Nlc3NUb2tlbiI6IjEyMzQ1In0=` |
|
|
70
152
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
console.error('Failed to create user:', error);
|
|
78
|
-
},
|
|
79
|
-
});
|
|
153
|
+
**Example `.env` file:**
|
|
154
|
+
```
|
|
155
|
+
VITE_BLUECOPA_API_URL=https://api.bluecopa.com
|
|
156
|
+
VITE_BLUECOPA_WORKSPACE_ID=your-workspace-id
|
|
157
|
+
VITE_BLUECOPA_API_TOKEN=base64-encoded-json-here
|
|
158
|
+
```
|
|
80
159
|
|
|
81
|
-
|
|
82
|
-
createUser.mutate(userData);
|
|
83
|
-
};
|
|
160
|
+
Then wrap your application with this provider:
|
|
84
161
|
|
|
162
|
+
```tsx
|
|
163
|
+
import QueryProvider from './providers/query-provider';
|
|
164
|
+
|
|
165
|
+
function App() {
|
|
85
166
|
return (
|
|
86
|
-
<
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
type="submit"
|
|
90
|
-
disabled={createUser.isPending}
|
|
91
|
-
>
|
|
92
|
-
{createUser.isPending ? 'Creating...' : 'Create User'}
|
|
93
|
-
</button>
|
|
94
|
-
</form>
|
|
167
|
+
<QueryProvider>
|
|
168
|
+
<YourApp />
|
|
169
|
+
</QueryProvider>
|
|
95
170
|
);
|
|
96
171
|
}
|
|
97
172
|
```
|
|
98
173
|
|
|
99
|
-
|
|
174
|
+
This setup automatically configures the API client with your environment-specific settings and applies optimal caching defaults.
|
|
175
|
+
|
|
176
|
+
### Hook Examples
|
|
177
|
+
|
|
178
|
+
#### `useUser` - Fetch authenticated user
|
|
100
179
|
|
|
101
180
|
```tsx
|
|
102
|
-
import
|
|
103
|
-
import { useInfiniteQuery } from '@bluecopa/reactjs';
|
|
104
|
-
|
|
105
|
-
function UserList() {
|
|
106
|
-
const {
|
|
107
|
-
data,
|
|
108
|
-
fetchNextPage,
|
|
109
|
-
hasNextPage,
|
|
110
|
-
isFetchingNextPage,
|
|
111
|
-
isLoading,
|
|
112
|
-
} = useInfiniteQuery({
|
|
113
|
-
queryKey: {
|
|
114
|
-
scope: 'users',
|
|
115
|
-
endpoint: '/users',
|
|
116
|
-
params: { limit: 10 },
|
|
117
|
-
},
|
|
118
|
-
getNextPageParam: (lastPage) => lastPage.nextPage,
|
|
119
|
-
});
|
|
181
|
+
import { useUser } from '@bluecopa/react';
|
|
120
182
|
|
|
183
|
+
function UserProfile() {
|
|
184
|
+
const { data, isLoading, error } = useUser({
|
|
185
|
+
staleTime: 5 * 60 * 1000, // 5 minutes
|
|
186
|
+
retry: 2
|
|
187
|
+
});
|
|
188
|
+
|
|
121
189
|
if (isLoading) return <div>Loading...</div>;
|
|
190
|
+
if (error) return <div>Error: {error.message}</div>;
|
|
191
|
+
|
|
192
|
+
return <div>Welcome, {data?.name}!</div>;
|
|
193
|
+
}
|
|
194
|
+
```
|
|
122
195
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
>
|
|
137
|
-
{isFetchingNextPage ? 'Loading more...' : 'Load More'}
|
|
138
|
-
</button>
|
|
139
|
-
)}
|
|
140
|
-
</div>
|
|
141
|
-
);
|
|
196
|
+
#### `useDataset` - Fetch dataset with query controls
|
|
197
|
+
|
|
198
|
+
```tsx
|
|
199
|
+
import { useDataset } from '@bluecopa/react';
|
|
200
|
+
|
|
201
|
+
function DatasetViewer({ datasetId }) {
|
|
202
|
+
const { data, isLoading } = useDataset(datasetId, {
|
|
203
|
+
limit: 500,
|
|
204
|
+
staleTime: 10 * 60 * 1000 // 10 minutes
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
if (isLoading) return <div>Loading dataset...</div>;
|
|
208
|
+
return <div>{data?.name} ({data?.records?.length} records)</div>;
|
|
142
209
|
}
|
|
143
210
|
```
|
|
144
211
|
|
|
145
|
-
## API
|
|
212
|
+
## API Documentation
|
|
213
|
+
|
|
214
|
+
### `useUser(options?)`
|
|
215
|
+
|
|
216
|
+
Fetches authenticated user details with query controls.
|
|
217
|
+
|
|
218
|
+
**Parameters:**
|
|
219
|
+
- `options` (optional): Query options extending TanStack React Query's `UseQueryOptions`
|
|
220
|
+
|
|
221
|
+
**Returns:**
|
|
222
|
+
- `data`: User object or `undefined`
|
|
223
|
+
- `isLoading`: Boolean indicating loading state
|
|
224
|
+
- `error`: Error object if request failed
|
|
225
|
+
- `refetch`: Function to manually trigger refetch
|
|
226
|
+
|
|
227
|
+
### `useDataset(datasetId, options?)`
|
|
228
|
+
|
|
229
|
+
Fetches dataset data by ID with configurable parameters.
|
|
230
|
+
|
|
231
|
+
**Parameters:**
|
|
232
|
+
- `datasetId`: ID of the dataset to fetch
|
|
233
|
+
- `options` (optional): Query options with:
|
|
234
|
+
- `limit`: Maximum records to fetch
|
|
235
|
+
- `staleTime`: Duration (ms) before data is considered stale
|
|
236
|
+
|
|
237
|
+
**Returns:**
|
|
238
|
+
- `data`: Dataset object containing name and records
|
|
239
|
+
- `isLoading`: Boolean indicating loading state
|
|
240
|
+
- `error`: Error object if request failed
|
|
241
|
+
- `refetch`: Function to manually trigger refetch
|
|
242
|
+
|
|
243
|
+
### `useDatasetSample(datasetId, options?)`
|
|
244
|
+
|
|
245
|
+
Fetches a representative sample of dataset data.
|
|
246
|
+
|
|
247
|
+
**Parameters:**
|
|
248
|
+
- `datasetId`: ID of the dataset
|
|
249
|
+
- `options` (optional): Query options with `enabled` flag
|
|
250
|
+
|
|
251
|
+
**Returns:**
|
|
252
|
+
- `data`: Object containing sample data
|
|
253
|
+
- `isLoading`: Boolean indicating loading state
|
|
254
|
+
- `refetch`: Function to manually trigger refetch
|
|
255
|
+
|
|
256
|
+
### `useMetric(metricId, options?)`
|
|
257
|
+
|
|
258
|
+
Fetches metric data by ID.
|
|
259
|
+
|
|
260
|
+
**Parameters:**
|
|
261
|
+
- `metricId`: ID of the metric
|
|
262
|
+
- `options` (optional): Query options
|
|
263
|
+
|
|
264
|
+
**Returns:**
|
|
265
|
+
- `data`: Metric object with name and value
|
|
266
|
+
- `isLoading`: Boolean indicating loading state
|
|
267
|
+
- `error`: Error object if request failed
|
|
268
|
+
- `refetch`: Function to manually trigger refetch
|
|
269
|
+
|
|
270
|
+
### `useInputTable(inputTableId, options?)`
|
|
271
|
+
|
|
272
|
+
Fetches input table data with limit parameters.
|
|
273
|
+
|
|
274
|
+
**Parameters:**
|
|
275
|
+
- `inputTableId`: ID of the input table
|
|
276
|
+
- `options` (optional): Query options with `limitParams`:
|
|
277
|
+
- `limit`: Maximum rows to fetch
|
|
278
|
+
- `limitFrom`: Direction to apply limit from ('top' or 'bottom')
|
|
279
|
+
|
|
280
|
+
**Returns:**
|
|
281
|
+
- `data`: Input table object with rows
|
|
282
|
+
- `isLoading`: Boolean indicating loading state
|
|
283
|
+
- `error`: Error object if request failed
|
|
284
|
+
- `refetch`: Function to manually trigger refetch
|
|
285
|
+
|
|
286
|
+
### `useGetFileUrlByFileId(fileId, options?)`
|
|
287
|
+
|
|
288
|
+
Fetches the URL for a file by its ID.
|
|
289
|
+
|
|
290
|
+
**Parameters:**
|
|
291
|
+
- `fileId`: ID of the file to fetch URL for
|
|
292
|
+
- `options` (optional): Query options extending TanStack React Query's `UseQueryOptions`
|
|
293
|
+
|
|
294
|
+
**Returns:**
|
|
295
|
+
- `data`: Object containing file URL
|
|
296
|
+
- `isLoading`: Boolean indicating loading state
|
|
297
|
+
- `error`: Error object if request failed
|
|
298
|
+
- `refetch`: Function to manually trigger refetch
|
|
299
|
+
|
|
300
|
+
### `useGetPublishedWorkbookById(workbookId, options?)`
|
|
301
|
+
|
|
302
|
+
Fetches published workbook details by ID.
|
|
303
|
+
|
|
304
|
+
**Parameters:**
|
|
305
|
+
- `workbookId`: ID of the published workbook
|
|
306
|
+
- `options` (optional): Query options
|
|
307
|
+
|
|
308
|
+
**Returns:**
|
|
309
|
+
- `data`: Published workbook object
|
|
310
|
+
- `isLoading`: Boolean indicating loading state
|
|
311
|
+
- `error`: Error object if request failed
|
|
312
|
+
- `refetch`: Function to manually trigger refetch
|
|
313
|
+
|
|
314
|
+
### `useGetTableById(tableId, options?)`
|
|
315
|
+
|
|
316
|
+
Fetches table metadata by ID.
|
|
317
|
+
|
|
318
|
+
**Parameters:**
|
|
319
|
+
- `tableId`: ID of the table
|
|
320
|
+
- `options` (optional): Query options
|
|
321
|
+
|
|
322
|
+
**Returns:**
|
|
323
|
+
- `data`: Table metadata object
|
|
324
|
+
- `isLoading`: Boolean indicating loading state
|
|
325
|
+
- `error`: Error object if request failed
|
|
326
|
+
- `refetch`: Function to manually trigger refetch
|
|
327
|
+
|
|
328
|
+
### `useGetWorkbooksByType(workbookType, options?)`
|
|
329
|
+
|
|
330
|
+
Fetches workbooks filtered by type.
|
|
331
|
+
|
|
332
|
+
**Parameters:**
|
|
333
|
+
- `workbookType`: Type of workbooks to fetch
|
|
334
|
+
- `options` (optional): Query options
|
|
335
|
+
|
|
336
|
+
**Returns:**
|
|
337
|
+
- `data`: Array of workbook objects
|
|
338
|
+
- `isLoading`: Boolean indicating loading state
|
|
339
|
+
- `error`: Error object if request failed
|
|
340
|
+
- `refetch`: Function to manually trigger refetch
|
|
341
|
+
|
|
342
|
+
### `useGetWorkflowInstanceStatusById(instanceId, options?)`
|
|
343
|
+
|
|
344
|
+
Fetches workflow instance status by ID.
|
|
345
|
+
|
|
346
|
+
**Parameters:**
|
|
347
|
+
- `instanceId`: ID of the workflow instance
|
|
348
|
+
- `options` (optional): Query options
|
|
349
|
+
|
|
350
|
+
**Returns:**
|
|
351
|
+
- `data`: Workflow status object
|
|
352
|
+
- `isLoading`: Boolean indicating loading state
|
|
353
|
+
- `error`: Error object if request failed
|
|
354
|
+
- `refetch`: Function to manually trigger refetch
|
|
355
|
+
|
|
356
|
+
### `useGetWorksheets(options?)`
|
|
357
|
+
|
|
358
|
+
Fetches all available worksheets.
|
|
359
|
+
|
|
360
|
+
**Parameters:**
|
|
361
|
+
- `options` (optional): Query options
|
|
362
|
+
|
|
363
|
+
**Returns:**
|
|
364
|
+
- `data`: Array of worksheet objects
|
|
365
|
+
- `isLoading`: Boolean indicating loading state
|
|
366
|
+
- `error`: Error object if request failed
|
|
367
|
+
- `refetch`: Function to manually trigger refetch
|
|
368
|
+
|
|
369
|
+
### `useGetWorksheetsByType(worksheetType, options?)`
|
|
370
|
+
|
|
371
|
+
Fetches worksheets filtered by type.
|
|
372
|
+
|
|
373
|
+
**Parameters:**
|
|
374
|
+
- `worksheetType`: Type of worksheets to fetch
|
|
375
|
+
- `options` (optional): Query options
|
|
376
|
+
|
|
377
|
+
**Returns:**
|
|
378
|
+
- `data`: Array of worksheet objects
|
|
379
|
+
- `isLoading`: Boolean indicating loading state
|
|
380
|
+
- `error`: Error object if request failed
|
|
381
|
+
- `refetch`: Function to manually trigger refetch
|
|
382
|
+
|
|
383
|
+
### `useRunDefinition(definitionId, options?)`
|
|
384
|
+
|
|
385
|
+
Executes a run definition.
|
|
386
|
+
|
|
387
|
+
**Parameters:**
|
|
388
|
+
- `definitionId`: ID of the run definition
|
|
389
|
+
- `options` (optional): Query options
|
|
390
|
+
|
|
391
|
+
**Returns:**
|
|
392
|
+
- `data`: Execution result
|
|
393
|
+
- `isLoading`: Boolean indicating loading state
|
|
394
|
+
- `error`: Error object if request failed
|
|
395
|
+
- `refetch`: Function to manually trigger refetch
|
|
396
|
+
|
|
397
|
+
### `useRunPublishedDefinition(publishedDefinitionId, options?)`
|
|
398
|
+
|
|
399
|
+
Executes a published run definition.
|
|
400
|
+
|
|
401
|
+
**Parameters:**
|
|
402
|
+
- `publishedDefinitionId`: ID of the published definition
|
|
403
|
+
- `options` (optional): Query options
|
|
404
|
+
|
|
405
|
+
**Returns:**
|
|
406
|
+
- `data`: Execution result
|
|
407
|
+
- `isLoading`: Boolean indicating loading state
|
|
408
|
+
- `error`: Error object if request failed
|
|
409
|
+
- `refetch`: Function to manually trigger refetch
|
|
410
|
+
|
|
411
|
+
### `useRunSampleDefinition(sampleDefinitionId, options?)`
|
|
412
|
+
|
|
413
|
+
Executes a sample run definition.
|
|
414
|
+
|
|
415
|
+
**Parameters:**
|
|
416
|
+
- `sampleDefinitionId`: ID of the sample definition
|
|
417
|
+
- `options` (optional): Query options
|
|
418
|
+
|
|
419
|
+
**Returns:**
|
|
420
|
+
- `data`: Sample execution result
|
|
421
|
+
- `isLoading`: Boolean indicating loading state
|
|
422
|
+
- `error`: Error object if request failed
|
|
423
|
+
- `refetch`: Function to manually trigger refetch
|
|
424
|
+
|
|
425
|
+
### `useTriggerHttpWorkflow(workflowId, payload, options?)`
|
|
426
|
+
|
|
427
|
+
Triggers an HTTP workflow execution.
|
|
428
|
+
|
|
429
|
+
**Parameters:**
|
|
430
|
+
- `workflowId`: ID of the workflow
|
|
431
|
+
- `payload`: Request payload
|
|
432
|
+
- `options` (optional): Query options
|
|
433
|
+
|
|
434
|
+
**Returns:**
|
|
435
|
+
- `data`: Workflow execution response
|
|
436
|
+
- `isLoading`: Boolean indicating loading state
|
|
437
|
+
- `error`: Error object if request failed
|
|
438
|
+
- `refetch`: Function to manually trigger refetch
|
|
439
|
+
|
|
440
|
+
### `useTriggerWorkflow(workflowId, options?)`
|
|
441
|
+
|
|
442
|
+
Triggers a workflow execution.
|
|
443
|
+
|
|
444
|
+
**Parameters:**
|
|
445
|
+
- `workflowId`: ID of the workflow
|
|
446
|
+
- `options` (optional): Query options
|
|
447
|
+
|
|
448
|
+
**Returns:**
|
|
449
|
+
- `data`: Workflow execution response
|
|
450
|
+
- `isLoading`: Boolean indicating loading state
|
|
451
|
+
- `error`: Error object if request failed
|
|
452
|
+
- `refetch`: Function to manually trigger refetch
|
|
453
|
+
|
|
454
|
+
### `useWorkbook(workbookId, options?)`
|
|
455
|
+
|
|
456
|
+
Fetches workbook details by ID.
|
|
457
|
+
|
|
458
|
+
**Parameters:**
|
|
459
|
+
- `workbookId`: ID of the workbook
|
|
460
|
+
- `options` (optional): Query options
|
|
461
|
+
|
|
462
|
+
**Returns:**
|
|
463
|
+
- `data`: Workbook object
|
|
464
|
+
- `isLoading`: Boolean indicating loading state
|
|
465
|
+
- `error`: Error object if request failed
|
|
466
|
+
- `refetch`: Function to manually trigger refetch
|
|
467
|
+
|
|
468
|
+
### `useWorkflow(workflowId, options?)`
|
|
469
|
+
|
|
470
|
+
Fetches workflow configuration by ID.
|
|
471
|
+
|
|
472
|
+
**Parameters:**
|
|
473
|
+
- `workflowId`: ID of the workflow
|
|
474
|
+
- `options` (optional): Query options
|
|
475
|
+
|
|
476
|
+
**Returns:**
|
|
477
|
+
- `data`: Workflow configuration object
|
|
478
|
+
- `isLoading`: Boolean indicating loading state
|
|
479
|
+
- `error`: Error object if request failed
|
|
480
|
+
- `refetch`: Function to manually trigger refetch
|
|
481
|
+
|
|
482
|
+
### `useWorksheet(worksheetId, options?)`
|
|
483
|
+
|
|
484
|
+
Fetches worksheet details by ID.
|
|
485
|
+
|
|
486
|
+
**Parameters:**
|
|
487
|
+
- `worksheetId`: ID of the worksheet
|
|
488
|
+
- `options` (optional): Query options
|
|
489
|
+
|
|
490
|
+
**Returns:**
|
|
491
|
+
- `data`: Worksheet object
|
|
492
|
+
- `isLoading`: Boolean indicating loading state
|
|
493
|
+
- `error`: Error object if request failed
|
|
494
|
+
- `refetch`: Function to manually trigger refetch
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
## Configuration
|
|
498
|
+
|
|
499
|
+
### Default Query Configuration
|
|
500
|
+
|
|
501
|
+
```tsx
|
|
502
|
+
const queryClient = new QueryClient({
|
|
503
|
+
defaultOptions: {
|
|
504
|
+
queries: {
|
|
505
|
+
retry: 3,
|
|
506
|
+
staleTime: 1000 * 60 * 5, // 5 minutes
|
|
507
|
+
gcTime: 1000 * 60 * 10, // 10 minutes
|
|
508
|
+
},
|
|
509
|
+
},
|
|
510
|
+
});
|
|
511
|
+
```
|
|
512
|
+
|
|
513
|
+
### Customizable Parameters
|
|
146
514
|
|
|
147
|
-
|
|
515
|
+
All hooks accept standard TanStack React Query options:
|
|
148
516
|
|
|
149
|
-
|
|
517
|
+
```ts
|
|
518
|
+
interface QueryOptions {
|
|
519
|
+
enabled?: boolean; // Enable/disable query
|
|
520
|
+
staleTime?: number; // Duration (ms) before data is stale
|
|
521
|
+
gcTime?: number; // Duration (ms) to keep data in cache
|
|
522
|
+
retry?: number | boolean; // Number of retries or disable retries
|
|
523
|
+
onSuccess?: (data: any) => void; // Success callback
|
|
524
|
+
onError?: (error: Error) => void; // Error callback
|
|
525
|
+
}
|
|
526
|
+
```
|
|
150
527
|
|
|
151
|
-
|
|
528
|
+
## Advanced Usage
|
|
152
529
|
|
|
153
|
-
|
|
530
|
+
### Error Handling
|
|
154
531
|
|
|
155
|
-
|
|
532
|
+
```tsx
|
|
533
|
+
useUser({
|
|
534
|
+
onError: (error) => {
|
|
535
|
+
console.error('User fetch failed:', error.message);
|
|
536
|
+
// Custom error recovery logic
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
```
|
|
540
|
+
|
|
541
|
+
### Manual Refetching
|
|
156
542
|
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
543
|
+
```tsx
|
|
544
|
+
function ManualRefetch() {
|
|
545
|
+
const { data, refetch } = useUser();
|
|
546
|
+
|
|
547
|
+
return (
|
|
548
|
+
<div>
|
|
549
|
+
<button onClick={() => refetch()}>Refresh</button>
|
|
550
|
+
</div>
|
|
551
|
+
);
|
|
165
552
|
}
|
|
166
553
|
```
|
|
167
554
|
|
|
168
|
-
|
|
555
|
+
## Re-exports
|
|
169
556
|
|
|
170
|
-
|
|
557
|
+
This package re-exports core TanStack React Query utilities:
|
|
171
558
|
|
|
172
|
-
|
|
559
|
+
```ts
|
|
560
|
+
import {
|
|
561
|
+
useQuery,
|
|
562
|
+
useMutation,
|
|
563
|
+
QueryClient,
|
|
564
|
+
QueryClientProvider,
|
|
565
|
+
ReactQueryDevtools
|
|
566
|
+
} from '@bluecopa/react';
|
|
567
|
+
```
|
|
173
568
|
|
|
174
|
-
|
|
569
|
+
## TypeScript Support
|
|
175
570
|
|
|
176
|
-
|
|
571
|
+
Fully typed with TypeScript. All hooks provide proper type inference and IntelliSense support. Extend types for custom use cases:
|
|
177
572
|
|
|
178
|
-
|
|
573
|
+
```ts
|
|
574
|
+
import { User } from '@bluecopa/react';
|
|
179
575
|
|
|
180
|
-
|
|
576
|
+
interface CustomUser extends User {
|
|
577
|
+
role: string;
|
|
578
|
+
permissions: string[];
|
|
579
|
+
}
|
|
580
|
+
```
|
|
181
581
|
|
|
182
582
|
## Development
|
|
183
583
|
|
|
@@ -188,13 +588,18 @@ pnpm install
|
|
|
188
588
|
# Build the package
|
|
189
589
|
pnpm build
|
|
190
590
|
|
|
191
|
-
# Run
|
|
591
|
+
# Run development server
|
|
192
592
|
pnpm dev
|
|
193
593
|
|
|
194
594
|
# Run tests
|
|
195
595
|
pnpm test
|
|
196
|
-
```
|
|
197
596
|
|
|
198
|
-
|
|
597
|
+
# Run tests in watch mode
|
|
598
|
+
pnpm test:watch
|
|
199
599
|
|
|
200
|
-
|
|
600
|
+
# Lint code
|
|
601
|
+
pnpm lint
|
|
602
|
+
|
|
603
|
+
# Format code
|
|
604
|
+
pnpm format
|
|
605
|
+
```
|