@taruvi/refine-providers 1.1.7 → 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/dist/index.d.ts CHANGED
@@ -20,36 +20,52 @@ interface StorageUploadVariables {
20
20
  declare function storageDataProvider(client: Client): DataProvider;
21
21
 
22
22
  /**
23
- * Extended meta options for function execution.
23
+ * Meta options for function execution via custom().
24
24
  */
25
25
  interface FunctionMeta {
26
+ kind: "function";
26
27
  /** Whether to execute the function asynchronously */
27
28
  async?: boolean;
28
29
  }
29
- declare function functionsDataProvider(client: Client): DataProvider;
30
-
30
+ /**
31
+ * Meta options for analytics query execution via custom().
32
+ */
33
+ interface AnalyticsMeta {
34
+ kind: "analytics";
35
+ }
36
+ type AppCustomMeta = FunctionMeta | AnalyticsMeta;
31
37
  /**
32
38
  * Creates a Refine DataProvider for Taruvi App operations.
33
39
  *
34
- * This provider is specialized for fetching app-level data like roles and settings.
35
- *
36
- * Supported resources:
37
- * - "roles" (getList): Fetch app roles
38
- * - "settings" (getOne): Fetch app settings
40
+ * Supported operations:
41
+ * - getList("roles"): Fetch app roles
42
+ * - getOne("settings"): Fetch app settings
43
+ * - custom(): Execute edge functions or analytics queries via meta.kind
39
44
  *
40
45
  * @example
41
46
  * ```typescript
42
47
  * // Get app roles
43
- * const { data } = useList({
48
+ * useList({ dataProviderName: "app", resource: "roles" });
49
+ *
50
+ * // Get app settings
51
+ * useOne({ dataProviderName: "app", resource: "settings", id: "" });
52
+ *
53
+ * // Execute an edge function
54
+ * useCustom({
44
55
  * dataProviderName: "app",
45
- * resource: "roles",
56
+ * url: "process-order",
57
+ * method: "post",
58
+ * config: { payload: { orderId: 123 } },
59
+ * meta: { kind: "function", async: false },
46
60
  * });
47
61
  *
48
- * // Get app settings
49
- * const { data } = useOne({
62
+ * // Execute an analytics query
63
+ * useCustom({
50
64
  * dataProviderName: "app",
51
- * resource: "settings",
52
- * id: "", // id is ignored for settings
65
+ * url: "monthly-report",
66
+ * method: "post",
67
+ * config: { payload: { period: "Q1" } },
68
+ * meta: { kind: "analytics" },
53
69
  * });
54
70
  * ```
55
71
  */
@@ -96,13 +112,10 @@ declare function appDataProvider(client: Client): DataProvider;
96
112
  */
97
113
  declare function userDataProvider(client: Client): DataProvider;
98
114
 
99
- /**
100
- * Extended meta options for analytics query execution.
101
- */
102
- interface AnalyticsMeta {
103
- /** Additional parameters to pass to the analytics query */
104
- params?: Record<string, unknown>;
105
- }
115
+ /** @deprecated Use `appDataProvider` with `useCustom` and `meta.kind: "function"` instead. */
116
+ declare function functionsDataProvider(client: Client): DataProvider;
117
+
118
+ /** @deprecated Use `appDataProvider` with `useCustom` and `meta.kind: "analytics"` instead. */
106
119
  declare function analyticsDataProvider(client: Client): DataProvider;
107
120
 
108
121
  /**
@@ -265,4 +278,4 @@ declare function buildQueryString(params?: Record<string, unknown>): string;
265
278
  */
266
279
  declare function handleError(error: unknown): never;
267
280
 
268
- export { type AnalyticsMeta, type FunctionMeta, type LoginParams, type LogoutParams, REFINE_OPERATOR_MAP, type RegisterParams, type StorageUploadVariables, type TaruviListResponse, type TaruviMeta, accessControlProvider, analyticsDataProvider, appDataProvider, authProvider, buildQueryString, buildRefineQueryParams, convertRefineFilters, convertRefinePagination, convertRefineSorters, dataProvider, functionsDataProvider, handleError, storageDataProvider, userDataProvider };
281
+ export { type AnalyticsMeta, type AppCustomMeta, type FunctionMeta, type LoginParams, type LogoutParams, REFINE_OPERATOR_MAP, type RegisterParams, type StorageUploadVariables, type TaruviListResponse, type TaruviMeta, accessControlProvider, analyticsDataProvider, appDataProvider, authProvider, buildQueryString, buildRefineQueryParams, convertRefineFilters, convertRefinePagination, convertRefineSorters, dataProvider, functionsDataProvider, handleError, storageDataProvider, userDataProvider };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Graph, Database, Storage, Functions, App, User, Analytics, Auth, Policy } from '@taruvi/sdk';
1
+ import { Graph, Database, Storage, Functions, Analytics, App, User, Auth, Policy } from '@taruvi/sdk';
2
2
  import DataLoader2 from 'dataloader';
