@taruvi/refine-providers 1.1.5 → 1.1.6

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.cts CHANGED
@@ -63,7 +63,7 @@ declare function appDataProvider(client: Client): DataProvider;
63
63
  * Supported resources:
64
64
  * - "users" (getList): Fetch list of users with filtering/pagination
65
65
  * - "users" (getOne): Fetch a specific user by username/id
66
- * - "me" (getOne): Fetch current user details
66
+ * - "roles" (getList): Fetch roles for a specific user (requires meta.username)
67
67
  *
68
68
  * @example
69
69
  * ```typescript
@@ -86,11 +86,11 @@ declare function appDataProvider(client: Client): DataProvider;
86
86
  * id: "john_doe",
87
87
  * });
88
88
  *
89
- * // Get current user details
90
- * const { data } = useOne({
89
+ * // Get roles for a specific user
90
+ * const { data } = useList({
91
91
  * dataProviderName: "user",
92
- * resource: "me",
93
- * id: "", // id is ignored for "me" resource
92
+ * resource: "roles",
93
+ * meta: { username: "john_doe" },
94
94
  * });
95
95
  * ```
96
96
  */
package/dist/index.d.ts CHANGED
@@ -63,7 +63,7 @@ declare function appDataProvider(client: Client): DataProvider;
63
63
  * Supported resources:
64
64
  * - "users" (getList): Fetch list of users with filtering/pagination
65
65
  * - "users" (getOne): Fetch a specific user by username/id
66
- * - "me" (getOne): Fetch current user details
66
+ * - "roles" (getList): Fetch roles for a specific user (requires meta.username)
67
67
  *
68
68
  * @example
69
69
  * ```typescript
@@ -86,11 +86,11 @@ declare function appDataProvider(client: Client): DataProvider;
86
86
  * id: "john_doe",
87
87
  * });
88
88
  *
89
- * // Get current user details
90
- * const { data } = useOne({
89
+ * // Get roles for a specific user
90
+ * const { data } = useList({
91
91
  * dataProviderName: "user",
92
- * resource: "me",
93
- * id: "", // id is ignored for "me" resource
92
+ * resource: "roles",
93
+ * meta: { username: "john_doe" },
94
94
  * });
95
95
  * ```
96
96
  */
package/dist/index.js CHANGED
@@ -82,7 +82,7 @@ function applyPopulate(query, meta) {
82
82
  }
