@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.cjs
CHANGED
|
@@ -11,7 +11,7 @@ var DataLoader__default = /*#__PURE__*/_interopDefault(DataLoader);
|
|
|
11
11
|
|
|
12
12
|
// package.json
|
|
13
13
|
var package_default = {
|
|
14
|
-
version: "1.3.
|
|
14
|
+
version: "1.3.5"};
|
|
15
15
|
|
|
16
16
|
// src/filterTypes.ts
|
|
17
17
|
var REFINE_OPERATOR_MAP = {
|
|
@@ -659,6 +659,13 @@ function dataProvider(client) {
|
|
|
659
659
|
getApiUrl: () => baseApiUrl
|
|
660
660
|
};
|
|
661
661
|
}
|
|
662
|
+
var BROWSE_SORT_FIELDS = /* @__PURE__ */ new Set(["name", "size", "created_at", "updated_at"]);
|
|
663
|
+
function extractBrowseSorter(sorters) {
|
|
664
|
+
if (!sorters?.length) return {};
|
|
665
|
+
const { field, order } = sorters[0];
|
|
666
|
+
if (!BROWSE_SORT_FIELDS.has(field)) return {};
|
|
667
|
+
return { sort: field, order };
|
|
668
|
+
}
|
|
662
669
|
function storageDataProvider(client) {
|
|
663
670
|
const config = client.getConfig();
|
|
664
671
|
const baseApiUrl = `${config.apiUrl}/api/apps/${config.appSlug}`;
|
|
@@ -675,6 +682,23 @@ function storageDataProvider(client) {
|
|
|
675
682
|
return {
|
|
676
683
|
getList: async (params) => {
|
|
677
684
|
const { resource, pagination, filters, sorters, meta } = params;
|
|
685
|
+
if (meta?.mode === "browse") {
|
|
686
|
+
const browseMeta = meta;
|
|
687
|
+
const bucket2 = browseMeta.bucketName ?? resource;
|
|
688
|
+
const { page = 1, page_size = 50 } = convertRefinePagination(pagination);
|
|
689
|
+
const { sort, order } = extractBrowseSorter(sorters);
|
|
690
|
+
const response2 = await new sdk.Storage(client).from(bucket2).browse({ prefix: browseMeta.prefix ?? "", page, page_size, sort, order }).execute();
|
|
691
|
+
const browseData = response2.data;
|
|
692
|
+
const items = [...browseData.folders, ...browseData.objects];
|
|
693
|
+
const hasNext = browseData.has_next;
|
|
694
|
+
const pg = browseData.page;
|
|
695
|
+
const pgSize = browseData.page_size;
|
|
696
|
+
return {
|
|
697
|
+
data: items,
|
|
698
|
+
total: hasNext ? pg * pgSize + 1 : (pg - 1) * pgSize + items.length,
|
|
699
|
+
cursor: { next: hasNext ? pg + 1 : void 0 }
|
|
700
|
+
};
|
|
701
|
+
}
|
|
678
702
|
const taruviMeta = meta;
|
|
679
703
|
const bucket = getBucketName(resource, taruviMeta);
|
|
680
704
|
const storageFilters = buildFilters({ filters, sorters, pagination});
|
|
@@ -740,7 +764,19 @@ function storageDataProvider(client) {
|
|
|
740
764
|
return { data: ids.map((id) => ({ id })) };
|
|
741
765
|
},
|
|
742
766
|
custom: async (params) => {
|
|
743
|
-
const { url, method, payload, query } = params;
|
|
767
|
+
const { url, method, payload, query, meta } = params;
|
|
768
|
+
if (meta?.kind === "viewAccess") {
|
|
769
|
+
const accessMeta = meta;
|
|
770
|
+
const bucket = accessMeta.bucketName ?? url;
|
|
771
|
+
const response = await new sdk.Storage(client).from(bucket).viewAccess(accessMeta.filePath).execute();
|
|
772
|
+
return { data: response.data };
|
|
773
|
+
}
|
|
774
|
+
if (meta?.kind === "editAccess") {
|
|
775
|
+
const accessMeta = meta;
|
|
776
|
+
const bucket = accessMeta.bucketName ?? url;
|
|
777
|
+
const response = await new sdk.Storage(client).from(bucket).editAccess(accessMeta.filePath).execute();
|
|
778
|
+
return { data: response.data };
|
|
779
|
+
}
|
|
744
780
|
let fullUrl = `api/apps/${config.appSlug}/storage/buckets/${url}`;
|
|
745
781
|
let data;
|
|
746
782
|
switch (method.toLowerCase()) {
|
|
@@ -769,7 +805,6 @@ function storageDataProvider(client) {
|
|
|
769
805
|
}
|
|
770
806
|
return { data };
|
|
771
807
|
},
|
|
772
|
-
// Not applicable for file storage - files are replaced, not updated
|
|
773
808
|
updateMany: void 0
|
|
774
809
|
};
|
|
775
810
|
}
|
|
@@ -1176,27 +1211,20 @@ var isBrowser = typeof window !== "undefined";
|
|
|
1176
1211
|
exports._cachedUser = null;
|
|
1177
1212
|
function authProvider(client) {
|
|
1178
1213
|
const auth = new sdk.Auth(client);
|
|
1214
|
+
function redirectToLogin() {
|
|
1215
|
+
exports._cachedUser = null;
|
|
1216
|
+
auth.login();
|
|
1217
|
+
}
|
|
1179
1218
|
return {
|
|
1180
|
-
login: async (
|
|
1181
|
-
|
|
1182
|
-
if (auth.isUserAuthenticated()) {
|
|
1183
|
-
return {
|
|
1184
|
-
success: true,
|
|
1185
|
-
redirectTo: callbackUrl || "/"
|
|
1186
|
-
};
|
|
1187
|
-
}
|
|
1188
|
-
if (redirect) {
|
|
1189
|
-
auth.login(callbackUrl);
|
|
1219
|
+
login: async () => {
|
|
1220
|
+
if (auth.hasToken()) {
|
|
1190
1221
|
return {
|
|
1191
1222
|
success: true
|
|
1192
1223
|
};
|
|
1193
1224
|
}
|
|
1225
|
+
redirectToLogin();
|
|
1194
1226
|
return {
|
|
1195
|
-
success:
|
|
1196
|
-
error: {
|
|
1197
|
-
name: "LoginError",
|
|
1198
|
-
message: "Login failed. Please try again."
|
|
1199
|
-
}
|
|
1227
|
+
success: true
|
|
1200
1228
|
};
|
|
1201
1229
|
},
|
|
1202
1230
|
logout: async (params = {}) => {
|
|
@@ -1209,19 +1237,20 @@ function authProvider(client) {
|
|
|
1209
1237
|
};
|
|
1210
1238
|
},
|
|
1211
1239
|
check: async () => {
|
|
1212
|
-
if (!auth.
|
|
1213
|
-
return { authenticated: false
|
|
1240
|
+
if (!auth.hasToken()) {
|
|
1241
|
+
return { authenticated: false };
|
|
1242
|
+
}
|
|
1243
|
+
const isValid = await auth.isUserAuthenticated();
|
|
1244
|
+
if (!isValid) {
|
|
1245
|
+
return { authenticated: false };
|
|
1214
1246
|
}
|
|
1215
1247
|
return { authenticated: true };
|
|
1216
1248
|
},
|
|
1217
1249
|
onError: async (error) => {
|
|
1218
1250
|
const status = error?.statusCode || error?.status || error?.response?.status;
|
|
1219
1251
|
if (status === 401) {
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
redirectTo: "/login",
|
|
1223
|
-
error
|
|
1224
|
-
};
|
|
1252
|
+
redirectToLogin();
|
|
1253
|
+
return { error };
|
|
1225
1254
|
}
|
|
1226
1255
|
if (status === 403) {
|
|
1227
1256
|
return { error };
|