@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.js CHANGED
@@ -6945,7 +6945,7 @@ function validateConfigSessionId(sessionId) {
6945
6945
  return null;
6946
6946
  }
6947
6947
  function getConfigsTableName(sessionId) {
6948
- return "".concat(sessionId, "__config__");
6948
+ return "".concat(sessionId.replace(/-/g, '_'), "__config__");
6949
6949
  }
6950
6950
  function normalizeValues(values) {
6951
6951
  if (!values || _typeof$1(values) !== "object" || Array.isArray(values)) {
@@ -6981,50 +6981,50 @@ function toConfigResponse(row, fallbackNamespace) {
6981
6981
  updated_at: row === null || row === void 0 ? void 0 : row.updated_at
6982
6982
  };
6983
6983
  }
6984
- function getConfig(_x2) {
6984
+ function getConfig(_x) {
6985
6985
  return _getConfig.apply(this, arguments);
6986
6986
  }
6987
6987
  function _getConfig() {
6988
- _getConfig = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(c) {
6988
+ _getConfig = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(c) {
6989
6989
  var namespace, namespaceError, _response, sessionId, sessionError, _response2, tableName, supabase, _yield$supabase$from$, data, error, response, _response3, _t;
6990
- return _regeneratorRuntime.wrap(function (_context2) {
6991
- while (1) switch (_context2.prev = _context2.next) {
6990
+ return _regeneratorRuntime.wrap(function (_context) {
6991
+ while (1) switch (_context.prev = _context.next) {
6992
6992
  case 0:
6993
- _context2.prev = 0;
6993
+ _context.prev = 0;
6994
6994
  namespace = (c.req.query("namespace") || "").trim();
6995
6995
  namespaceError = validateNamespace(namespace);
6996
6996
  if (!namespaceError) {
6997
- _context2.next = 1;
6997
+ _context.next = 1;
6998
6998
  break;
6999
6999
  }
7000
7000
  _response = {
7001
7001
  success: false,
7002
7002
  message: namespaceError
7003
7003
  };
7004
- return _context2.abrupt("return", c.json(_response, 200));
7004
+ return _context.abrupt("return", c.json(_response, 200));
7005
7005
  case 1:
7006
7006
  sessionId = getConfigSessionId(c);
7007
7007
  sessionError = validateConfigSessionId(sessionId);
7008
7008
  if (!sessionError) {
7009
- _context2.next = 2;
7009
+ _context.next = 2;
7010
7010
  break;
7011
7011
  }
7012
7012
  _response2 = {
7013
7013
  success: false,
7014
7014
  message: sessionError
7015
7015
  };
7016
- return _context2.abrupt("return", c.json(_response2, 200));
7016
+ return _context.abrupt("return", c.json(_response2, 200));
7017
7017
  case 2:
7018
7018
  tableName = getConfigsTableName(sessionId);
7019
7019
  supabase = getSupabase();
7020
- _context2.next = 3;
7020
+ _context.next = 3;
7021
7021
  return supabase.from(tableName).select("*").eq("namespace", namespace).maybeSingle();
7022
7022
  case 3:
7023
- _yield$supabase$from$ = _context2.sent;
7023
+ _yield$supabase$from$ = _context.sent;
7024
7024
  data = _yield$supabase$from$.data;
7025
7025
  error = _yield$supabase$from$.error;
7026
7026
  if (!error) {
7027
- _context2.next = 4;
7027
+ _context.next = 4;
7028
7028
  break;
7029
7029
  }
7030
7030
  throw error;
@@ -7033,80 +7033,80 @@ function _getConfig() {
7033
7033
  success: true,
7034
7034
  data: toConfigResponse(data, namespace)
7035
7035
  };
7036
- return _context2.abrupt("return", c.json(response, 200));
7036
+ return _context.abrupt("return", c.json(response, 200));
7037
7037
  case 5:
7038
- _context2.prev = 5;
7039
- _t = _context2["catch"](0);
7038
+ _context.prev = 5;
7039
+ _t = _context["catch"](0);
7040
7040
  console.error("获取配置失败:", _t);
7041
7041
  _response3 = {
7042
7042
  success: false,
7043
7043
  message: "获取配置失败",
7044
7044
  error: _t.message
7045
7045
  };
7046
- return _context2.abrupt("return", c.json(_response3, 500));
7046
+ return _context.abrupt("return", c.json(_response3, 500));
7047
7047
  case 6:
7048
7048
  case "end":
7049
- return _context2.stop();
7049
+ return _context.stop();
7050
7050
  }
7051
- }, _callee2, null, [[0, 5]]);
7051
+ }, _callee, null, [[0, 5]]);
7052
7052
  }));
7053
7053
  return _getConfig.apply(this, arguments);
7054
7054
  }
7055
- function updateConfig(_x3) {
7055
+ function updateConfig(_x2) {
7056
7056
  return _updateConfig.apply(this, arguments);
7057
7057
  }
7058
7058
  function _updateConfig() {
7059
- _updateConfig = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(c) {
7059
+ _updateConfig = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(c) {
7060
7060
  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;
7061
- return _regeneratorRuntime.wrap(function (_context3) {
7062
- while (1) switch (_context3.prev = _context3.next) {
7061
+ return _regeneratorRuntime.wrap(function (_context2) {
7062
+ while (1) switch (_context2.prev = _context2.next) {
7063
7063
  case 0:
7064
- _context3.prev = 0;
7064
+ _context2.prev = 0;
7065
7065
  namespace = (c.req.param("namespace") || "").trim();
7066
7066
  namespaceError = validateNamespace(namespace);
7067
7067
  if (!namespaceError) {
7068
- _context3.next = 1;
7068
+ _context2.next = 1;
7069
7069
  break;
7070
7070
  }
7071
7071
  _response4 = {
7072
7072
  success: false,
7073
7073
  message: namespaceError
7074
7074
  };
7075
- return _context3.abrupt("return", c.json(_response4, 200));
7075
+ return _context2.abrupt("return", c.json(_response4, 200));
7076
7076
  case 1:
7077
- _context3.next = 2;
7077
+ _context2.next = 2;
7078
7078
  return c.req.json();
7079
7079
  case 2:
7080
- body = _context3.sent;
7080
+ body = _context2.sent;
7081
7081
  values = normalizeValues(body === null || body === void 0 ? void 0 : body.values);
7082
7082
  sessionId = getConfigSessionId(c);
7083
7083
  sessionError = validateConfigSessionId(sessionId);
7084
7084
  if (!sessionError) {
7085
- _context3.next = 3;
7085
+ _context2.next = 3;
7086
7086
  break;
7087
7087
  }
7088
7088
  _response5 = {
7089
7089
  success: false,
7090
7090
  message: sessionError
7091
7091
  };
7092
- return _context3.abrupt("return", c.json(_response5, 200));
7092
+ return _context2.abrupt("return", c.json(_response5, 200));
7093
7093
  case 3:
7094
7094
  tableName = getConfigsTableName(sessionId);
7095
7095
  supabase = getSupabase();
7096
- _context3.next = 4;
7096
+ _context2.next = 4;
7097
7097
  return supabase.from(tableName).select("values").eq("namespace", namespace).maybeSingle();
7098
7098
  case 4:
7099
- _yield$supabase$from$2 = _context3.sent;
7099
+ _yield$supabase$from$2 = _context2.sent;
7100
7100
  existing = _yield$supabase$from$2.data;
7101
7101
  existingError = _yield$supabase$from$2.error;
7102
7102
  if (!existingError) {
7103
- _context3.next = 5;
7103
+ _context2.next = 5;
7104
7104
  break;
7105
7105
  }
7106
7106
  throw existingError;
7107
7107
  case 5:
7108
7108
  nextValues = _objectSpread(_objectSpread({}, normalizeValues(existing === null || existing === void 0 ? void 0 : existing.values)), values);
7109
- _context3.next = 6;
7109
+ _context2.next = 6;
7110
7110
  return supabase.from(tableName).upsert({
7111
7111
  namespace: namespace,
7112
7112
  values: nextValues,
@@ -7115,11 +7115,11 @@ function _updateConfig() {
7115
7115
  onConflict: "namespace"
7116
7116
  }).select("*").single();
7117
7117
  case 6:
7118
- _yield$supabase$from$3 = _context3.sent;
7118
+ _yield$supabase$from$3 = _context2.sent;
7119
7119
  data = _yield$supabase$from$3.data;
7120
7120
  error = _yield$supabase$from$3.error;
7121
7121
  if (!error) {
7122
- _context3.next = 7;
7122
+ _context2.next = 7;
7123
7123
  break;
7124
7124
  }
7125
7125
  throw error;
@@ -7129,22 +7129,22 @@ function _updateConfig() {
7129
7129
  message: "配置保存成功",
7130
7130
  data: toConfigResponse(data, namespace)
7131
7131
  };
7132
- return _context3.abrupt("return", c.json(response, 200));
7132
+ return _context2.abrupt("return", c.json(response, 200));
7133
7133
  case 8:
7134
- _context3.prev = 8;
7135
- _t2 = _context3["catch"](0);
7134
+ _context2.prev = 8;
7135
+ _t2 = _context2["catch"](0);
7136
7136
  console.error("保存配置失败:", _t2);
7137
7137
  _response6 = {
7138
7138
  success: false,
7139
7139
  message: "保存配置失败",
7140
7140
  error: _t2.message
7141
7141
  };
7142
- return _context3.abrupt("return", c.json(_response6, 500));
7142
+ return _context2.abrupt("return", c.json(_response6, 500));
7143
7143
  case 9:
7144
7144
  case "end":
7145
- return _context3.stop();
7145
+ return _context2.stop();
7146
7146
  }
7147
- }, _callee3, null, [[0, 8]]);
7147
+ }, _callee2, null, [[0, 8]]);
7148
7148
  }));
7149
7149
  return _updateConfig.apply(this, arguments);
7150
7150
  }
@@ -7661,8 +7661,8 @@ function createOssUploadRoute(app) {
7661
7661
  return app;
7662
7662
  }
7663
7663
  function createConfigRoute(app) {
7664
- app.get("/configs", requireJwtAuth, requireAdminRole, getConfig);
7665
- app.put("/configs/:namespace", requireJwtAuth, requireAdminRole, function (c) {
7664
+ app.get("/configs", requireAdminRole, getConfig);
7665
+ app.put("/configs/:namespace", requireAdminRole, function (c) {
7666
7666
  return updateConfig(c);
7667
7667
  });
7668
7668
  return app;