83
83
  function dataProvider(client) {
84
84
  const config = client.getConfig();
85
- const baseApiUrl = `${config.apiUrl}/api/apps/${config.appSlug}`;
85
+ const baseApiUrl = `${config.baseUrl}/api/apps/${config.appSlug}`;
86
86
  const getIdColumn = (meta) => meta?.idColumnName ?? "id";
87
87
  const getTableName = (resource, meta) => meta?.tableName ?? resource;
88
88
  return {
@@ -173,21 +173,26 @@ function dataProvider(client) {
173
173
  return { data };
174
174
  },
175
175
  custom: async (params) => {
176
- const { url, method, payload } = params;
177
- const fullUrl = url.startsWith("http") ? url : `${baseApiUrl}${url}`;
176
+ const { url, method, payload, query } = params;
178
177
  let data;
179
178
  switch (method.toLowerCase()) {
180
- case "get":
181
- data = await client.httpClient.get(fullUrl);
179
+ case "get": {
180
+ let requestUrl = url;
181
+ if (query && Object.keys(query).length > 0) {
182
+ const queryString = new URLSearchParams(query).toString();
183
+ requestUrl = `${url}${url.includes("?") ? "&" : "?"}${queryString}`;
184
+ }
185
+ data = await client.httpClient.get(requestUrl);
182
186
  break;
187
+ }
183
188
  case "post":
184
- data = await client.httpClient.post(fullUrl, payload);
189
+ data = await client.httpClient.post(url, payload);
185
190
  break;
186
191
  case "put":
187
- data = await client.httpClient.put(fullUrl, payload);
192
+ data = await client.httpClient.put(url, payload);
188
193
  break;
189
194
  case "delete":
190
- data = await client.httpClient.delete(fullUrl);
195
+ data = await client.httpClient.delete(url);
191
196
  break;
192
197
  default:
193
198
  throw new Error(`Unsupported HTTP method: ${method}`);
@@ -321,7 +326,7 @@ function handleError(error) {
321
326
  // src/storageDataProvider.ts
322
327
  function storageDataProvider(client) {
323
328
  const config = client.getConfig();
324
- const baseApiUrl = `${config.apiUrl}/api/apps/${config.appSlug}`;
329
+ const baseApiUrl = `${config.baseUrl}/api/apps/${config.appSlug}`;
325
330
  const getBucketName = (resource, meta) => meta?.bucketName ?? resource;
326
331
  const buildFilters = (params) => {
327
332
  const filters = {
@@ -395,21 +400,26 @@ function storageDataProvider(client) {
395
400
  return { data: [data] };
396
401
  },
397
402
  custom: async (params) => {
398
- const { url, method, payload } = params;
399
- const fullUrl = url.startsWith("http") ? url : `${baseApiUrl}${url}`;
403
+ const { url, method, payload, query } = params;
400
404
  let data;
401
405
  switch (method.toLowerCase()) {
402
- case "get":
403
- data = await client.httpClient.get(fullUrl);
406
+ case "get": {
407
+ let requestUrl = url;
408
+ if (query && Object.keys(query).length > 0) {
409
+ const queryString = new URLSearchParams(query).toString();
410
+ requestUrl = `${url}${url.includes("?") ? "&" : "?"}${queryString}`;
411
+ }
412
+ data = await client.httpClient.get(requestUrl);
404
413
  break;
414
+ }
405
415
  case "post":
406
- data = await client.httpClient.post(fullUrl, payload);
416
+ data = await client.httpClient.post(url, payload);
407
417
  break;
408
418
  case "put":
409
- data = await client.httpClient.put(fullUrl, payload);
419
+ data = await client.httpClient.put(url, payload);
410
420
  break;
411
421
  case "delete":
412
- data = await client.httpClient.delete(fullUrl);
422
+ data = await client.httpClient.delete(url);
413
423
  break;
414
424
  default:
415
425
  throw new Error(`Unsupported HTTP method: ${method}`);
@@ -422,7 +432,7 @@ function storageDataProvider(client) {
422
432
  }
423
433
  function functionsDataProvider(client) {
424
434
  const config = client.getConfig();
425
- const baseApiUrl = `${config.apiUrl}/api/apps/${config.appSlug}`;
435
+ const baseApiUrl = `${config.baseUrl}/api/apps/${config.appSlug}`;
426
436
  const functions = new Functions(client);
427
437
  return {
428
438
  /**
@@ -496,7 +506,7 @@ function functionsDataProvider(client) {
496
506
  }
497
507
  function appDataProvider(client) {
498
508
  const config = client.getConfig();
499
- const baseApiUrl = `${config.apiUrl}/api/apps/${config.appSlug}`;
509
+ const baseApiUrl = `${config.baseUrl}/api/apps/${config.appSlug}`;
500
510
  return {
501
511
  getList: async (params) => {
502
512
  const { resource } = params;
@@ -592,10 +602,10 @@ function buildUserListFilters(filters, sorters, pagination) {
592
602
  }
593
603
  function userDataProvider(client) {
594
604
  const config = client.getConfig();
595
- const baseApiUrl = `${config.apiUrl}/api/apps/${config.appSlug}`;
605
+ const baseApiUrl = `${config.baseUrl}/api/apps/${config.appSlug}`;
596
606
  return {
597
607
  getList: async (params) => {
598
- const { resource, pagination, filters, sorters } = params;
608
+ const { resource, pagination, filters, sorters, meta } = params;
599
609
  if (resource === "users") {
600
610
  const user = new User(client);
601
611
  const userFilters = buildUserListFilters(filters, sorters, pagination);
@@ -605,18 +615,29 @@ function userDataProvider(client) {
605
615
  total: response.total
606
616
  };
607
617
  }
608
- throw new Error(`Unknown user resource for getList: ${resource}. Supported resources: users`);
618
+ if (resource === "roles") {
619
+ const username = meta?.username;
620
+ if (!username) {
621
+ throw new Error("roles resource requires meta.username");
622
+ }
623
+ const user = new User(client);
624
+ const response = await user.getUser(username);
625
+ const roles = response.roles || [];
626
+ return {
627
+ data: roles,
628
+ total: roles.length
629
+ };
630
+ }
631
+ throw new Error(`Unknown user resource for getList: ${resource}. Supported: users, roles`);
609
632
  },
610
633
  getOne: async (params) => {
611
634
  const { resource, id } = params;
612
635
  if (resource === "users") {
613
636
  const user = new User(client);
614
637
  const response = await user.getUser(String(id));
615
- return {
616
- data: response
617
- };
638
+ return { data: response };
618
639
  }
619
- throw new Error(`Unknown user resource for getOne: ${resource}. Supported resources: me, users`);
640
+ throw new Error(`Unknown user resource for getOne: ${resource}. Supported: users`);
620
641
  },
621
642
  getApiUrl: () => baseApiUrl,
622
643
  create: async (params) => {
@@ -676,7 +697,7 @@ function userDataProvider(client) {
676
697
  }
677
698
  function analyticsDataProvider(client) {
678
699
  const config = client.getConfig();
679
- const baseApiUrl = `${config.apiUrl}/api/apps/${config.appSlug}`;
700
+ const baseApiUrl = `${config.baseUrl}/api/apps/${config.appSlug}`;
680
701
  const analytics = new Analytics(client);
681
702
  return {
682
703
  /**