@wecode-team/cms-supabase-api 0.1.53 → 0.1.54

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.js CHANGED
@@ -7554,64 +7554,117 @@ function _supabaseCurrentUser() {
7554
7554
  return _supabaseCurrentUser.apply(this, arguments);
7555
7555
  }
7556
7556
 
7557
+ function isSkipAuthRequest(c) {
7558
+ return c.req.header("X-CMS-Skip-Auth") === "true";
7559
+ }
7560
+ function withAdmin() {
7561
+ return [(/*#__PURE__*/function () {
7562
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(c, next) {
7563
+ return _regeneratorRuntime.wrap(function (_context) {
7564
+ while (1) switch (_context.prev = _context.next) {
7565
+ case 0:
7566
+ if (!isSkipAuthRequest(c)) {
7567
+ _context.next = 2;
7568
+ break;
7569
+ }
7570
+ _context.next = 1;
7571
+ return next();
7572
+ case 1:
7573
+ return _context.abrupt("return");
7574
+ case 2:
7575
+ return _context.abrupt("return", requireJwtAuth(c, next));
7576
+ case 3:
7577
+ case "end":
7578
+ return _context.stop();
7579
+ }
7580
+ }, _callee);
7581
+ }));
7582
+ return function (_x, _x2) {
7583
+ return _ref.apply(this, arguments);
7584
+ };
7585
+ }()), (/*#__PURE__*/function () {
7586
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(c, next) {
7587
+ return _regeneratorRuntime.wrap(function (_context2) {
7588
+ while (1) switch (_context2.prev = _context2.next) {
7589
+ case 0:
7590
+ if (!isSkipAuthRequest(c)) {
7591
+ _context2.next = 2;
7592
+ break;
7593
+ }
7594
+ _context2.next = 1;
7595
+ return next();
7596
+ case 1:
7597
+ return _context2.abrupt("return");
7598
+ case 2:
7599
+ return _context2.abrupt("return", requireAdminRole(c, next));
7600
+ case 3:
7601
+ case "end":
7602
+ return _context2.stop();
7603
+ }
7604
+ }, _callee2);
7605
+ }));
7606
+ return function (_x3, _x4) {
7607
+ return _ref2.apply(this, arguments);
7608
+ };
7609
+ }())];
7610
+ }
7557
7611
  // 创建模型路由处理器
7558
7612
  function createModelRoute(app) {
7559
- // CMS 管理接口:要求登录 + admin 权限(兼容 Supabase Auth JWT / 旧 CMS JWT)
7560
- app.get("/models", requireJwtAuth, requireAdminRole, getModels);
7561
- app.post("/models", requireJwtAuth, requireAdminRole, createModel);
7562
- app.put("/models", requireJwtAuth, requireAdminRole, updateModel);
7563
- app["delete"]("/models", requireJwtAuth, requireAdminRole, deleteModel);
7613
+ app.get.apply(app, ["/models"].concat(_toConsumableArray(withAdmin()), [getModels]));
7614
+ app.post.apply(app, ["/models"].concat(_toConsumableArray(withAdmin()), [createModel]));
7615
+ app.put.apply(app, ["/models"].concat(_toConsumableArray(withAdmin()), [updateModel]));
7616
+ app["delete"].apply(app, ["/models"].concat(_toConsumableArray(withAdmin()), [deleteModel]));
7564
7617
  return app;
7565
7618
  }
7566
7619
  // 创建数据表路由处理器(固定表名)
7567
7620
  function createDataRoute(app, tableName) {
7568
- app.get("/data/".concat(tableName), requireJwtAuth, requireAdminRole, function (c) {
7621
+ app.get.apply(app, ["/data/".concat(tableName)].concat(_toConsumableArray(withAdmin()), [function (c) {
7569
7622
  return getTableData(c, tableName);
7570
- });
7571
- app.post("/data/".concat(tableName), requireJwtAuth, requireAdminRole, function (c) {
7623
+ }]));
7624
+ app.post.apply(app, ["/data/".concat(tableName)].concat(_toConsumableArray(withAdmin()), [function (c) {
7572
7625
  return createTableData(c, tableName);
7573
- });
7574
- app.put("/data/".concat(tableName), requireJwtAuth, requireAdminRole, function (c) {
7626
+ }]));
7627
+ app.put.apply(app, ["/data/".concat(tableName)].concat(_toConsumableArray(withAdmin()), [function (c) {
7575
7628
  return updateTableData(c, tableName);
7576
- });
7577
- app["delete"]("/data/".concat(tableName), requireJwtAuth, requireAdminRole, function (c) {
7629
+ }]));
7630
+ app["delete"].apply(app, ["/data/".concat(tableName)].concat(_toConsumableArray(withAdmin()), [function (c) {
7578
7631
  return deleteTableData(c, tableName);
7579
- });
7632
+ }]));
7580
7633
  return app;
7581
7634
  }
