@wecode-team/cms-supabase-api 0.1.45 → 0.1.47

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
@@ -6612,7 +6612,7 @@ function validateConfigSessionId(sessionId) {
6612
6612
  return null;
6613
6613
  }
6614
6614
  function getConfigsTableName(sessionId) {
6615
- return "".concat(sessionId, "__config__");
6615
+ return "".concat(sessionId.replace('-', '_'), "__config__");
6616
6616
  }
6617
6617
  function normalizeValues(values) {
6618
6618
  if (!values || _typeof$1(values) !== "object" || Array.isArray(values)) {
@@ -6630,37 +6630,6 @@ function buildFieldStatus(values) {
6630
6630
  }];
6631
6631
  }));
6632
6632
  }
6633
- function ensureConfigsTable(_x) {
6634
- return _ensureConfigsTable.apply(this, arguments);
6635
- }
6636
- function _ensureConfigsTable() {
6637
- _ensureConfigsTable = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(tableName) {
6638
- var supabase, createTableSQL, _yield$supabase$rpc, error;
6639
- return _regeneratorRuntime.wrap(function (_context) {
6640
- while (1) switch (_context.prev = _context.next) {
6641
- case 0:
6642
- supabase = getSupabase();
6643
- createTableSQL = "\n CREATE TABLE IF NOT EXISTS \"".concat(tableName, "\" (\n id SERIAL PRIMARY KEY,\n namespace TEXT NOT NULL UNIQUE,\n values JSONB NOT NULL DEFAULT '{}'::jsonb,\n created_at TIMESTAMPTZ DEFAULT NOW(),\n updated_at TIMESTAMPTZ DEFAULT NOW()\n );\n ");
6644
- _context.next = 1;
6645
- return supabase.rpc("execute_sql", {
6646
- sql_query: createTableSQL
6647
- });
6648
- case 1:
6649
- _yield$supabase$rpc = _context.sent;
6650
- error = _yield$supabase$rpc.error;
6651
- if (!error) {
6652
- _context.next = 2;
6653
- break;
6654
- }
6655
- throw error;
6656
- case 2:
6657
- case "end":
6658
- return _context.stop();
6659
- }
6660
- }, _callee);
6661
- }));
6662
- return _ensureConfigsTable.apply(this, arguments);
6663
- }
6664
6633
  function validateNamespace(namespace) {
6665
6634
  if (!namespace) return "缺少 namespace";
6666
6635
  if (!CONFIG_NAMESPACE_RE.test(namespace)) {
@@ -6679,138 +6648,132 @@ function toConfigResponse(row, fallbackNamespace) {
6679
6648
  updated_at: row === null || row === void 0 ? void 0 : row.updated_at
6680
6649
  };
6681
6650
  }
6682
- function getConfig(_x2) {
6651
+ function getConfig(_x) {
6683
6652
  return _getConfig.apply(this, arguments);
6684
6653
  }
6685
6654
  function _getConfig() {
6686
- _getConfig = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(c) {
6655
+ _getConfig = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(c) {
6687
6656
  var namespace, namespaceError, _response, sessionId, sessionError, _response2, tableName, supabase, _yield$supabase$from$, data, error, response, _response3, _t;
6688
- return _regeneratorRuntime.wrap(function (_context2) {
6689
- while (1) switch (_context2.prev = _context2.next) {
6657
+ return _regeneratorRuntime.wrap(function (_context) {
6658
+ while (1) switch (_context.prev = _context.next) {
6690
6659
  case 0:
6691
- _context2.prev = 0;
6660
+ _context.prev = 0;
6692
6661
  namespace = (c.req.query("namespace") || "").trim();
6693
6662
  namespaceError = validateNamespace(namespace);
6694
6663
  if (!namespaceError) {
6695
- _context2.next = 1;
6664
+ _context.next = 1;
6696
6665
  break;
6697
6666
  }
6698
6667
  _response = {
6699
6668
  success: false,
6700
6669
  message: namespaceError
6701
6670
  };
6702
- return _context2.abrupt("return", c.json(_response, 200));
6671
+ return _context.abrupt("return", c.json(_response, 200));
6703
6672
  case 1:
6704
6673
  sessionId = getConfigSessionId(c);
6705
6674
  sessionError = validateConfigSessionId(sessionId);
6706
6675
  if (!sessionError) {
6707
- _context2.next = 2;
6676
+ _context.next = 2;
6708
6677
  break;
6709
6678
  }
6710
6679
  _response2 = {
6711
6680
  success: false,
6712
6681
  message: sessionError
6713
6682
  };
6714
- return _context2.abrupt("return", c.json(_response2, 200));
6683
+ return _context.abrupt("return", c.json(_response2, 200));
6715
6684
  case 2:
6716
- tableName = getConfigsTableName(sessionId);
6717
- _context2.next = 3;
6718
- return ensureConfigsTable(tableName);
6719
- case 3:
6685
+ tableName = getConfigsTableName(sessionId); // await ensureConfigsTable(tableName)
6720
6686
  supabase = getSupabase();
6721
- _context2.next = 4;
6687
+ _context.next = 3;
6722
6688
  return supabase.from(tableName).select("*").eq("namespace", namespace).maybeSingle();
6723
- case 4:
6724
- _yield$supabase$from$ = _context2.sent;
6689
+ case 3:
6690
+ _yield$supabase$from$ = _context.sent;
6725
6691
  data = _yield$supabase$from$.data;
6726
6692
  error = _yield$supabase$from$.error;
6727
6693
  if (!error) {
6728
- _context2.next = 5;
6694
+ _context.next = 4;
6729
6695
  break;
6730
6696
  }
6731
6697
  throw error;
6732
- case 5:
6698
+ case 4:
6733
6699
  response = {
6734
6700
  success: true,
6735
6701
  data: toConfigResponse(data, namespace)
6736
6702
  };
6737
- return _context2.abrupt("return", c.json(response, 200));
6738
- case 6:
6739
- _context2.prev = 6;
6740
- _t = _context2["catch"](0);
6703
+ return _context.abrupt("return", c.json(response, 200));
6704
+ case 5:
6705
+ _context.prev = 5;
6706
+ _t = _context["catch"](0);
6741
6707
  console.error("获取配置失败:", _t);
6742
6708
  _response3 = {
6743
6709
  success: false,
6744
6710
  message: "获取配置失败",
6745
6711
  error: _t.message
6746
6712
  };
6747
- return _context2.abrupt("return", c.json(_response3, 500));
6748
- case 7:
6713
+ return _context.abrupt("return", c.json(_response3, 500));
6714
+ case 6:
6749
6715
  case "end":
6750
- return _context2.stop();
6716
+ return _context.stop();
6751
6717
  }
6752
- }, _callee2, null, [[0, 6]]);
6718
+ }, _callee, null, [[0, 5]]);
6753
6719
  }));
6754
6720
  return _getConfig.apply(this, arguments);
6755
6721
  }
6756
- function updateConfig(_x3) {
6722
+ function updateConfig(_x2) {
6757
6723
  return _updateConfig.apply(this, arguments);
6758
6724
  }
6759
6725
  function _updateConfig() {
6760
- _updateConfig = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(c) {
6726
+ _updateConfig = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(c) {
6761
6727
  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;
6762
- return _regeneratorRuntime.wrap(function (_context3) {
6763
- while (1) switch (_context3.prev = _context3.next) {
6728
+ return _regeneratorRuntime.wrap(function (_context2) {
6729
+ while (1) switch (_context2.prev = _context2.next) {
6764
6730
  case 0:
6765
- _context3.prev = 0;
6731
+ _context2.prev = 0;
6766
6732
  namespace = (c.req.param("namespace") || "").trim();
6767
6733
  namespaceError = validateNamespace(namespace);
6768
6734
  if (!namespaceError) {
6769
- _context3.next = 1;
6735
+ _context2.next = 1;
6770
6736
  break;
6771
6737
  }
6772
6738
  _response4 = {
6773
6739
  success: false,
6774
6740
  message: namespaceError
6775
6741
  };
6776
- return _context3.abrupt("return", c.json(_response4, 200));
6742
+ return _context2.abrupt("return", c.json(_response4, 200));
6777
6743
  case 1:
6778
- _context3.next = 2;
6744
+ _context2.next = 2;
6779
6745
  return c.req.json();
6780
6746
  case 2:
6781
- body = _context3.sent;
6747
+ body = _context2.sent;
6782
6748
  values = normalizeValues(body === null || body === void 0 ? void 0 : body.values);
6783
6749
  sessionId = getConfigSessionId(c);
6784
6750
  sessionError = validateConfigSessionId(sessionId);
6785
6751
  if (!sessionError) {
6786
- _context3.next = 3;
6752
+ _context2.next = 3;
6787
6753
  break;
6788
6754
  }
6789
6755
  _response5 = {
6790
6756
  success: false,
6791
6757
  message: sessionError
6792
6758
  };
6793
- return _context3.abrupt("return", c.json(_response5, 200));
6759
+ return _context2.abrupt("return", c.json(_response5, 200));
6794
6760
  case 3:
6795
- tableName = getConfigsTableName(sessionId);
6796
- _context3.next = 4;
6797
- return ensureConfigsTable(tableName);
6798
- case 4:
6761
+ tableName = getConfigsTableName(sessionId); // await ensureConfigsTable(tableName)
6799
6762
  supabase = getSupabase();
6800
- _context3.next = 5;
6763
+ _context2.next = 4;
6801
6764
  return supabase.from(tableName).select("values").eq("namespace", namespace).maybeSingle();
6802
- case 5:
6803
- _yield$supabase$from$2 = _context3.sent;
6765
+ case 4:
6766
+ _yield$supabase$from$2 = _context2.sent;
6804
6767
  existing = _yield$supabase$from$2.data;
6805
6768
  existingError = _yield$supabase$from$2.error;
6806
6769
  if (!existingError) {
6807
- _context3.next = 6;
6770
+ _context2.next = 5;
6808
6771
  break;
6809
6772
  }
6810
6773
  throw existingError;
6811
- case 6:
6774
+ case 5:
6812
6775
  nextValues = _objectSpread(_objectSpread({}, normalizeValues(existing === null || existing === void 0 ? void 0 : existing.values)), values);
6813
- _context3.next = 7;
6776
+ _context2.next = 6;
6814
6777
  return supabase.from(tableName).upsert({
6815
6778
  namespace: namespace,
6816
6779
  values: nextValues,
@@ -6818,37 +6781,37 @@ function _updateConfig() {
6818
6781
  }, {
6819
6782
  onConflict: "namespace"
6820
6783
  }).select("*").single();
6821
- case 7:
6822
- _yield$supabase$from$3 = _context3.sent;
6784
+ case 6:
6785
+ _yield$supabase$from$3 = _context2.sent;
6823
6786
  data = _yield$supabase$from$3.data;
6824
6787
  error = _yield$supabase$from$3.error;
6825
6788
  if (!error) {
6826
- _context3.next = 8;
6789
+ _context2.next = 7;
6827
6790
  break;
6828
6791
  }
6829
6792
  throw error;
6830
- case 8:
6793
+ case 7:
6831
6794
  response = {
6832
6795
  success: true,
6833
6796
  message: "配置保存成功",
6834
6797
  data: toConfigResponse(data, namespace)
6835
6798
  };
6836
- return _context3.abrupt("return", c.json(response, 200));
6837
- case 9:
6838
- _context3.prev = 9;
6839
- _t2 = _context3["catch"](0);
6799
+ return _context2.abrupt("return", c.json(response, 200));
6800
+ case 8:
6801
+ _context2.prev = 8;
6802
+ _t2 = _context2["catch"](0);
6840
6803
  console.error("保存配置失败:", _t2);
6841
6804
  _response6 = {
6842
6805
  success: false,
6843
6806
  message: "保存配置失败",
6844
6807
  error: _t2.message
6845
6808
  };
6846
- return _context3.abrupt("return", c.json(_response6, 500));
6847
- case 10:
6809
+ return _context2.abrupt("return", c.json(_response6, 500));
6810
+ case 9:
6848
6811
  case "end":
6849
- return _context3.stop();
6812
+ return _context2.stop();
6850
6813
  }
6851
- }, _callee3, null, [[0, 9]]);
6814
+ }, _callee2, null, [[0, 8]]);
6852
6815
  }));
6853
6816
  return _updateConfig.apply(this, arguments);
6854
6817
  }
@@ -7349,8 +7312,8 @@ function createOssUploadRoute(app) {
7349
7312
  return app;
7350
7313
  }
7351
7314
  function createConfigRoute(app) {
7352
- app.get("/configs", requireJwtAuth, requireAdminRole, getConfig);
7353
- app.put("/configs/:namespace", requireJwtAuth, requireAdminRole, function (c) {
7315
+ app.get("/configs", requireAdminRole, getConfig);
7316
+ app.put("/configs/:namespace", requireAdminRole, function (c) {
7354
7317
  return updateConfig(c);
7355
7318
  });
7356
7319
  return app;