@wecode-team/cms-supabase-api 0.1.53 → 0.1.55
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/config/feishu-alert.d.ts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +97 -39
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +97 -39
- package/dist/index.js.map +1 -1
- package/dist/utils/route-helpers.d.ts +9 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -697,6 +697,7 @@ function getSupabaseSetupSQL() {
|
|
|
697
697
|
}
|
|
698
698
|
|
|
699
699
|
var feishuAlertConfig = {
|
|
700
|
+
environment: process.env.CMS_ALERT_ENV || process.env.NODE_ENV || "development",
|
|
700
701
|
crudErrorWebhookUrls: ["https://open.feishu.cn/open-apis/bot/v2/hook/784e9470-c1fd-4e38-97a2-b9a1856c00b1"]
|
|
701
702
|
};
|
|
702
703
|
|
|
@@ -4169,6 +4170,10 @@ function getWebhookUrls() {
|
|
|
4169
4170
|
return item.trim();
|
|
4170
4171
|
}).filter(Boolean);
|
|
4171
4172
|
}
|
|
4173
|
+
function getAlertEnvironmentLabel() {
|
|
4174
|
+
var environment = String(feishuAlertConfig.environment || "").trim();
|
|
4175
|
+
return environment === "production" ? "生产" : "测试";
|
|
4176
|
+
}
|
|
4172
4177
|
function safeJsonStringify(value) {
|
|
4173
4178
|
var seen = new WeakSet();
|
|
4174
4179
|
try {
|
|
@@ -4287,7 +4292,7 @@ function _notifyCmsCrudErrorToFeishu() {
|
|
|
4287
4292
|
content: {
|
|
4288
4293
|
post: {
|
|
4289
4294
|
zh_cn: {
|
|
4290
|
-
title: "[cms-supabase-api] ".concat(TARGET_LABELS[options.target]).concat(ACTION_LABELS[options.action], "\u5F02\u5E38"),
|
|
4295
|
+
title: "[".concat(getAlertEnvironmentLabel(), "][cms-supabase-api] ").concat(TARGET_LABELS[options.target]).concat(ACTION_LABELS[options.action], "\u5F02\u5E38"),
|
|
4291
4296
|
content: [[{
|
|
4292
4297
|
tag: "text",
|
|
4293
4298
|
text: buildAlertText(c, options)
|
|
@@ -7554,64 +7559,117 @@ function _supabaseCurrentUser() {
|
|
|
7554
7559
|
return _supabaseCurrentUser.apply(this, arguments);
|
|
7555
7560
|
}
|
|
7556
7561
|
|
|
7562
|
+
function isSkipAuthRequest(c) {
|
|
7563
|
+
return c.req.header("X-CMS-Skip-Auth") === "true";
|
|
7564
|
+
}
|
|
7565
|
+
function withAdmin() {
|
|
7566
|
+
return [(/*#__PURE__*/function () {
|
|
7567
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(c, next) {
|
|
7568
|
+
return _regeneratorRuntime.wrap(function (_context) {
|
|
7569
|
+
while (1) switch (_context.prev = _context.next) {
|
|
7570
|
+
case 0:
|
|
7571
|
+
if (!isSkipAuthRequest(c)) {
|
|
7572
|
+
_context.next = 2;
|
|
7573
|
+
break;
|
|
7574
|
+
}
|
|
7575
|
+
_context.next = 1;
|
|
7576
|
+
return next();
|
|
7577
|
+
case 1:
|
|
7578
|
+
return _context.abrupt("return");
|
|
7579
|
+
case 2:
|
|
7580
|
+
return _context.abrupt("return", requireJwtAuth(c, next));
|
|
7581
|
+
case 3:
|
|
7582
|
+
case "end":
|
|
7583
|
+
return _context.stop();
|
|
7584
|
+
}
|
|
7585
|
+
}, _callee);
|
|
7586
|
+
}));
|
|
7587
|
+
return function (_x, _x2) {
|
|
7588
|
+
return _ref.apply(this, arguments);
|
|
7589
|
+
};
|
|
7590
|
+
}()), (/*#__PURE__*/function () {
|
|
7591
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(c, next) {
|
|
7592
|
+
return _regeneratorRuntime.wrap(function (_context2) {
|
|
7593
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
7594
|
+
case 0:
|
|
7595
|
+
if (!isSkipAuthRequest(c)) {
|
|
7596
|
+
_context2.next = 2;
|
|
7597
|
+
break;
|
|
7598
|
+
}
|
|
7599
|
+
_context2.next = 1;
|
|
7600
|
+
return next();
|
|
7601
|
+
case 1:
|
|
7602
|
+
return _context2.abrupt("return");
|
|
7603
|
+
case 2:
|
|
7604
|
+
return _context2.abrupt("return", requireAdminRole(c, next));
|
|
7605
|
+
case 3:
|
|
7606
|
+
case "end":
|
|
7607
|
+
return _context2.stop();
|
|
7608
|
+
}
|
|
7609
|
+
}, _callee2);
|
|
7610
|
+
}));
|
|
7611
|
+
return function (_x3, _x4) {
|
|
7612
|
+
return _ref2.apply(this, arguments);
|
|
7613
|
+
};
|
|
7614
|
+
}())];
|
|
7615
|
+
}
|
|
7557
7616
|
// 创建模型路由处理器
|
|
7558
7617
|
function createModelRoute(app) {
|
|
7559
|
-
|
|
7560
|
-
app.
|
|
7561
|
-
app.
|
|
7562
|
-
app.
|
|
7563
|
-
app["delete"]("/models", requireJwtAuth, requireAdminRole, deleteModel);
|
|
7618
|
+
app.get.apply(app, ["/models"].concat(_toConsumableArray(withAdmin()), [getModels]));
|
|
7619
|
+
app.post.apply(app, ["/models"].concat(_toConsumableArray(withAdmin()), [createModel]));
|
|
7620
|
+
app.put.apply(app, ["/models"].concat(_toConsumableArray(withAdmin()), [updateModel]));
|
|
7621
|
+
app["delete"].apply(app, ["/models"].concat(_toConsumableArray(withAdmin()), [deleteModel]));
|
|
7564
7622
|
return app;
|
|
7565
7623
|
}
|
|
7566
7624
|
// 创建数据表路由处理器(固定表名)
|
|
7567
7625
|
function createDataRoute(app, tableName) {
|
|
7568
|
-
app.get("/data/".concat(tableName),
|
|
7626
|
+
app.get.apply(app, ["/data/".concat(tableName)].concat(_toConsumableArray(withAdmin()), [function (c) {
|
|
7569
7627
|
return getTableData(c, tableName);
|
|
7570
|
-
});
|
|
7571
|
-
app.post("/data/".concat(tableName),
|
|
7628
|
+
}]));
|
|
7629
|
+
app.post.apply(app, ["/data/".concat(tableName)].concat(_toConsumableArray(withAdmin()), [function (c) {
|
|
7572
7630
|
return createTableData(c, tableName);
|
|
7573
|
-
});
|
|
7574
|
-
app.put("/data/".concat(tableName),
|
|
7631
|
+
}]));
|
|
7632
|
+
app.put.apply(app, ["/data/".concat(tableName)].concat(_toConsumableArray(withAdmin()), [function (c) {
|
|
7575
7633
|
return updateTableData(c, tableName);
|
|
7576
|
-
});
|
|
7577
|
-
app["delete"]("/data/".concat(tableName),
|
|
7634
|
+
}]));
|
|
7635
|
+
app["delete"].apply(app, ["/data/".concat(tableName)].concat(_toConsumableArray(withAdmin()), [function (c) {
|
|
7578
7636
|
return deleteTableData(c, tableName);
|
|
7579
|
-
});
|
|
7637
|
+
}]));
|
|
7580
7638
|
return app;
|
|
7581
7639
|
}
|
|
7582
7640
|
// 动态创建数据表路由处理器(从URL参数获取表名)
|
|
7583
7641
|
function createDynamicDataRoute(app) {
|
|
7584
7642
|
// 获取关联表选项(放在 :tableName 路由之前,避免被匹配)
|
|
7585
|
-
app.get("/relation/:tableName/options",
|
|
7586
|
-
var tableName = c.req.param("tableName");
|
|
7643
|
+
app.get.apply(app, ["/relation/:tableName/options"].concat(_toConsumableArray(withAdmin()), [function (c) {
|
|
7644
|
+
var tableName = c.req.param("tableName") || "";
|
|
7587
7645
|
return getRelationOptions(c, tableName);
|
|
7588
|
-
});
|
|
7646
|
+
}]));
|
|
7589
7647
|
// 获取带关联数据的表数据
|
|
7590
|
-
app.get("/data/:tableName/with-relations",
|
|
7591
|
-
var tableName = c.req.param("tableName");
|
|
7648
|
+
app.get.apply(app, ["/data/:tableName/with-relations"].concat(_toConsumableArray(withAdmin()), [function (c) {
|
|
7649
|
+
var tableName = c.req.param("tableName") || "";
|
|
7592
7650
|
return getTableDataWithRelations(c, tableName);
|
|
7593
|
-
});
|
|
7594
|
-
app.get("/data/:tableName",
|
|
7595
|
-
var tableName = c.req.param("tableName");
|
|
7651
|
+
}]));
|
|
7652
|
+
app.get.apply(app, ["/data/:tableName"].concat(_toConsumableArray(withAdmin()), [function (c) {
|
|
7653
|
+
var tableName = c.req.param("tableName") || "";
|
|
7596
7654
|
return getTableData(c, tableName);
|
|
7597
|
-
});
|
|
7598
|
-
app.post("/data/:tableName",
|
|
7599
|
-
var tableName = c.req.param("tableName");
|
|
7655
|
+
}]));
|
|
7656
|
+
app.post.apply(app, ["/data/:tableName"].concat(_toConsumableArray(withAdmin()), [function (c) {
|
|
7657
|
+
var tableName = c.req.param("tableName") || "";
|
|
7600
7658
|
return createTableData(c, tableName);
|
|
7601
|
-
});
|
|
7602
|
-
app.put("/data/:tableName",
|
|
7603
|
-
var tableName = c.req.param("tableName");
|
|
7659
|
+
}]));
|
|
7660
|
+
app.put.apply(app, ["/data/:tableName"].concat(_toConsumableArray(withAdmin()), [function (c) {
|
|
7661
|
+
var tableName = c.req.param("tableName") || "";
|
|
7604
7662
|
return updateTableData(c, tableName);
|
|
7605
|
-
});
|
|
7606
|
-
app["delete"]("/data/:tableName",
|
|
7607
|
-
var tableName = c.req.param("tableName");
|
|
7663
|
+
}]));
|
|
7664
|
+
app["delete"].apply(app, ["/data/:tableName"].concat(_toConsumableArray(withAdmin()), [function (c) {
|
|
7665
|
+
var tableName = c.req.param("tableName") || "";
|
|
7608
7666
|
return deleteTableData(c, tableName);
|
|
7609
|
-
});
|
|
7667
|
+
}]));
|
|
7610
7668
|
// 删除表的所有外键约束(用于解决外键引用错误表的问题)
|
|
7611
|
-
app["delete"]("/data/:tableName/foreign-keys",
|
|
7612
|
-
var tableName = c.req.param("tableName");
|
|
7669
|
+
app["delete"].apply(app, ["/data/:tableName/foreign-keys"].concat(_toConsumableArray(withAdmin()), [function (c) {
|
|
7670
|
+
var tableName = c.req.param("tableName") || "";
|
|
7613
7671
|
return dropForeignKeys(c, tableName);
|
|
7614
|
-
});
|
|
7672
|
+
}]));
|
|
7615
7673
|
return app;
|
|
7616
7674
|
}
|
|
7617
7675
|
// 动态创建认证路由处理器(从URL参数获取表名)
|
|
@@ -7694,14 +7752,14 @@ function createAuthRoute(app, tableName) {
|
|
|
7694
7752
|
return app;
|
|
7695
7753
|
}
|
|
7696
7754
|
function createOssUploadRoute(app) {
|
|
7697
|
-
app.post("/upload",
|
|
7755
|
+
app.post.apply(app, ["/upload"].concat(_toConsumableArray(withAdmin()), [uploadToOss]));
|
|
7698
7756
|
return app;
|
|
7699
7757
|
}
|
|
7700
7758
|
function createConfigRoute(app) {
|
|
7701
|
-
app.get("/configs",
|
|
7702
|
-
app.put("/configs/:namespace",
|
|
7759
|
+
app.get.apply(app, ["/configs"].concat(_toConsumableArray(withAdmin()), [getConfig]));
|
|
7760
|
+
app.put.apply(app, ["/configs/:namespace"].concat(_toConsumableArray(withAdmin()), [function (c) {
|
|
7703
7761
|
return updateConfig(c);
|
|
7704
|
-
});
|
|
7762
|
+
}]));
|
|
7705
7763
|
return app;
|
|
7706
7764
|
}
|
|
7707
7765
|
// 一键创建所有CMS路由
|