@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.
@@ -1,4 +1,5 @@
1
1
  export type FeishuAlertConfig = {
2
+ environment?: string;
2
3
  crudErrorWebhookUrls: string[];
3
4
  };
4
5
  export declare const feishuAlertConfig: FeishuAlertConfig;
package/dist/index.d.ts CHANGED
@@ -14,5 +14,6 @@ export { getConfig, updateConfig, } from "./handlers/configs";
14
14
  export type { SchemaField, JsonSchema, CmsModelAttributes, CmsModelCreationAttributes, ApiResponse, PaginatedResponse, SupabaseConfig, DatabaseConfig, TableDataOptions, SupabaseFilter, FieldTypeMapping, RelationType, RelationConfig, RelationOption, GetRelationOptionsParams, } from "./types";
15
15
  export type { User, UserInfo, LoginRequest, ForgotPasswordRequest, ResetPasswordRequest, LoginResponse, } from "./handlers/auth";
16
16
  export { createCmsRoutes, createModelRoute, createDynamicDataRoute, createDynamicAuthRoute, createDataRoute, createAuthRoute, createOssUploadRoute, createConfigRoute, } from "./utils/route-helpers";
17
+ export type { CmsRouteOptions, } from "./utils/route-helpers";
17
18
  export { notifyCmsCrudErrorToFeishu, reportCmsCrudErrorToFeishu, } from "./utils/feishu-alert";
18
19
  export type { OssUploadProvider, OssUploadReturnMode, OssUploadConfig, NormalizedOssUploadConfig, OssUploadInput, OssUploadResult, UploadRouteResponse, } from "./types/upload";
package/dist/index.esm.js CHANGED
@@ -675,6 +675,7 @@ function getSupabaseSetupSQL() {
675
675
  }
676
676
 
677
677
  var feishuAlertConfig = {
678
+ environment: process.env.CMS_ALERT_ENV || process.env.NODE_ENV || "development",
678
679
  crudErrorWebhookUrls: ["https://open.feishu.cn/open-apis/bot/v2/hook/784e9470-c1fd-4e38-97a2-b9a1856c00b1"]
679
680
  };
680
681
 
@@ -4147,6 +4148,10 @@ function getWebhookUrls() {
4147
4148
  return item.trim();
4148
4149
  }).filter(Boolean);
4149
4150
  }
