@taruvi/refine-providers 1.1.7 → 1.1.8-beta.1
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/dist/index.cjs +345 -296
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +20 -32
- package/dist/index.d.ts +20 -32
- package/dist/index.js +345 -296
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,38 +1,57 @@
|
|
|
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
|
-
|
|
12
|
-
|
|
11
|
+
|
|
12
|
+
// src/utils.ts
|
|
13
|
+
var REFINE_OPERATOR_MAP = {
|
|
14
|
+
// Equality
|
|
15
|
+
eq: "",
|
|
16
|
+
// exact match (no suffix)
|
|
13
17
|
ne: "ne",
|
|
18
|
+
// Comparison
|
|
14
19
|
lt: "lt",
|
|
15
20
|
gt: "gt",
|
|
16
21
|
lte: "lte",
|
|
17
22
|
gte: "gte",
|
|
23
|
+
// String operations (case-sensitive)
|
|
18
24
|
contains: "contains",
|
|
19
|
-
|
|
20
|
-
// case-insensitive
|
|
25
|
+
ncontains: "ncontains",
|
|
21
26
|
startswith: "startswith",
|
|
22
|
-
|
|
27
|
+
nstartswith: "nstartswith",
|
|
23
28
|
endswith: "endswith",
|
|
29
|
+
nendswith: "nendswith",
|
|
30
|
+
// String operations (case-insensitive)
|
|
31
|
+
containss: "icontains",
|
|
32
|
+
ncontainss: "nicontains",
|
|
33
|
+
startswiths: "istartswith",
|
|
34
|
+
nstartswiths: "nistartswith",
|
|
24
35
|
endswiths: "iendswith",
|
|
36
|
+
nendswiths: "niendswith",
|
|
37
|
+
// Array operations
|
|
25
38
|
in: "in",
|
|
26
39
|
nin: "nin",
|
|
27
|
-
|
|
40
|
+
// Null checks
|
|
41
|
+
null: "null",
|
|
42
|
+
nnull: "nnull",
|
|
43
|
+
// Range
|
|
44
|
+
between: "between",
|
|
45
|
+
nbetween: "nbetween"
|
|
28
46
|
};
|
|
29
|
-
function
|
|
30
|
-
if (!filters || filters.length === 0) return
|
|
31
|
-
|
|
47
|
+
function convertRefineFilters(filters) {
|
|
48
|
+
if (!filters || filters.length === 0) return {};
|
|
49
|
+
const params = {};
|
|
32
50
|
for (const filter of filters) {
|
|
33
51
|
if ("operator" in filter && (filter.operator === "and" || filter.operator === "or")) {
|
|
34
52
|
if (filter.value && Array.isArray(filter.value)) {
|
|
35
|
-
|
|
53
|
+
const nested = convertRefineFilters(filter.value);
|
|
54
|
+
Object.assign(params, nested);
|
|
36
55
|
}
|
|
37
56
|
continue;
|
|
38
57
|
}
|
|
@@ -41,22 +60,104 @@ function applyFilters(query, filters) {
|
|
|
41
60
|
if (value === void 0 || value === null && operator !== "null") {
|
|
42
61
|
continue;
|
|
43
62
|
}
|
|
44
|
-
const
|
|
45
|
-
if (
|
|
63
|
+
const suffix = REFINE_OPERATOR_MAP[operator];
|
|
64
|
+
if (suffix === void 0) {
|
|
46
65
|
console.warn(`Unknown Refine operator: ${operator}`);
|
|
47
66
|
continue;
|
|
48
67
|
}
|
|
49
|
-
|
|
68
|
+
const paramKey = suffix ? `${field}__${suffix}` : String(field);
|
|
50
69
|
if (operator === "in" || operator === "nin") {
|
|
51
|
-
|
|
70
|
+
params[paramKey] = Array.isArray(value) ? value.join(",") : String(value);
|
|
71
|
+
} else if (operator === "between" || operator === "nbetween") {
|
|
72
|
+
params[paramKey] = Array.isArray(value) ? value.join(",") : String(value);
|
|
73
|
+
} else if (operator === "null" || operator === "nnull") {
|
|
74
|
+
params[paramKey] = "true";
|
|
75
|
+
} else {
|
|
76
|
+
params[paramKey] = String(value);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return params;
|
|
81
|
+
}
|
|
82
|
+
function convertRefineSorters(sorters) {
|
|
83
|
+
if (!sorters || sorters.length === 0) return void 0;
|
|
84
|
+
return sorters.map((sort) => sort.order === "desc" ? `-${sort.field}` : sort.field).join(",");
|
|
85
|
+
}
|
|
86
|
+
function convertRefinePagination(pagination) {
|
|
87
|
+
if (!pagination) return {};
|
|
88
|
+
const { currentPage, pageSize, mode } = pagination;
|
|
89
|
+
if (mode === "off") return {};
|
|
90
|
+
return {
|
|
91
|
+
page: currentPage ?? 1,
|
|
92
|
+
// Default to page 1 if currentPage is undefined
|
|
93
|
+
page_size: pageSize
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function buildRefineQueryParams(options) {
|
|
97
|
+
const { filters, sorters, pagination, meta } = options;
|
|
98
|
+
const params = {
|
|
99
|
+
...convertRefineFilters(filters),
|
|
100
|
+
...convertRefinePagination(pagination)
|
|
101
|
+
};
|
|
102
|
+
const ordering = convertRefineSorters(sorters);
|
|
103
|
+
if (ordering) {
|
|
104
|
+
params.ordering = ordering;
|
|
105
|
+
}
|
|
106
|
+
if (meta?.populate) {
|
|
107
|
+
params.populate = Array.isArray(meta.populate) ? meta.populate.join(",") : meta.populate;
|
|
108
|
+
}
|
|
109
|
+
return params;
|
|
110
|
+
}
|
|
111
|
+
function buildQueryString(params) {
|
|
112
|
+
if (!params || Object.keys(params).length === 0) return "";
|
|
113
|
+
const searchParams = new URLSearchParams();
|
|
114
|
+
for (const [key, value] of Object.entries(params)) {
|
|
115
|
+
if (value !== void 0 && value !== null) {
|
|
116
|
+
searchParams.append(key, String(value));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const queryString = searchParams.toString();
|
|
120
|
+
return queryString ? `?${queryString}` : "";
|
|
121
|
+
}
|
|
122
|
+
function handleError(error) {
|
|
123
|
+
if (error instanceof Error) {
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
if (typeof error === "object" && error !== null && "message" in error) {
|
|
127
|
+
throw new Error(String(error.message));
|
|
128
|
+
}
|
|
129
|
+
throw new Error("Unknown error occurred");
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// src/dataProvider.ts
|
|
133
|
+
function applyFilters(query, filters) {
|
|
134
|
+
if (!filters || filters.length === 0) return query;
|
|
135
|
+
let result = query;
|
|
136
|
+
for (const filter of filters) {
|
|
137
|
+
if ("operator" in filter && (filter.operator === "and" || filter.operator === "or")) {
|
|
138
|
+
if (filter.value && Array.isArray(filter.value)) {
|
|
139
|
+
result = applyFilters(result, filter.value);
|
|
140
|
+
}
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
if ("field" in filter && filter.field && filter.operator) {
|
|
144
|
+
const { field, operator, value } = filter;
|
|
145
|
+
if (value === void 0 || value === null && operator !== "null") continue;
|
|
146
|
+
const suffix = REFINE_OPERATOR_MAP[operator];
|
|
147
|
+
if (suffix === void 0) {
|
|
148
|
+
console.warn(`Unknown Refine operator: ${operator}`);
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
const paramKey = suffix ? `${field}__${suffix}` : String(field);
|
|
152
|
+
let paramValue;
|
|
153
|
+
if (operator === "in" || operator === "nin" || operator === "between" || operator === "nbetween") {
|
|
154
|
+
paramValue = Array.isArray(value) ? value.join(",") : String(value);
|
|
52
155
|
} else if (operator === "null" || operator === "nnull") {
|
|
53
|
-
|
|
54
|
-
} else if (typeof value === "boolean" || typeof value === "number") {
|
|
55
|
-
sdkValue = value;
|
|
156
|
+
paramValue = "true";
|
|
56
157
|
} else {
|
|
57
|
-
|
|
158
|
+
paramValue = String(value);
|
|
58
159
|
}
|
|
59
|
-
result = result.filter(
|
|
160
|
+
result = result.filter(paramKey, "eq", paramValue);
|
|
60
161
|
}
|
|
61
162
|
}
|
|
62
163
|
return result;
|
|
@@ -65,20 +166,15 @@ function applySorters(query, sorters) {
|
|
|
65
166
|
if (!sorters || sorters.length === 0) return query;
|
|
66
167
|
let result = query;
|
|
67
168
|
for (const sorter of sorters) {
|
|
68
|
-
|
|
69
|
-
result = result.sort(sorter.field, order);
|
|
169
|
+
result = result.sort(sorter.field, sorter.order === "desc" ? "desc" : "asc");
|
|
70
170
|
}
|
|
71
171
|
return result;
|
|
72
172
|
}
|
|
73
173
|
function applyPagination(query, pagination) {
|
|
74
174
|
if (!pagination || pagination.mode === "off") return query;
|
|
75
175
|
let result = query;
|
|
76
|
-
if (pagination.currentPage)
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
if (pagination.pageSize) {
|
|
80
|
-
result = result.pageSize(pagination.pageSize);
|
|
81
|
-
}
|
|
176
|
+
if (pagination.currentPage) result = result.page(pagination.currentPage);
|
|
177
|
+
if (pagination.pageSize) result = result.pageSize(pagination.pageSize);
|
|
82
178
|
return result;
|
|
83
179
|
}
|
|
84
180
|
function applyPopulate(query, meta) {
|
|
@@ -100,7 +196,7 @@ function buildGraphQuery(client, tableName, meta, recordId) {
|
|
|
100
196
|
}
|
|
101
197
|
function dataProvider(client) {
|
|
102
198
|
const config = client.getConfig();
|
|
103
|
-
const baseApiUrl = `${config.
|
|
199
|
+
const baseApiUrl = `${config.apiUrl}/api/apps/${config.appSlug}`;
|
|
104
200
|
const getIdColumn = (meta) => meta?.idColumnName ?? "id";
|
|
105
201
|
const getTableName = (resource, meta) => meta?.tableName ?? resource;
|
|
106
202
|
return {
|
|
@@ -131,9 +227,9 @@ function dataProvider(client) {
|
|
|
131
227
|
const data = Array.isArray(response2) ? response2[0] : response2?.data?.[0] ?? response2;
|
|
132
228
|
return { data };
|
|
133
229
|
}
|
|
134
|
-
let query = new sdk.Database(client).from(tableName);
|
|
230
|
+
let query = new sdk.Database(client).from(tableName).get(String(id));
|
|
135
231
|
query = applyPopulate(query, taruviMeta);
|
|
136
|
-
const response = await query.
|
|
232
|
+
const response = await query.execute();
|
|
137
233
|
return { data: response.data };
|
|
138
234
|
},
|
|
139
235
|
getMany: async (params) => {
|
|
@@ -161,11 +257,11 @@ function dataProvider(client) {
|
|
|
161
257
|
const taruviMeta = meta;
|
|
162
258
|
const tableName = getTableName(resource, taruviMeta);
|
|
163
259
|
if (isGraphQuery(taruviMeta)) {
|
|
164
|
-
const
|
|
165
|
-
return { data:
|
|
260
|
+
const response2 = await new sdk.Graph(client).from(tableName).create(variables).execute();
|
|
261
|
+
return { data: response2.data };
|
|
166
262
|
}
|
|
167
|
-
const
|
|
168
|
-
return { data };
|
|
263
|
+
const response = await new sdk.Database(client).from(tableName).create(variables).execute();
|
|
264
|
+
return { data: response.data };
|
|
169
265
|
},
|
|
170
266
|
createMany: async (params) => {
|
|
171
267
|
const { resource, variables, meta } = params;
|
|
@@ -173,7 +269,8 @@ function dataProvider(client) {
|
|
|
173
269
|
const tableName = getTableName(resource, taruviMeta);
|
|
174
270
|
const data = await Promise.all(
|
|
175
271
|
variables.map(async (vars) => {
|
|
176
|
-
|
|
272
|
+
const response = await new sdk.Database(client).from(tableName).create(vars).execute();
|
|
273
|
+
return response.data;
|
|
177
274
|
})
|
|
178
275
|
);
|
|
179
276
|
return { data };
|
|
@@ -183,11 +280,11 @@ function dataProvider(client) {
|
|
|
183
280
|
const taruviMeta = meta;
|
|
184
281
|
const tableName = getTableName(resource, taruviMeta);
|
|
185
282
|
if (isGraphQuery(taruviMeta)) {
|
|
186
|
-
const
|
|
187
|
-
return { data:
|
|
283
|
+
const response2 = await new sdk.Graph(client).from(tableName).update(String(id), variables).execute();
|
|
284
|
+
return { data: response2.data };
|
|
188
285
|
}
|
|
189
|
-
const
|
|
190
|
-
return { data };
|
|
286
|
+
const response = await new sdk.Database(client).from(tableName).get(String(id)).update(variables).execute();
|
|
287
|
+
return { data: response.data };
|
|
191
288
|
},
|
|
192
289
|
updateMany: async (params) => {
|
|
193
290
|
const { resource, ids, variables, meta } = params;
|
|
@@ -195,7 +292,8 @@ function dataProvider(client) {
|
|
|
195
292
|
const tableName = getTableName(resource, taruviMeta);
|
|
196
293
|
const data = await Promise.all(
|
|
197
294
|
ids.map(async (id) => {
|
|
198
|
-
|
|
295
|
+
const response = await new sdk.Database(client).from(tableName).get(String(id)).update(variables).execute();
|
|
296
|
+
return response.data;
|
|
199
297
|
})
|
|
200
298
|
);
|
|
201
299
|
return { data };
|
|
@@ -205,46 +303,51 @@ function dataProvider(client) {
|
|
|
205
303
|
const taruviMeta = meta;
|
|
206
304
|
const tableName = getTableName(resource, taruviMeta);
|
|
207
305
|
if (isGraphQuery(taruviMeta)) {
|
|
208
|
-
const
|
|
209
|
-
return { data:
|
|
306
|
+
const response = await new sdk.Graph(client).from(tableName).delete([Number(id)]).execute();
|
|
307
|
+
return { data: response.data };
|
|
210
308
|
}
|
|
211
|
-
|
|
212
|
-
return { data };
|
|
309
|
+
await new sdk.Database(client).from(tableName).delete(String(id)).execute();
|
|
310
|
+
return { data: { id } };
|
|
213
311
|
},
|
|
214
312
|
deleteMany: async (params) => {
|
|
215
313
|
const { resource, ids, meta } = params;
|
|
216
314
|
const taruviMeta = meta;
|
|
217
315
|
const tableName = getTableName(resource, taruviMeta);
|
|
218
316
|
if (isGraphQuery(taruviMeta)) {
|
|
219
|
-
const
|
|
220
|
-
return { data: [
|
|
317
|
+
const response = await new sdk.Graph(client).from(tableName).delete(ids.map(Number)).execute();
|
|
318
|
+
return { data: [response.data] };
|
|
221
319
|
}
|
|
222
|
-
|
|
223
|
-
ids.map((id) =>
|
|
320
|
+
await Promise.all(
|
|
321
|
+
ids.map(async (id) => {
|
|
322
|
+
await new sdk.Database(client).from(tableName).delete(String(id)).execute();
|
|
323
|
+
})
|
|
224
324
|
);
|
|
225
|
-
return { data };
|
|
325
|
+
return { data: ids.map((id) => ({ id })) };
|
|
226
326
|
},
|
|
227
327
|
custom: async (params) => {
|
|
228
328
|
const { url, method, payload, query } = params;
|
|
229
|
-
let
|
|
329
|
+
let endpoint = `api/apps/${config.appSlug}/datatables/${url}`;
|
|
230
330
|
let data;
|
|
231
331
|
switch (method.toLowerCase()) {
|
|
232
332
|
case "get": {
|
|
233
333
|
if (query && Object.keys(query).length > 0) {
|
|
234
334
|
const queryString = new URLSearchParams(query).toString();
|
|
235
|
-
|
|
335
|
+
endpoint = `${endpoint}${endpoint.includes("?") ? "&" : "?"}${queryString}`;
|
|
236
336
|
}
|
|
237
|
-
data = await client.httpClient.get(
|
|
337
|
+
data = await client.httpClient.get(endpoint);
|
|
238
338
|
break;
|
|
239
339
|
}
|
|
240
340
|
case "post":
|
|
241
|
-
data = await client.httpClient.post(
|
|
341
|
+
data = await client.httpClient.post(endpoint, payload);
|
|
242
342
|
break;
|
|
243
343
|
case "put":
|
|
244
|
-
data = await client.httpClient.put(
|
|
344
|
+
data = await client.httpClient.put(endpoint, payload);
|
|
345
|
+
break;
|
|
346
|
+
case "patch":
|
|
347
|
+
data = await client.httpClient.patch(endpoint, payload);
|
|
245
348
|
break;
|
|
246
349
|
case "delete":
|
|
247
|
-
data = await client.httpClient.delete(
|
|
350
|
+
data = await client.httpClient.delete(endpoint);
|
|
248
351
|
break;
|
|
249
352
|
default:
|
|
250
353
|
throw new Error(`Unsupported HTTP method: ${method}`);
|
|
@@ -254,131 +357,9 @@ function dataProvider(client) {
|
|
|
254
357
|
getApiUrl: () => baseApiUrl
|
|
255
358
|
};
|
|
256
359
|
}
|
|
257
|
-
|
|
258
|
-
// src/utils.ts
|
|
259
|
-
var REFINE_OPERATOR_MAP = {
|
|
260
|
-
// Equality
|
|
261
|
-
eq: "",
|
|
262
|
-
// exact match (no suffix)
|
|
263
|
-
ne: "ne",
|
|
264
|
-
// Comparison
|
|
265
|
-
lt: "lt",
|
|
266
|
-
gt: "gt",
|
|
267
|
-
lte: "lte",
|
|
268
|
-
gte: "gte",
|
|
269
|
-
// String operations (case-sensitive)
|
|
270
|
-
contains: "contains",
|
|
271
|
-
ncontains: "ncontains",
|
|
272
|
-
startswith: "startswith",
|
|
273
|
-
nstartswith: "nstartswith",
|
|
274
|
-
endswith: "endswith",
|
|
275
|
-
nendswith: "nendswith",
|
|
276
|
-
// String operations (case-insensitive)
|
|
277
|
-
containss: "icontains",
|
|
278
|
-
ncontainss: "nicontains",
|
|
279
|
-
startswiths: "istartswith",
|
|
280
|
-
nstartswiths: "nistartswith",
|
|
281
|
-
endswiths: "iendswith",
|
|
282
|
-
nendswiths: "niendswith",
|
|
283
|
-
// Array operations
|
|
284
|
-
in: "in",
|
|
285
|
-
nin: "nin",
|
|
286
|
-
// Null checks
|
|
287
|
-
null: "null",
|
|
288
|
-
nnull: "nnull",
|
|
289
|
-
// Range
|
|
290
|
-
between: "between",
|
|
291
|
-
nbetween: "nbetween"
|
|
292
|
-
};
|
|
293
|
-
function convertRefineFilters(filters) {
|
|
294
|
-
if (!filters || filters.length === 0) return {};
|
|
295
|
-
const params = {};
|
|
296
|
-
for (const filter of filters) {
|
|
297
|
-
if ("operator" in filter && (filter.operator === "and" || filter.operator === "or")) {
|
|
298
|
-
if (filter.value && Array.isArray(filter.value)) {
|
|
299
|
-
const nested = convertRefineFilters(filter.value);
|
|
300
|
-
Object.assign(params, nested);
|
|
301
|
-
}
|
|
302
|
-
continue;
|
|
303
|
-
}
|
|
304
|
-
if ("field" in filter && filter.field && filter.operator) {
|
|
305
|
-
const { field, operator, value } = filter;
|
|
306
|
-
if (value === void 0 || value === null && operator !== "null") {
|
|
307
|
-
continue;
|
|
308
|
-
}
|
|
309
|
-
const suffix = REFINE_OPERATOR_MAP[operator];
|
|
310
|
-
if (suffix === void 0) {
|
|
311
|
-
console.warn(`Unknown Refine operator: ${operator}`);
|
|
312
|
-
continue;
|
|
313
|
-
}
|
|
314
|
-
const paramKey = suffix ? `${field}__${suffix}` : String(field);
|
|
315
|
-
if (operator === "in" || operator === "nin") {
|
|
316
|
-
params[paramKey] = Array.isArray(value) ? value.join(",") : String(value);
|
|
317
|
-
} else if (operator === "between" || operator === "nbetween") {
|
|
318
|
-
params[paramKey] = Array.isArray(value) ? value.join(",") : String(value);
|
|
319
|
-
} else if (operator === "null" || operator === "nnull") {
|
|
320
|
-
params[paramKey] = "true";
|
|
321
|
-
} else {
|
|
322
|
-
params[paramKey] = String(value);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
return params;
|
|
327
|
-
}
|
|
328
|
-
function convertRefineSorters(sorters) {
|
|
329
|
-
if (!sorters || sorters.length === 0) return void 0;
|
|
330
|
-
return sorters.map((sort) => sort.order === "desc" ? `-${sort.field}` : sort.field).join(",");
|
|
331
|
-
}
|
|
332
|
-
function convertRefinePagination(pagination) {
|
|
333
|
-
if (!pagination) return {};
|
|
334
|
-
const { currentPage, pageSize, mode } = pagination;
|
|
335
|
-
if (mode === "off") return {};
|
|
336
|
-
return {
|
|
337
|
-
page: currentPage ?? 1,
|
|
338
|
-
// Default to page 1 if currentPage is undefined
|
|
339
|
-
page_size: pageSize
|
|
340
|
-
};
|
|
341
|
-
}
|
|
342
|
-
function buildRefineQueryParams(options) {
|
|
343
|
-
const { filters, sorters, pagination, meta } = options;
|
|
344
|
-
const params = {
|
|
345
|
-
...convertRefineFilters(filters),
|
|
346
|
-
...convertRefinePagination(pagination)
|
|
347
|
-
};
|
|
348
|
-
const ordering = convertRefineSorters(sorters);
|
|
349
|
-
if (ordering) {
|
|
350
|
-
params.ordering = ordering;
|
|
351
|
-
}
|
|
352
|
-
if (meta?.populate) {
|
|
353
|
-
params.populate = Array.isArray(meta.populate) ? meta.populate.join(",") : meta.populate;
|
|
354
|
-
}
|
|
355
|
-
return params;
|
|
356
|
-
}
|
|
357
|
-
function buildQueryString(params) {
|
|
358
|
-
if (!params || Object.keys(params).length === 0) return "";
|
|
359
|
-
const searchParams = new URLSearchParams();
|
|
360
|
-
for (const [key, value] of Object.entries(params)) {
|
|
361
|
-
if (value !== void 0 && value !== null) {
|
|
362
|
-
searchParams.append(key, String(value));
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
const queryString = searchParams.toString();
|
|
366
|
-
return queryString ? `?${queryString}` : "";
|
|
367
|
-
}
|
|
368
|
-
function handleError(error) {
|
|
369
|
-
if (error instanceof Error) {
|
|
370
|
-
throw error;
|
|
371
|
-
}
|
|
372
|
-
if (typeof error === "object" && error !== null && "message" in error) {
|
|
373
|
-
throw new Error(String(error.message));
|
|
374
|
-
}
|
|
375
|
-
throw new Error("Unknown error occurred");
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
// src/storageDataProvider.ts
|
|
379
360
|
function storageDataProvider(client) {
|
|
380
361
|
const config = client.getConfig();
|
|
381
|
-
const baseApiUrl = `${config.
|
|
362
|
+
const baseApiUrl = `${config.apiUrl}/api/apps/${config.appSlug}`;
|
|
382
363
|
const getBucketName = (resource, meta) => meta?.bucketName ?? resource;
|
|
383
364
|
const buildFilters = (params) => {
|
|
384
365
|
const filters = {
|
|
@@ -395,16 +376,14 @@ function storageDataProvider(client) {
|
|
|
395
376
|
const taruviMeta = meta;
|
|
396
377
|
const bucket = getBucketName(resource, taruviMeta);
|
|
397
378
|
const storageFilters = buildFilters({ filters, sorters, pagination});
|
|
398
|
-
const response = await new sdk.Storage(client
|
|
379
|
+
const response = await new sdk.Storage(client).from(bucket).filter(storageFilters).execute();
|
|
399
380
|
return { data: response.data, total: response.total };
|
|
400
381
|
},
|
|
401
382
|
getOne: async (params) => {
|
|
402
383
|
const { resource, id: path, meta } = params;
|
|
403
384
|
const taruviMeta = meta;
|
|
404
385
|
const bucket = getBucketName(resource, taruviMeta);
|
|
405
|
-
const
|
|
406
|
-
const url = `${baseApiUrl}/storage/buckets/${bucket}/objects/${encodedPath}`;
|
|
407
|
-
const data = url;
|
|
386
|
+
const data = await new sdk.Storage(client).from(bucket).download(String(path)).execute();
|
|
408
387
|
return { data };
|
|
409
388
|
},
|
|
410
389
|
create: async (params) => {
|
|
@@ -414,25 +393,25 @@ function storageDataProvider(client) {
|
|
|
414
393
|
const { files, paths = [], metadatas = [] } = variables;
|
|
415
394
|
const filePaths = files.map((file, i) => paths[i] || file.name);
|
|
416
395
|
const fileMetadatas = files.map((_, i) => metadatas[i] || {});
|
|
417
|
-
const
|
|
418
|
-
|
|
396
|
+
const response = await new sdk.Storage(client).from(bucket).upload({ files, paths: filePaths, metadatas: fileMetadatas }).execute();
|
|
397
|
+
const firstUploaded = response.data?.successful?.[0]?.object;
|
|
398
|
+
return { data: firstUploaded ?? response.data };
|
|
419
399
|
},
|
|
420
400
|
update: async (params) => {
|
|
421
401
|
const { resource, id: path, variables, meta } = params;
|
|
422
402
|
const taruviMeta = meta;
|
|
423
403
|
const bucket = getBucketName(resource, taruviMeta);
|
|
424
|
-
const
|
|
425
|
-
return { data };
|
|
404
|
+
const response = await new sdk.Storage(client).from(bucket).update(String(path), variables).execute();
|
|
405
|
+
return { data: response.data };
|
|
426
406
|
},
|
|
427
407
|
deleteOne: async (params) => {
|
|
428
408
|
const { resource, id: path, meta } = params;
|
|
429
409
|
const taruviMeta = meta;
|
|
430
410
|
const bucket = getBucketName(resource, taruviMeta);
|
|
431
|
-
|
|
432
|
-
return { data };
|
|
411
|
+
await new sdk.Storage(client).from(bucket).delete([String(path)]).execute();
|
|
412
|
+
return { data: { id: path } };
|
|
433
413
|
},
|
|
434
414
|
getApiUrl: () => baseApiUrl,
|
|
435
|
-
// Not applicable for storage - return empty array
|
|
436
415
|
getMany: async () => ({ data: [] }),
|
|
437
416
|
createMany: async (params) => {
|
|
438
417
|
const { resource, variables, meta } = params;
|
|
@@ -441,15 +420,16 @@ function storageDataProvider(client) {
|
|
|
441
420
|
const { files, paths = [], metadatas = [] } = variables;
|
|
442
421
|
const filePaths = files.map((file, i) => paths[i] || file.name);
|
|
443
422
|
const fileMetadatas = files.map((_, i) => metadatas[i] || {});
|
|
444
|
-
const
|
|
445
|
-
|
|
423
|
+
const response = await new sdk.Storage(client).from(bucket).upload({ files, paths: filePaths, metadatas: fileMetadatas }).execute();
|
|
424
|
+
const uploaded = response.data?.successful?.map((s) => s.object) ?? [];
|
|
425
|
+
return { data: uploaded.length > 0 ? uploaded[0] : response.data };
|
|
446
426
|
},
|
|
447
427
|
deleteMany: async (params) => {
|
|
448
428
|
const { resource, ids, meta } = params;
|
|
449
429
|
const taruviMeta = meta;
|
|
450
430
|
const bucket = getBucketName(resource, taruviMeta);
|
|
451
|
-
|
|
452
|
-
return { data:
|
|
431
|
+
await new sdk.Storage(client).from(bucket).delete(ids.map(String)).execute();
|
|
432
|
+
return { data: ids.map((id) => ({ id })) };
|
|
453
433
|
},
|
|
454
434
|
custom: async (params) => {
|
|
455
435
|
const { url, method, payload, query } = params;
|
|
@@ -470,6 +450,9 @@ function storageDataProvider(client) {
|
|
|
470
450
|
case "put":
|
|
471
451
|
data = await client.httpClient.put(fullUrl, payload);
|
|
472
452
|
break;
|
|
453
|
+
case "patch":
|
|
454
|
+
data = await client.httpClient.patch(fullUrl, payload);
|
|
455
|
+
break;
|
|
473
456
|
case "delete":
|
|
474
457
|
data = await client.httpClient.delete(fullUrl);
|
|
475
458
|
break;
|
|
@@ -482,86 +465,14 @@ function storageDataProvider(client) {
|
|
|
482
465
|
updateMany: void 0
|
|
483
466
|
};
|
|
484
467
|
}
|
|
485
|
-
function functionsDataProvider(client) {
|
|
486
|
-
const config = client.getConfig();
|
|
487
|
-
const baseApiUrl = `${config.baseUrl}/api/apps/${config.appSlug}`;
|
|
488
|
-
const functions = new sdk.Functions(client);
|
|
489
|
-
return {
|
|
490
|
-
/**
|
|
491
|
-
* Execute an edge function.
|
|
492
|
-
*
|
|
493
|
-
* @param resource - The function slug to execute
|
|
494
|
-
* @param variables - Parameters to pass to the function
|
|
495
|
-
* @param meta.async - Whether to execute asynchronously (default: false)
|
|
496
|
-
*/
|
|
497
|
-
create: async ({
|
|
498
|
-
resource,
|
|
499
|
-
variables,
|
|
500
|
-
meta
|
|
501
|
-
}) => {
|
|
502
|
-
const functionMeta = meta;
|
|
503
|
-
const response = await functions.execute(resource, {
|
|
504
|
-
async: functionMeta?.async ?? false,
|
|
505
|
-
params: variables
|
|
506
|
-
});
|
|
507
|
-
return { data: response.data };
|
|
508
|
-
},
|
|
509
|
-
getApiUrl: () => baseApiUrl,
|
|
510
|
-
// Edge functions don't support custom method - use create() instead
|
|
511
|
-
custom: async () => {
|
|
512
|
-
throw new Error(
|
|
513
|
-
"custom is not supported for edge functions. Use useCreate to execute functions."
|
|
514
|
-
);
|
|
515
|
-
},
|
|
516
|
-
// Edge functions don't support other CRUD operations
|
|
517
|
-
getList: async () => {
|
|
518
|
-
throw new Error(
|
|
519
|
-
"getList is not supported for edge functions. Use useCreate to execute functions."
|
|
520
|
-
);
|
|
521
|
-
},
|
|
522
|
-
getOne: async () => {
|
|
523
|
-
throw new Error(
|
|
524
|
-
"getOne is not supported for edge functions. Use useCreate to execute functions."
|
|
525
|
-
);
|
|
526
|
-
},
|
|
527
|
-
getMany: async () => {
|
|
528
|
-
throw new Error(
|
|
529
|
-
"getMany is not supported for edge functions. Use useCreate to execute functions."
|
|
530
|
-
);
|
|
531
|
-
},
|
|
532
|
-
createMany: async () => {
|
|
533
|
-
throw new Error(
|
|
534
|
-
"createMany is not supported for edge functions. Use useCreate to execute functions."
|
|
535
|
-
);
|
|
536
|
-
},
|
|
537
|
-
update: async () => {
|
|
538
|
-
throw new Error(
|
|
539
|
-
"update is not supported for edge functions. Use useCreate to execute functions."
|
|
540
|
-
);
|
|
541
|
-
},
|
|
542
|
-
updateMany: async () => {
|
|
543
|
-
throw new Error(
|
|
544
|
-
"updateMany is not supported for edge functions. Use useCreate to execute functions."
|
|
545
|
-
);
|
|
546
|
-
},
|
|
547
|
-
deleteOne: async () => {
|
|
548
|
-
throw new Error(
|
|
549
|
-
"deleteOne is not supported for edge functions. Use useCreate to execute functions."
|
|
550
|
-
);
|
|
551
|
-
},
|
|
552
|
-
deleteMany: async () => {
|
|
553
|
-
throw new Error(
|
|
554
|
-
"deleteMany is not supported for edge functions. Use useCreate to execute functions."
|
|
555
|
-
);
|
|
556
|
-
}
|
|
557
|
-
};
|
|
558
|
-
}
|
|
559
468
|
function appDataProvider(client) {
|
|
560
469
|
const config = client.getConfig();
|
|
561
|
-
const baseApiUrl = `${config.
|
|
470
|
+
const baseApiUrl = `${config.apiUrl}/api/apps/${config.appSlug}`;
|
|
471
|
+
const functions = new sdk.Functions(client);
|
|
472
|
+
const analytics = new sdk.Analytics(client);
|
|
562
473
|
return {
|
|
563
474
|
getList: async (params) => {
|
|
564
|
-
const { resource } = params;
|
|
475
|
+
const { resource, meta } = params;
|
|
565
476
|
if (resource === "roles") {
|
|
566
477
|
const app = new sdk.App(client);
|
|
567
478
|
const response = await app.roles().execute();
|
|
@@ -570,26 +481,67 @@ function appDataProvider(client) {
|
|
|
570
481
|
total: response.total ?? (Array.isArray(response) ? response.length : response.data?.length ?? 0)
|
|
571
482
|
};
|
|
572
483
|
}
|
|
573
|
-
|
|
484
|
+
if (resource === "secrets") {
|
|
485
|
+
const keys = meta?.keys;
|
|
486
|
+
if (!keys || keys.length === 0) {
|
|
487
|
+
throw new Error("secrets resource requires meta.keys array");
|
|
488
|
+
}
|
|
489
|
+
const secrets = new sdk.Secrets(client);
|
|
490
|
+
const response = await secrets.list(keys, {
|
|
491
|
+
app: meta?.app,
|
|
492
|
+
includeMetadata: meta?.includeMetadata
|
|
493
|
+
});
|
|
494
|
+
const raw = response.data || response;
|
|
495
|
+
const data = Array.isArray(raw) ? raw : Object.entries(raw).map(([key, value]) => ({ key, value }));
|
|
496
|
+
return { data, total: data.length };
|
|
497
|
+
}
|
|
498
|
+
throw new Error(`Unknown app resource: ${resource}. Supported resources: roles, secrets`);
|
|
574
499
|
},
|
|
575
|
-
getApiUrl: () => baseApiUrl,
|
|
576
500
|
getOne: async (params) => {
|
|
577
|
-
const { resource } = params;
|
|
501
|
+
const { resource, id, meta } = params;
|
|
578
502
|
if (resource === "settings") {
|
|
579
503
|
const app = new sdk.App(client);
|
|
580
504
|
const response = await app.settings().execute();
|
|
581
505
|
return {
|
|
582
|
-
data: response
|
|
506
|
+
data: response.data
|
|
583
507
|
};
|
|
584
508
|
}
|
|
585
|
-
|
|
509
|
+
if (resource === "secrets") {
|
|
510
|
+
const secrets = new sdk.Secrets(client);
|
|
511
|
+
const response = await secrets.get(String(id), {
|
|
512
|
+
app: meta?.app,
|
|
513
|
+
tags: meta?.tags
|
|
514
|
+
}).execute();
|
|
515
|
+
return { data: response.data ?? response };
|
|
516
|
+
}
|
|
517
|
+
throw new Error(`Unknown app resource for getOne: ${resource}. Supported resources: settings, secrets`);
|
|
518
|
+
},
|
|
519
|
+
custom: async (params) => {
|
|
520
|
+
const { url: slug, payload, meta } = params;
|
|
521
|
+
const customMeta = meta;
|
|
522
|
+
if (customMeta?.kind === "function") {
|
|
523
|
+
const response = await functions.execute(slug, {
|
|
524
|
+
async: customMeta.async ?? false,
|
|
525
|
+
params: payload ?? {}
|
|
526
|
+
});
|
|
527
|
+
return { data: response.data };
|
|
528
|
+
}
|
|
529
|
+
if (customMeta?.kind === "analytics") {
|
|
530
|
+
const response = await analytics.execute(slug, {
|
|
531
|
+
params: payload ?? {}
|
|
532
|
+
});
|
|
533
|
+
return { data: response.data };
|
|
534
|
+
}
|
|
535
|
+
throw new Error(
|
|
536
|
+
'Specify meta.kind as "function" or "analytics" for custom operations on the app provider.'
|
|
537
|
+
);
|
|
586
538
|
},
|
|
587
|
-
|
|
539
|
+
getApiUrl: () => baseApiUrl,
|
|
588
540
|
getMany: async () => {
|
|
589
541
|
throw new Error("getMany is not supported for app resources");
|
|
590
542
|
},
|
|
591
543
|
create: async () => {
|
|
592
|
-
throw new Error("create is not supported for app resources");
|
|
544
|
+
throw new Error("create is not supported for app resources. Use useCustom with meta.kind");
|
|
593
545
|
},
|
|
594
546
|
createMany: async () => {
|
|
595
547
|
throw new Error("createMany is not supported for app resources");
|
|
@@ -605,9 +557,6 @@ function appDataProvider(client) {
|
|
|
605
557
|
},
|
|
606
558
|
deleteMany: async () => {
|
|
607
559
|
throw new Error("deleteMany is not supported for app resources");
|
|
608
|
-
},
|
|
609
|
-
custom: async () => {
|
|
610
|
-
throw new Error("custom is not supported for app resources");
|
|
611
560
|
}
|
|
612
561
|
};
|
|
613
562
|
}
|
|
@@ -654,7 +603,7 @@ function buildUserListFilters(filters, sorters, pagination) {
|
|
|
654
603
|
}
|
|
655
604
|
function userDataProvider(client) {
|
|
656
605
|
const config = client.getConfig();
|
|
657
|
-
const baseApiUrl = `${config.
|
|
606
|
+
const baseApiUrl = `${config.apiUrl}/api/apps/${config.appSlug}`;
|
|
658
607
|
return {
|
|
659
608
|
getList: async (params) => {
|
|
660
609
|
const { resource, pagination, filters, sorters, meta } = params;
|
|
@@ -674,20 +623,41 @@ function userDataProvider(client) {
|
|
|
674
623
|
}
|
|
675
624
|
const user = new sdk.User(client);
|
|
676
625
|
const response = await user.getUser(username);
|
|
677
|
-
const roles = response.roles || [];
|
|
626
|
+
const roles = response.data?.roles || response.roles || [];
|
|
678
627
|
return {
|
|
679
628
|
data: roles,
|
|
680
629
|
total: roles.length
|
|
681
630
|
};
|
|
682
631
|
}
|
|
683
|
-
|
|
632
|
+
if (resource === "apps") {
|
|
633
|
+
const username = meta?.username;
|
|
634
|
+
if (!username) {
|
|
635
|
+
throw new Error("apps resource requires meta.username");
|
|
636
|
+
}
|
|
637
|
+
const user = new sdk.User(client);
|
|
638
|
+
const response = await user.getUserApps(username);
|
|
639
|
+
const apps = response.data || response;
|
|
640
|
+
return {
|
|
641
|
+
data: apps,
|
|
642
|
+
total: Array.isArray(apps) ? apps.length : 0
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
throw new Error(`Unknown user resource for getList: ${resource}. Supported: users, roles, apps`);
|
|
684
646
|
},
|
|
685
647
|
getOne: async (params) => {
|
|
686
648
|
const { resource, id } = params;
|
|
687
649
|
if (resource === "users") {
|
|
688
650
|
const user = new sdk.User(client);
|
|
651
|
+
if (String(id) === "me") {
|
|
652
|
+
const auth = new sdk.Auth(client);
|
|
653
|
+
const response2 = await auth.getCurrentUser();
|
|
654
|
+
const data = response2 ? response2.data ?? response2 : null;
|
|
655
|
+
return { data };
|
|
656
|
+
}
|
|
689
657
|
const response = await user.getUser(String(id));
|
|
690
|
-
return {
|
|
658
|
+
return {
|
|
659
|
+
data: response.data
|
|
660
|
+
};
|
|
691
661
|
}
|
|
692
662
|
throw new Error(`Unknown user resource for getOne: ${resource}. Supported: users`);
|
|
693
663
|
},
|
|
@@ -699,7 +669,7 @@ function userDataProvider(client) {
|
|
|
699
669
|
const userData = variables;
|
|
700
670
|
const response = await user.createUser(userData);
|
|
701
671
|
return {
|
|
702
|
-
data: response
|
|
672
|
+
data: response.data
|
|
703
673
|
};
|
|
704
674
|
}
|
|
705
675
|
throw new Error(`Unknown user resource for create: ${resource}. Supported resources: users`);
|
|
@@ -712,7 +682,7 @@ function userDataProvider(client) {
|
|
|
712
682
|
const updateData = variables;
|
|
713
683
|
const response = await user.updateUser(username, updateData);
|
|
714
684
|
return {
|
|
715
|
-
data: response
|
|
685
|
+
data: response.data
|
|
716
686
|
};
|
|
717
687
|
}
|
|
718
688
|
throw new Error(`Unknown user resource for update: ${resource}. Supported resources: users`);
|
|
@@ -747,9 +717,83 @@ function userDataProvider(client) {
|
|
|
747
717
|
}
|
|
748
718
|
};
|
|
749
719
|
}
|
|
720
|
+
function functionsDataProvider(client) {
|
|
721
|
+
const config = client.getConfig();
|
|
722
|
+
const baseApiUrl = `${config.apiUrl}/api/apps/${config.appSlug}`;
|
|
723
|
+
const functions = new sdk.Functions(client);
|
|
724
|
+
return {
|
|
725
|
+
/**
|
|
726
|
+
* Execute an edge function.
|
|
727
|
+
*
|
|
728
|
+
* @param resource - The function slug to execute
|
|
729
|
+
* @param variables - Parameters to pass to the function
|
|
730
|
+
* @param meta.async - Whether to execute asynchronously (default: false)
|
|
731
|
+
*/
|
|
732
|
+
create: async ({
|
|
733
|
+
resource,
|
|
734
|
+
variables,
|
|
735
|
+
meta
|
|
736
|
+
}) => {
|
|
737
|
+
const functionMeta = meta;
|
|
738
|
+
const response = await functions.execute(resource, {
|
|
739
|
+
async: functionMeta?.async ?? false,
|
|
740
|
+
params: variables
|
|
741
|
+
});
|
|
742
|
+
return { data: response.data };
|
|
743
|
+
},
|
|
744
|
+
getApiUrl: () => baseApiUrl,
|
|
745
|
+
// Edge functions don't support custom method - use create() instead
|
|
746
|
+
custom: async () => {
|
|
747
|
+
throw new Error(
|
|
748
|
+
"custom is not supported for edge functions. Use useCreate to execute functions."
|
|
749
|
+
);
|
|
750
|
+
},
|
|
751
|
+
// Edge functions don't support other CRUD operations
|
|
752
|
+
getList: async () => {
|
|
753
|
+
throw new Error(
|
|
754
|
+
"getList is not supported for edge functions. Use useCreate to execute functions."
|
|
755
|
+
);
|
|
756
|
+
},
|
|
757
|
+
getOne: async () => {
|
|
758
|
+
throw new Error(
|
|
759
|
+
"getOne is not supported for edge functions. Use useCreate to execute functions."
|
|
760
|
+
);
|
|
761
|
+
},
|
|
762
|
+
getMany: async () => {
|
|
763
|
+
throw new Error(
|
|
764
|
+
"getMany is not supported for edge functions. Use useCreate to execute functions."
|
|
765
|
+
);
|
|
766
|
+
},
|
|
767
|
+
createMany: async () => {
|
|
768
|
+
throw new Error(
|
|
769
|
+
"createMany is not supported for edge functions. Use useCreate to execute functions."
|
|
770
|
+
);
|
|
771
|
+
},
|
|
772
|
+
update: async () => {
|
|
773
|
+
throw new Error(
|
|
774
|
+
"update is not supported for edge functions. Use useCreate to execute functions."
|
|
775
|
+
);
|
|
776
|
+
},
|
|
777
|
+
updateMany: async () => {
|
|
778
|
+
throw new Error(
|
|
779
|
+
"updateMany is not supported for edge functions. Use useCreate to execute functions."
|
|
780
|
+
);
|
|
781
|
+
},
|
|
782
|
+
deleteOne: async () => {
|
|
783
|
+
throw new Error(
|
|
784
|
+
"deleteOne is not supported for edge functions. Use useCreate to execute functions."
|
|
785
|
+
);
|
|
786
|
+
},
|
|
787
|
+
deleteMany: async () => {
|
|
788
|
+
throw new Error(
|
|
789
|
+
"deleteMany is not supported for edge functions. Use useCreate to execute functions."
|
|
790
|
+
);
|
|
791
|
+
}
|
|
792
|
+
};
|
|
793
|
+
}
|
|
750
794
|
function analyticsDataProvider(client) {
|
|
751
795
|
const config = client.getConfig();
|
|
752
|
-
const baseApiUrl = `${config.
|
|
796
|
+
const baseApiUrl = `${config.apiUrl}/api/apps/${config.appSlug}`;
|
|
753
797
|
const analytics = new sdk.Analytics(client);
|
|
754
798
|
return {
|
|
755
799
|
/**
|
|
@@ -844,7 +888,7 @@ function authProvider(client) {
|
|
|
844
888
|
},
|
|
845
889
|
logout: async (params = {}) => {
|
|
846
890
|
const { callbackUrl } = params;
|
|
847
|
-
auth.logout(callbackUrl);
|
|
891
|
+
await auth.logout(callbackUrl);
|
|
848
892
|
return {
|
|
849
893
|
success: true,
|
|
850
894
|
redirectTo: callbackUrl || "/login"
|
|
@@ -914,14 +958,18 @@ function authProvider(client) {
|
|
|
914
958
|
};
|
|
915
959
|
},
|
|
916
960
|
getIdentity: async () => {
|
|
917
|
-
const
|
|
918
|
-
if (!
|
|
961
|
+
const response = await auth.getCurrentUser();
|
|
962
|
+
if (!response) {
|
|
919
963
|
return null;
|
|
920
964
|
}
|
|
921
|
-
return
|
|
965
|
+
return response.data ?? response;
|
|
922
966
|
},
|
|
923
967
|
getPermissions: async () => {
|
|
924
|
-
const
|
|
968
|
+
const response = await auth.getCurrentUser();
|
|
969
|
+
if (!response) {
|
|
970
|
+
return null;
|
|
971
|
+
}
|
|
972
|
+
const user = response.data ?? response;
|
|
925
973
|
if (!user) {
|
|
926
974
|
return null;
|
|
927
975
|
}
|
|
@@ -939,9 +987,10 @@ function accessControlProvider(client, options) {
|
|
|
939
987
|
const policy = new sdk.Policy(client);
|
|
940
988
|
const auth = new sdk.Auth(client);
|
|
941
989
|
const { batchDelayMs = 50 } = options ?? {};
|
|
942
|
-
const permissionLoader = new
|
|
990
|
+
const permissionLoader = new DataLoader__default.default(
|
|
943
991
|
async (checks) => {
|
|
944
|
-
const
|
|
992
|
+
const response = await auth.getCurrentUser();
|
|
993
|
+
const user = response ? response.data ?? response : null;
|
|
945
994
|
if (!user) {
|
|
946
995
|
return checks.map(() => ({
|
|
947
996
|
can: false,
|
|
@@ -1008,7 +1057,7 @@ function accessControlProvider(client, options) {
|
|
|
1008
1057
|
if (!resource) {
|
|
1009
1058
|
return { can: false, reason: "Resource not specified" };
|
|
1010
1059
|
}
|
|
1011
|
-
const entityType = params?.resource?.meta?.entityType;
|
|
1060
|
+
const entityType = params?.entityType ?? params?.resource?.meta?.entityType;
|
|
1012
1061
|
return permissionLoader.load({
|
|
1013
1062
|
resource,
|
|
1014
1063
|
action,
|