3
3
 
4
4
  // src/dataProvider.ts
@@ -476,83 +476,11 @@ function storageDataProvider(client) {
476
476
  updateMany: void 0
477
477
  };
478
478
  }
479
- function functionsDataProvider(client) {
480
- const config = client.getConfig();
481
- const baseApiUrl = `${config.baseUrl}/api/apps/${config.appSlug}`;
482
- const functions = new Functions(client);
483
- return {
484
- /**
485
- * Execute an edge function.
486
- *
487
- * @param resource - The function slug to execute
488
- * @param variables - Parameters to pass to the function
489
- * @param meta.async - Whether to execute asynchronously (default: false)
490
- */
491
- create: async ({
492
- resource,
493
- variables,
494
- meta
495
- }) => {
496
- const functionMeta = meta;
497
- const response = await functions.execute(resource, {
498
- async: functionMeta?.async ?? false,
499
- params: variables
500
- });
501
- return { data: response.data };
502
- },
503
- getApiUrl: () => baseApiUrl,
504
- // Edge functions don't support custom method - use create() instead
505
- custom: async () => {
506
- throw new Error(
507
- "custom is not supported for edge functions. Use useCreate to execute functions."
508
- );
509
- },
510
- // Edge functions don't support other CRUD operations
511
- getList: async () => {
512
- throw new Error(
513
- "getList is not supported for edge functions. Use useCreate to execute functions."
514
- );
515
- },
516
- getOne: async () => {
517
- throw new Error(
518
- "getOne is not supported for edge functions. Use useCreate to execute functions."
519
- );
520
- },
521
- getMany: async () => {
522
- throw new Error(
523
- "getMany is not supported for edge functions. Use useCreate to execute functions."
524
- );
525
- },
526
- createMany: async () => {
527
- throw new Error(
528
- "createMany is not supported for edge functions. Use useCreate to execute functions."
529
- );
530
- },
531
- update: async () => {
532
- throw new Error(
533
- "update is not supported for edge functions. Use useCreate to execute functions."
534
- );
535
- },
536
- updateMany: async () => {
537
- throw new Error(
538
- "updateMany is not supported for edge functions. Use useCreate to execute functions."
539
- );
540
- },
541
- deleteOne: async () => {
542
- throw new Error(
543
- "deleteOne is not supported for edge functions. Use useCreate to execute functions."
544
- );
545
- },
546
- deleteMany: async () => {
547
- throw new Error(
548
- "deleteMany is not supported for edge functions. Use useCreate to execute functions."
549
- );
550
- }
551
- };
552
- }
553
479
  function appDataProvider(client) {
554
480
  const config = client.getConfig();
555
481
  const baseApiUrl = `${config.baseUrl}/api/apps/${config.appSlug}`;
482
+ const functions = new Functions(client);
483
+ const analytics = new Analytics(client);
556
484
  return {
557
485
  getList: async (params) => {
558
486
  const { resource } = params;
@@ -566,7 +494,6 @@ function appDataProvider(client) {
566
494
  }
567
495
  throw new Error(`Unknown app resource: ${resource}. Supported resources: roles`);
568
496
  },
569
- getApiUrl: () => baseApiUrl,
570
497
  getOne: async (params) => {
571
498
  const { resource } = params;
572
499
  if (resource === "settings") {
@@ -578,12 +505,32 @@ function appDataProvider(client) {
578
505
  }
579
506
  throw new Error(`Unknown app resource for getOne: ${resource}. Supported resources: settings`);
580
507
  },
581
- // App resources are read-only
508
+ custom: async (params) => {
509
+ const { url: slug, payload, meta } = params;
510
+ const customMeta = meta;
511
+ if (customMeta?.kind === "function") {
512
+ const response = await functions.execute(slug, {
513
+ async: customMeta.async ?? false,
514
+ params: payload ?? {}
515
+ });
516
+ return { data: response.data };
517
+ }
518
+ if (customMeta?.kind === "analytics") {
519
+ const response = await analytics.execute(slug, {
520
+ params: payload ?? {}
521
+ });
522
+ return { data: response.data };
523
+ }
524
+ throw new Error(
525
+ 'Specify meta.kind as "function" or "analytics" for custom operations on the app provider.'
526
+ );
527
+ },
528
+ getApiUrl: () => baseApiUrl,
582
529
  getMany: async () => {
583
530
  throw new Error("getMany is not supported for app resources");
584
531
  },
585
532
  create: async () => {
586
- throw new Error("create is not supported for app resources");
533
+ throw new Error("create is not supported for app resources. Use useCustom with meta.kind");
587
534
  },
588
535
  createMany: async () => {
589
536
  throw new Error("createMany is not supported for app resources");
@@ -599,9 +546,6 @@ function appDataProvider(client) {
599
546
  },
600
547
  deleteMany: async () => {
601
548
  throw new Error("deleteMany is not supported for app resources");
602
- },
603
- custom: async () => {
604
- throw new Error("custom is not supported for app resources");
605
549
  }
606
550
  };
607
551
  }
@@ -741,6 +685,80 @@ function userDataProvider(client) {
741
685
  }
742
686
  };
743
687
  }
