@wecode-team/cms-supabase-api 0.1.51 → 0.1.52

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 CHANGED
@@ -6923,7 +6923,7 @@ function validateConfigSessionId(sessionId) {
6923
6923
  return null;
6924
6924
  }
6925
6925
  function getConfigsTableName(sessionId) {
6926
- return "".concat(sessionId, "__config__");
6926
+ return "".concat(sessionId.replace(/-/g, '_'), "__config__");
6927
6927
  }
6928
6928
  function normalizeValues(values) {
6929
6929
  if (!values || _typeof$1(values) !== "object" || Array.isArray(values)) {
@@ -6959,50 +6959,50 @@ function toConfigResponse(row, fallbackNamespace) {
6959
6959
  updated_at: row === null || row === void 0 ? void 0 : row.updated_at
6960
6960
  };
6961
6961
  }
6962
- function getConfig(_x2) {
6962
+ function getConfig(_x) {
6963
6963
  return _getConfig.apply(this, arguments);
6964
6964
  }
6965
6965
  function _getConfig() {
6966
- _getConfig = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(c) {
6966
+ _getConfig = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(c) {
6967
6967
  var namespace, namespaceError, _response, sessionId, sessionError, _response2, tableName, supabase, _yield$supabase$from$, data, error, response, _response3, _t;
6968
- return _regeneratorRuntime.wrap(function (_context2) {
6969
- while (1) switch (_context2.prev = _context2.next) {
6968
+ return _regeneratorRuntime.wrap(function (_context) {
6969
+ while (1) switch (_context.prev = _context.next) {
6970
6970
  case 0:
6971
- _context2.prev = 0;
6971
+ _context.prev = 0;
6972
6972
  namespace = (c.req.query("namespace") || "").trim();
6973
6973
  namespaceError = validateNamespace(namespace);
6974
6974
  if (!namespaceError) {
6975
- _context2.next = 1;
6975
+ _context.next = 1;
6976
6976
  break;
6977
6977
  }
6978
6978
  _response = {
6979
6979
  success: false,
6980
6980
  message: namespaceError
6981
6981
  };
6982
- return _context2.abrupt("return", c.json(_response, 200));
6982
+ return _context.abrupt("return", c.json(_response, 200));
6983
6983
  case 1:
6984
6984
  sessionId = getConfigSessionId(c);
6985
6985
  sessionError = validateConfigSessionId(sessionId);
6986
6986
  if (!sessionError) {
6987
- _context2.next = 2;
6987
+ _context.next = 2;
6988
6988
  break;
6989
6989
  }
6990
6990
  _response2 = {
6991
6991
  success: false,
6992
6992
  message: sessionError
6993
6993
  };
6994
- return _context2.abrupt("return", c.json(_response2, 200));
6994
+ return _context.abrupt("return", c.json(_response2, 200));
6995
6995
  case 2:
6996
6996
  tableName = getConfigsTableName(sessionId);
6997
6997
  supabase = getSupabase();
6998
- _context2.next = 3;
6998
+ _context.next = 3;
6999
6999
  return supabase.from(tableName).select("*").eq("namespace", namespace).maybeSingle();
7000
7000
  case 3:
7001
- _yield$supabase$from$ = _context2.sent;
7001
+ _yield$supabase$from$ = _context.sent;
7002
7002
  data = _yield$supabase$from$.data;
7003
7003
  error = _yield$supabase$from$.error;
7004
7004
  if (!error) {
7005
- _context2.next = 4;
7005
+ _context.next = 4;
7006
7006
  break;
7007
7007
  }
7008
7008
  throw error;
@@ -7011,80 +7011,80 @@ function _getConfig() {
7011
7011
  success: true,
7012
7012
  data: toConfigResponse(data, namespace)
7013
7013
  };
7014
- return _context2.abrupt("return", c.json(response, 200));
7014
+ return _context.abrupt("return", c.json(response, 200));
7015
7015
  case 5:
7016
- _context2.prev = 5;
7017
- _t = _context2["catch"](0);
7016
+ _context.prev = 5;
7017
+ _t = _context["catch"](0);
7018
7018
  console.error("获取配置失败:", _t);
7019
7019
  _response3 = {
7020
7020
  success: false,
7021
7021
  message: "获取配置失败",
7022
7022
  error: _t.message
7023
7023
  };
7024
- return _context2.abrupt("return", c.json(_response3, 500));
7024
+ return _context.abrupt("return", c.json(_response3, 500));
7025
7025
  case 6:
7026
7026
  case "end":
7027
- return _context2.stop();
7027
+ return _context.stop();
7028
7028
  }
7029
- }, _callee2, null, [[0, 5]]);
7029
+ }, _callee, null, [[0, 5]]);
7030
7030
  }));
7031
7031
  return _getConfig.apply(this, arguments);
7032
7032
  }
7033
- function updateConfig(_x3) {
7033
+ function updateConfig(_x2) {
7034
7034
  return _updateConfig.apply(this, arguments);
7035
7035
  }
7036
7036
  function _updateConfig() {
7037
- _updateConfig = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(c) {
7037
+ _updateConfig = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(c) {
7038
7038
  var namespace, namespaceError, _response4, body, values, sessionId, sessionError, _response5, tableName, supabase, _yield$supabase$from$2, existing, existingError, nextValues, _yield$supabase$from$3, data, error, response, _response6, _t2;
7039
- return _regeneratorRuntime.wrap(function (_context3) {
7040
- while (1) switch (_context3.prev = _context3.next) {
7039
+ return _regeneratorRuntime.wrap(function (_context2) {
7040
+ while (1) switch (_context2.prev = _context2.next) {
7041
7041
  case 0:
7042
- _context3.prev = 0;
7042
+ _context2.prev = 0;
7043
7043
  namespace = (c.req.param("namespace") || "").trim();
7044
7044
  namespaceError = validateNamespace(namespace);
7045
7045
  if (!namespaceError) {
7046
- _context3.next = 1;
7046
+ _context2.next = 1;
7047
7047
  break;
7048
7048
  }
7049
7049
  _response4 = {
7050
7050
  success: false,
7051
7051
  message: namespaceError
7052
7052
  };
7053
- return _context3.abrupt("return", c.json(_response4, 200));
7053
+ return _context2.abrupt("return", c.json(_response4, 200));
7054
7054
  case 1:
7055
- _context3.next = 2;
7055
+ _context2.next = 2;
7056
7056
  return c.req.json();
7057
7057
  case 2:
7058
- body = _context3.sent;
7058
+ body = _context2.sent;
7059
7059
  values = normalizeValues(body === null || body === void 0 ? void 0 : body.values);
7060
7060
  sessionId = getConfigSessionId(c);
7061
7061
  sessionError = validateConfigSessionId(sessionId);
7062
7062
  if (!sessionError) {
7063
- _context3.next = 3;
7063
+ _context2.next = 3;
7064
7064
  break;
7065
7065
  }
7066
7066
  _response5 = {
7067
7067
  success: false,
7068
7068
  message: sessionError
7069
7069
  };
7070
- return _context3.abrupt("return", c.json(_response5, 200));
7070
+ return _context2.abrupt("return", c.json(_response5, 200));
7071
7071
  case 3:
7072
7072
  tableName = getConfigsTableName(sessionId);
7073
7073
  supabase = getSupabase();
7074
- _context3.next = 4;
7074
+ _context2.next = 4;
7075
7075
  return supabase.from(tableName).select("values").eq("namespace", namespace).maybeSingle();
7076
7076
  case 4:
7077
- _yield$supabase$from$2 = _context3.sent;
7077
+ _yield$supabase$from$2 = _context2.sent;
7078
7078
  existing = _yield$supabase$from$2.data;
7079
7079
  existingError = _yield$supabase$from$2.error;
7080
7080
  if (!existingError) {
7081
- _context3.next = 5;
7081
+ _context2.next = 5;
7082
7082
  break;
7083
7083
  }
7084
7084
  throw existingError;
7085
7085
  case 5:
7086
7086
  nextValues = _objectSpread(_objectSpread({}, normalizeValues(existing === null || existing === void 0 ? void 0 : existing.values)), values);
7087
- _context3.next = 6;
7087
+ _context2.next = 6;
7088
7088
  return supabase.from(tableName).upsert({
7089
7089
  namespace: namespace,
7090
7090
  values: nextValues,
@@ -7093,11 +7093,11 @@ function _updateConfig() {
7093
7093
  onConflict: "namespace"
7094
7094
  }).select("*").single();
7095
7095
  case 6:
7096
- _yield$supabase$from$3 = _context3.sent;
7096
+ _yield$supabase$from$3 = _context2.sent;
7097
7097
  data = _yield$supabase$from$3.data;
7098
7098
  error = _yield$supabase$from$3.error;
7099
7099
  if (!error) {
7100
- _context3.next = 7;
7100
+ _context2.next = 7;
7101
7101
  break;
7102
7102
  }
7103
7103
  throw error;
@@ -7107,22 +7107,22 @@ function _updateConfig() {
7107
7107
  message: "配置保存成功",
7108
7108
  data: toConfigResponse(data, namespace)
7109
7109
  };
7110
- return _context3.abrupt("return", c.json(response, 200));
7110
+ return _context2.abrupt("return", c.json(response, 200));
7111
7111
  case 8:
7112
- _context3.prev = 8;
7113
- _t2 = _context3["catch"](0);
7112
+ _context2.prev = 8;
7113
+ _t2 = _context2["catch"](0);
7114
7114
  console.error("保存配置失败:", _t2);
7115
7115
  _response6 = {
7116
7116
  success: false,
7117
7117
  message: "保存配置失败",
7118
7118
  error: _t2.message
7119
7119
  };
7120
- return _context3.abrupt("return", c.json(_response6, 500));
7120
+ return _context2.abrupt("return", c.json(_response6, 500));
7121
7121
  case 9:
7122
7122
  case "end":
7123
- return _context3.stop();
7123
+ return _context2.stop();
7124
7124
  }
7125
- }, _callee3, null, [[0, 8]]);
7125
+ }, _callee2, null, [[0, 8]]);
7126
7126
  }));
7127
7127
  return _updateConfig.apply(this, arguments);
7128
7128
  }
@@ -7639,8 +7639,8 @@ function createOssUploadRoute(app) {
7639
7639
  return app;
7640
7640
  }
7641
7641
  function createConfigRoute(app) {
7642
- app.get("/configs", requireJwtAuth, requireAdminRole, getConfig);
7643
- app.put("/configs/:namespace", requireJwtAuth, requireAdminRole, function (c) {
7642
+ app.get("/configs", requireAdminRole, getConfig);
7643
+ app.put("/configs/:namespace", requireAdminRole, function (c) {
7644
7644
  return updateConfig(c);
7645
7645
  });
7646
7646
  return app;