7582
7635
  // 动态创建数据表路由处理器(从URL参数获取表名)
7583
7636
  function createDynamicDataRoute(app) {
7584
7637
  // 获取关联表选项(放在 :tableName 路由之前,避免被匹配)
7585
- app.get("/relation/:tableName/options", requireJwtAuth, requireAdminRole, function (c) {
7586
- var tableName = c.req.param("tableName");
7638
+ app.get.apply(app, ["/relation/:tableName/options"].concat(_toConsumableArray(withAdmin()), [function (c) {
7639
+ var tableName = c.req.param("tableName") || "";
7587
7640
  return getRelationOptions(c, tableName);
7588
- });
7641
+ }]));
7589
7642
  // 获取带关联数据的表数据
7590
- app.get("/data/:tableName/with-relations", requireJwtAuth, requireAdminRole, function (c) {
7591
- var tableName = c.req.param("tableName");
7643
+ app.get.apply(app, ["/data/:tableName/with-relations"].concat(_toConsumableArray(withAdmin()), [function (c) {
7644
+ var tableName = c.req.param("tableName") || "";
7592
7645
  return getTableDataWithRelations(c, tableName);
7593
- });
7594
- app.get("/data/:tableName", requireJwtAuth, requireAdminRole, function (c) {
7595
- var tableName = c.req.param("tableName");
7646
+ }]));
7647
+ app.get.apply(app, ["/data/:tableName"].concat(_toConsumableArray(withAdmin()), [function (c) {
7648
+ var tableName = c.req.param("tableName") || "";
7596
7649
  return getTableData(c, tableName);
7597
- });
7598
- app.post("/data/:tableName", requireJwtAuth, requireAdminRole, function (c) {
7599
- var tableName = c.req.param("tableName");
7650
+ }]));
7651
+ app.post.apply(app, ["/data/:tableName"].concat(_toConsumableArray(withAdmin()), [function (c) {
7652
+ var tableName = c.req.param("tableName") || "";
7600
7653
  return createTableData(c, tableName);
7601
- });
7602
- app.put("/data/:tableName", requireJwtAuth, requireAdminRole, function (c) {
7603
- var tableName = c.req.param("tableName");
7654
+ }]));
7655
+ app.put.apply(app, ["/data/:tableName"].concat(_toConsumableArray(withAdmin()), [function (c) {
7656
+ var tableName = c.req.param("tableName") || "";
7604
7657
  return updateTableData(c, tableName);
7605
- });
7606
- app["delete"]("/data/:tableName", requireJwtAuth, requireAdminRole, function (c) {
7607
- var tableName = c.req.param("tableName");
7658
+ }]));
7659
+ app["delete"].apply(app, ["/data/:tableName"].concat(_toConsumableArray(withAdmin()), [function (c) {
7660
+ var tableName = c.req.param("tableName") || "";
7608
7661
  return deleteTableData(c, tableName);
7609
- });
7662
+ }]));
7610
7663
  // 删除表的所有外键约束(用于解决外键引用错误表的问题)
7611
- app["delete"]("/data/:tableName/foreign-keys", requireJwtAuth, requireAdminRole, function (c) {
7612
- var tableName = c.req.param("tableName");
7664
+ app["delete"].apply(app, ["/data/:tableName/foreign-keys"].concat(_toConsumableArray(withAdmin()), [function (c) {
7665
+ var tableName = c.req.param("tableName") || "";
7613
7666
  return dropForeignKeys(c, tableName);
7614
- });
7667
+ }]));
7615
7668
  return app;
7616
7669
  }
7617
7670
  // 动态创建认证路由处理器(从URL参数获取表名)
@@ -7694,14 +7747,14 @@ function createAuthRoute(app, tableName) {
7694
7747
  return app;
7695
7748
  }
7696
7749
  function createOssUploadRoute(app) {
7697
- app.post("/upload", requireJwtAuth, requireAdminRole, uploadToOss);
7750
+ app.post.apply(app, ["/upload"].concat(_toConsumableArray(withAdmin()), [uploadToOss]));
7698
7751
  return app;
7699
7752
  }
7700
7753
  function createConfigRoute(app) {
7701
- app.get("/configs", requireJwtAuth, requireAdminRole, getConfig);
7702
- app.put("/configs/:namespace", requireJwtAuth, requireAdminRole, function (c) {
7754
+ app.get.apply(app, ["/configs"].concat(_toConsumableArray(withAdmin()), [getConfig]));
7755
+ app.put.apply(app, ["/configs/:namespace"].concat(_toConsumableArray(withAdmin()), [function (c) {
7703
7756
  return updateConfig(c);
7704
- });
7757
+ }]));
7705
7758
  return app;
7706
7759
  }
7707
7760
  // 一键创建所有CMS路由