@wecode-team/cms-supabase-api 0.1.33 → 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 -126
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +134 -126
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2706,6 +2706,130 @@ function getAuthService() {
|
|
|
2706
2706
|
return defaultService;
|
|
2707
2707
|
}
|
|
2708
2708
|
|
|
2709
|
+
var ADMIN_REGISTRY_TABLE = "_cms_admin_registry";
|
|
2710
|
+
var ensured = false;
|
|
2711
|
+
function normalizeSessionId(sessionId) {
|
|
2712
|
+
// 统一将连字符转换为下划线,确保 UUID 格式一致性
|
|
2713
|
+
// 例如:1047aab4-eecb-4538-ad8d-b5847e762f30 和 1047aab4_eecb_4538_ad8d_b5847e762f30 被视为相同
|
|
2714
|
+
return (sessionId || "").trim().replace(/-/g, "_");
|
|
2715
|
+
}
|
|
2716
|
+
/**
|
|
2717
|
+
* 从前端传来的 auth tableName 中提取 session_id
|
|
2718
|
+
* 约定:auth tableName 形如 `${sessionId}_cms_users`;无前缀则为 `cms_users`
|
|
2719
|
+
*/
|
|
2720
|
+
function extractSessionIdFromAuthTableName(tableName) {
|
|
2721
|
+
var name = (tableName || "").trim();
|
|
2722
|
+
if (!name) return "";
|
|
2723
|
+
if (name === "cms_users") return "";
|
|
2724
|
+
if (name.endsWith("_cms_users")) return name.slice(0, -"_cms_users".length);
|
|
2725
|
+
// 兼容:如果传入的不是 cms_users,也允许把最后一个 "_cms_users" 前缀当作 session
|
|
2726
|
+
var idx = name.lastIndexOf("_cms_users");
|
|
2727
|
+
if (idx > 0) return name.slice(0, idx);
|
|
2728
|
+
return "";
|
|
2729
|
+
}
|
|
2730
|
+
function ensureAdminRegistryTable(_x) {
|
|
2731
|
+
return _ensureAdminRegistryTable.apply(this, arguments);
|
|
2732
|
+
}
|
|
2733
|
+
function _ensureAdminRegistryTable() {
|
|
2734
|
+
_ensureAdminRegistryTable = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(supabase) {
|
|
2735
|
+
var _yield$supabase$from$, error;
|
|
2736
|
+
return _regeneratorRuntime.wrap(function (_context) {
|
|
2737
|
+
while (1) switch (_context.prev = _context.next) {
|
|
2738
|
+
case 0:
|
|
2739
|
+
if (!ensured) {
|
|
2740
|
+
_context.next = 1;
|
|
2741
|
+
break;
|
|
2742
|
+
}
|
|
2743
|
+
return _context.abrupt("return", true);
|
|
2744
|
+
case 1:
|
|
2745
|
+
_context.prev = 1;
|
|
2746
|
+
_context.next = 2;
|
|
2747
|
+
return supabase.from(ADMIN_REGISTRY_TABLE).select("session_id").limit(1);
|
|
2748
|
+
case 2:
|
|
2749
|
+
_yield$supabase$from$ = _context.sent;
|
|
2750
|
+
error = _yield$supabase$from$.error;
|
|
2751
|
+
if (error) {
|
|
2752
|
+
_context.next = 3;
|
|
2753
|
+
break;
|
|
2754
|
+
}
|
|
2755
|
+
ensured = true;
|
|
2756
|
+
return _context.abrupt("return", true);
|
|
2757
|
+
case 3:
|
|
2758
|
+
_context.next = 5;
|
|
2759
|
+
break;
|
|
2760
|
+
case 4:
|
|
2761
|
+
_context.prev = 4;
|
|
2762
|
+
_context["catch"](1);
|
|
2763
|
+
case 5:
|
|
2764
|
+
return _context.abrupt("return", false);
|
|
2765
|
+
case 6:
|
|
2766
|
+
case "end":
|
|
2767
|
+
return _context.stop();
|
|
2768
|
+
}
|
|
2769
|
+
}, _callee, null, [[1, 4]]);
|
|
2770
|
+
}));
|
|
2771
|
+
return _ensureAdminRegistryTable.apply(this, arguments);
|
|
2772
|
+
}
|
|
2773
|
+
function getSessionAdminRow(_x2, _x3) {
|
|
2774
|
+
return _getSessionAdminRow.apply(this, arguments);
|
|
2775
|
+
}
|
|
2776
|
+
function _getSessionAdminRow() {
|
|
2777
|
+
_getSessionAdminRow = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(supabase, sessionId) {
|
|
2778
|
+
var sid, _yield$supabase$from$2, data, error;
|
|
2779
|
+
return _regeneratorRuntime.wrap(function (_context2) {
|
|
2780
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
2781
|
+
case 0:
|
|
2782
|
+
sid = normalizeSessionId(sessionId);
|
|
2783
|
+
_context2.next = 1;
|
|
2784
|
+
return supabase.from(ADMIN_REGISTRY_TABLE).select("session_id,user_id,email").eq("session_id", sid).maybeSingle();
|
|
2785
|
+
case 1:
|
|
2786
|
+
_yield$supabase$from$2 = _context2.sent;
|
|
2787
|
+
data = _yield$supabase$from$2.data;
|
|
2788
|
+
error = _yield$supabase$from$2.error;
|
|
2789
|
+
if (!(error || !data)) {
|
|
2790
|
+
_context2.next = 2;
|
|
2791
|
+
break;
|
|
2792
|
+
}
|
|
2793
|
+
return _context2.abrupt("return", null);
|
|
2794
|
+
case 2:
|
|
2795
|
+
return _context2.abrupt("return", data);
|
|
2796
|
+
case 3:
|
|
2797
|
+
case "end":
|
|
2798
|
+
return _context2.stop();
|
|
2799
|
+
}
|
|
2800
|
+
}, _callee2);
|
|
2801
|
+
}));
|
|
2802
|
+
return _getSessionAdminRow.apply(this, arguments);
|
|
2803
|
+
}
|
|
2804
|
+
function isUserSessionAdmin(_x4, _x5, _x6) {
|
|
2805
|
+
return _isUserSessionAdmin.apply(this, arguments);
|
|
2806
|
+
}
|
|
2807
|
+
function _isUserSessionAdmin() {
|
|
2808
|
+
_isUserSessionAdmin = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(supabase, sessionId, userId) {
|
|
2809
|
+
var row;
|
|
2810
|
+
return _regeneratorRuntime.wrap(function (_context3) {
|
|
2811
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
2812
|
+
case 0:
|
|
2813
|
+
_context3.next = 1;
|
|
2814
|
+
return getSessionAdminRow(supabase, sessionId);
|
|
2815
|
+
case 1:
|
|
2816
|
+
row = _context3.sent;
|
|
2817
|
+
if (row) {
|
|
2818
|
+
_context3.next = 2;
|
|
2819
|
+
break;
|
|
2820
|
+
}
|
|
2821
|
+
return _context3.abrupt("return", false);
|
|
2822
|
+
case 2:
|
|
2823
|
+
return _context3.abrupt("return", row.user_id === userId);
|
|
2824
|
+
case 3:
|
|
2825
|
+
case "end":
|
|
2826
|
+
return _context3.stop();
|
|
2827
|
+
}
|
|
2828
|
+
}, _callee3);
|
|
2829
|
+
}));
|
|
2830
|
+
return _isUserSessionAdmin.apply(this, arguments);
|
|
2831
|
+
}
|
|
2832
|
+
|
|
2709
2833
|
// 初始化Supabase连接和CMS系统
|
|
2710
2834
|
function initializeSystem() {
|
|
2711
2835
|
return _initializeSystem.apply(this, arguments);
|
|
@@ -2746,7 +2870,7 @@ function getModels(_x) {
|
|
|
2746
2870
|
// POST - 创建新模型
|
|
2747
2871
|
function _getModels() {
|
|
2748
2872
|
_getModels = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(c) {
|
|
2749
|
-
var cmsModelService, page, limit, name, models, total, offset, paginatedModels, response, _response, _t2;
|
|
2873
|
+
var cmsModelService, page, limit, name, sessionId, models, tablePrefix, total, offset, paginatedModels, response, _response, _t2;
|
|
2750
2874
|
return _regeneratorRuntime.wrap(function (_context2) {
|
|
2751
2875
|
while (1) switch (_context2.prev = _context2.next) {
|
|
2752
2876
|
case 0:
|
|
@@ -2757,11 +2881,19 @@ function _getModels() {
|
|
|
2757
2881
|
cmsModelService = getCmsModelService();
|
|
2758
2882
|
page = parseInt(c.req.query("page") || "1");
|
|
2759
2883
|
limit = parseInt(c.req.query("limit") || "10");
|
|
2760
|
-
name = c.req.query("name"); //
|
|
2884
|
+
name = c.req.query("name"); // 获取当前请求的 session_id
|
|
2885
|
+
sessionId = normalizeSessionId(c.req.header("X-Session-Id") || c.req.header("x-session-id")); // 获取所有模型
|
|
2761
2886
|
_context2.next = 2;
|
|
2762
2887
|
return cmsModelService.findAll();
|
|
2763
2888
|
case 2:
|
|
2764
2889
|
models = _context2.sent;
|
|
2890
|
+
// 根据 session_id 过滤模型(只返回属于当前 session 的表)
|
|
2891
|
+
if (sessionId) {
|
|
2892
|
+
tablePrefix = sessionId + "_";
|
|
2893
|
+
models = models.filter(function (model) {
|
|
2894
|
+
return model.table_name.startsWith(tablePrefix);
|
|
2895
|
+
});
|
|
2896
|
+
}
|
|
2765
2897
|
// 如果有名称过滤
|
|
2766
2898
|
if (name) {
|
|
2767
2899
|
models = models.filter(function (model) {
|
|
@@ -4221,130 +4353,6 @@ var AuthUtils = /*#__PURE__*/function () {
|
|
|
4221
4353
|
}]);
|
|
4222
4354
|
}();
|
|
4223
4355
|
|
|
4224
|
-
var ADMIN_REGISTRY_TABLE = "_cms_admin_registry";
|
|
4225
|
-
var ensured = false;
|
|
4226
|
-
function normalizeSessionId(sessionId) {
|
|
4227
|
-
// 统一将连字符转换为下划线,确保 UUID 格式一致性
|
|
4228
|
-
// 例如:1047aab4-eecb-4538-ad8d-b5847e762f30 和 1047aab4_eecb_4538_ad8d_b5847e762f30 被视为相同
|
|
4229
|
-
return (sessionId || "").trim().replace(/-/g, "_");
|
|
4230
|
-
}
|
|
4231
|
-
/**
|
|
4232
|
-
* 从前端传来的 auth tableName 中提取 session_id
|
|
4233
|
-
* 约定:auth tableName 形如 `${sessionId}_cms_users`;无前缀则为 `cms_users`
|
|
4234
|
-
*/
|
|
4235
|
-
function extractSessionIdFromAuthTableName(tableName) {
|
|
4236
|
-
var name = (tableName || "").trim();
|
|
4237
|
-
if (!name) return "";
|
|
4238
|
-
if (name === "cms_users") return "";
|
|
4239
|
-
if (name.endsWith("_cms_users")) return name.slice(0, -"_cms_users".length);
|
|
4240
|
-
// 兼容:如果传入的不是 cms_users,也允许把最后一个 "_cms_users" 前缀当作 session
|
|
4241
|
-
var idx = name.lastIndexOf("_cms_users");
|
|
4242
|
-
if (idx > 0) return name.slice(0, idx);
|
|
4243
|
-
return "";
|
|
4244
|
-
}
|
|
4245
|
-
function ensureAdminRegistryTable(_x) {
|
|
4246
|
-
return _ensureAdminRegistryTable.apply(this, arguments);
|
|
4247
|
-
}
|
|
4248
|
-
function _ensureAdminRegistryTable() {
|
|
4249
|
-
_ensureAdminRegistryTable = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(supabase) {
|
|
4250
|
-
var _yield$supabase$from$, error;
|
|
4251
|
-
return _regeneratorRuntime.wrap(function (_context) {
|
|
4252
|
-
while (1) switch (_context.prev = _context.next) {
|
|
4253
|
-
case 0:
|
|
4254
|
-
if (!ensured) {
|
|
4255
|
-
_context.next = 1;
|
|
4256
|
-
break;
|
|
4257
|
-
}
|
|
4258
|
-
return _context.abrupt("return", true);
|
|
4259
|
-
case 1:
|
|
4260
|
-
_context.prev = 1;
|
|
4261
|
-
_context.next = 2;
|
|
4262
|
-
return supabase.from(ADMIN_REGISTRY_TABLE).select("session_id").limit(1);
|
|
4263
|
-
case 2:
|
|
4264
|
-
_yield$supabase$from$ = _context.sent;
|
|
4265
|
-
error = _yield$supabase$from$.error;
|
|
4266
|
-
if (error) {
|
|
4267
|
-
_context.next = 3;
|
|
4268
|
-
break;
|
|
4269
|
-
}
|
|
4270
|
-
ensured = true;
|
|
4271
|
-
return _context.abrupt("return", true);
|
|
4272
|
-
case 3:
|
|
4273
|
-
_context.next = 5;
|
|
4274
|
-
break;
|
|
4275
|
-
case 4:
|
|
4276
|
-
_context.prev = 4;
|
|
4277
|
-
_context["catch"](1);
|
|
4278
|
-
case 5:
|
|
4279
|
-
return _context.abrupt("return", false);
|
|
4280
|
-
case 6:
|
|
4281
|
-
case "end":
|
|
4282
|
-
return _context.stop();
|
|
4283
|
-
}
|
|
4284
|
-
}, _callee, null, [[1, 4]]);
|
|
4285
|
-
}));
|
|
4286
|
-
return _ensureAdminRegistryTable.apply(this, arguments);
|
|
4287
|
-
}
|
|
4288
|
-
function getSessionAdminRow(_x2, _x3) {
|
|
4289
|
-
return _getSessionAdminRow.apply(this, arguments);
|
|
4290
|
-
}
|
|
4291
|
-
function _getSessionAdminRow() {
|
|
4292
|
-
_getSessionAdminRow = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(supabase, sessionId) {
|
|
4293
|
-
var sid, _yield$supabase$from$2, data, error;
|
|
4294
|
-
return _regeneratorRuntime.wrap(function (_context2) {
|
|
4295
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
4296
|
-
case 0:
|
|
4297
|
-
sid = normalizeSessionId(sessionId);
|
|
4298
|
-
_context2.next = 1;
|
|
4299
|
-
return supabase.from(ADMIN_REGISTRY_TABLE).select("session_id,user_id,email").eq("session_id", sid).maybeSingle();
|
|
4300
|
-
case 1:
|
|
4301
|
-
_yield$supabase$from$2 = _context2.sent;
|
|
4302
|
-
data = _yield$supabase$from$2.data;
|
|
4303
|
-
error = _yield$supabase$from$2.error;
|
|
4304
|
-
if (!(error || !data)) {
|
|
4305
|
-
_context2.next = 2;
|
|
4306
|
-
break;
|
|
4307
|
-
}
|
|
4308
|
-
return _context2.abrupt("return", null);
|
|
4309
|
-
case 2:
|
|
4310
|
-
return _context2.abrupt("return", data);
|
|
4311
|
-
case 3:
|
|
4312
|
-
case "end":
|
|
4313
|
-
return _context2.stop();
|
|
4314
|
-
}
|
|
4315
|
-
}, _callee2);
|
|
4316
|
-
}));
|
|
4317
|
-
return _getSessionAdminRow.apply(this, arguments);
|
|
4318
|
-
}
|
|
4319
|
-
function isUserSessionAdmin(_x4, _x5, _x6) {
|
|
4320
|
-
return _isUserSessionAdmin.apply(this, arguments);
|
|
4321
|
-
}
|
|
4322
|
-
function _isUserSessionAdmin() {
|
|
4323
|
-
_isUserSessionAdmin = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(supabase, sessionId, userId) {
|
|
4324
|
-
var row;
|
|
4325
|
-
return _regeneratorRuntime.wrap(function (_context3) {
|
|
4326
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
4327
|
-
case 0:
|
|
4328
|
-
_context3.next = 1;
|
|
4329
|
-
return getSessionAdminRow(supabase, sessionId);
|
|
4330
|
-
case 1:
|
|
4331
|
-
row = _context3.sent;
|
|
4332
|
-
if (row) {
|
|
4333
|
-
_context3.next = 2;
|
|
4334
|
-
break;
|
|
4335
|
-
}
|
|
4336
|
-
return _context3.abrupt("return", false);
|
|
4337
|
-
case 2:
|
|
4338
|
-
return _context3.abrupt("return", row.user_id === userId);
|
|
4339
|
-
case 3:
|
|
4340
|
-
case "end":
|
|
4341
|
-
return _context3.stop();
|
|
4342
|
-
}
|
|
4343
|
-
}, _callee3);
|
|
4344
|
-
}));
|
|
4345
|
-
return _isUserSessionAdmin.apply(this, arguments);
|
|
4346
|
-
}
|
|
4347
|
-
|
|
4348
4356
|
function getRoleFromSupabaseUser$2(user) {
|
|
4349
4357
|
var _user$app_metadata, _user$user_metadata;
|
|
4350
4358
|
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;
|