688
+ function functionsDataProvider(client) {
689
+ const config = client.getConfig();
690
+ const baseApiUrl = `${config.baseUrl}/api/apps/${config.appSlug}`;
691
+ const functions = new Functions(client);
692
+ return {
693
+ /**
694
+ * Execute an edge function.
695
+ *
696
+ * @param resource - The function slug to execute
697
+ * @param variables - Parameters to pass to the function
698
+ * @param meta.async - Whether to execute asynchronously (default: false)
699
+ */
700
+ create: async ({
701
+ resource,
702
+ variables,
703
+ meta
704
+ }) => {
705
+ const functionMeta = meta;
706
+ const response = await functions.execute(resource, {
707
+ async: functionMeta?.async ?? false,
708
+ params: variables
709
+ });
710
+ return { data: response.data };
711
+ },
712
+ getApiUrl: () => baseApiUrl,
713
+ // Edge functions don't support custom method - use create() instead
714
+ custom: async () => {
715
+ throw new Error(
716
+ "custom is not supported for edge functions. Use useCreate to execute functions."
717
+ );
718
+ },
719
+ // Edge functions don't support other CRUD operations
720
+ getList: async () => {
721
+ throw new Error(
722
+ "getList is not supported for edge functions. Use useCreate to execute functions."
723
+ );
724
+ },
725
+ getOne: async () => {
726
+ throw new Error(
727
+ "getOne is not supported for edge functions. Use useCreate to execute functions."
728
+ );
729
+ },
730
+ getMany: async () => {
731
+ throw new Error(
732
+ "getMany is not supported for edge functions. Use useCreate to execute functions."
733
+ );
734
+ },
735
+ createMany: async () => {
736
+ throw new Error(
737
+ "createMany is not supported for edge functions. Use useCreate to execute functions."
738
+ );
739
+ },
740
+ update: async () => {
741
+ throw new Error(
742
+ "update is not supported for edge functions. Use useCreate to execute functions."
743
+ );
744
+ },
745
+ updateMany: async () => {
746
+ throw new Error(
747
+ "updateMany is not supported for edge functions. Use useCreate to execute functions."
748
+ );
749
+ },
750
+ deleteOne: async () => {
751
+ throw new Error(
752
+ "deleteOne is not supported for edge functions. Use useCreate to execute functions."
753
+ );
754
+ },
755
+ deleteMany: async () => {
756
+ throw new Error(
757
+ "deleteMany is not supported for edge functions. Use useCreate to execute functions."
758
+ );
759
+ }
760
+ };
761
+ }
744
762
  function analyticsDataProvider(client) {
745
763
  const config = client.getConfig();
746
764
  const baseApiUrl = `${config.baseUrl}/api/apps/${config.appSlug}`;