@taruvi/refine-providers 1.3.2 → 1.3.4-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.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { DataProvider, AuthProvider, AccessControlProvider, MetaQuery, CrudFilter, CrudSort, Pagination } from '@refinedev/core';
2
- import { Client, GraphFormat, GraphInclude } from '@taruvi/sdk';
2
+ import { Client, GraphFormat, GraphInclude, Database, BackendFilterTreeRoot } from '@taruvi/sdk';
3
3
 
4
4
  /**
5
5
  * Creates a Refine DataProvider for Taruvi database operations.
@@ -94,11 +94,16 @@ declare function functionsDataProvider(client: Client): DataProvider;
94
94
  declare function analyticsDataProvider(client: Client): DataProvider;
95
95
 
96
96
  /**
97
- * Login params
97
+ * Login params - supports both redirect flow and credentials flow
98
98
  */
99
99
  interface LoginParams {
100
- /** URL to redirect after successful login */
100
+ /** For redirect-based login - URL to redirect after successful login */
101
101
  callbackUrl?: string;
102
+ /** For credentials-based login (if supported) */
103
+ username?: string;
104
+ password?: string;
105
+ /** Whether to use redirect flow (default: true) */
106
+ redirect?: boolean;
102
107
  }
103
108
  /**
104
109
  * Logout params
@@ -118,10 +123,11 @@ declare let _cachedUser: Record<string, any> | null;
118
123
  /**
119
124
  * Creates a Refine AuthProvider for Taruvi authentication.
120
125
  *
121
- * Uses redirect-based Web UI Flow:
126
+ * Supports redirect-based authentication flow (Web UI Flow):
122
127
  * 1. User calls login() → Redirects to backend /accounts/login/
123
128
  * 2. User authenticates on backend
124
- * 3. Backend redirects back and sets session token
129
+ * 3. Backend redirects back with tokens in URL hash
130
+ * 4. Client extracts and stores tokens automatically
125
131
  */
126
132
  declare function authProvider(client: Client): AuthProvider;
127
133
 
