@taruvi/refine-providers 1.1.7 → 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/dist/index.cjs +116 -88
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +116 -88
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/index.d.cts +0 -268
- package/dist/index.d.ts +0 -268
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 = {
|
|
@@ -402,10 +402,20 @@ function storageDataProvider(client) {
|
|
|
402
402
|
const { resource, id: path, meta } = params;
|
|
403
403
|
const taruviMeta = meta;
|
|
404
404
|
const bucket = getBucketName(resource, taruviMeta);
|
|
405
|
-
const encodedPath =
|
|
406
|
-
const url = `${baseApiUrl}/storage/buckets/${bucket}/objects/${encodedPath}
|
|
407
|
-
const
|
|
408
|
-
|
|
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 };
|
|
409
419
|
},
|
|
410
420
|
create: async (params) => {
|
|
411
421
|
const { resource, variables, meta } = params;
|
|
@@ -482,83 +492,11 @@ function storageDataProvider(client) {
|
|
|
482
492
|
updateMany: void 0
|
|
483
493
|
};
|
|
484
494
|
}
|
|
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
495
|
function appDataProvider(client) {
|
|
560
496
|
const config = client.getConfig();
|
|
561
497
|
const baseApiUrl = `${config.baseUrl}/api/apps/${config.appSlug}`;
|
|
498
|
+
const functions = new sdk.Functions(client);
|
|
499
|
+
const analytics = new sdk.Analytics(client);
|
|
562
500
|
return {
|
|
563
501
|
getList: async (params) => {
|
|
564
502
|
const { resource } = params;
|
|
@@ -572,7 +510,6 @@ function appDataProvider(client) {
|
|
|
572
510
|
}
|
|
573
511
|
throw new Error(`Unknown app resource: ${resource}. Supported resources: roles`);
|
|
574
512
|
},
|
|
575
|
-
getApiUrl: () => baseApiUrl,
|
|
576
513
|
getOne: async (params) => {
|
|
577
514
|
const { resource } = params;
|
|
578
515
|
if (resource === "settings") {
|
|
@@ -584,12 +521,32 @@ function appDataProvider(client) {
|
|
|
584
521
|
}
|
|
585
522
|
throw new Error(`Unknown app resource for getOne: ${resource}. Supported resources: settings`);
|
|
586
523
|
},
|
|
587
|
-
|
|
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,
|
|
588
545
|
getMany: async () => {
|
|
589
546
|
throw new Error("getMany is not supported for app resources");
|
|
590
547
|
},
|
|
591
548
|
create: async () => {
|
|
592
|
-
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");
|
|
593
550
|
},
|
|
594
551
|
createMany: async () => {
|
|
595
552
|
throw new Error("createMany is not supported for app resources");
|
|
@@ -605,9 +562,6 @@ function appDataProvider(client) {
|
|
|
605
562
|
},
|
|
606
563
|
deleteMany: async () => {
|
|
607
564
|
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
565
|
}
|
|
612
566
|
};
|
|
613
567
|
}
|
|
@@ -747,6 +701,80 @@ function userDataProvider(client) {
|
|
|
747
701
|
}
|
|
748
702
|
};
|
|
749
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
|
+
}
|
|
750
778
|
function analyticsDataProvider(client) {
|
|
751
779
|
const config = client.getConfig();
|
|
752
780
|
const baseApiUrl = `${config.baseUrl}/api/apps/${config.appSlug}`;
|
|
@@ -939,7 +967,7 @@ function accessControlProvider(client, options) {
|
|
|
939
967
|
const policy = new sdk.Policy(client);
|
|
940
968
|
const auth = new sdk.Auth(client);
|
|
941
969
|
const { batchDelayMs = 50 } = options ?? {};
|
|
942
|
-
const permissionLoader = new
|
|
970
|
+
const permissionLoader = new DataLoader__default.default(
|
|
943
971
|
async (checks) => {
|
|
944
972
|
const user = await auth.getCurrentUser();
|
|
945
973
|
if (!user) {
|
|
@@ -1008,7 +1036,7 @@ function accessControlProvider(client, options) {
|
|
|
1008
1036
|
if (!resource) {
|
|
1009
1037
|
return { can: false, reason: "Resource not specified" };
|
|
1010
1038
|
}
|
|
1011
|
-
const entityType = params?.resource?.meta?.entityType;
|
|
1039
|
+
const entityType = params?.entityType ?? params?.resource?.meta?.entityType;
|
|
1012
1040
|
return permissionLoader.load({
|
|
1013
1041
|
resource,
|
|
1014
1042
|
action,
|