@taruvi/refine-providers 1.2.3 → 1.2.5

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
@@ -199,6 +199,10 @@ interface TaruviMeta extends MetaQuery {
199
199
  depth?: number;
200
200
  /** Graph edge types to filter */
201
201
  graph_types?: string[];
202
+ /** Use upsert instead of create (insert or update on conflict) */
203
+ upsert?: boolean;
204
+ /** Delete records by filter instead of by IDs */
205
+ deleteByFilter?: boolean;
202
206
  }
203
207
  /**
204
208
  * Response wrapper for Taruvi list endpoints.
package/dist/index.d.ts CHANGED
@@ -199,6 +199,10 @@ interface TaruviMeta extends MetaQuery {
199
199
  depth?: number;
200
200
  /** Graph edge types to filter */
201
201
  graph_types?: string[];
202
+ /** Use upsert instead of create (insert or update on conflict) */
203
+ upsert?: boolean;
204
+ /** Delete records by filter instead of by IDs */
205
+ deleteByFilter?: boolean;
202
206
  }
203
207
  /**
204
208
  * Response wrapper for Taruvi list endpoints.
package/dist/index.js CHANGED
@@ -3,6 +3,10 @@ import DataLoader from 'dataloader';
3
3
 
4
4
  // src/dataProvider.ts
5
5
 
6
+ // package.json
7
+ var package_default = {
8
+ version: "1.2.5"};
9
+
6
10
  // src/utils.ts
7
11
  var REFINE_OPERATOR_MAP = {
8
12
  // Equality
@@ -189,6 +193,7 @@ function buildGraphQuery(client, tableName, meta, recordId) {
189
193
  return query;
190
194
  }
191
195
  function dataProvider(client) {
196
+ console.log(`Taruvi Refine Provider v${package_default.version} initialized`);
192
197
  const config = client.getConfig();
193
198
  const baseApiUrl = `${config.apiUrl}/api/apps/${config.appSlug}`;
194
199
  const getIdColumn = (meta) => meta?.idColumnName ?? "id";
@@ -254,7 +259,9 @@ function dataProvider(client) {
254
259
  const response2 = await new Database(client).from(tableName).edges().create(variables).execute();
255
260
  return { data: response2.data };
256
261
  }
257
- const response = await new Database(client).from(tableName).create(variables).execute();
262
+ const db = new Database(client).from(tableName);
263
+ const query = taruviMeta?.upsert ? db.upsert(variables) : db.create(variables);
264
+ const response = await query.execute();
258
265
  return { data: response.data };
259
266
  },
260
267
  createMany: async (params) => {
@@ -284,13 +291,10 @@ function dataProvider(client) {
284
291
  const { resource, ids, variables, meta } = params;
285
292
  const taruviMeta = meta;
286
293
  const tableName = getTableName(resource, taruviMeta);
287
- const data = await Promise.all(
288
- ids.map(async (id) => {
289
- const response = await new Database(client).from(tableName).get(String(id)).update(variables).execute();
290
- return response.data;
291
- })
292
- );
293
- return { data };
294
+ const idColumn = getIdColumn(taruviMeta);
295
+ const body = ids.map((id) => ({ [idColumn]: id, ...variables }));
296
+ const response = await new Database(client).from(tableName).bulkUpdate(body).execute();
297
+ return { data: response.data };
294
298
  },
295
299
  deleteOne: async (params) => {
296
300
  const { resource, id, meta } = params;
@@ -311,11 +315,13 @@ function dataProvider(client) {
311
315
  const response = await new Database(client).from(tableName).edges().delete(ids.map(Number)).execute();
312
316
  return { data: [response.data] };
313
317
  }
314
- await Promise.all(
315
- ids.map(async (id) => {
316
- await new Database(client).from(tableName).delete(String(id)).execute();
317
- })
318
- );
318
+ if (taruviMeta?.deleteByFilter && taruviMeta?.filters) {
319
+ let query = new Database(client).from(tableName);
320
+ query = applyFilters(query, taruviMeta.filters);
321
+ await query.deleteFiltered().execute();
322
+ return { data: ids.map((id) => ({ id })) };
323
+ }
324
+ await new Database(client).from(tableName).bulkDelete(ids.map(String)).execute();
319
325
  return { data: ids.map((id) => ({ id })) };
320
326
  },
321
327
  custom: async (params) => {
@@ -890,59 +896,23 @@ function authProvider(client) {
890
896
  },
891
897
  check: async () => {
892
898
  if (auth.isUserAuthenticated()) {
893
- if (auth.isTokenExpired()) {
894
- const refreshed = await auth.refreshAccessToken();
895
- if (refreshed) {
896
- return {
897
- authenticated: true
898
- };
899
- }
900
- return {
901
- authenticated: false,
902
- logout: true,
903
- redirectTo: "/login",
904
- error: {
905
- name: "SessionExpired",
906
- message: "Your session has expired. Please log in again."
907
- }
908
- };
909
- }
910
- return {
911
- authenticated: true
912
- };
899
+ return { authenticated: true };
913
900
  }
914
901
  return {
915
902
  authenticated: false,
916
903
  redirectTo: "/login"
917
904
  };
918
905
  },
919
- //TODO need to check if max retries logic is needed
920
906
  onError: async (error) => {
921
907
  const status = error?.statusCode || error?.status || error?.response?.status;
922
- if (status === 401) {
923
- if (auth.isUserAuthenticated()) {
924
- const refreshed = await auth.refreshAccessToken();
925
- if (refreshed) {
926
- return {
927
- error
928
- };
929
- }
930
- }
908
+ if (status === 401 || status === 403) {
931
909
  return {
932
910
  logout: true,
933
911
  redirectTo: "/login",
934
912
  error
935
913
  };
936
914
  }
937
- if (status === 403) {
938
- return {
939
- error
940
- // Don't logout for 403, user is authenticated but not authorized
941
- };
942
- }
943
- return {
944
- error
945
- };
915
+ return { error };
946
916
  },
947
917
  register: async (params = {}) => {
948
918
  const { callbackUrl } = params;