@wecode-team/cms-supabase-api 0.1.32 → 0.1.34
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.esm.js +134 -124
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +134 -124
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -2684,6 +2684,130 @@ function getAuthService() {
|
|
|
2684
2684
|
return defaultService;
|
|
2685
2685
|
}
|
|
2686
2686
|
|
|
2687
|
+
var ADMIN_REGISTRY_TABLE = "_cms_admin_registry";
|
|
2688
|
+
var ensured = false;
|
|
2689
|
+
function normalizeSessionId(sessionId) {
|
|
2690
|
+
// 统一将连字符转换为下划线,确保 UUID 格式一致性
|
|
2691
|
+
// 例如:1047aab4-eecb-4538-ad8d-b5847e762f30 和 1047aab4_eecb_4538_ad8d_b5847e762f30 被视为相同
|
|
2692
|
+
return (sessionId || "").trim().replace(/-/g, "_");
|
|
2693
|
+
}
|
|
2694
|
+
/**
|
|
2695
|
+
* 从前端传来的 auth tableName 中提取 session_id
|
|
2696
|
+
* 约定:auth tableName 形如 `${sessionId}_cms_users`;无前缀则为 `cms_users`
|
|
2697
|
+
*/
|
|
2698
|
+
function extractSessionIdFromAuthTableName(tableName) {
|
|
2699
|
+
var name = (tableName || "").trim();
|
|
2700
|
+
if (!name) return "";
|
|
2701
|
+
if (name === "cms_users") return "";
|
|
2702
|
+
if (name.endsWith("_cms_users")) return name.slice(0, -"_cms_users".length);
|
|
2703
|
+
// 兼容:如果传入的不是 cms_users,也允许把最后一个 "_cms_users" 前缀当作 session
|
|
2704
|
+
var idx = name.lastIndexOf("_cms_users");
|
|
2705
|
+
if (idx > 0) return name.slice(0, idx);
|
|
2706
|
+
return "";
|
|
2707
|
+
}
|
|
2708
|
+
function ensureAdminRegistryTable(_x) {
|
|
2709
|
+
return _ensureAdminRegistryTable.apply(this, arguments);
|
|
2710
|
+
}
|
|
2711
|
+
function _ensureAdminRegistryTable() {
|
|
2712
|
+
_ensureAdminRegistryTable = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(supabase) {
|
|
2713
|
+
var _yield$supabase$from$, error;
|
|
2714
|
+
return _regeneratorRuntime.wrap(function (_context) {
|
|
2715
|
+
while (1) switch (_context.prev = _context.next) {
|
|
2716
|
+
case 0:
|
|
2717
|
+
if (!ensured) {
|
|
2718
|
+
_context.next = 1;
|
|
2719
|
+
break;
|
|
2720
|
+
}
|
|
2721
|
+
return _context.abrupt("return", true);
|
|
2722
|
+
case 1:
|
|
2723
|
+
_context.prev = 1;
|
|
2724
|
+
_context.next = 2;
|
|
2725
|
+
return supabase.from(ADMIN_REGISTRY_TABLE).select("session_id").limit(1);
|
|
2726
|
+
case 2:
|
|
2727
|
+
_yield$supabase$from$ = _context.sent;
|
|
2728
|
+
error = _yield$supabase$from$.error;
|
|
2729
|
+
if (error) {
|
|
2730
|
+
_context.next = 3;
|
|
2731
|
+
break;
|
|
2732
|
+
}
|
|
2733
|
+
ensured = true;
|
|
2734
|
+
return _context.abrupt("return", true);
|
|
2735
|
+
case 3:
|
|
2736
|
+
_context.next = 5;
|
|
2737
|
+
break;
|
|
2738
|
+
case 4:
|
|
2739
|
+
_context.prev = 4;
|
|
2740
|
+
_context["catch"](1);
|
|
2741
|
+
case 5:
|
|
2742
|
+
return _context.abrupt("return", false);
|
|
2743
|
+
case 6:
|
|
2744
|
+
case "end":
|
|
2745
|
+
return _context.stop();
|
|
2746
|
+
}
|
|
2747
|
+
}, _callee, null, [[1, 4]]);
|
|
2748
|
+
}));
|
|
2749
|
+
return _ensureAdminRegistryTable.apply(this, arguments);
|
|
2750
|
+
}
|
|
2751
|
+
function getSessionAdminRow(_x2, _x3) {
|
|
2752
|
+
return _getSessionAdminRow.apply(this, arguments);
|
|
2753
|
+
}
|
|
2754
|
+
function _getSessionAdminRow() {
|
|
2755
|
+
_getSessionAdminRow = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(supabase, sessionId) {
|
|
2756
|
+
var sid, _yield$supabase$from$2, data, error;
|
|
2757
|
+
return _regeneratorRuntime.wrap(function (_context2) {
|
|
2758
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
2759
|
+
case 0:
|
|
2760
|
+
sid = normalizeSessionId(sessionId);
|
|
2761
|
+
_context2.next = 1;
|
|
2762
|
+
return supabase.from(ADMIN_REGISTRY_TABLE).select("session_id,user_id,email").eq("session_id", sid).maybeSingle();
|
|
2763
|
+
case 1:
|
|
2764
|
+
_yield$supabase$from$2 = _context2.sent;
|
|
2765
|
+
data = _yield$supabase$from$2.data;
|
|
2766
|
+
error = _yield$supabase$from$2.error;
|
|
2767
|
+
if (!(error || !data)) {
|
|
2768
|
+
_context2.next = 2;
|
|
2769
|
+
break;
|
|
2770
|
+
}
|
|
2771
|
+
return _context2.abrupt("return", null);
|
|
2772
|
+
case 2:
|
|
2773
|
+
return _context2.abrupt("return", data);
|
|
2774
|
+
case 3:
|
|
2775
|
+
case "end":
|
|
2776
|
+
return _context2.stop();
|
|
2777
|
+
}
|
|
2778
|
+
}, _callee2);
|
|
2779
|
+
}));
|
|
2780
|
+
return _getSessionAdminRow.apply(this, arguments);
|
|
2781
|
+
}
|
|
2782
|
+
function isUserSessionAdmin(_x4, _x5, _x6) {
|
|
2783
|
+
return _isUserSessionAdmin.apply(this, arguments);
|
|
2784
|
+
}
|
|
2785
|
+
function _isUserSessionAdmin() {
|
|
2786
|
+
_isUserSessionAdmin = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(supabase, sessionId, userId) {
|
|
2787
|
+
var row;
|
|
2788
|
+
return _regeneratorRuntime.wrap(function (_context3) {
|
|
2789
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
2790
|
+
case 0:
|
|
2791
|
+
_context3.next = 1;
|
|
2792
|
+
return getSessionAdminRow(supabase, sessionId);
|
|
2793
|
+
case 1:
|
|
2794
|
+
row = _context3.sent;
|
|
2795
|
+
if (row) {
|
|
2796
|
+
_context3.next = 2;
|
|
2797
|
+
break;
|
|
2798
|
+
}
|
|
2799
|
+
return _context3.abrupt("return", false);
|
|
2800
|
+
case 2:
|
|
2801
|
+
return _context3.abrupt("return", row.user_id === userId);
|
|
2802
|
+
case 3:
|
|
2803
|
+
case "end":
|
|
2804
|
+
return _context3.stop();
|
|
2805
|
+
}
|
|
2806
|
+
}, _callee3);
|
|
2807
|
+
}));
|
|
2808
|
+
return _isUserSessionAdmin.apply(this, arguments);
|
|
2809
|
+
}
|
|
2810
|
+
|
|
2687
2811
|
// 初始化Supabase连接和CMS系统
|
|
2688
2812
|
function initializeSystem() {
|
|
2689
2813
|
return _initializeSystem.apply(this, arguments);
|
|
@@ -2724,7 +2848,7 @@ function getModels(_x) {
|
|
|
2724
2848
|
// POST - 创建新模型
|
|
2725
2849
|
function _getModels() {
|
|
2726
2850
|
_getModels = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(c) {
|
|
2727
|
-
var cmsModelService, page, limit, name, models, total, offset, paginatedModels, response, _response, _t2;
|
|
2851
|
+
var cmsModelService, page, limit, name, sessionId, models, tablePrefix, total, offset, paginatedModels, response, _response, _t2;
|
|
2728
2852
|
return _regeneratorRuntime.wrap(function (_context2) {
|
|
2729
2853
|
while (1) switch (_context2.prev = _context2.next) {
|
|
2730
2854
|
case 0:
|
|
@@ -2735,11 +2859,19 @@ function _getModels() {
|
|
|
2735
2859
|
cmsModelService = getCmsModelService();
|
|
2736
2860
|
page = parseInt(c.req.query("page") || "1");
|
|
2737
2861
|
limit = parseInt(c.req.query("limit") || "10");
|
|
2738
|
-
name = c.req.query("name"); //
|
|
2862
|
+
name = c.req.query("name"); // 获取当前请求的 session_id
|
|
2863
|
+
sessionId = normalizeSessionId(c.req.header("X-Session-Id") || c.req.header("x-session-id")); // 获取所有模型
|
|
2739
2864
|
_context2.next = 2;
|
|
2740
2865
|
return cmsModelService.findAll();
|
|
2741
2866
|
case 2:
|
|
2742
2867
|
models = _context2.sent;
|
|
2868
|
+
// 根据 session_id 过滤模型(只返回属于当前 session 的表)
|
|
2869
|
+
if (sessionId) {
|
|
2870
|
+
tablePrefix = sessionId + "_";
|
|
2871
|
+
models = models.filter(function (model) {
|
|
2872
|
+
return model.table_name.startsWith(tablePrefix);
|
|
2873
|
+
});
|
|
2874
|
+
}
|
|
2743
2875
|
// 如果有名称过滤
|
|
2744
2876
|
if (name) {
|
|
2745
2877
|
models = models.filter(function (model) {
|
|
@@ -4199,128 +4331,6 @@ var AuthUtils = /*#__PURE__*/function () {
|
|
|
4199
4331
|
}]);
|
|
4200
4332
|
}();
|
|
4201
4333
|
|
|
4202
|
-
var ADMIN_REGISTRY_TABLE = "_cms_admin_registry";
|
|
4203
|
-
var ensured = false;
|
|
4204
|
-
function normalizeSessionId(sessionId) {
|
|
4205
|
-
return (sessionId || "").trim();
|
|
4206
|
-
}
|
|
4207
|
-
/**
|
|
4208
|
-
* 从前端传来的 auth tableName 中提取 session_id
|
|
4209
|
-
* 约定:auth tableName 形如 `${sessionId}_cms_users`;无前缀则为 `cms_users`
|
|
4210
|
-
*/
|
|
4211
|
-
function extractSessionIdFromAuthTableName(tableName) {
|
|
4212
|
-
var name = (tableName || "").trim();
|
|
4213
|
-
if (!name) return "";
|
|
4214
|
-
if (name === "cms_users") return "";
|
|
4215
|
-
if (name.endsWith("_cms_users")) return name.slice(0, -"_cms_users".length);
|
|
4216
|
-
// 兼容:如果传入的不是 cms_users,也允许把最后一个 "_cms_users" 前缀当作 session
|
|
4217
|
-
var idx = name.lastIndexOf("_cms_users");
|
|
4218
|
-
if (idx > 0) return name.slice(0, idx);
|
|
4219
|
-
return "";
|
|
4220
|
-
}
|
|
4221
|
-
function ensureAdminRegistryTable(_x) {
|
|
4222
|
-
return _ensureAdminRegistryTable.apply(this, arguments);
|
|
4223
|
-
}
|
|
4224
|
-
function _ensureAdminRegistryTable() {
|
|
4225
|
-
_ensureAdminRegistryTable = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(supabase) {
|
|
4226
|
-
var _yield$supabase$from$, error;
|
|
4227
|
-
return _regeneratorRuntime.wrap(function (_context) {
|
|
4228
|
-
while (1) switch (_context.prev = _context.next) {
|
|
4229
|
-
case 0:
|
|
4230
|
-
if (!ensured) {
|
|
4231
|
-
_context.next = 1;
|
|
4232
|
-
break;
|
|
4233
|
-
}
|
|
4234
|
-
return _context.abrupt("return", true);
|
|
4235
|
-
case 1:
|
|
4236
|
-
_context.prev = 1;
|
|
4237
|
-
_context.next = 2;
|
|
4238
|
-
return supabase.from(ADMIN_REGISTRY_TABLE).select("session_id").limit(1);
|
|
4239
|
-
case 2:
|
|
4240
|
-
_yield$supabase$from$ = _context.sent;
|
|
4241
|
-
error = _yield$supabase$from$.error;
|
|
4242
|
-
if (error) {
|
|
4243
|
-
_context.next = 3;
|
|
4244
|
-
break;
|
|
4245
|
-
}
|
|
4246
|
-
ensured = true;
|
|
4247
|
-
return _context.abrupt("return", true);
|
|
4248
|
-
case 3:
|
|
4249
|
-
_context.next = 5;
|
|
4250
|
-
break;
|
|
4251
|
-
case 4:
|
|
4252
|
-
_context.prev = 4;
|
|
4253
|
-
_context["catch"](1);
|
|
4254
|
-
case 5:
|
|
4255
|
-
return _context.abrupt("return", false);
|
|
4256
|
-
case 6:
|
|
4257
|
-
case "end":
|
|
4258
|
-
return _context.stop();
|
|
4259
|
-
}
|
|
4260
|
-
}, _callee, null, [[1, 4]]);
|
|
4261
|
-
}));
|
|
4262
|
-
return _ensureAdminRegistryTable.apply(this, arguments);
|
|
4263
|
-
}
|
|
4264
|
-
function getSessionAdminRow(_x2, _x3) {
|
|
4265
|
-
return _getSessionAdminRow.apply(this, arguments);
|
|
4266
|
-
}
|
|
4267
|
-
function _getSessionAdminRow() {
|
|
4268
|
-
_getSessionAdminRow = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(supabase, sessionId) {
|
|
4269
|
-
var sid, _yield$supabase$from$2, data, error;
|
|
4270
|
-
return _regeneratorRuntime.wrap(function (_context2) {
|
|
4271
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
4272
|
-
case 0:
|
|
4273
|
-
sid = normalizeSessionId(sessionId);
|
|
4274
|
-
_context2.next = 1;
|
|
4275
|
-
return supabase.from(ADMIN_REGISTRY_TABLE).select("session_id,user_id,email").eq("session_id", sid).maybeSingle();
|
|
4276
|
-
case 1:
|
|
4277
|
-
_yield$supabase$from$2 = _context2.sent;
|
|
4278
|
-
data = _yield$supabase$from$2.data;
|
|
4279
|
-
error = _yield$supabase$from$2.error;
|
|
4280
|
-
if (!(error || !data)) {
|
|
4281
|
-
_context2.next = 2;
|
|
4282
|
-
break;
|
|
4283
|
-
}
|
|
4284
|
-
return _context2.abrupt("return", null);
|
|
4285
|
-
case 2:
|
|
4286
|
-
return _context2.abrupt("return", data);
|
|
4287
|
-
case 3:
|
|
4288
|
-
case "end":
|
|
4289
|
-
return _context2.stop();
|
|
4290
|
-
}
|
|
4291
|
-
}, _callee2);
|
|
4292
|
-
}));
|
|
4293
|
-
return _getSessionAdminRow.apply(this, arguments);
|
|
4294
|
-
}
|
|
4295
|
-
function isUserSessionAdmin(_x4, _x5, _x6) {
|
|
4296
|
-
return _isUserSessionAdmin.apply(this, arguments);
|
|
4297
|
-
}
|
|
4298
|
-
function _isUserSessionAdmin() {
|
|
4299
|
-
_isUserSessionAdmin = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(supabase, sessionId, userId) {
|
|
4300
|
-
var row;
|
|
4301
|
-
return _regeneratorRuntime.wrap(function (_context3) {
|
|
4302
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
4303
|
-
case 0:
|
|
4304
|
-
_context3.next = 1;
|
|
4305
|
-
return getSessionAdminRow(supabase, sessionId);
|
|
4306
|
-
case 1:
|
|
4307
|
-
row = _context3.sent;
|
|
4308
|
-
if (row) {
|
|
4309
|
-
_context3.next = 2;
|
|
4310
|
-
break;
|
|
4311
|
-
}
|
|
4312
|
-
return _context3.abrupt("return", false);
|
|
4313
|
-
case 2:
|
|
4314
|
-
return _context3.abrupt("return", row.user_id === userId);
|
|
4315
|
-
case 3:
|
|
4316
|
-
case "end":
|
|
4317
|
-
return _context3.stop();
|
|
4318
|
-
}
|
|
4319
|
-
}, _callee3);
|
|
4320
|
-
}));
|
|
4321
|
-
return _isUserSessionAdmin.apply(this, arguments);
|
|
4322
|
-
}
|
|
4323
|
-
|
|
4324
4334
|
function getRoleFromSupabaseUser$2(user) {
|
|
4325
4335
|
var _user$app_metadata, _user$user_metadata;
|
|
4326
4336
|
var appRole = user === null || user === void 0 || (_user$app_metadata = user.app_metadata) === null || _user$app_metadata === void 0 ? void 0 : _user$app_metadata.role;
|