@taruvi/refine-providers 1.3.4-beta.4 → 1.3.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.cjs +54 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +31 -13
- package/dist/index.d.ts +31 -13
- package/dist/index.js +54 -25
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DataProvider, AuthProvider, AccessControlProvider, CrudFilter, MetaQuery, CrudSort, Pagination } from '@refinedev/core';
|
|
2
|
-
import { Client, GraphFormat, GraphInclude, Database, BackendFilterTreeRoot } from '@taruvi/sdk';
|
|
3
|
-
export { UserData as TaruviUser } from '@taruvi/sdk';
|
|
2
|
+
import { Client, StorageBrowseFolder, StorageBrowseFile, GraphFormat, GraphInclude, Database, BackendFilterTreeRoot } from '@taruvi/sdk';
|
|
3
|
+
export { StorageAccessLinkResponse, StorageBrowseData, StorageBrowseFile, StorageBrowseFilters, StorageBrowseFolder, UserData as TaruviUser } from '@taruvi/sdk';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Creates a Refine DataProvider for Taruvi database operations.
|
|
@@ -95,16 +95,11 @@ declare function functionsDataProvider(client: Client): DataProvider;
|
|
|
95
95
|
declare function analyticsDataProvider(client: Client): DataProvider;
|
|
96
96
|
|
|
97
97
|
/**
|
|
98
|
-
* Login params
|
|
98
|
+
* Login params
|
|
99
99
|
*/
|
|
100
100
|
interface LoginParams {
|
|
101
|
-
/**
|
|
101
|
+
/** URL to redirect after successful login */
|
|
102
102
|
callbackUrl?: string;
|
|
103
|
-
/** For credentials-based login (if supported) */
|
|
104
|
-
username?: string;
|
|
105
|
-
password?: string;
|
|
106
|
-
/** Whether to use redirect flow (default: true) */
|
|
107
|
-
redirect?: boolean;
|
|
108
103
|
}
|
|
109
104
|
/**
|
|
110
105
|
* Logout params
|
|
@@ -124,11 +119,10 @@ declare let _cachedUser: Record<string, any> | null;
|
|
|
124
119
|
/**
|
|
125
120
|
* Creates a Refine AuthProvider for Taruvi authentication.
|
|
126
121
|
*
|
|
127
|
-
*
|
|
122
|
+
* Uses redirect-based Web UI Flow:
|
|
128
123
|
* 1. User calls login() → Redirects to backend /accounts/login/
|
|
129
124
|
* 2. User authenticates on backend
|
|
130
|
-
* 3. Backend redirects back
|
|
131
|
-
* 4. Client extracts and stores tokens automatically
|
|
125
|
+
* 3. Backend redirects back and sets session token
|
|
132
126
|
*/
|
|
133
127
|
declare function authProvider(client: Client): AuthProvider;
|
|
134
128
|
|
|
@@ -322,6 +316,30 @@ interface TaruviListResponse<T> {
|
|
|
322
316
|
has_more?: boolean;
|
|
323
317
|
};
|
|
324
318
|
}
|
|
319
|
+
/** `meta` for `useList`/`useDataGrid`/`useInfiniteList` — folder browse mode. */
|
|
320
|
+
interface StorageBrowseMeta {
|
|
321
|
+
mode: "browse";
|
|
322
|
+
/** Virtual folder prefix. Omit for root. */
|
|
323
|
+
prefix?: string;
|
|
324
|
+
/** Override bucket when `resource` differs from the bucket slug. */
|
|
325
|
+
bucketName?: string;
|
|
326
|
+
}
|
|
327
|
+
/** `meta` for `useCustom` — SharePoint view-access URL for an Office file. */
|
|
328
|
+
interface StorageViewAccessMeta {
|
|
329
|
+
kind: "viewAccess";
|
|
330
|
+
filePath: string;
|
|
331
|
+
bucketName?: string;
|
|
332
|
+
}
|
|
333
|
+
/** `meta` for `useCustom` — SharePoint edit-access URL for an Office file. */
|
|
334
|
+
interface StorageEditAccessMeta {
|
|
335
|
+
kind: "editAccess";
|
|
336
|
+
filePath: string;
|
|
337
|
+
bucketName?: string;
|
|
338
|
+
}
|
|
339
|
+
/** Union of all storage meta types. */
|
|
340
|
+
type StorageMeta = StorageBrowseMeta | StorageViewAccessMeta | StorageEditAccessMeta;
|
|
341
|
+
/** Browse result item — folder (`type: "folder"`) or file (`type: "file"`). */
|
|
342
|
+
type StorageBrowseItem = StorageBrowseFolder | StorageBrowseFile;
|
|
325
343
|
|
|
326
344
|
type ConvertRefineFiltersOptions = {
|
|
327
345
|
/**
|
|
@@ -402,4 +420,4 @@ declare function buildRefineQueryParams(options: {
|
|
|
402
420
|
*/
|
|
403
421
|
declare function buildQueryString(params?: Record<string, unknown>): string;
|
|
404
422
|
|
|
405
|
-
export { type AllowedAction, type AnalyticsMeta, type AppCustomMeta, type ConvertRefineFiltersOptions, type FlatFilterLeaf, type FunctionMeta, type LogicalCrudFilter, type LoginParams, type LogoutParams, REFINE_OPERATOR_MAP, type RegisterParams, type StorageDownloadResponse, type StorageUploadVariables, type TaruviConditionalFilter, type TaruviCrudFilter, type TaruviCrudOperator, type TaruviFieldFilter, type TaruviListFilters, type TaruviListResponse, type TaruviMeta, _cachedUser, accessControlProvider, analyticsDataProvider, appDataProvider, applyRefineQueryParamsToDatabase, authProvider, buildQueryString, buildRefineQueryParams, collectFlatLeaves, convertLogicalFilterToBackendTree, convertRefineFilters, convertRefineFiltersToBackendTree, convertRefinePagination, convertRefineSorters, dataProvider, encodeCrudFilterBracket, encodeFlatFilterListToParams, formatRefineLeafValue, functionsDataProvider, hasTaruviOperator, isFlatFilterList, isLogicalCrudFilter, normalizeTaruviListFilters, refineOperatorToBackendKey, storageDataProvider, taruviOperatorSuffix, toRefineFilters, userDataProvider };
|
|
423
|
+
export { type AllowedAction, type AnalyticsMeta, type AppCustomMeta, type ConvertRefineFiltersOptions, type FlatFilterLeaf, type FunctionMeta, type LogicalCrudFilter, type LoginParams, type LogoutParams, REFINE_OPERATOR_MAP, type RegisterParams, type StorageBrowseItem, type StorageBrowseMeta, type StorageDownloadResponse, type StorageEditAccessMeta, type StorageMeta, type StorageUploadVariables, type StorageViewAccessMeta, type TaruviConditionalFilter, type TaruviCrudFilter, type TaruviCrudOperator, type TaruviFieldFilter, type TaruviListFilters, type TaruviListResponse, type TaruviMeta, _cachedUser, accessControlProvider, analyticsDataProvider, appDataProvider, applyRefineQueryParamsToDatabase, authProvider, buildQueryString, buildRefineQueryParams, collectFlatLeaves, convertLogicalFilterToBackendTree, convertRefineFilters, convertRefineFiltersToBackendTree, convertRefinePagination, convertRefineSorters, dataProvider, encodeCrudFilterBracket, encodeFlatFilterListToParams, formatRefineLeafValue, functionsDataProvider, hasTaruviOperator, isFlatFilterList, isLogicalCrudFilter, normalizeTaruviListFilters, refineOperatorToBackendKey, storageDataProvider, taruviOperatorSuffix, toRefineFilters, userDataProvider };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DataProvider, AuthProvider, AccessControlProvider, CrudFilter, MetaQuery, CrudSort, Pagination } from '@refinedev/core';
|
|
2
|
-
import { Client, GraphFormat, GraphInclude, Database, BackendFilterTreeRoot } from '@taruvi/sdk';
|
|
3
|
-
export { UserData as TaruviUser } from '@taruvi/sdk';
|
|
2
|
+
import { Client, StorageBrowseFolder, StorageBrowseFile, GraphFormat, GraphInclude, Database, BackendFilterTreeRoot } from '@taruvi/sdk';
|
|
3
|
+
export { StorageAccessLinkResponse, StorageBrowseData, StorageBrowseFile, StorageBrowseFilters, StorageBrowseFolder, UserData as TaruviUser } from '@taruvi/sdk';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Creates a Refine DataProvider for Taruvi database operations.
|
|
@@ -95,16 +95,11 @@ declare function functionsDataProvider(client: Client): DataProvider;
|
|
|
95
95
|
declare function analyticsDataProvider(client: Client): DataProvider;
|
|
96
96
|
|
|
97
97
|
/**
|
|
98
|
-
* Login params
|
|
98
|
+
* Login params
|
|
99
99
|
*/
|
|
100
100
|
interface LoginParams {
|
|
101
|
-
/**
|
|
101
|
+
/** URL to redirect after successful login */
|
|
102
102
|
callbackUrl?: string;
|
|
103
|
-
/** For credentials-based login (if supported) */
|
|
104
|
-
username?: string;
|
|
105
|
-
password?: string;
|
|
106
|
-
/** Whether to use redirect flow (default: true) */
|
|
107
|
-
redirect?: boolean;
|
|
108
103
|
}
|
|
109
104
|
/**
|
|
110
105
|
* Logout params
|
|
@@ -124,11 +119,10 @@ declare let _cachedUser: Record<string, any> | null;
|
|
|
124
119
|
/**
|
|
125
120
|
* Creates a Refine AuthProvider for Taruvi authentication.
|
|
126
121
|
*
|
|
127
|
-
*
|
|
122
|
+
* Uses redirect-based Web UI Flow:
|
|
128
123
|
* 1. User calls login() → Redirects to backend /accounts/login/
|
|
129
124
|
* 2. User authenticates on backend
|
|
130
|
-
* 3. Backend redirects back
|
|
131
|
-
* 4. Client extracts and stores tokens automatically
|
|
125
|
+
* 3. Backend redirects back and sets session token
|
|
132
126
|
*/
|
|
133
127
|
declare function authProvider(client: Client): AuthProvider;
|
|
134
128
|
|
|
@@ -322,6 +316,30 @@ interface TaruviListResponse<T> {
|
|
|
322
316
|
has_more?: boolean;
|
|
323
317
|
};
|
|
324
318
|
}
|
|
319
|
+
/** `meta` for `useList`/`useDataGrid`/`useInfiniteList` — folder browse mode. */
|
|
320
|
+
interface StorageBrowseMeta {
|
|
321
|
+
mode: "browse";
|
|
322
|
+
/** Virtual folder prefix. Omit for root. */
|
|
323
|
+
prefix?: string;
|
|
324
|
+
/** Override bucket when `resource` differs from the bucket slug. */
|
|
325
|
+
bucketName?: string;
|
|
326
|
+
}
|
|
327
|
+
/** `meta` for `useCustom` — SharePoint view-access URL for an Office file. */
|
|
328
|
+
interface StorageViewAccessMeta {
|
|
329
|
+
kind: "viewAccess";
|
|
330
|
+
filePath: string;
|
|
331
|
+
bucketName?: string;
|
|
332
|
+
}
|
|
333
|
+
/** `meta` for `useCustom` — SharePoint edit-access URL for an Office file. */
|
|
334
|
+
interface StorageEditAccessMeta {
|
|
335
|
+
kind: "editAccess";
|
|
336
|
+
filePath: string;
|
|
337
|
+
bucketName?: string;
|
|
338
|
+
}
|
|
339
|
+
/** Union of all storage meta types. */
|
|
340
|
+
type StorageMeta = StorageBrowseMeta | StorageViewAccessMeta | StorageEditAccessMeta;
|
|
341
|
+
/** Browse result item — folder (`type: "folder"`) or file (`type: "file"`). */
|
|
342
|
+
type StorageBrowseItem = StorageBrowseFolder | StorageBrowseFile;
|
|
325
343
|
|
|
326
344
|
type ConvertRefineFiltersOptions = {
|
|
327
345
|
/**
|
|
@@ -402,4 +420,4 @@ declare function buildRefineQueryParams(options: {
|
|
|
402
420
|
*/
|
|
403
421
|
declare function buildQueryString(params?: Record<string, unknown>): string;
|
|
404
422
|
|
|
405
|
-
export { type AllowedAction, type AnalyticsMeta, type AppCustomMeta, type ConvertRefineFiltersOptions, type FlatFilterLeaf, type FunctionMeta, type LogicalCrudFilter, type LoginParams, type LogoutParams, REFINE_OPERATOR_MAP, type RegisterParams, type StorageDownloadResponse, type StorageUploadVariables, type TaruviConditionalFilter, type TaruviCrudFilter, type TaruviCrudOperator, type TaruviFieldFilter, type TaruviListFilters, type TaruviListResponse, type TaruviMeta, _cachedUser, accessControlProvider, analyticsDataProvider, appDataProvider, applyRefineQueryParamsToDatabase, authProvider, buildQueryString, buildRefineQueryParams, collectFlatLeaves, convertLogicalFilterToBackendTree, convertRefineFilters, convertRefineFiltersToBackendTree, convertRefinePagination, convertRefineSorters, dataProvider, encodeCrudFilterBracket, encodeFlatFilterListToParams, formatRefineLeafValue, functionsDataProvider, hasTaruviOperator, isFlatFilterList, isLogicalCrudFilter, normalizeTaruviListFilters, refineOperatorToBackendKey, storageDataProvider, taruviOperatorSuffix, toRefineFilters, userDataProvider };
|
|
423
|
+
export { type AllowedAction, type AnalyticsMeta, type AppCustomMeta, type ConvertRefineFiltersOptions, type FlatFilterLeaf, type FunctionMeta, type LogicalCrudFilter, type LoginParams, type LogoutParams, REFINE_OPERATOR_MAP, type RegisterParams, type StorageBrowseItem, type StorageBrowseMeta, type StorageDownloadResponse, type StorageEditAccessMeta, type StorageMeta, type StorageUploadVariables, type StorageViewAccessMeta, type TaruviConditionalFilter, type TaruviCrudFilter, type TaruviCrudOperator, type TaruviFieldFilter, type TaruviListFilters, type TaruviListResponse, type TaruviMeta, _cachedUser, accessControlProvider, analyticsDataProvider, appDataProvider, applyRefineQueryParamsToDatabase, authProvider, buildQueryString, buildRefineQueryParams, collectFlatLeaves, convertLogicalFilterToBackendTree, convertRefineFilters, convertRefineFiltersToBackendTree, convertRefinePagination, convertRefineSorters, dataProvider, encodeCrudFilterBracket, encodeFlatFilterListToParams, formatRefineLeafValue, functionsDataProvider, hasTaruviOperator, isFlatFilterList, isLogicalCrudFilter, normalizeTaruviListFilters, refineOperatorToBackendKey, storageDataProvider, taruviOperatorSuffix, toRefineFilters, 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.
|
|
8
|
+
version: "1.3.5"};
|
|
9
9
|
|
|
10
10
|
// src/filterTypes.ts
|
|
11
11
|
var REFINE_OPERATOR_MAP = {
|
|
@@ -653,6 +653,13 @@ function dataProvider(client) {
|
|
|
653
653
|
getApiUrl: () => baseApiUrl
|
|
654
654
|
};
|
|
655
655
|
}
|
|
656
|
+
var BROWSE_SORT_FIELDS = /* @__PURE__ */ new Set(["name", "size", "created_at", "updated_at"]);
|
|
657
|
+
function extractBrowseSorter(sorters) {
|
|
658
|
+
if (!sorters?.length) return {};
|
|
659
|
+
const { field, order } = sorters[0];
|
|
660
|
+
if (!BROWSE_SORT_FIELDS.has(field)) return {};
|
|
661
|
+
return { sort: field, order };
|
|
662
|
+
}
|
|
656
663
|
function storageDataProvider(client) {
|
|
657
664
|
const config = client.getConfig();
|
|
658
665
|
const baseApiUrl = `${config.apiUrl}/api/apps/${config.appSlug}`;
|
|
@@ -669,6 +676,23 @@ function storageDataProvider(client) {
|
|
|
669
676
|
return {
|
|
670
677
|
getList: async (params) => {
|
|
671
678
|
const { resource, pagination, filters, sorters, meta } = params;
|
|
679
|
+
if (meta?.mode === "browse") {
|
|
680
|
+
const browseMeta = meta;
|
|
681
|
+
const bucket2 = browseMeta.bucketName ?? resource;
|
|
682
|
+
const { page = 1, page_size = 50 } = convertRefinePagination(pagination);
|
|
683
|
+
const { sort, order } = extractBrowseSorter(sorters);
|
|
684
|
+
const response2 = await new Storage(client).from(bucket2).browse({ prefix: browseMeta.prefix ?? "", page, page_size, sort, order }).execute();
|
|
685
|
+
const browseData = response2.data;
|
|
686
|
+
const items = [...browseData.folders, ...browseData.objects];
|
|
687
|
+
const hasNext = browseData.has_next;
|
|
688
|
+
const pg = browseData.page;
|
|
689
|
+
const pgSize = browseData.page_size;
|
|
690
|
+
return {
|
|
691
|
+
data: items,
|
|
692
|
+
total: hasNext ? pg * pgSize + 1 : (pg - 1) * pgSize + items.length,
|
|
693
|
+
cursor: { next: hasNext ? pg + 1 : void 0 }
|
|
694
|
+
};
|
|
695
|
+
}
|
|
672
696
|
const taruviMeta = meta;
|
|
673
697
|
const bucket = getBucketName(resource, taruviMeta);
|
|
674
698
|
const storageFilters = buildFilters({ filters, sorters, pagination});
|
|
@@ -734,7 +758,19 @@ function storageDataProvider(client) {
|
|
|
734
758
|
return { data: ids.map((id) => ({ id })) };
|
|
735
759
|
},
|
|
736
760
|
custom: async (params) => {
|
|
737
|
-
const { url, method, payload, query } = params;
|
|
761
|
+
const { url, method, payload, query, meta } = params;
|
|
762
|
+
if (meta?.kind === "viewAccess") {
|
|
763
|
+
const accessMeta = meta;
|
|
764
|
+
const bucket = accessMeta.bucketName ?? url;
|
|
765
|
+
const response = await new Storage(client).from(bucket).viewAccess(accessMeta.filePath).execute();
|
|
766
|
+
return { data: response.data };
|
|
767
|
+
}
|
|
768
|
+
if (meta?.kind === "editAccess") {
|
|
769
|
+
const accessMeta = meta;
|
|
770
|
+
const bucket = accessMeta.bucketName ?? url;
|
|
771
|
+
const response = await new Storage(client).from(bucket).editAccess(accessMeta.filePath).execute();
|
|
772
|
+
return { data: response.data };
|
|
773
|
+
}
|
|
738
774
|
let fullUrl = `api/apps/${config.appSlug}/storage/buckets/${url}`;
|
|
739
775
|
let data;
|
|
740
776
|
switch (method.toLowerCase()) {
|
|
@@ -763,7 +799,6 @@ function storageDataProvider(client) {
|
|
|
763
799
|
}
|
|
764
800
|
return { data };
|
|
765
801
|
},
|
|
766
|
-
// Not applicable for file storage - files are replaced, not updated
|
|
767
802
|
updateMany: void 0
|
|
768
803
|
};
|
|
769
804
|
}
|
|
@@ -1170,27 +1205,20 @@ var isBrowser = typeof window !== "undefined";
|
|
|
1170
1205
|
var _cachedUser = null;
|
|
1171
1206
|
function authProvider(client) {
|
|
1172
1207
|
const auth = new Auth(client);
|
|
1208
|
+
function redirectToLogin() {
|
|
1209
|
+
_cachedUser = null;
|
|
1210
|
+
auth.login();
|
|
1211
|
+
}
|
|
1173
1212
|
return {
|
|
1174
|
-
login: async (
|
|
1175
|
-
|
|
1176
|
-
if (auth.isUserAuthenticated()) {
|
|
1177
|
-
return {
|
|
1178
|
-
success: true,
|
|
1179
|
-
redirectTo: callbackUrl || "/"
|
|
1180
|
-
};
|
|
1181
|
-
}
|
|
1182
|
-
if (redirect) {
|
|
1183
|
-
auth.login(callbackUrl);
|
|
1213
|
+
login: async () => {
|
|
1214
|
+
if (auth.hasToken()) {
|
|
1184
1215
|
return {
|
|
1185
1216
|
success: true
|
|
1186
1217
|
};
|
|
1187
1218
|
}
|
|
1219
|
+
redirectToLogin();
|
|
1188
1220
|
return {
|
|
1189
|
-
success:
|
|
1190
|
-
error: {
|
|
1191
|
-
name: "LoginError",
|
|
1192
|
-
message: "Login failed. Please try again."
|
|
1193
|
-
}
|
|
1221
|
+
success: true
|
|
1194
1222
|
};
|
|
1195
1223
|
},
|
|
1196
1224
|
logout: async (params = {}) => {
|
|
@@ -1203,19 +1231,20 @@ function authProvider(client) {
|
|
|
1203
1231
|
};
|
|
1204
1232
|
},
|
|
1205
1233
|
check: async () => {
|
|
1206
|
-
if (!auth.
|
|
1207
|
-
return { authenticated: false
|
|
1234
|
+
if (!auth.hasToken()) {
|
|
1235
|
+
return { authenticated: false };
|
|
1236
|
+
}
|
|
1237
|
+
const isValid = await auth.isUserAuthenticated();
|
|
1238
|
+
if (!isValid) {
|
|
1239
|
+
return { authenticated: false };
|
|
1208
1240
|
}
|
|
1209
1241
|
return { authenticated: true };
|
|
1210
1242
|
},
|
|
1211
1243
|
onError: async (error) => {
|
|
1212
1244
|
const status = error?.statusCode || error?.status || error?.response?.status;
|
|
1213
1245
|
if (status === 401) {
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
redirectTo: "/login",
|
|
1217
|
-
error
|
|
1218
|
-
};
|
|
1246
|
+
redirectToLogin();
|
|
1247
|
+
return { error };
|
|
1219
1248
|
}
|
|
1220
1249
|
if (status === 403) {
|
|
1221
1250
|
return { error };
|