@taruvi/refine-providers 1.1.6 → 1.1.8
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 +101 -39
- package/dist/index.cjs +159 -95
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +44 -23
- package/dist/index.d.ts +44 -23
- package/dist/index.js +160 -96
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -12,8 +12,8 @@ npm install @taruvi/refine-providers @taruvi/sdk @refinedev/core
|
|
|
12
12
|
|
|
13
13
|
```tsx
|
|
14
14
|
import { Refine } from "@refinedev/core";
|
|
15
|
+
import { Client } from "@taruvi/sdk";
|
|
15
16
|
import {
|
|
16
|
-
Client,
|
|
17
17
|
dataProvider,
|
|
18
18
|
storageDataProvider,
|
|
19
19
|
appDataProvider,
|
|
@@ -52,7 +52,7 @@ This package includes multiple specialized data providers:
|
|
|
52
52
|
|
|
53
53
|
| Provider | Purpose | SDK Class | Hook |
|
|
54
54
|
|----------|---------|-----------|------|
|
|
55
|
-
| `dataProvider` | Database CRUD operations | `Database` | `useList`, `useOne`, `useCreate`, etc. |
|
|
55
|
+
| `dataProvider` | Database CRUD & Graph operations | `Database`, `Graph` | `useList`, `useOne`, `useCreate`, etc. |
|
|
56
56
|
| `storageDataProvider` | File storage operations | `Storage` | `useList`, `useCreate`, `useDelete` |
|
|
57
57
|
| `functionsDataProvider` | Edge function execution | `Functions` | `useCreate` |
|
|
58
58
|
| `appDataProvider` | App-level data (roles, settings) | `App` | `useList`, `useOne` |
|
|
@@ -68,7 +68,8 @@ The main data provider for CRUD operations on database tables.
|
|
|
68
68
|
### Basic Usage
|
|
69
69
|
|
|
70
70
|
```tsx
|
|
71
|
-
import {
|
|
71
|
+
import { Client } from "@taruvi/sdk";
|
|
72
|
+
import { dataProvider } from "@taruvi/refine-providers";
|
|
72
73
|
|
|
73
74
|
const client = new Client({ apiKey, appSlug, baseUrl });
|
|
74
75
|
|
|
@@ -192,6 +193,93 @@ const { data } = useList({
|
|
|
192
193
|
});
|
|
193
194
|
```
|
|
194
195
|
|
|
196
|
+
### Graph Operations
|
|
197
|
+
|
|
198
|
+
The data provider supports graph traversal and edge management when graph meta options are provided.
|
|
199
|
+
|
|
200
|
+
#### Reading Graph Data
|
|
201
|
+
|
|
202
|
+
```tsx
|
|
203
|
+
// Get graph structure for a record
|
|
204
|
+
const { data } = useOne({
|
|
205
|
+
resource: "employees",
|
|
206
|
+
id: "1",
|
|
207
|
+
meta: {
|
|
208
|
+
format: "graph", // 'tree' or 'graph'
|
|
209
|
+
include: "descendants", // 'descendants', 'ancestors', or 'both'
|
|
210
|
+
depth: 2, // traversal depth
|
|
211
|
+
graph_types: ["manager", "mentor"], // filter by edge types
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
// List with graph format
|
|
216
|
+
const { data } = useList({
|
|
217
|
+
resource: "employees",
|
|
218
|
+
meta: {
|
|
219
|
+
format: "tree",
|
|
220
|
+
include: "both",
|
|
221
|
+
depth: 3,
|
|
222
|
+
},
|
|
223
|
+
});
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
#### Graph Meta Options
|
|
227
|
+
|
|
228
|
+
| Option | Type | Description |
|
|
229
|
+
|--------|------|-------------|
|
|
230
|
+
| `format` | `'tree' \| 'graph'` | Output format for graph data |
|
|
231
|
+
| `include` | `'descendants' \| 'ancestors' \| 'both'` | Direction of graph traversal |
|
|
232
|
+
| `depth` | `number` | How deep to traverse relationships |
|
|
233
|
+
| `graph_types` | `string[]` | Filter edges by type |
|
|
234
|
+
|
|
235
|
+
#### Managing Graph Edges
|
|
236
|
+
|
|
237
|
+
When any graph meta option is present, mutation operations work with edges:
|
|
238
|
+
|
|
239
|
+
```tsx
|
|
240
|
+
// Create an edge
|
|
241
|
+
const { mutate: createEdge } = useCreate();
|
|
242
|
+
createEdge({
|
|
243
|
+
resource: "employees",
|
|
244
|
+
values: {
|
|
245
|
+
from_id: 1,
|
|
246
|
+
to_id: 2,
|
|
247
|
+
type: "manager",
|
|
248
|
+
metadata: { since: "2024-01-01" },
|
|
249
|
+
},
|
|
250
|
+
meta: { format: "graph" }, // triggers graph mode
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
// Update an edge
|
|
254
|
+
const { mutate: updateEdge } = useUpdate();
|
|
255
|
+
updateEdge({
|
|
256
|
+
resource: "employees",
|
|
257
|
+
id: "edge-123", // edge ID
|
|
258
|
+
values: {
|
|
259
|
+
from_id: 1,
|
|
260
|
+
to_id: 3,
|
|
261
|
+
type: "manager",
|
|
262
|
+
},
|
|
263
|
+
meta: { format: "graph" },
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
// Delete edges
|
|
267
|
+
const { mutate: deleteEdge } = useDelete();
|
|
268
|
+
deleteEdge({
|
|
269
|
+
resource: "employees",
|
|
270
|
+
id: "edge-123",
|
|
271
|
+
meta: { format: "graph" },
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
// Delete multiple edges
|
|
275
|
+
const { mutate: deleteEdges } = useDeleteMany();
|
|
276
|
+
deleteEdges({
|
|
277
|
+
resource: "employees",
|
|
278
|
+
ids: ["edge-123", "edge-456"],
|
|
279
|
+
meta: { format: "graph" },
|
|
280
|
+
});
|
|
281
|
+
```
|
|
282
|
+
|
|
195
283
|
---
|
|
196
284
|
|
|
197
285
|
## Storage Data Provider
|
|
@@ -201,7 +289,8 @@ For file upload, download, and management operations.
|
|
|
201
289
|
### Setup
|
|
202
290
|
|
|
203
291
|
```tsx
|
|
204
|
-
import {
|
|
292
|
+
import { Client } from "@taruvi/sdk";
|
|
293
|
+
import { storageDataProvider } from "@taruvi/refine-providers";
|
|
205
294
|
|
|
206
295
|
const client = new Client({ apiKey, appSlug, baseUrl });
|
|
207
296
|
|
|
@@ -291,7 +380,7 @@ For executing Taruvi edge functions.
|
|
|
291
380
|
### Setup
|
|
292
381
|
|
|
293
382
|
```tsx
|
|
294
|
-
import { functionsDataProvider
|
|
383
|
+
import { functionsDataProvider } from "@taruvi/refine-providers";
|
|
295
384
|
|
|
296
385
|
<Refine
|
|
297
386
|
dataProvider={{
|
|
@@ -366,7 +455,7 @@ For fetching app-level data like roles and settings.
|
|
|
366
455
|
### Setup
|
|
367
456
|
|
|
368
457
|
```tsx
|
|
369
|
-
import { appDataProvider
|
|
458
|
+
import { appDataProvider } from "@taruvi/refine-providers";
|
|
370
459
|
|
|
371
460
|
<Refine
|
|
372
461
|
dataProvider={{
|
|
@@ -408,7 +497,7 @@ For fetching user-level data including users list and current user details.
|
|
|
408
497
|
### Setup
|
|
409
498
|
|
|
410
499
|
```tsx
|
|
411
|
-
import { userDataProvider
|
|
500
|
+
import { userDataProvider } from "@taruvi/refine-providers";
|
|
412
501
|
|
|
413
502
|
<Refine
|
|
414
503
|
dataProvider={{
|
|
@@ -466,7 +555,7 @@ For executing predefined analytics queries.
|
|
|
466
555
|
### Setup
|
|
467
556
|
|
|
468
557
|
```tsx
|
|
469
|
-
import { analyticsDataProvider
|
|
558
|
+
import { analyticsDataProvider } from "@taruvi/refine-providers";
|
|
470
559
|
|
|
471
560
|
<Refine
|
|
472
561
|
dataProvider={{
|
|
@@ -541,7 +630,8 @@ Redirect-based authentication using Taruvi's Web UI Flow.
|
|
|
541
630
|
### Setup
|
|
542
631
|
|
|
543
632
|
```tsx
|
|
544
|
-
import {
|
|
633
|
+
import { Client } from "@taruvi/sdk";
|
|
634
|
+
import { authProvider } from "@taruvi/refine-providers";
|
|
545
635
|
|
|
546
636
|
const client = new Client({ apiKey, appSlug, baseUrl });
|
|
547
637
|
|
|
@@ -613,7 +703,7 @@ Resource-based authorization using Cerbos policies.
|
|
|
613
703
|
### Setup
|
|
614
704
|
|
|
615
705
|
```tsx
|
|
616
|
-
import { accessControlProvider
|
|
706
|
+
import { accessControlProvider } from "@taruvi/refine-providers";
|
|
617
707
|
|
|
618
708
|
<Refine
|
|
619
709
|
authProvider={authProvider(client)}
|
|
@@ -692,8 +782,8 @@ const { data } = useCan({
|
|
|
692
782
|
Use multiple providers together:
|
|
693
783
|
|
|
694
784
|
```tsx
|
|
785
|
+
import { Client } from "@taruvi/sdk";
|
|
695
786
|
import {
|
|
696
|
-
Client,
|
|
697
787
|
dataProvider,
|
|
698
788
|
storageDataProvider,
|
|
699
789
|
functionsDataProvider,
|
|
@@ -744,42 +834,14 @@ import type {
|
|
|
744
834
|
StorageUploadVariables,
|
|
745
835
|
|
|
746
836
|
// Auth types
|
|
747
|
-
TaruviUser,
|
|
748
837
|
LoginParams,
|
|
749
838
|
LogoutParams,
|
|
750
839
|
RegisterParams,
|
|
751
|
-
|
|
752
|
-
// SDK types (re-exported)
|
|
753
|
-
TaruviConfig,
|
|
754
|
-
RoleResponse,
|
|
755
|
-
AnalyticsRequest,
|
|
756
|
-
AnalyticsResponse,
|
|
757
840
|
} from "@taruvi/refine-providers";
|
|
758
841
|
```
|
|
759
842
|
|
|
760
843
|
---
|
|
761
844
|
|
|
762
|
-
## SDK Re-exports
|
|
763
|
-
|
|
764
|
-
For convenience, SDK classes are re-exported:
|
|
765
|
-
|
|
766
|
-
```tsx
|
|
767
|
-
import {
|
|
768
|
-
Client,
|
|
769
|
-
Auth,
|
|
770
|
-
Policy,
|
|
771
|
-
Functions,
|
|
772
|
-
App,
|
|
773
|
-
Analytics,
|
|
774
|
-
} from "@taruvi/refine-providers";
|
|
775
|
-
|
|
776
|
-
// Use SDK directly when needed
|
|
777
|
-
const auth = new Auth(client);
|
|
778
|
-
const isLoggedIn = auth.isUserAuthenticated();
|
|
779
|
-
```
|
|
780
|
-
|
|
781
|
-
---
|
|
782
|
-
|
|
783
845
|
## Utility Functions
|
|
784
846
|
|
|
785
847
|
Advanced users can access utility functions:
|
package/dist/index.cjs
CHANGED
|
@@ -86,6 +86,18 @@ function applyPopulate(query, meta) {
|
|
|
86
86
|
const populateArray = Array.isArray(meta.populate) ? meta.populate : meta.populate.split(",").map((s) => s.trim());
|
|
87
87
|
return query.populate(populateArray);
|
|
88
88
|
}
|
|
89
|
+
function isGraphQuery(meta) {
|
|
90
|
+
return !!(meta?.format || meta?.graph_types || meta?.include || meta?.depth);
|
|
91
|
+
}
|
|
92
|
+
function buildGraphQuery(client, tableName, meta, recordId) {
|
|
93
|
+
let query = new sdk.Graph(client).from(tableName);
|
|
94
|
+
if (recordId) query = query.get(recordId);
|
|
95
|
+
if (meta?.format) query = query.format(meta.format);
|
|
96
|
+
if (meta?.include) query = query.include(meta.include);
|
|
97
|
+
if (meta?.depth) query = query.depth(meta.depth);
|
|
98
|
+
if (meta?.graph_types) query = query.types(meta.graph_types);
|
|
99
|
+
return query;
|
|
100
|
+
}
|
|
89
101
|
function dataProvider(client) {
|
|
90
102
|
const config = client.getConfig();
|
|
91
103
|
const baseApiUrl = `${config.baseUrl}/api/apps/${config.appSlug}`;
|
|
@@ -96,6 +108,12 @@ function dataProvider(client) {
|
|
|
96
108
|
const { resource, pagination, filters, sorters, meta } = params;
|
|
97
109
|
const taruviMeta = meta;
|
|
98
110
|
const tableName = getTableName(resource, taruviMeta);
|
|
111
|
+
if (isGraphQuery(taruviMeta)) {
|
|
112
|
+
const response2 = await buildGraphQuery(client, tableName, taruviMeta).execute();
|
|
113
|
+
const data = Array.isArray(response2) ? response2 : response2?.data ?? [];
|
|
114
|
+
const total = response2?.total ?? data.length;
|
|
115
|
+
return { data, total };
|
|
116
|
+
}
|
|
99
117
|
let query = new sdk.Database(client).from(tableName);
|
|
100
118
|
query = applyFilters(query, filters);
|
|
101
119
|
query = applySorters(query, sorters);
|
|
@@ -108,6 +126,11 @@ function dataProvider(client) {
|
|
|
108
126
|
const { resource, id, meta } = params;
|
|
109
127
|
const taruviMeta = meta;
|
|
110
128
|
const tableName = getTableName(resource, taruviMeta);
|
|
129
|
+
if (isGraphQuery(taruviMeta)) {
|
|
130
|
+
const response2 = await buildGraphQuery(client, tableName, taruviMeta, String(id)).execute();
|
|
131
|
+
const data = Array.isArray(response2) ? response2[0] : response2?.data?.[0] ?? response2;
|
|
132
|
+
return { data };
|
|
133
|
+
}
|
|
111
134
|
let query = new sdk.Database(client).from(tableName);
|
|
112
135
|
query = applyPopulate(query, taruviMeta);
|
|
113
136
|
const response = await query.get(String(id)).execute();
|
|
@@ -117,6 +140,15 @@ function dataProvider(client) {
|
|
|
117
140
|
const { resource, ids, meta } = params;
|
|
118
141
|
const taruviMeta = meta;
|
|
119
142
|
const tableName = getTableName(resource, taruviMeta);
|
|
143
|
+
if (isGraphQuery(taruviMeta)) {
|
|
144
|
+
const data = await Promise.all(
|
|
145
|
+
ids.map(async (id) => {
|
|
146
|
+
const response2 = await buildGraphQuery(client, tableName, taruviMeta, String(id)).execute();
|
|
147
|
+
return Array.isArray(response2) ? response2[0] : response2?.data?.[0] ?? response2;
|
|
148
|
+
})
|
|
149
|
+
);
|
|
150
|
+
return { data };
|
|
151
|
+
}
|
|
120
152
|
const idColumn = getIdColumn(taruviMeta);
|
|
121
153
|
let query = new sdk.Database(client).from(tableName);
|
|
122
154
|
query = query.filter(idColumn, "in", ids.map(String));
|
|
@@ -128,6 +160,10 @@ function dataProvider(client) {
|
|
|
128
160
|
const { resource, variables, meta } = params;
|
|
129
161
|
const taruviMeta = meta;
|
|
130
162
|
const tableName = getTableName(resource, taruviMeta);
|
|
163
|
+
if (isGraphQuery(taruviMeta)) {
|
|
164
|
+
const data2 = await new sdk.Graph(client).from(tableName).createEdge(variables).execute();
|
|
165
|
+
return { data: data2 };
|
|
166
|
+
}
|
|
131
167
|
const data = await new sdk.Database(client).from(tableName).create(variables).execute();
|
|
132
168
|
return { data };
|
|
133
169
|
},
|
|
@@ -146,6 +182,10 @@ function dataProvider(client) {
|
|
|
146
182
|
const { resource, id, variables, meta } = params;
|
|
147
183
|
const taruviMeta = meta;
|
|
148
184
|
const tableName = getTableName(resource, taruviMeta);
|
|
185
|
+
if (isGraphQuery(taruviMeta)) {
|
|
186
|
+
const data2 = await new sdk.Graph(client).from(tableName).updateEdge(String(id), variables).execute();
|
|
187
|
+
return { data: data2 };
|
|
188
|
+
}
|
|
149
189
|
const data = await new sdk.Database(client).from(tableName).get(String(id)).update(variables).execute();
|
|
150
190
|
return { data };
|
|
151
191
|
},
|
|
@@ -164,6 +204,10 @@ function dataProvider(client) {
|
|
|
164
204
|
const { resource, id, meta } = params;
|
|
165
205
|
const taruviMeta = meta;
|
|
166
206
|
const tableName = getTableName(resource, taruviMeta);
|
|
207
|
+
if (isGraphQuery(taruviMeta)) {
|
|
208
|
+
const data2 = await new sdk.Graph(client).from(tableName).deleteEdge([String(id)]).execute();
|
|
209
|
+
return { data: data2 };
|
|
210
|
+
}
|
|
167
211
|
const data = await new sdk.Database(client).from(tableName).delete(String(id)).execute();
|
|
168
212
|
return { data };
|
|
169
213
|
},
|
|
@@ -171,34 +215,36 @@ function dataProvider(client) {
|
|
|
171
215
|
const { resource, ids, meta } = params;
|
|
172
216
|
const taruviMeta = meta;
|
|
173
217
|
const tableName = getTableName(resource, taruviMeta);
|
|
218
|
+
if (isGraphQuery(taruviMeta)) {
|
|
219
|
+
const data2 = await new sdk.Graph(client).from(tableName).deleteEdge(ids.map(String)).execute();
|
|
220
|
+
return { data: [data2] };
|
|
221
|
+
}
|
|
174
222
|
const data = await Promise.all(
|
|
175
|
-
ids.map(
|
|
176
|
-
return new sdk.Database(client).from(tableName).delete(String(id)).execute();
|
|
177
|
-
})
|
|
223
|
+
ids.map((id) => new sdk.Database(client).from(tableName).delete(String(id)).execute())
|
|
178
224
|
);
|
|
179
225
|
return { data };
|
|
180
226
|
},
|
|
181
227
|
custom: async (params) => {
|
|
182
228
|
const { url, method, payload, query } = params;
|
|
229
|
+
let fullUrl = `api/apps/${config.appSlug}/datatables/${url}`;
|
|
183
230
|
let data;
|
|
184
231
|
switch (method.toLowerCase()) {
|
|
185
232
|
case "get": {
|
|
186
|
-
let requestUrl = url;
|
|
187
233
|
if (query && Object.keys(query).length > 0) {
|
|
188
234
|
const queryString = new URLSearchParams(query).toString();
|
|
189
|
-
|
|
235
|
+
fullUrl = `${fullUrl}${fullUrl.includes("?") ? "&" : "?"}${queryString}`;
|
|
190
236
|
}
|
|
191
|
-
data = await client.httpClient.get(
|
|
237
|
+
data = await client.httpClient.get(fullUrl);
|
|
192
238
|
break;
|
|
193
239
|
}
|
|
194
240
|
case "post":
|
|
195
|
-
data = await client.httpClient.post(
|
|
241
|
+
data = await client.httpClient.post(fullUrl, payload);
|
|
196
242
|
break;
|
|
197
243
|
case "put":
|
|
198
|
-
data = await client.httpClient.put(
|
|
244
|
+
data = await client.httpClient.put(fullUrl, payload);
|
|
199
245
|
break;
|
|
200
246
|
case "delete":
|
|
201
|
-
data = await client.httpClient.delete(
|
|
247
|
+
data = await client.httpClient.delete(fullUrl);
|
|
202
248
|
break;
|
|
203
249
|
default:
|
|
204
250
|
throw new Error(`Unsupported HTTP method: ${method}`);
|
|
@@ -407,25 +453,25 @@ function storageDataProvider(client) {
|
|
|
407
453
|
},
|
|
408
454
|
custom: async (params) => {
|
|
409
455
|
const { url, method, payload, query } = params;
|
|
456
|
+
let fullUrl = `api/apps/${config.appSlug}/storage/buckets/${url}`;
|
|
410
457
|
let data;
|
|
411
458
|
switch (method.toLowerCase()) {
|
|
412
459
|
case "get": {
|
|
413
|
-
let requestUrl = url;
|
|
414
460
|
if (query && Object.keys(query).length > 0) {
|
|
415
461
|
const queryString = new URLSearchParams(query).toString();
|
|
416
|
-
|
|
462
|
+
fullUrl = `${fullUrl}${fullUrl.includes("?") ? "&" : "?"}${queryString}`;
|
|
417
463
|
}
|
|
418
|
-
data = await client.httpClient.get(
|
|
464
|
+
data = await client.httpClient.get(fullUrl);
|
|
419
465
|
break;
|
|
420
466
|
}
|
|
421
467
|
case "post":
|
|
422
|
-
data = await client.httpClient.post(
|
|
468
|
+
data = await client.httpClient.post(fullUrl, payload);
|
|
423
469
|
break;
|
|
424
470
|
case "put":
|
|
425
|
-
data = await client.httpClient.put(
|
|
471
|
+
data = await client.httpClient.put(fullUrl, payload);
|
|
426
472
|
break;
|
|
427
473
|
case "delete":
|
|
428
|
-
data = await client.httpClient.delete(
|
|
474
|
+
data = await client.httpClient.delete(fullUrl);
|
|
429
475
|
break;
|
|
430
476
|
default:
|
|
431
477
|
throw new Error(`Unsupported HTTP method: ${method}`);
|
|
@@ -436,83 +482,11 @@ function storageDataProvider(client) {
|
|
|
436
482
|
updateMany: void 0
|
|
437
483
|
};
|
|
438
484
|
}
|
|
439
|
-
function functionsDataProvider(client) {
|
|
440
|
-
const config = client.getConfig();
|
|
441
|
-
const baseApiUrl = `${config.baseUrl}/api/apps/${config.appSlug}`;
|
|
442
|
-
const functions = new sdk.Functions(client);
|
|
443
|
-
return {
|
|
444
|
-
/**
|
|
445
|
-
* Execute an edge function.
|
|
446
|
-
*
|
|
447
|
-
* @param resource - The function slug to execute
|
|
448
|
-
* @param variables - Parameters to pass to the function
|
|
449
|
-
* @param meta.async - Whether to execute asynchronously (default: false)
|
|
450
|
-
*/
|
|
451
|
-
create: async ({
|
|
452
|
-
resource,
|
|
453
|
-
variables,
|
|
454
|
-
meta
|
|
455
|
-
}) => {
|
|
456
|
-
const functionMeta = meta;
|
|
457
|
-
const response = await functions.execute(resource, {
|
|
458
|
-
async: functionMeta?.async ?? false,
|
|
459
|
-
params: variables
|
|
460
|
-
});
|
|
461
|
-
return { data: response.data };
|
|
462
|
-
},
|
|
463
|
-
getApiUrl: () => baseApiUrl,
|
|
464
|
-
// Edge functions don't support custom method - use create() instead
|
|
465
|
-
custom: async () => {
|
|
466
|
-
throw new Error(
|
|
467
|
-
"custom is not supported for edge functions. Use useCreate to execute functions."
|
|
468
|
-
);
|
|
469
|
-
},
|
|
470
|
-
// Edge functions don't support other CRUD operations
|
|
471
|
-
getList: async () => {
|
|
472
|
-
throw new Error(
|
|
473
|
-
"getList is not supported for edge functions. Use useCreate to execute functions."
|
|
474
|
-
);
|
|
475
|
-
},
|
|
476
|
-
getOne: async () => {
|
|
477
|
-
throw new Error(
|
|
478
|
-
"getOne is not supported for edge functions. Use useCreate to execute functions."
|
|
479
|
-
);
|
|
480
|
-
},
|
|
481
|
-
getMany: async () => {
|
|
482
|
-
throw new Error(
|
|
483
|
-
"getMany is not supported for edge functions. Use useCreate to execute functions."
|
|
484
|
-
);
|
|
485
|
-
},
|
|
486
|
-
createMany: async () => {
|
|
487
|
-
throw new Error(
|
|
488
|
-
"createMany is not supported for edge functions. Use useCreate to execute functions."
|
|
489
|
-
);
|
|
490
|
-
},
|
|
491
|
-
update: async () => {
|
|
492
|
-
throw new Error(
|
|
493
|
-
"update is not supported for edge functions. Use useCreate to execute functions."
|
|
494
|
-
);
|
|
495
|
-
},
|
|
496
|
-
updateMany: async () => {
|
|
497
|
-
throw new Error(
|
|
498
|
-
"updateMany is not supported for edge functions. Use useCreate to execute functions."
|
|
499
|
-
);
|
|
500
|
-
},
|
|
501
|
-
deleteOne: async () => {
|
|
502
|
-
throw new Error(
|
|
503
|
-
"deleteOne is not supported for edge functions. Use useCreate to execute functions."
|
|
504
|
-
);
|
|
505
|
-
},
|
|
506
|
-
deleteMany: async () => {
|
|
507
|
-
throw new Error(
|
|
508
|
-
"deleteMany is not supported for edge functions. Use useCreate to execute functions."
|
|
509
|
-
);
|
|
510
|
-
}
|
|
511
|
-
};
|
|
512
|
-
}
|
|
513
485
|
function appDataProvider(client) {
|
|
514
486
|
const config = client.getConfig();
|
|
515
487
|
const baseApiUrl = `${config.baseUrl}/api/apps/${config.appSlug}`;
|
|
488
|
+
const functions = new sdk.Functions(client);
|
|
489
|
+
const analytics = new sdk.Analytics(client);
|
|
516
490
|
return {
|
|
517
491
|
getList: async (params) => {
|
|
518
492
|
const { resource } = params;
|
|
@@ -526,7 +500,6 @@ function appDataProvider(client) {
|
|
|
526
500
|
}
|
|
527
501
|
throw new Error(`Unknown app resource: ${resource}. Supported resources: roles`);
|
|
528
502
|
},
|
|
529
|
-
getApiUrl: () => baseApiUrl,
|
|
530
503
|
getOne: async (params) => {
|
|
531
504
|
const { resource } = params;
|
|
532
505
|
if (resource === "settings") {
|
|
@@ -538,12 +511,32 @@ function appDataProvider(client) {
|
|
|
538
511
|
}
|
|
539
512
|
throw new Error(`Unknown app resource for getOne: ${resource}. Supported resources: settings`);
|
|
540
513
|
},
|
|
541
|
-
|
|
514
|
+
custom: async (params) => {
|
|
515
|
+
const { url: slug, payload, meta } = params;
|
|
516
|
+
const customMeta = meta;
|
|
517
|
+
if (customMeta?.kind === "function") {
|
|
518
|
+
const response = await functions.execute(slug, {
|
|
519
|
+
async: customMeta.async ?? false,
|
|
520
|
+
params: payload ?? {}
|
|
521
|
+
});
|
|
522
|
+
return { data: response.data };
|
|
523
|
+
}
|
|
524
|
+
if (customMeta?.kind === "analytics") {
|
|
525
|
+
const response = await analytics.execute(slug, {
|
|
526
|
+
params: payload ?? {}
|
|
527
|
+
});
|
|
528
|
+
return { data: response.data };
|
|
529
|
+
}
|
|
530
|
+
throw new Error(
|
|
531
|
+
'Specify meta.kind as "function" or "analytics" for custom operations on the app provider.'
|
|
532
|
+
);
|
|
533
|
+
},
|
|
534
|
+
getApiUrl: () => baseApiUrl,
|
|
542
535
|
getMany: async () => {
|
|
543
536
|
throw new Error("getMany is not supported for app resources");
|
|
544
537
|
},
|
|
545
538
|
create: async () => {
|
|
546
|
-
throw new Error("create is not supported for app resources");
|
|
539
|
+
throw new Error("create is not supported for app resources. Use useCustom with meta.kind");
|
|
547
540
|
},
|
|
548
541
|
createMany: async () => {
|
|
549
542
|
throw new Error("createMany is not supported for app resources");
|
|
@@ -559,9 +552,6 @@ function appDataProvider(client) {
|
|
|
559
552
|
},
|
|
560
553
|
deleteMany: async () => {
|
|
561
554
|
throw new Error("deleteMany is not supported for app resources");
|
|
562
|
-
},
|
|
563
|
-
custom: async () => {
|
|
564
|
-
throw new Error("custom is not supported for app resources");
|
|
565
555
|
}
|
|
566
556
|
};
|
|
567
557
|
}
|
|
@@ -701,6 +691,80 @@ function userDataProvider(client) {
|
|
|
701
691
|
}
|
|
702
692
|
};
|
|
703
693
|
}
|
|
694
|
+
function functionsDataProvider(client) {
|
|
695
|
+
const config = client.getConfig();
|
|
696
|
+
const baseApiUrl = `${config.baseUrl}/api/apps/${config.appSlug}`;
|
|
697
|
+
const functions = new sdk.Functions(client);
|
|
698
|
+
return {
|
|
699
|
+
/**
|
|
700
|
+
* Execute an edge function.
|
|
701
|
+
*
|
|
702
|
+
* @param resource - The function slug to execute
|
|
703
|
+
* @param variables - Parameters to pass to the function
|
|
704
|
+
* @param meta.async - Whether to execute asynchronously (default: false)
|
|
705
|
+
*/
|
|
706
|
+
create: async ({
|
|
707
|
+
resource,
|
|
708
|
+
variables,
|
|
709
|
+
meta
|
|
710
|
+
}) => {
|
|
711
|
+
const functionMeta = meta;
|
|
712
|
+
const response = await functions.execute(resource, {
|
|
713
|
+
async: functionMeta?.async ?? false,
|
|
714
|
+
params: variables
|
|
715
|
+
});
|
|
716
|
+
return { data: response.data };
|
|
717
|
+
},
|
|
718
|
+
getApiUrl: () => baseApiUrl,
|
|
719
|
+
// Edge functions don't support custom method - use create() instead
|
|
720
|
+
custom: async () => {
|
|
721
|
+
throw new Error(
|
|
722
|
+
"custom is not supported for edge functions. Use useCreate to execute functions."
|
|
723
|
+
);
|
|
724
|
+
},
|
|
725
|
+
// Edge functions don't support other CRUD operations
|
|
726
|
+
getList: async () => {
|
|
727
|
+
throw new Error(
|
|
728
|
+
"getList is not supported for edge functions. Use useCreate to execute functions."
|
|
729
|
+
);
|
|
730
|
+
},
|
|
731
|
+
getOne: async () => {
|
|
732
|
+
throw new Error(
|
|
733
|
+
"getOne is not supported for edge functions. Use useCreate to execute functions."
|
|
734
|
+
);
|
|
735
|
+
},
|
|
736
|
+
getMany: async () => {
|
|
737
|
+
throw new Error(
|
|
738
|
+
"getMany is not supported for edge functions. Use useCreate to execute functions."
|
|
739
|
+
);
|
|
740
|
+
},
|
|
741
|
+
createMany: async () => {
|
|
742
|
+
throw new Error(
|
|
743
|
+
"createMany is not supported for edge functions. Use useCreate to execute functions."
|
|
744
|
+
);
|
|
745
|
+
},
|
|
746
|
+
update: async () => {
|
|
747
|
+
throw new Error(
|
|
748
|
+
"update is not supported for edge functions. Use useCreate to execute functions."
|
|
749
|
+
);
|
|
750
|
+
},
|
|
751
|
+
updateMany: async () => {
|
|
752
|
+
throw new Error(
|
|
753
|
+
"updateMany is not supported for edge functions. Use useCreate to execute functions."
|
|
754
|
+
);
|
|
755
|
+
},
|
|
756
|
+
deleteOne: async () => {
|
|
757
|
+
throw new Error(
|
|
758
|
+
"deleteOne is not supported for edge functions. Use useCreate to execute functions."
|
|
759
|
+
);
|
|
760
|
+
},
|
|
761
|
+
deleteMany: async () => {
|
|
762
|
+
throw new Error(
|
|
763
|
+
"deleteMany is not supported for edge functions. Use useCreate to execute functions."
|
|
764
|
+
);
|
|
765
|
+
}
|
|
766
|
+
};
|
|
767
|
+
}
|
|
704
768
|
function analyticsDataProvider(client) {
|
|
705
769
|
const config = client.getConfig();
|
|
706
770
|
const baseApiUrl = `${config.baseUrl}/api/apps/${config.appSlug}`;
|