@taruvi/refine-providers 1.1.6 → 1.1.8-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +101 -39
- package/dist/index.cjs +177 -103
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +177 -103
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/index.d.cts +0 -260
- package/dist/index.d.ts +0 -260
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
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var sdk = require('@taruvi/sdk');
|
|
4
|
-
var
|
|
4
|
+
var DataLoader = require('dataloader');
|
|
5
5
|
|
|
6
6
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var DataLoader__default = /*#__PURE__*/_interopDefault(DataLoader);
|
|
9
9
|
|
|
10
10
|
// src/dataProvider.ts
|
|
11
11
|
var REFINE_TO_SDK_OPERATOR = {
|
|
@@ -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}`);
|
|
@@ -356,10 +402,20 @@ function storageDataProvider(client) {
|
|
|
356
402
|
const { resource, id: path, meta } = params;
|
|
357
403
|
const taruviMeta = meta;
|
|
358
404
|
const bucket = getBucketName(resource, taruviMeta);
|
|
359
|
-
const encodedPath =
|
|
360
|
-
const url = `${baseApiUrl}/storage/buckets/${bucket}/objects/${encodedPath}
|
|
361
|
-
const
|
|
362
|
-
|
|
405
|
+
const encodedPath = String(path);
|
|
406
|
+
const url = `${baseApiUrl}/storage/buckets/${bucket}/objects/${encodedPath}/`;
|
|
407
|
+
const headers = {};
|
|
408
|
+
const token = client.tokenClient.getToken();
|
|
409
|
+
if (token) headers["Authorization"] = `Bearer ${token}`;
|
|
410
|
+
if (taruviMeta?.metadata) {
|
|
411
|
+
const res2 = await fetch(`${url}?metadata=true`, { headers });
|
|
412
|
+
const data = await res2.json();
|
|
413
|
+
return { data };
|
|
414
|
+
}
|
|
415
|
+
const res = await fetch(url, { headers });
|
|
416
|
+
const blob = await res.blob();
|
|
417
|
+
const blobUrl = URL.createObjectURL(blob);
|
|
418
|
+
return { data: blobUrl };
|
|
363
419
|
},
|
|
364
420
|
create: async (params) => {
|
|
365
421
|
const { resource, variables, meta } = params;
|
|
@@ -407,25 +463,25 @@ function storageDataProvider(client) {
|
|
|
407
463
|
},
|
|
408
464
|
custom: async (params) => {
|
|
409
465
|
const { url, method, payload, query } = params;
|
|
466
|
+
let fullUrl = `api/apps/${config.appSlug}/storage/buckets/${url}`;
|
|
410
467
|
let data;
|
|
411
468
|
switch (method.toLowerCase()) {
|
|
412
469
|
case "get": {
|
|
413
|
-
let requestUrl = url;
|
|
414
470
|
if (query && Object.keys(query).length > 0) {
|
|
415
471
|
const queryString = new URLSearchParams(query).toString();
|
|
416
|
-
|
|
472
|
+
fullUrl = `${fullUrl}${fullUrl.includes("?") ? "&" : "?"}${queryString}`;
|
|
417
473
|
}
|
|
418
|
-
data = await client.httpClient.get(
|
|
474
|
+
data = await client.httpClient.get(fullUrl);
|
|
419
475
|
break;
|
|
420
476
|
}
|
|
421
477
|
case "post":
|
|
422
|
-
data = await client.httpClient.post(
|
|
478
|
+
data = await client.httpClient.post(fullUrl, payload);
|
|
423
479
|
break;
|
|
424
480
|
case "put":
|
|
425
|
-
data = await client.httpClient.put(
|
|
481
|
+
data = await client.httpClient.put(fullUrl, payload);
|
|
426
482
|
break;
|
|
427
483
|
case "delete":
|
|
428
|
-
data = await client.httpClient.delete(
|
|
484
|
+
data = await client.httpClient.delete(fullUrl);
|
|
429
485
|
break;
|
|
430
486
|
default:
|
|
431
487
|
throw new Error(`Unsupported HTTP method: ${method}`);
|
|
@@ -436,83 +492,11 @@ function storageDataProvider(client) {
|
|
|
436
492
|
updateMany: void 0
|
|
437
493
|
};
|
|
438
494
|
}
|
|
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
495
|
function appDataProvider(client) {
|
|
514
496
|
const config = client.getConfig();
|
|
515
497
|
const baseApiUrl = `${config.baseUrl}/api/apps/${config.appSlug}`;
|
|
498
|
+
const functions = new sdk.Functions(client);
|
|
499
|
+
const analytics = new sdk.Analytics(client);
|
|
516
500
|
return {
|
|
517
501
|
getList: async (params) => {
|
|
518
502
|
const { resource } = params;
|
|
@@ -526,7 +510,6 @@ function appDataProvider(client) {
|
|
|
526
510
|
}
|
|
527
511
|
throw new Error(`Unknown app resource: ${resource}. Supported resources: roles`);
|
|
528
512
|
},
|
|
529
|
-
getApiUrl: () => baseApiUrl,
|
|
530
513
|
getOne: async (params) => {
|
|
531
514
|
const { resource } = params;
|
|
532
515
|
if (resource === "settings") {
|
|
@@ -538,12 +521,32 @@ function appDataProvider(client) {
|
|
|
538
521
|
}
|
|
539
522
|
throw new Error(`Unknown app resource for getOne: ${resource}. Supported resources: settings`);
|
|
540
523
|
},
|
|
541
|
-
|
|
524
|
+
custom: async (params) => {
|
|
525
|
+
const { url: slug, payload, meta } = params;
|
|
526
|
+
const customMeta = meta;
|
|
527
|
+
if (customMeta?.kind === "function") {
|
|
528
|
+
const response = await functions.execute(slug, {
|
|
529
|
+
async: customMeta.async ?? false,
|
|
530
|
+
params: payload ?? {}
|
|
531
|
+
});
|
|
532
|
+
return { data: response.data };
|
|
533
|
+
}
|
|
534
|
+
if (customMeta?.kind === "analytics") {
|
|
535
|
+
const response = await analytics.execute(slug, {
|
|
536
|
+
params: payload ?? {}
|
|
537
|
+
});
|
|
538
|
+
return { data: response.data };
|
|
539
|
+
}
|
|
540
|
+
throw new Error(
|
|
541
|
+
'Specify meta.kind as "function" or "analytics" for custom operations on the app provider.'
|
|
542
|
+
);
|
|
543
|
+
},
|
|
544
|
+
getApiUrl: () => baseApiUrl,
|
|
542
545
|
getMany: async () => {
|
|
543
546
|
throw new Error("getMany is not supported for app resources");
|
|
544
547
|
},
|
|
545
548
|
create: async () => {
|
|
546
|
-
throw new Error("create is not supported for app resources");
|
|
549
|
+
throw new Error("create is not supported for app resources. Use useCustom with meta.kind");
|
|
547
550
|
},
|
|
548
551
|
createMany: async () => {
|
|
549
552
|
throw new Error("createMany is not supported for app resources");
|
|
@@ -559,9 +562,6 @@ function appDataProvider(client) {
|
|
|
559
562
|
},
|
|
560
563
|
deleteMany: async () => {
|
|
561
564
|
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
565
|
}
|
|
566
566
|
};
|
|
567
567
|
}
|
|
@@ -701,6 +701,80 @@ function userDataProvider(client) {
|
|
|
701
701
|
}
|
|
702
702
|
};
|
|
703
703
|
}
|
|
704
|
+
function functionsDataProvider(client) {
|
|
705
|
+
const config = client.getConfig();
|
|
706
|
+
const baseApiUrl = `${config.baseUrl}/api/apps/${config.appSlug}`;
|
|
707
|
+
const functions = new sdk.Functions(client);
|
|
708
|
+
return {
|
|
709
|
+
/**
|
|
710
|
+
* Execute an edge function.
|
|
711
|
+
*
|
|
712
|
+
* @param resource - The function slug to execute
|
|
713
|
+
* @param variables - Parameters to pass to the function
|
|
714
|
+
* @param meta.async - Whether to execute asynchronously (default: false)
|
|
715
|
+
*/
|
|
716
|
+
create: async ({
|
|
717
|
+
resource,
|
|
718
|
+
variables,
|
|
719
|
+
meta
|
|
720
|
+
}) => {
|
|
721
|
+
const functionMeta = meta;
|
|
722
|
+
const response = await functions.execute(resource, {
|
|
723
|
+
async: functionMeta?.async ?? false,
|
|
724
|
+
params: variables
|
|
725
|
+
});
|
|
726
|
+
return { data: response.data };
|
|
727
|
+
},
|
|
728
|
+
getApiUrl: () => baseApiUrl,
|
|
729
|
+
// Edge functions don't support custom method - use create() instead
|
|
730
|
+
custom: async () => {
|
|
731
|
+
throw new Error(
|
|
732
|
+
"custom is not supported for edge functions. Use useCreate to execute functions."
|
|
733
|
+
);
|
|
734
|
+
},
|
|
735
|
+
// Edge functions don't support other CRUD operations
|
|
736
|
+
getList: async () => {
|
|
737
|
+
throw new Error(
|
|
738
|
+
"getList is not supported for edge functions. Use useCreate to execute functions."
|
|
739
|
+
);
|
|
740
|
+
},
|
|
741
|
+
getOne: async () => {
|
|
742
|
+
throw new Error(
|
|
743
|
+
"getOne is not supported for edge functions. Use useCreate to execute functions."
|
|
744
|
+
);
|
|
745
|
+
},
|
|
746
|
+
getMany: async () => {
|
|
747
|
+
throw new Error(
|
|
748
|
+
"getMany is not supported for edge functions. Use useCreate to execute functions."
|
|
749
|
+
);
|
|
750
|
+
},
|
|
751
|
+
createMany: async () => {
|
|
752
|
+
throw new Error(
|
|
753
|
+
"createMany is not supported for edge functions. Use useCreate to execute functions."
|
|
754
|
+
);
|
|
755
|
+
},
|
|
756
|
+
update: async () => {
|
|
757
|
+
throw new Error(
|
|
758
|
+
"update is not supported for edge functions. Use useCreate to execute functions."
|
|
759
|
+
);
|
|
760
|
+
},
|
|
761
|
+
updateMany: async () => {
|
|
762
|
+
throw new Error(
|
|
763
|
+
"updateMany is not supported for edge functions. Use useCreate to execute functions."
|
|
764
|
+
);
|
|
765
|
+
},
|
|
766
|
+
deleteOne: async () => {
|
|
767
|
+
throw new Error(
|
|
768
|
+
"deleteOne is not supported for edge functions. Use useCreate to execute functions."
|
|
769
|
+
);
|
|
770
|
+
},
|
|
771
|
+
deleteMany: async () => {
|
|
772
|
+
throw new Error(
|
|
773
|
+
"deleteMany is not supported for edge functions. Use useCreate to execute functions."
|
|
774
|
+
);
|
|
775
|
+
}
|
|
776
|
+
};
|
|
777
|
+
}
|
|
704
778
|
function analyticsDataProvider(client) {
|
|
705
779
|
const config = client.getConfig();
|
|
706
780
|
const baseApiUrl = `${config.baseUrl}/api/apps/${config.appSlug}`;
|
|
@@ -893,7 +967,7 @@ function accessControlProvider(client, options) {
|
|
|
893
967
|
const policy = new sdk.Policy(client);
|
|
894
968
|
const auth = new sdk.Auth(client);
|
|
895
969
|
const { batchDelayMs = 50 } = options ?? {};
|
|
896
|
-
const permissionLoader = new
|
|
970
|
+
const permissionLoader = new DataLoader__default.default(
|
|
897
971
|
async (checks) => {
|
|
898
972
|
const user = await auth.getCurrentUser();
|
|
899
973
|
if (!user) {
|
|
@@ -962,7 +1036,7 @@ function accessControlProvider(client, options) {
|
|
|
962
1036
|
if (!resource) {
|
|
963
1037
|
return { can: false, reason: "Resource not specified" };
|
|
964
1038
|
}
|
|
965
|
-
const entityType = params?.resource?.meta?.entityType;
|
|
1039
|
+
const entityType = params?.entityType ?? params?.resource?.meta?.entityType;
|
|
966
1040
|
return permissionLoader.load({
|
|
967
1041
|
resource,
|
|
968
1042
|
action,
|