4151
+ function getAlertEnvironmentLabel() {
4152
+ var environment = String(feishuAlertConfig.environment || "").trim();
4153
+ return environment === "production" ? "生产" : "测试";
4154
+ }
4150
4155
  function safeJsonStringify(value) {
4151
4156
  var seen = new WeakSet();
4152
4157
  try {
@@ -4265,7 +4270,7 @@ function _notifyCmsCrudErrorToFeishu() {
4265
4270
  content: {
4266
4271
  post: {
4267
4272
  zh_cn: {
4268
- title: "[cms-supabase-api] ".concat(TARGET_LABELS[options.target]).concat(ACTION_LABELS[options.action], "\u5F02\u5E38"),
4273
+ title: "[".concat(getAlertEnvironmentLabel(), "][cms-supabase-api] ").concat(TARGET_LABELS[options.target]).concat(ACTION_LABELS[options.action], "\u5F02\u5E38"),
4269
4274
  content: [[{
4270
4275
  tag: "text",
4271
4276
  text: buildAlertText(c, options)
@@ -7532,64 +7537,117 @@ function _supabaseCurrentUser() {
7532
7537
  return _supabaseCurrentUser.apply(this, arguments);
7533
7538
  }
7534
7539
 
7540
+ function isSkipAuthRequest(c) {
7541
+ return c.req.header("X-CMS-Skip-Auth") === "true";
7542
+ }
7543
+ function withAdmin() {
7544
+ return [(/*#__PURE__*/function () {
7545
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(c, next) {
7546
+ return _regeneratorRuntime.wrap(function (_context) {
7547
+ while (1) switch (_context.prev = _context.next) {
7548
+ case 0:
7549
+ if (!isSkipAuthRequest(c)) {
7550
+ _context.next = 2;
7551
+ break;
7552
+ }
7553
+ _context.next = 1;
7554
+ return next();
7555
+ case 1:
7556
+ return _context.abrupt("return");
7557
+ case 2:
7558
+ return _context.abrupt("return", requireJwtAuth(c, next));
7559
+ case 3:
7560
+ case "end":
7561
+ return _context.stop();
7562
+ }
7563
+ }, _callee);
7564
+ }));
7565
+ return function (_x, _x2) {
7566
+ return _ref.apply(this, arguments);
7567
+ };
7568
+ }()), (/*#__PURE__*/function () {
7569
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(c, next) {
7570
+ return _regeneratorRuntime.wrap(function (_context2) {
7571
+ while (1) switch (_context2.prev = _context2.next) {
7572
+ case 0:
7573
+ if (!isSkipAuthRequest(c)) {
7574
+ _context2.next = 2;
7575
+ break;
7576
+ }
7577
+ _context2.next = 1;
7578
+ return next();
7579
+ case 1:
7580
+ return _context2.abrupt("return");
7581
+ case 2:
7582
+ return _context2.abrupt("return", requireAdminRole(c, next));
7583
+ case 3:
7584
+ case "end":
7585
+ return _context2.stop();
7586
+ }
7587
+ }, _callee2);
7588
+ }));
7589
+ return function (_x3, _x4) {
7590
+ return _ref2.apply(this, arguments);
7591
+ };
7592
+ }())];
7593
+ }
7535
7594
  // 创建模型路由处理器
7536
7595
  function createModelRoute(app) {
7537
- // CMS 管理接口:要求登录 + admin 权限(兼容 Supabase Auth JWT / 旧 CMS JWT)
7538
- app.get("/models", requireJwtAuth, requireAdminRole, getModels);
7539
- app.post("/models", requireJwtAuth, requireAdminRole, createModel);
7540
- app.put("/models", requireJwtAuth, requireAdminRole, updateModel);
7541
- app["delete"]("/models", requireJwtAuth, requireAdminRole, deleteModel);
7596
+ app.get.apply(app, ["/models"].concat(_toConsumableArray(withAdmin()), [getModels]));
7597
+ app.post.apply(app, ["/models"].concat(_toConsumableArray(withAdmin()), [createModel]));
7598
+ app.put.apply(app, ["/models"].concat(_toConsumableArray(withAdmin()), [updateModel]));
7599
+ app["delete"].apply(app, ["/models"].concat(_toConsumableArray(withAdmin()), [deleteModel]));
7542
7600
  return app;
7543
7601
  }
7544
7602
  // 创建数据表路由处理器(固定表名)
7545
7603
  function createDataRoute(app, tableName) {
7546
- app.get("/data/".concat(tableName), requireJwtAuth, requireAdminRole, function (c) {
7604
+ app.get.apply(app, ["/data/".concat(tableName)].concat(_toConsumableArray(withAdmin()), [function (c) {
7547
7605
  return getTableData(c, tableName);
7548
- });
7549
- app.post("/data/".concat(tableName), requireJwtAuth, requireAdminRole, function (c) {
7606
+ }]));
7607
+ app.post.apply(app, ["/data/".concat(tableName)].concat(_toConsumableArray(withAdmin()), [function (c) {
7550
7608
  return createTableData(c, tableName);
7551
- });
7552
- app.put("/data/".concat(tableName), requireJwtAuth, requireAdminRole, function (c) {
7609
+ }]));
7610
+ app.put.apply(app, ["/data/".concat(tableName)].concat(_toConsumableArray(withAdmin()), [function (c) {
7553
7611
  return updateTableData(c, tableName);
7554
- });
7555
- app["delete"]("/data/".concat(tableName), requireJwtAuth, requireAdminRole, function (c) {
7612
+ }]));
7613
+ app["delete"].apply(app, ["/data/".concat(tableName)].concat(_toConsumableArray(withAdmin()), [function (c) {
7556
7614
  return deleteTableData(c, tableName);
7557
- });
7615
+ }]));
7558
7616
  return app;
7559
7617
  }
7560
7618
  // 动态创建数据表路由处理器(从URL参数获取表名)
7561
7619
  function createDynamicDataRoute(app) {
7562
7620
  // 获取关联表选项(放在 :tableName 路由之前,避免被匹配)
7563
- app.get("/relation/:tableName/options", requireJwtAuth, requireAdminRole, function (c) {
7564
- var tableName = c.req.param("tableName");
7621
+ app.get.apply(app, ["/relation/:tableName/options"].concat(_toConsumableArray(withAdmin()), [function (c) {
7622
+ var tableName = c.req.param("tableName") || "";
7565
7623
  return getRelationOptions(c, tableName);
7566
- });
7624
+ }]));
7567
7625
  // 获取带关联数据的表数据
7568
- app.get("/data/:tableName/with-relations", requireJwtAuth, requireAdminRole, function (c) {
7569
- var tableName = c.req.param("tableName");
7626
+ app.get.apply(app, ["/data/:tableName/with-relations"].concat(_toConsumableArray(withAdmin()), [function (c) {
7627
+ var tableName = c.req.param("tableName") || "";
7570
7628
  return getTableDataWithRelations(c, tableName);
7571
- });
7572
- app.get("/data/:tableName", requireJwtAuth, requireAdminRole, function (c) {
7573
- var tableName = c.req.param("tableName");
7629
+ }]));
7630
+ app.get.apply(app, ["/data/:tableName"].concat(_toConsumableArray(withAdmin()), [function (c) {
7631
+ var tableName = c.req.param("tableName") || "";
7574
7632
  return getTableData(c, tableName);
7575
- });
7576
- app.post("/data/:tableName", requireJwtAuth, requireAdminRole, function (c) {
7577
- var tableName = c.req.param("tableName");
7633
+ }]));
7634
+ app.post.apply(app, ["/data/:tableName"].concat(_toConsumableArray(withAdmin()), [function (c) {
7635
+ var tableName = c.req.param("tableName") || "";
7578
7636
  return createTableData(c, tableName);
7579
- });
7580
- app.put("/data/:tableName", requireJwtAuth, requireAdminRole, function (c) {
7581
- var tableName = c.req.param("tableName");
7637
+ }]));
7638
+ app.put.apply(app, ["/data/:tableName"].concat(_toConsumableArray(withAdmin()), [function (c) {
7639
+ var tableName = c.req.param("tableName") || "";
7582
7640
  return updateTableData(c, tableName);
7583
- });
7584
- app["delete"]("/data/:tableName", requireJwtAuth, requireAdminRole, function (c) {
7585
- var tableName = c.req.param("tableName");
7641
+ }]));
7642
+ app["delete"].apply(app, ["/data/:tableName"].concat(_toConsumableArray(withAdmin()), [function (c) {
7643
+ var tableName = c.req.param("tableName") || "";
7586
7644
  return deleteTableData(c, tableName);
7587
- });
7645
+ }]));
7588
7646
  // 删除表的所有外键约束(用于解决外键引用错误表的问题)
7589
- app["delete"]("/data/:tableName/foreign-keys", requireJwtAuth, requireAdminRole, function (c) {
7590
- var tableName = c.req.param("tableName");
7647
+ app["delete"].apply(app, ["/data/:tableName/foreign-keys"].concat(_toConsumableArray(withAdmin()), [function (c) {
7648
+ var tableName = c.req.param("tableName") || "";
7591
7649
  return dropForeignKeys(c, tableName);
7592
- });
7650
+ }]));
7593
7651
  return app;
7594
7652
  }
7595
7653
  // 动态创建认证路由处理器(从URL参数获取表名)
@@ -7672,14 +7730,14 @@ function createAuthRoute(app, tableName) {
7672
7730
  return app;
7673
7731
  }
7674
7732
  function createOssUploadRoute(app) {
7675
- app.post("/upload", requireJwtAuth, requireAdminRole, uploadToOss);
7733
+ app.post.apply(app, ["/upload"].concat(_toConsumableArray(withAdmin()), [uploadToOss]));
7676
7734
  return app;
7677
7735
  }
7678
7736
  function createConfigRoute(app) {
7679
- app.get("/configs", requireJwtAuth, requireAdminRole, getConfig);
7680
- app.put("/configs/:namespace", requireJwtAuth, requireAdminRole, function (c) {
7737
+ app.get.apply(app, ["/configs"].concat(_toConsumableArray(withAdmin()), [getConfig]));
7738
+ app.put.apply(app, ["/configs/:namespace"].concat(_toConsumableArray(withAdmin()), [function (c) {
7681
7739
  return updateConfig(c);
7682
- });
7740
+ }]));
7683
7741
  return app;
7684
7742
  }
7685
7743
  // 一键创建所有CMS路由