@@ -229,11 +235,37 @@ interface TaruviListResponse<T> {
229
235
  * Example: { field: "age", operator: "gte", value: 18 } → "age__gte=18"
230
236
  */
231
237
  declare const REFINE_OPERATOR_MAP: Record<string, string>;
238
+ type ConvertRefineFiltersOptions = {
239
+ /**
240
+ * `bracket` (default): logical `and` / `or` use Taruvi CrudFilters bracket query keys.
241
+ * `flatten`: legacy merge (OR becomes AND) — only for Storage list filters that do not support CrudFilters.
242
+ */
243
+ logicalEncoding?: "bracket" | "flatten";
244
+ };
245
+ /** Backend operator token for CrudFilters bracket payloads (suffix or `eq`). */
246
+ declare function refineOperatorToBackendKey(operator: string): string;
247
+ /** String value for a leaf filter (flat or bracket). */
248
+ declare function formatRefineLeafValue(operator: string, value: unknown): string;
249
+ /** Encode one CrudFilter node (logical or leaf) into bracket-style flat query keys. */
250
+ declare function encodeCrudFilterBracket(filter: CrudFilter, path: string, out: Record<string, string>): void;
251
+ /**
252
+ * Converts Refine `CrudFilter[]` into the backend JSON `filters` query param tree
253
+ * (root array of `{ operator: "and"|"or", value: [...] }` nodes).
254
+ *
255
+ * Leaf `operator` values are **Taruvi / platform** tokens after `refineOperatorToBackendKey`.
256
+ * String contains variants are normalized to backend-safe case-sensitive LIKE tokens so the
257
+ * frontend does not depend on comparator-specific support in the backend SQLAlchemy build.
258
+ */
259
+ declare function convertRefineFiltersToBackendTree(filters?: CrudFilter[]): BackendFilterTreeRoot | null;
232
260
  /**
233
261
  * Converts Refine CrudFilter[] to Taruvi query parameters.
234
- * Handles both simple filters and logical operators (and/or).
262
+ * Logical `and` / `or` use CrudFilters bracket notation unless `logicalEncoding: 'flatten'`.
263
+ */
264
+ declare function convertRefineFilters(filters?: CrudFilter[], options?: ConvertRefineFiltersOptions): Record<string, string>;
265
+ /**
266
+ * Applies flat query param entries (including bracket keys) onto a Database query.
235
267
  */
236
- declare function convertRefineFilters(filters?: CrudFilter[]): Record<string, string>;
268
+ declare function applyRefineQueryParamsToDatabase<T>(query: Database<T>, params: Record<string, string>): Database<T>;
237
269
  /**
238
270
  * Converts Refine CrudSort[] to Taruvi ordering parameter.
239
271
  * Uses DRF convention: "-field" for DESC, "field" for ASC.
@@ -264,4 +296,4 @@ declare function buildQueryString(params?: Record<string, unknown>): string;
264
296
  */
265
297
  declare function handleError(error: unknown): never;
266
298
 
267
- export { type AllowedAction, type AnalyticsMeta, type AppCustomMeta, type FunctionMeta, type LoginParams, type LogoutParams, REFINE_OPERATOR_MAP, type RegisterParams, type StorageDownloadResponse, type StorageUploadVariables, type TaruviListResponse, type TaruviMeta, _cachedUser, accessControlProvider, analyticsDataProvider, appDataProvider, authProvider, buildQueryString, buildRefineQueryParams, convertRefineFilters, convertRefinePagination, convertRefineSorters, dataProvider, functionsDataProvider, handleError, storageDataProvider, userDataProvider };
299
+ export { type AllowedAction, type AnalyticsMeta, type AppCustomMeta, type ConvertRefineFiltersOptions, type FunctionMeta, type LoginParams, type LogoutParams, REFINE_OPERATOR_MAP, type RegisterParams, type StorageDownloadResponse, type StorageUploadVariables, type TaruviListResponse, type TaruviMeta, _cachedUser, accessControlProvider, analyticsDataProvider, appDataProvider, applyRefineQueryParamsToDatabase, authProvider, buildQueryString, buildRefineQueryParams, convertRefineFilters, convertRefineFiltersToBackendTree, convertRefinePagination, convertRefineSorters, dataProvider, encodeCrudFilterBracket, formatRefineLeafValue, functionsDataProvider, handleError, refineOperatorToBackendKey, storageDataProvider, userDataProvider };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { DataProvider, AuthProvider, AccessControlProvider, MetaQuery, CrudFilter, CrudSort, Pagination } from '@refinedev/core';
2
- import { Client, GraphFormat, GraphInclude } from '@taruvi/sdk';
2
+ import { Client, GraphFormat, GraphInclude, Database, BackendFilterTreeRoot } from '@taruvi/sdk';
3
3
 
4
4
  /**
5
5
  * Creates a Refine DataProvider for Taruvi database operations.
@@ -94,11 +94,16 @@ declare function functionsDataProvider(client: Client): DataProvider;
94
94
  declare function analyticsDataProvider(client: Client): DataProvider;
95
95
 
96
96
  /**
97
- * Login params
97
+ * Login params - supports both redirect flow and credentials flow
98
98
  */
99
99
  interface LoginParams {
100
- /** URL to redirect after successful login */
100
+ /** For redirect-based login - URL to redirect after successful login */
101
101
  callbackUrl?: string;
102
+ /** For credentials-based login (if supported) */
103
+ username?: string;
104
+ password?: string;
105
+ /** Whether to use redirect flow (default: true) */
106
+ redirect?: boolean;
102
107
  }
103
108
  /**
104
109
  * Logout params
@@ -118,10 +123,11 @@ declare let _cachedUser: Record<string, any> | null;
118
123
  /**
119
124
  * Creates a Refine AuthProvider for Taruvi authentication.
120
125
  *
121
- * Uses redirect-based Web UI Flow:
126
+ * Supports redirect-based authentication flow (Web UI Flow):
122
127
  * 1. User calls login() → Redirects to backend /accounts/login/
123
128
  * 2. User authenticates on backend
124
- * 3. Backend redirects back and sets session token
129
+ * 3. Backend redirects back with tokens in URL hash
130
+ * 4. Client extracts and stores tokens automatically
125
131
  */
126
132
  declare function authProvider(client: Client): AuthProvider;
127
133
 
@@ -229,11 +235,37 @@ interface TaruviListResponse<T> {
229
235
  * Example: { field: "age", operator: "gte", value: 18 } → "age__gte=18"
230
236
  */
231
237
  declare const REFINE_OPERATOR_MAP: Record<string, string>;
238
+ type ConvertRefineFiltersOptions = {
239
+ /**
240
+ * `bracket` (default): logical `and` / `or` use Taruvi CrudFilters bracket query keys.
241
+ * `flatten`: legacy merge (OR becomes AND) — only for Storage list filters that do not support CrudFilters.
242
+ */
243
+ logicalEncoding?: "bracket" | "flatten";
244
+ };
245
+ /** Backend operator token for CrudFilters bracket payloads (suffix or `eq`). */
246
+ declare function refineOperatorToBackendKey(operator: string): string;
247
+ /** String value for a leaf filter (flat or bracket). */
248
+ declare function formatRefineLeafValue(operator: string, value: unknown): string;
249
+ /** Encode one CrudFilter node (logical or leaf) into bracket-style flat query keys. */
250
+ declare function encodeCrudFilterBracket(filter: CrudFilter, path: string, out: Record<string, string>): void;
251
+ /**
252
+ * Converts Refine `CrudFilter[]` into the backend JSON `filters` query param tree
253
+ * (root array of `{ operator: "and"|"or", value: [...] }` nodes).
254
+ *
255
+ * Leaf `operator` values are **Taruvi / platform** tokens after `refineOperatorToBackendKey`.
256
+ * String contains variants are normalized to backend-safe case-sensitive LIKE tokens so the
257
+ * frontend does not depend on comparator-specific support in the backend SQLAlchemy build.
258
+ */
259
+ declare function convertRefineFiltersToBackendTree(filters?: CrudFilter[]): BackendFilterTreeRoot | null;
232
260
  /**
233
261
  * Converts Refine CrudFilter[] to Taruvi query parameters.
234
- * Handles both simple filters and logical operators (and/or).
262
+ * Logical `and` / `or` use CrudFilters bracket notation unless `logicalEncoding: 'flatten'`.
263
+ */
264
+ declare function convertRefineFilters(filters?: CrudFilter[], options?: ConvertRefineFiltersOptions): Record<string, string>;
265
+ /**
266
+ * Applies flat query param entries (including bracket keys) onto a Database query.
235
267
  */
236
- declare function convertRefineFilters(filters?: CrudFilter[]): Record<string, string>;
268
+ declare function applyRefineQueryParamsToDatabase<T>(query: Database<T>, params: Record<string, string>): Database<T>;
237
269
  /**
238
270
  * Converts Refine CrudSort[] to Taruvi ordering parameter.
239
271
  * Uses DRF convention: "-field" for DESC, "field" for ASC.
@@ -264,4 +296,4 @@ declare function buildQueryString(params?: Record<string, unknown>): string;
264
296
  */
265
297
  declare function handleError(error: unknown): never;
266
298
 
267
- export { type AllowedAction, type AnalyticsMeta, type AppCustomMeta, type FunctionMeta, type LoginParams, type LogoutParams, REFINE_OPERATOR_MAP, type RegisterParams, type StorageDownloadResponse, type StorageUploadVariables, type TaruviListResponse, type TaruviMeta, _cachedUser, accessControlProvider, analyticsDataProvider, appDataProvider, authProvider, buildQueryString, buildRefineQueryParams, convertRefineFilters, convertRefinePagination, convertRefineSorters, dataProvider, functionsDataProvider, handleError, storageDataProvider, userDataProvider };
299
+ export { type AllowedAction, type AnalyticsMeta, type AppCustomMeta, type ConvertRefineFiltersOptions, type FunctionMeta, type LoginParams, type LogoutParams, REFINE_OPERATOR_MAP, type RegisterParams, type StorageDownloadResponse, type StorageUploadVariables, type TaruviListResponse, type TaruviMeta, _cachedUser, accessControlProvider, analyticsDataProvider, appDataProvider, applyRefineQueryParamsToDatabase, authProvider, buildQueryString, buildRefineQueryParams, convertRefineFilters, convertRefineFiltersToBackendTree, convertRefinePagination, convertRefineSorters, dataProvider, encodeCrudFilterBracket, formatRefineLeafValue, functionsDataProvider, handleError, refineOperatorToBackendKey, storageDataProvider, userDataProvider };
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import DataLoader from 'dataloader';
5
5
 
6
6
  // package.json
7
7
  var package_default = {
8
- version: "1.3.2"};
8
+ version: "1.3.4-beta.0"};
9
9
 
10
10
  // src/utils.ts
11
11
  var REFINE_OPERATOR_MAP = {
@@ -18,65 +18,231 @@ var REFINE_OPERATOR_MAP = {
18
18
  gt: "gt",
19
19
  lte: "lte",
20
20
  gte: "gte",
21
- // String operations (case-sensitive)
22
- contains: "contains",
23
- ncontains: "ncontains",
24
- startswith: "startswith",
25
- nstartswith: "nstartswith",
26
- endswith: "endswith",
27
- nendswith: "nendswith",
28
- // String operations (case-insensitive)
29
- containss: "icontains",
30
- ncontainss: "nicontains",
31
- startswiths: "istartswith",
32
- nstartswiths: "nistartswith",
33
- endswiths: "iendswith",
34
- nendswiths: "niendswith",
35
- // Array operations
21
+ // String operators mapped to backend-safe case-sensitive LIKE variants.
22
+ contains: "containss",
23
+ ncontains: "ncontainss",
24
+ containss: "containss",
25
+ ncontainss: "ncontainss",
26
+ // String operators mapped to backend-safe case-sensitive prefix/suffix LIKE.
27
+ startswith: "startswiths",
28
+ nstartswith: "nstartswiths",
29
+ endswith: "endswiths",
30
+ nendswith: "nendswiths",
31
+ startswiths: "startswiths",
32
+ nstartswiths: "nstartswiths",
33
+ endswiths: "endswiths",
34
+ nendswiths: "nendswiths",
35
+ // Aliases mapped to backend-safe case-sensitive LIKE variants.
36
+ icontains: "containss",
37
+ nicontains: "ncontainss",
38
+ // Array / membership
36
39
  in: "in",
37
40
  nin: "nin",
41
+ ina: "ina",
42
+ nina: "nina",
38
43
  // Null checks
39
44
  null: "null",
40
45
  nnull: "nnull",
41
46
  // Range
42
47
  between: "between",
43
- nbetween: "nbetween"
48
+ nbetween: "nbetween",
49
+ // PostgreSQL array ops (pass-through suffix names)
50
+ acontains: "acontains",
51
+ nacontains: "nacontains",
52
+ acontainedby: "acontainedby",
53
+ nacontainedby: "nacontainedby",
54
+ aoverlap: "aoverlap",
55
+ naoverlap: "naoverlap",
56
+ aelement: "aelement",
57
+ naelement: "naelement",
58
+ // PostgreSQL range column ops
59
+ rcontains: "rcontains",
60
+ rcontainedby: "rcontainedby",
61
+ roverlaps: "roverlaps",
62
+ radjacent: "radjacent",
63
+ rstrictleft: "rstrictleft",
64
+ rstrictright: "rstrictright",
65
+ // Raw pattern / field search
66
+ like: "like",
67
+ ilike: "ilike",
68
+ search: "search"
44
69
  };
45
- function convertRefineFilters(filters) {
70
+ var COMMA_VALUE_OPERATORS = /* @__PURE__ */ new Set([
71
+ "in",
72
+ "nin",
73
+ "ina",
74
+ "nina",
75
+ "between",
76
+ "nbetween",
77
+ "acontains",
78
+ "nacontains",
79
+ "acontainedby",
80
+ "nacontainedby",
81
+ "aoverlap",
82
+ "naoverlap",
83
+ "aelement",
84
+ "naelement",
85
+ "rcontains",
86
+ "rcontainedby",
87
+ "roverlaps",
88
+ "radjacent",
89
+ "rstrictleft",
90
+ "rstrictright"
91
+ ]);
92
+ function isLogicalFilter(filter) {
93
+ return typeof filter === "object" && filter !== null && "operator" in filter && (filter.operator === "and" || filter.operator === "or") && "value" in filter && Array.isArray(filter.value);
94
+ }
95
+ function isFieldFilter(filter) {
96
+ return typeof filter === "object" && filter !== null && "field" in filter && "operator" in filter && typeof filter.field === "string" && typeof filter.operator === "string";
97
+ }
98
+ function refineOperatorToBackendKey(operator) {
99
+ const suffix = REFINE_OPERATOR_MAP[operator];
100
+ if (suffix === void 0) return operator;
101
+ return suffix === "" ? "eq" : suffix;
102
+ }
103
+ function formatRefineLeafValue(operator, value) {
104
+ if (COMMA_VALUE_OPERATORS.has(operator)) {
105
+ return Array.isArray(value) ? value.join(",") : String(value);
106
+ }
107
+ if (operator === "null" || operator === "nnull") {
108
+ return "true";
109
+ }
110
+ return String(value);
111
+ }
112
+ function encodeLeafFlat(field, operator, value, params) {
113
+ if (value === void 0 || value === null && operator !== "null") {
114
+ return;
115
+ }
116
+ const suffix = REFINE_OPERATOR_MAP[operator];
117
+ if (suffix === void 0) {
118
+ console.warn(`Unknown Refine operator: ${operator}`);
119
+ return;
120
+ }
121
+ const paramKey = suffix ? `${field}__${suffix}` : String(field);
122
+ params[paramKey] = formatRefineLeafValue(operator, value);
123
+ }
124
+ function encodeCrudFilterBracket(filter, path, out) {
125
+ if (isLogicalFilter(filter)) {
126
+ const op = filter.operator;
127
+ out[`${path}[operator]`] = op;
128
+ const children = filter.value;
129
+ children.forEach((child, i) => {
130
+ encodeCrudFilterBracket(child, `${path}[value][${i}]`, out);
131
+ });
132
+ return;
133
+ }
134
+ if (!isFieldFilter(filter)) {
135
+ return;
136
+ }
137
+ const leaf = filter;
138
+ const { field, operator, value } = leaf;
139
+ if (value === void 0 || value === null && operator !== "null") {
140
+ return;
141
+ }
142
+ const suffix = REFINE_OPERATOR_MAP[operator];
143
+ if (suffix === void 0) {
144
+ console.warn(`Unknown Refine operator: ${operator}`);
145
+ return;
146
+ }
147
+ out[`${path}[field]`] = field;
148
+ out[`${path}[operator]`] = refineOperatorToBackendKey(operator);
149
+ out[`${path}[value]`] = formatRefineLeafValue(operator, value);
150
+ }
151
+ function isLogicalBackendNode(n) {
152
+ return !("field" in n) && (n.operator === "and" || n.operator === "or");
153
+ }
154
+ function jsonLeafValue(operator, value) {
155
+ if (operator === "null" || operator === "nnull") return true;
156
+ return value;
157
+ }
158
+ function crudFilterToBackendNodeOrNull(filter) {
159
+ if (isLogicalFilter(filter)) {
160
+ const children = filter.value.map(crudFilterToBackendNodeOrNull).filter((n) => n !== null);
161
+ if (children.length === 0) return null;
162
+ return { operator: filter.operator, value: children };
163
+ }
164
+ if (isFieldFilter(filter)) {
165
+ const leaf = filter;
166
+ if (leaf.value === void 0 || leaf.value === null && leaf.operator !== "null") {
167
+ return null;
168
+ }
169
+ if (REFINE_OPERATOR_MAP[leaf.operator] === void 0) {
170
+ console.warn(`Unknown Refine operator: ${leaf.operator}`);
171
+ return null;
172
+ }
173
+ const backendOp = refineOperatorToBackendKey(leaf.operator);
174
+ return {
175
+ field: leaf.field,
176
+ operator: backendOp,
177
+ value: jsonLeafValue(leaf.operator, leaf.value)
178
+ };
179
+ }
180
+ return null;
181
+ }
182
+ function convertRefineFiltersToBackendTree(filters) {
183
+ if (!filters?.length) return null;
184
+ const nodes = filters.map(crudFilterToBackendNodeOrNull).filter((n) => n !== null);
185
+ if (nodes.length === 0) return null;
186
+ if (nodes.length === 1 && isLogicalBackendNode(nodes[0])) {
187
+ return [nodes[0]];
188
+ }
189
+ return [{ operator: "and", value: nodes }];
190
+ }
191
+ function convertRefineFiltersFlattened(filters) {
46
192
  if (!filters || filters.length === 0) return {};
47
193
  const params = {};
48
194
  for (const filter of filters) {
49
- if ("operator" in filter && (filter.operator === "and" || filter.operator === "or")) {
195
+ if (isLogicalFilter(filter)) {
50
196
  if (filter.value && Array.isArray(filter.value)) {
51
- const nested = convertRefineFilters(filter.value);
197
+ const nested = convertRefineFiltersFlattened(
198
+ filter.value
199
+ );
52
200
  Object.assign(params, nested);
53
201
  }
54
202
  continue;
55
203
  }
56
- if ("field" in filter && filter.field && filter.operator) {
57
- const { field, operator, value } = filter;
58
- if (value === void 0 || value === null && operator !== "null") {
59
- continue;
60
- }
61
- const suffix = REFINE_OPERATOR_MAP[operator];
62
- if (suffix === void 0) {
63
- console.warn(`Unknown Refine operator: ${operator}`);
64
- continue;
65
- }
66
- const paramKey = suffix ? `${field}__${suffix}` : String(field);
67
- if (operator === "in" || operator === "nin") {
68
- params[paramKey] = Array.isArray(value) ? value.join(",") : String(value);
69
- } else if (operator === "between" || operator === "nbetween") {
70
- params[paramKey] = Array.isArray(value) ? value.join(",") : String(value);
71
- } else if (operator === "null" || operator === "nnull") {
72
- params[paramKey] = "true";
73
- } else {
74
- params[paramKey] = String(value);
75
- }
204
+ if (isFieldFilter(filter)) {
205
+ const leaf = filter;
206
+ encodeLeafFlat(leaf.field, leaf.operator, leaf.value, params);
76
207
  }
77
208
  }
78
209
  return params;
79
210
  }
211
+ function convertRefineFilters(filters, options) {
212
+ if (!filters || filters.length === 0) return {};
213
+ if (options?.logicalEncoding === "flatten") {
214
+ return convertRefineFiltersFlattened(filters);
215
+ }
216
+ const hasLogical = filters.some(isLogicalFilter);
217
+ if (!hasLogical) {
218
+ const params = {};
219
+ for (const filter of filters) {
220
+ if (isFieldFilter(filter)) {
221
+ const leaf = filter;
222
+ encodeLeafFlat(leaf.field, leaf.operator, leaf.value, params);
223
+ }
224
+ }
225
+ return params;
226
+ }
227
+ if (filters.length === 1 && isLogicalFilter(filters[0])) {
228
+ const out2 = {};
229
+ encodeCrudFilterBracket(filters[0], "filters[0]", out2);
230
+ return out2;
231
+ }
232
+ const out = {};
233
+ out["filters[0][operator]"] = "and";
234
+ filters.forEach((f, i) => {
235
+ encodeCrudFilterBracket(f, `filters[0][value][${i}]`, out);
236
+ });
237
+ return out;
238
+ }
239
+ function applyRefineQueryParamsToDatabase(query, params) {
240
+ let result = query;
241
+ for (const [key, val] of Object.entries(params)) {
242
+ result = result.filters(key, "eq", val);
243
+ }
244
+ return result;
245
+ }
80
246
  function convertRefineSorters(sorters) {
81
247
  if (!sorters || sorters.length === 0) return void 0;
82
248
  return sorters.map((sort) => sort.order === "desc" ? `-${sort.field}` : sort.field).join(",");
@@ -132,16 +298,7 @@ function formatHaving(having) {
132
298
  continue;
133
299
  }
134
300
  const paramKey = suffix ? `${field}__${suffix}` : String(field);
135
- let paramValue;
136
- if (operator === "in" || operator === "nin") {
137
- paramValue = Array.isArray(value) ? value.join(",") : String(value);
138
- } else if (operator === "between" || operator === "nbetween") {
139
- paramValue = Array.isArray(value) ? value.join(",") : String(value);
140
- } else if (operator === "null" || operator === "nnull") {
141
- paramValue = "true";
142
- } else {
143
- paramValue = String(value);
144
- }
301
+ const paramValue = formatRefineLeafValue(operator, value);
145
302
  params.push(`${paramKey}=${paramValue}`);
146
303
  }
147
304
  }
@@ -175,43 +332,13 @@ function applyAggregations(query, meta) {
175
332
  }
176
333
  function applyFilters(query, filters) {
177
334
  if (!filters || filters.length === 0) return query;
178
- let result = query;
179
- for (const filter of filters) {
180
- if ("operator" in filter && (filter.operator === "and" || filter.operator === "or")) {
181
- if (filter.value && Array.isArray(filter.value)) {
182
- result = applyFilters(result, filter.value);
183
- }
184
- continue;
185
- }
186
- if ("field" in filter && filter.field && filter.operator) {
187
- const { field, operator, value } = filter;
188
- if (value === void 0 || value === null && operator !== "null") continue;
189
- const suffix = REFINE_OPERATOR_MAP[operator];
190
- if (suffix === void 0) {
191
- console.warn(`Unknown Refine operator: ${operator}`);
192
- continue;
193
- }
194
- const paramKey = suffix ? `${field}__${suffix}` : String(field);
195
- let paramValue;
196
- if (operator === "in" || operator === "nin" || operator === "between" || operator === "nbetween") {
197
- paramValue = Array.isArray(value) ? value.join(",") : String(value);
198
- } else if (operator === "null" || operator === "nnull") {
199
- paramValue = "true";
200
- } else {
201
- paramValue = String(value);
202
- }
203
- result = result.filter(paramKey, "eq", paramValue);
204
- }
205
- }
206
- return result;
335
+ const tree = convertRefineFiltersToBackendTree(filters);
336
+ if (!tree) return query;
337
+ return query.filters(tree);
207
338
  }
208
339
  function applySorters(query, sorters) {
209
- if (!sorters || sorters.length === 0) return query;
210
- let result = query;
211
- for (const sorter of sorters) {
212
- result = result.sort(sorter.field, sorter.order === "desc" ? "desc" : "asc");
213
- }
214
- return result;
340
+ const ordering = convertRefineSorters(sorters);
341
+ return ordering ? query.orderBy(ordering) : query;
215
342
  }
216
343
  function applyPagination(query, pagination) {
217
344
  if (!pagination || pagination.mode === "off") return query;
@@ -299,7 +426,7 @@ function dataProvider(client) {
299
426
  }
300
427
  const idColumn = getIdColumn(taruviMeta);
301
428
  let query = new Database(client).from(tableName);
302
- query = query.filter(idColumn, "in", ids.map(String));
429
+ query = query.filters(idColumn, "in", ids.map(String));
303
430
  query = applyPopulate(query, taruviMeta);
304
431
  const response = await query.execute();
305
432
  return { data: response.data };
@@ -416,7 +543,7 @@ function storageDataProvider(client) {
416
543
  const getBucketName = (resource, meta) => meta?.bucketName ?? resource;
417
544
  const buildFilters = (params) => {
418
545
  const filters = {
419
- ...convertRefineFilters(params.filters),
546
+ ...convertRefineFilters(params.filters, { logicalEncoding: "flatten" }),
420
547
  ...convertRefinePagination(params.pagination)
421
548
  };
422
549
  const ordering = convertRefineSorters(params.sorters);
@@ -924,22 +1051,27 @@ function analyticsDataProvider(client) {
924
1051
  var _cachedUser = null;
925
1052
  function authProvider(client) {
926
1053
  const auth = new Auth(client);
927
- function redirectToLogin() {
928
- _cachedUser = null;
929
- auth.login();
930
- }
931
1054
  return {
932
1055
  login: async (params = {}) => {
933
- const { callbackUrl } = params;
934
- if (auth.hasToken()) {
1056
+ const { callbackUrl, redirect = true } = params;
1057
+ if (auth.isUserAuthenticated()) {
935
1058
  return {
936
1059
  success: true,
937
1060
  redirectTo: callbackUrl || "/"
938
1061
  };
939
1062
  }
940
- auth.login(callbackUrl);
1063
+ if (redirect) {
1064
+ auth.login(callbackUrl);
1065
+ return {
1066
+ success: true
1067
+ };
1068
+ }
941
1069
  return {
942
- success: true
1070
+ success: false,
1071
+ error: {
1072
+ name: "LoginError",
1073
+ message: "Login failed. Please try again."
1074
+ }
943
1075
  };
944
1076
  },
945
1077
  logout: async (params = {}) => {
@@ -952,22 +1084,19 @@ function authProvider(client) {
952
1084
  };
953
1085
  },
954
1086
  check: async () => {
955
- if (!auth.hasToken()) {
956
- redirectToLogin();
957
- return { authenticated: false };
958
- }
959
- const isValid = await auth.isUserAuthenticated();
960
- if (!isValid) {
961
- redirectToLogin();
962
- return { authenticated: false };
1087
+ if (!auth.isUserAuthenticated()) {
1088
+ return { authenticated: false, redirectTo: "/login" };
963
1089
  }
964
1090
  return { authenticated: true };
965
1091
  },
966
1092
  onError: async (error) => {
967
1093
  const status = error?.statusCode || error?.status || error?.response?.status;
968
1094
  if (status === 401) {
969
- redirectToLogin();
970
- return { error };
1095
+ return {
1096
+ logout: true,
1097
+ redirectTo: "/login",
1098
+ error
1099
+ };
971
1100
  }
972
1101
  if (status === 403) {
973
1102
  return { error };
@@ -1106,6 +1235,6 @@ function accessControlProvider(client, options) {
1106
1235
  };
1107
1236
  }
1108
1237
 
1109
- export { REFINE_OPERATOR_MAP, _cachedUser, accessControlProvider, analyticsDataProvider, appDataProvider, authProvider, buildQueryString, buildRefineQueryParams, convertRefineFilters, convertRefinePagination, convertRefineSorters, dataProvider, functionsDataProvider, handleError, storageDataProvider, userDataProvider };
1238
+ export { REFINE_OPERATOR_MAP, _cachedUser, accessControlProvider, analyticsDataProvider, appDataProvider, applyRefineQueryParamsToDatabase, authProvider, buildQueryString, buildRefineQueryParams, convertRefineFilters, convertRefineFiltersToBackendTree, convertRefinePagination, convertRefineSorters, dataProvider, encodeCrudFilterBracket, formatRefineLeafValue, functionsDataProvider, handleError, refineOperatorToBackendKey, storageDataProvider, userDataProvider };
1110
1239
  //# sourceMappingURL=index.js.map
1111
1240
  //# sourceMappingURL=index.js.map