@wecode-team/cms-supabase-api 0.1.33 → 0.1.35

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
@@ -1007,11 +1007,11 @@ function _defineProperty(e, r, t) {
1007
1007
  }) : e[r] = t, e;
1008
1008
  }
1009
1009
 
1010
- function ownKeys$2(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1011
- function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$2(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$2(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1012
- function _createForOfIteratorHelper$1(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray$2(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
1013
- function _unsupportedIterableToArray$2(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray$2(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray$2(r, a) : void 0; } }
1014
- function _arrayLikeToArray$2(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
1010
+ function ownKeys$3(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1011
+ function _objectSpread$3(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$3(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$3(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1012
+ function _createForOfIteratorHelper$3(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray$4(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
1013
+ function _unsupportedIterableToArray$4(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray$4(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray$4(r, a) : void 0; } }
1014
+ function _arrayLikeToArray$4(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
1015
1015
  // 字段类型映射到PostgreSQL类型
1016
1016
  var fieldTypeMapping = {
1017
1017
  string: "text",
@@ -1101,7 +1101,7 @@ var DynamicTableService = /*#__PURE__*/function () {
1101
1101
  value: function applySupabaseFilters(query, filters) {
1102
1102
  if (!filters || filters.length === 0) return query;
1103
1103
  var q = query;
1104
- var _iterator = _createForOfIteratorHelper$1(filters),
1104
+ var _iterator = _createForOfIteratorHelper$3(filters),
1105
1105
  _step;
1106
1106
  try {
1107
1107
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
@@ -2063,7 +2063,7 @@ var DynamicTableService = /*#__PURE__*/function () {
2063
2063
  throw error;
2064
2064
  case 2:
2065
2065
  return _context14.abrupt("return", (data || []).map(function (item) {
2066
- return _objectSpread$2({
2066
+ return _objectSpread$3({
2067
2067
  id: item.id,
2068
2068
  label: item[displayField] || "ID: ".concat(item.id)
2069
2069
  }, item);
@@ -2176,8 +2176,8 @@ function getDynamicTableService() {
2176
2176
  return defaultService$1;
2177
2177
  }
2178
2178
 
2179
- function ownKeys$1(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2180
- function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2179
+ function ownKeys$2(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2180
+ function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$2(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$2(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2181
2181
  var AuthService = /*#__PURE__*/function () {
2182
2182
  function AuthService() {
2183
2183
  _classCallCheck(this, AuthService);
@@ -2354,7 +2354,7 @@ var AuthService = /*#__PURE__*/function () {
2354
2354
  return _regeneratorRuntime.wrap(function (_context4) {
2355
2355
  while (1) switch (_context4.prev = _context4.next) {
2356
2356
  case 0:
2357
- finalUserData = _objectSpread$1({
2357
+ finalUserData = _objectSpread$2({
2358
2358
  tableName: this.defaultTableName
2359
2359
  }, userData);
2360
2360
  _context4.prev = 1;
@@ -2412,7 +2412,7 @@ var AuthService = /*#__PURE__*/function () {
2412
2412
  case 0:
2413
2413
  updateData = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : {};
2414
2414
  // 设置默认值
2415
- finalUpdateData = _objectSpread$1({
2415
+ finalUpdateData = _objectSpread$2({
2416
2416
  tableName: this.defaultTableName
2417
2417
  }, updateData);
2418
2418
  _context5.prev = 1;
@@ -2684,10 +2684,652 @@ function getAuthService() {
2684
2684
  return defaultService;
2685
2685
  }
2686
2686
 
2687
+ function _objectWithoutPropertiesLoose(r, e) {
2688
+ if (null == r) return {};
2689
+ var t = {};
2690
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
2691
+ if (-1 !== e.indexOf(n)) continue;
2692
+ t[n] = r[n];
2693
+ }
2694
+ return t;
2695
+ }
2696
+
2697
+ function _objectWithoutProperties(e, t) {
2698
+ if (null == e) return {};
2699
+ var o,
2700
+ r,
2701
+ i = _objectWithoutPropertiesLoose(e, t);
2702
+ if (Object.getOwnPropertySymbols) {
2703
+ var n = Object.getOwnPropertySymbols(e);
2704
+ for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
2705
+ }
2706
+ return i;
2707
+ }
2708
+
2709
+ function _assertThisInitialized(e) {
2710
+ if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
2711
+ return e;
2712
+ }
2713
+
2714
+ function _possibleConstructorReturn(t, e) {
2715
+ if (e && ("object" == _typeof$1(e) || "function" == typeof e)) return e;
2716
+ if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
2717
+ return _assertThisInitialized(t);
2718
+ }
2719
+
2720
+ function _getPrototypeOf(t) {
2721
+ return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
2722
+ return t.__proto__ || Object.getPrototypeOf(t);
2723
+ }, _getPrototypeOf(t);
2724
+ }
2725
+
2726
+ function _setPrototypeOf(t, e) {
2727
+ return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
2728
+ return t.__proto__ = e, t;
2729
+ }, _setPrototypeOf(t, e);
2730
+ }
2731
+
2732
+ function _inherits(t, e) {
2733
+ if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
2734
+ t.prototype = Object.create(e && e.prototype, {
2735
+ constructor: {
2736
+ value: t,
2737
+ writable: !0,
2738
+ configurable: !0
2739
+ }
2740
+ }), Object.defineProperty(t, "prototype", {
2741
+ writable: !1
2742
+ }), e && _setPrototypeOf(t, e);
2743
+ }
2744
+
2745
+ function _isNativeFunction(t) {
2746
+ try {
2747
+ return -1 !== Function.toString.call(t).indexOf("[native code]");
2748
+ } catch (n) {
2749
+ return "function" == typeof t;
2750
+ }
2751
+ }
2752
+
2753
+ function _isNativeReflectConstruct$1() {
2754
+ try {
2755
+ var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
2756
+ } catch (t) {}
2757
+ return (_isNativeReflectConstruct$1 = function _isNativeReflectConstruct() {
2758
+ return !!t;
2759
+ })();
2760
+ }
2761
+
2762
+ function _construct(t, e, r) {
2763
+ if (_isNativeReflectConstruct$1()) return Reflect.construct.apply(null, arguments);
2764
+ var o = [null];
2765
+ o.push.apply(o, e);
2766
+ var p = new (t.bind.apply(t, o))();
2767
+ return r && _setPrototypeOf(p, r.prototype), p;
2768
+ }
2769
+
2770
+ function _wrapNativeSuper(t) {
2771
+ var r = "function" == typeof Map ? new Map() : void 0;
2772
+ return _wrapNativeSuper = function _wrapNativeSuper(t) {
2773
+ if (null === t || !_isNativeFunction(t)) return t;
2774
+ if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function");
2775
+ if (void 0 !== r) {
2776
+ if (r.has(t)) return r.get(t);
2777
+ r.set(t, Wrapper);
2778
+ }
2779
+ function Wrapper() {
2780
+ return _construct(t, arguments, _getPrototypeOf(this).constructor);
2781
+ }
2782
+ return Wrapper.prototype = Object.create(t.prototype, {
2783
+ constructor: {
2784
+ value: Wrapper,
2785
+ enumerable: !1,
2786
+ writable: !0,
2787
+ configurable: !0
2788
+ }
2789
+ }), _setPrototypeOf(Wrapper, t);
2790
+ }, _wrapNativeSuper(t);
2791
+ }
2792
+
2793
+ var _excluded$1 = ["accessKeyId", "accessKeySecret"];
2794
+ function ownKeys$1(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2795
+ function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2796
+ function _createForOfIteratorHelper$2(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray$3(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
2797
+ function _unsupportedIterableToArray$3(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray$3(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray$3(r, a) : void 0; } }
2798
+ function _arrayLikeToArray$3(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
2799
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
2800
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
2801
+ var DEFAULT_MAX_SIZE = 2 * 1024 * 1024;
2802
+ var DEFAULT_SIGNED_URL_EXPIRES_IN = 60 * 60;
2803
+ var OssUploadError = /*#__PURE__*/function (_Error) {
2804
+ function OssUploadError(message) {
2805
+ var _this;
2806
+ var status = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 400;
2807
+ _classCallCheck(this, OssUploadError);
2808
+ _this = _callSuper(this, OssUploadError, [message]);
2809
+ _this.name = "OssUploadError";
2810
+ _this.status = status;
2811
+ return _this;
2812
+ }
2813
+ _inherits(OssUploadError, _Error);
2814
+ return _createClass(OssUploadError);
2815
+ }(/*#__PURE__*/_wrapNativeSuper(Error));
2816
+ function requiredValue(value, name) {
2817
+ var trimmed = String(value || "").trim();
2818
+ if (!trimmed) {
2819
+ throw new OssUploadError("Missing required OSS config: ".concat(name), 500);
2820
+ }
2821
+ return trimmed;
2822
+ }
2823
+ function normalizeHost(value) {
2824
+ return value.replace(/^https?:\/\//, "").replace(/\/+$/, "");
2825
+ }
2826
+ function buildBucketBaseUrl(bucket, endpoint) {
2827
+ return "https://".concat(bucket, ".").concat(endpoint);
2828
+ }
2829
+ function normalizePublicBaseUrl(value, bucket, endpoint) {
2830
+ var raw = String(value || "").trim();
2831
+ if (!raw) {
2832
+ return buildBucketBaseUrl(bucket, endpoint);
2833
+ }
2834
+ var withProtocol = /^https?:\/\//i.test(raw) ? raw : "https://".concat(raw);
2835
+ try {
2836
+ var url = new URL(withProtocol);
2837
+ if (url.host === endpoint) {
2838
+ url.host = "".concat(bucket, ".").concat(endpoint);
2839
+ }
2840
+ return url.toString().replace(/\/+$/, "");
2841
+ } catch (_unused) {
2842
+ return withProtocol.replace(/\/+$/, "");
2843
+ }
2844
+ }
2845
+ function sanitizePathSegment(value) {
2846
+ return String(value || "").trim().replace(/[^a-zA-Z0-9/_-]+/g, "-").replace(/\/{2,}/g, "/").replace(/^\/+|\/+$/g, "");
2847
+ }
2848
+ function extFromName() {
2849
+ var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
2850
+ var match = String(name).match(/(\.[a-zA-Z0-9]+)$/);
2851
+ return match ? match[1].toLowerCase() : "";
2852
+ }
2853
+ function encodeObjectKey(objectKey) {
2854
+ return objectKey.split("/").map(function (segment) {
2855
+ return encodeURIComponent(segment);
2856
+ }).join("/");
2857
+ }
2858
+ function buildObjectKey(config, directory, originalName) {
2859
+ var safeDirectory = sanitizePathSegment(directory || "uploads");
2860
+ var safePrefix = sanitizePathSegment(config.prefix || "cms-assets");
2861
+ var extension = extFromName(originalName) || ".bin";
2862
+ var stamp = new Date().toISOString().replace(/[-:.TZ]/g, "").slice(0, 14);
2863
+ var random = Math.random().toString(16).slice(2, 10).padEnd(8, "0");
2864
+ return "".concat(safePrefix, "/").concat(safeDirectory, "/").concat(stamp, "-").concat(random).concat(extension);
2865
+ }
2866
+ function extractXmlField(errorText, fieldName) {
2867
+ var match = String(errorText || "").match(new RegExp("<".concat(fieldName, ">([^<]+)</").concat(fieldName, ">"), "i"));
2868
+ return match ? match[1].trim() : "";
2869
+ }
2870
+ function extractRecommendedEndpoint(errorText) {
2871
+ return normalizeHost(extractXmlField(errorText, "Endpoint"));
2872
+ }
2873
+ function resolvePublicBaseUrl(publicBaseUrl, bucket, endpoint, nextEndpoint) {
2874
+ var defaultBaseUrl = buildBucketBaseUrl(bucket, endpoint);
2875
+ if (publicBaseUrl === defaultBaseUrl) {
2876
+ return buildBucketBaseUrl(bucket, nextEndpoint);
2877
+ }
2878
+ return publicBaseUrl;
2879
+ }
2880
+ function arrayBufferToBase64(value) {
2881
+ var bytes = new Uint8Array(value);
2882
+ if (typeof Buffer !== "undefined") {
2883
+ return Buffer.from(bytes).toString("base64");
2884
+ }
2885
+ var binary = "";
2886
+ var _iterator = _createForOfIteratorHelper$2(bytes),
2887
+ _step;
2888
+ try {
2889
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
2890
+ var _byte = _step.value;
2891
+ binary += String.fromCharCode(_byte);
2892
+ }
2893
+ } catch (err) {
2894
+ _iterator.e(err);
2895
+ } finally {
2896
+ _iterator.f();
2897
+ }
2898
+ return btoa(binary);
2899
+ }
2900
+ function signBase64(_x, _x2) {
2901
+ return _signBase.apply(this, arguments);
2902
+ }
2903
+ function _signBase() {
2904
+ _signBase = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(secret, stringToSign) {
2905
+ var _globalThis$crypto;
2906
+ var encoder, key, signature;
2907
+ return _regeneratorRuntime.wrap(function (_context2) {
2908
+ while (1) switch (_context2.prev = _context2.next) {
2909
+ case 0:
2910
+ if ((_globalThis$crypto = globalThis.crypto) !== null && _globalThis$crypto !== void 0 && _globalThis$crypto.subtle) {
2911
+ _context2.next = 1;
2912
+ break;
2913
+ }
2914
+ throw new OssUploadError("Web Crypto is unavailable in the current runtime", 500);
2915
+ case 1:
2916
+ encoder = new TextEncoder();
2917
+ _context2.next = 2;
2918
+ return globalThis.crypto.subtle.importKey("raw", encoder.encode(secret), {
2919
+ name: "HMAC",
2920
+ hash: "SHA-1"
2921
+ }, false, ["sign"]);
2922
+ case 2:
2923
+ key = _context2.sent;
2924
+ _context2.next = 3;
2925
+ return globalThis.crypto.subtle.sign("HMAC", key, encoder.encode(stringToSign));
2926
+ case 3:
2927
+ signature = _context2.sent;
2928
+ return _context2.abrupt("return", arrayBufferToBase64(signature));
2929
+ case 4:
2930
+ case "end":
2931
+ return _context2.stop();
2932
+ }
2933
+ }, _callee2);
2934
+ }));
2935
+ return _signBase.apply(this, arguments);
2936
+ }
2937
+ function createPermissionDeniedMessage(bucket, objectKey, errorText) {
2938
+ var action = extractXmlField(errorText, "AuthAction");
2939
+ var principalType = extractXmlField(errorText, "AuthPrincipalType");
2940
+ var principalName = extractXmlField(errorText, "AuthPrincipalDisplayName");
2941
+ var policyType = extractXmlField(errorText, "PolicyType");
2942
+ var denyType = extractXmlField(errorText, "NoPermissionType");
2943
+ var parts = ["OSS permission denied for bucket \"".concat(bucket, "\""), action ? "missing ".concat(action) : "missing required OSS permission", "resource ".concat(bucket, "/").concat(objectKey)];
2944
+ if (principalType || principalName) {
2945
+ parts.push("principal ".concat([principalType, principalName].filter(Boolean).join(":")));
2946
+ }
2947
+ if (policyType || denyType) {
2948
+ parts.push("policy ".concat([policyType, denyType].filter(Boolean).join("/")));
2949
+ }
2950
+ parts.push("Grant oss:PutObject to the configured RAM user for this bucket or prefix.");
2951
+ return parts.join("; ");
2952
+ }
2953
+ function createEndpointMismatchMessage(bucket, endpoint, suggestedEndpoint) {
2954
+ return ["OSS endpoint mismatch for bucket \"".concat(bucket, "\""), "configured OSS_ENDPOINT=".concat(endpoint), "OSS says use ".concat(suggestedEndpoint), "Update OSS_ENDPOINT and OSS_PUBLIC_BASE_URL to the bucket's actual region."].join("; ");
2955
+ }
2956
+ function createAuthorization(_x3, _x4, _x5, _x6, _x7) {
2957
+ return _createAuthorization.apply(this, arguments);
2958
+ }
2959
+ function _createAuthorization() {
2960
+ _createAuthorization = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(config, method, objectKey, contentType, date) {
2961
+ var stringToSign, signature;
2962
+ return _regeneratorRuntime.wrap(function (_context3) {
2963
+ while (1) switch (_context3.prev = _context3.next) {
2964
+ case 0:
2965
+ stringToSign = [method, "", contentType, date, "/".concat(config.bucket, "/").concat(objectKey)].join("\n");
2966
+ _context3.next = 1;
2967
+ return signBase64(config.accessKeySecret, stringToSign);
2968
+ case 1:
2969
+ signature = _context3.sent;
2970
+ return _context3.abrupt("return", "OSS ".concat(config.accessKeyId, ":").concat(signature));
2971
+ case 2:
2972
+ case "end":
2973
+ return _context3.stop();
2974
+ }
2975
+ }, _callee3);
2976
+ }));
2977
+ return _createAuthorization.apply(this, arguments);
2978
+ }
2979
+ function createSignedGetUrl(_x8, _x9, _x0) {
2980
+ return _createSignedGetUrl.apply(this, arguments);
2981
+ }
2982
+ function _createSignedGetUrl() {
2983
+ _createSignedGetUrl = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(config, objectKey, expiresIn) {
2984
+ var expires, stringToSign, signature, encodedObjectKey, url;
2985
+ return _regeneratorRuntime.wrap(function (_context4) {
2986
+ while (1) switch (_context4.prev = _context4.next) {
2987
+ case 0:
2988
+ expires = Math.max(1, Math.floor(Date.now() / 1000) + expiresIn);
2989
+ stringToSign = ["GET", "", "", String(expires), "/".concat(config.bucket, "/").concat(objectKey)].join("\n");
2990
+ _context4.next = 1;
2991
+ return signBase64(config.accessKeySecret, stringToSign);
2992
+ case 1:
2993
+ signature = _context4.sent;
2994
+ encodedObjectKey = encodeObjectKey(objectKey);
2995
+ url = new URL("".concat(buildBucketBaseUrl(config.bucket, config.endpoint), "/").concat(encodedObjectKey));
2996
+ url.searchParams.set("OSSAccessKeyId", config.accessKeyId);
2997
+ url.searchParams.set("Expires", String(expires));
2998
+ url.searchParams.set("Signature", signature);
2999
+ return _context4.abrupt("return", url.toString());
3000
+ case 2:
3001
+ case "end":
3002
+ return _context4.stop();
3003
+ }
3004
+ }, _callee4);
3005
+ }));
3006
+ return _createSignedGetUrl.apply(this, arguments);
3007
+ }
3008
+ function putObjectToOss(_x1, _x10, _x11, _x12, _x13) {
3009
+ return _putObjectToOss.apply(this, arguments);
3010
+ }
3011
+ function _putObjectToOss() {
3012
+ _putObjectToOss = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(config, endpoint, objectKey, contentType, buffer) {
3013
+ var date, authorization, bodyBytes, body;
3014
+ return _regeneratorRuntime.wrap(function (_context5) {
3015
+ while (1) switch (_context5.prev = _context5.next) {
3016
+ case 0:
3017
+ date = new Date().toUTCString();
3018
+ _context5.next = 1;
3019
+ return createAuthorization(config, "PUT", objectKey, contentType, date);
3020
+ case 1:
3021
+ authorization = _context5.sent;
3022
+ bodyBytes = Uint8Array.from(buffer);
3023
+ body = new Blob([bodyBytes], {
3024
+ type: contentType
3025
+ });
3026
+ return _context5.abrupt("return", fetch("".concat(buildBucketBaseUrl(config.bucket, endpoint), "/").concat(encodeObjectKey(objectKey)), {
3027
+ method: "PUT",
3028
+ headers: {
3029
+ Authorization: authorization,
3030
+ Date: date,
3031
+ "Content-Type": contentType
3032
+ },
3033
+ body: body
3034
+ }));
3035
+ case 2:
3036
+ case "end":
3037
+ return _context5.stop();
3038
+ }
3039
+ }, _callee5);
3040
+ }));
3041
+ return _putObjectToOss.apply(this, arguments);
3042
+ }
3043
+ function normalizeConfig(config) {
3044
+ var bucket = requiredValue(config.bucket, "bucket");
3045
+ var endpoint = normalizeHost(requiredValue(config.endpoint, "endpoint"));
3046
+ return {
3047
+ provider: "aliyun-oss",
3048
+ bucket: bucket,
3049
+ endpoint: endpoint,
3050
+ accessKeyId: requiredValue(config.accessKeyId, "accessKeyId"),
3051
+ accessKeySecret: requiredValue(config.accessKeySecret, "accessKeySecret"),
3052
+ publicBaseUrl: normalizePublicBaseUrl(config.publicBaseUrl, bucket, endpoint),
3053
+ prefix: sanitizePathSegment(config.prefix || "cms-assets"),
3054
+ maxSize: Number(config.maxSize || DEFAULT_MAX_SIZE),
3055
+ returnMode: config.returnMode || "both",
3056
+ signedUrlExpiresIn: Number(config.signedUrlExpiresIn || DEFAULT_SIGNED_URL_EXPIRES_IN)
3057
+ };
3058
+ }
3059
+ var OssUploadService = /*#__PURE__*/function () {
3060
+ function OssUploadService(config) {
3061
+ _classCallCheck(this, OssUploadService);
3062
+ this.config = normalizeConfig(config);
3063
+ }
3064
+ return _createClass(OssUploadService, [{
3065
+ key: "getConfig",
3066
+ value: function getConfig() {
3067
+ var _this$config = this.config;
3068
+ _this$config.accessKeyId;
3069
+ _this$config.accessKeySecret;
3070
+ var safeConfig = _objectWithoutProperties(_this$config, _excluded$1);
3071
+ return safeConfig;
3072
+ }
3073
+ }, {
3074
+ key: "upload",
3075
+ value: function () {
3076
+ var _upload = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(input) {
3077
+ var contentType, buffer, objectKey, activeEndpoint, publicBaseUrl, response, lastErrorText, errorText, suggestedEndpoint, finalErrorText, finalSuggestedEndpoint, encodedObjectKey, publicUrl, signedUrl, _t;
3078
+ return _regeneratorRuntime.wrap(function (_context) {
3079
+ while (1) switch (_context.prev = _context.next) {
3080
+ case 0:
3081
+ contentType = String(input.contentType || "application/octet-stream").trim() || "application/octet-stream";
3082
+ buffer = new Uint8Array(input.buffer);
3083
+ if (buffer.byteLength) {
3084
+ _context.next = 1;
3085
+ break;
3086
+ }
3087
+ throw new OssUploadError("Uploaded file is empty");
3088
+ case 1:
3089
+ if (!(buffer.byteLength > this.config.maxSize)) {
3090
+ _context.next = 2;
3091
+ break;
3092
+ }
3093
+ throw new OssUploadError("File exceeds max size of ".concat(this.config.maxSize, " bytes"));
3094
+ case 2:
3095
+ objectKey = buildObjectKey(this.config, input.directory, input.originalName);
3096
+ activeEndpoint = this.config.endpoint;
3097
+ publicBaseUrl = this.config.publicBaseUrl;
3098
+ _context.next = 3;
3099
+ return putObjectToOss(this.config, activeEndpoint, objectKey, contentType, buffer);
3100
+ case 3:
3101
+ response = _context.sent;
3102
+ lastErrorText = "";
3103
+ if (response.ok) {
3104
+ _context.next = 10;
3105
+ break;
3106
+ }
3107
+ _context.next = 4;
3108
+ return response.text();
3109
+ case 4:
3110
+ errorText = _context.sent;
3111
+ lastErrorText = errorText;
3112
+ suggestedEndpoint = extractRecommendedEndpoint(errorText);
3113
+ if (!(response.status === 403 && suggestedEndpoint && suggestedEndpoint !== activeEndpoint)) {
3114
+ _context.next = 7;
3115
+ break;
3116
+ }
3117
+ activeEndpoint = suggestedEndpoint;
3118
+ publicBaseUrl = resolvePublicBaseUrl(publicBaseUrl, this.config.bucket, this.config.endpoint, suggestedEndpoint);
3119
+ _context.next = 5;
3120
+ return putObjectToOss(this.config, activeEndpoint, objectKey, contentType, buffer);
3121
+ case 5:
3122
+ response = _context.sent;
3123
+ if (response.ok) {
3124
+ _context.next = 7;
3125
+ break;
3126
+ }
3127
+ _context.next = 6;
3128
+ return response.text();
3129
+ case 6:
3130
+ lastErrorText = _context.sent;
3131
+ case 7:
3132
+ if (response.ok) {
3133
+ _context.next = 10;
3134
+ break;
3135
+ }
3136
+ finalErrorText = lastErrorText;
3137
+ finalSuggestedEndpoint = extractRecommendedEndpoint(finalErrorText);
3138
+ if (!(response.status === 403 && finalSuggestedEndpoint && finalSuggestedEndpoint !== this.config.endpoint)) {
3139
+ _context.next = 8;
3140
+ break;
3141
+ }
3142
+ throw new OssUploadError(createEndpointMismatchMessage(this.config.bucket, this.config.endpoint, finalSuggestedEndpoint), 400);
3143
+ case 8:
3144
+ if (!(response.status === 403 && /<Code>AccessDenied<\/Code>/i.test(finalErrorText))) {
3145
+ _context.next = 9;
3146
+ break;
3147
+ }
3148
+ throw new OssUploadError(createPermissionDeniedMessage(this.config.bucket, objectKey, finalErrorText), 403);
3149
+ case 9:
3150
+ throw new OssUploadError("OSS upload failed: ".concat(response.status, " ").concat(finalErrorText), 502);
3151
+ case 10:
3152
+ encodedObjectKey = encodeObjectKey(objectKey);
3153
+ publicUrl = "".concat(publicBaseUrl, "/").concat(encodedObjectKey);
3154
+ if (!(this.config.returnMode === "public-url")) {
3155
+ _context.next = 11;
3156
+ break;
3157
+ }
3158
+ _t = undefined;
3159
+ _context.next = 13;
3160
+ break;
3161
+ case 11:
3162
+ _context.next = 12;
3163
+ return createSignedGetUrl(_objectSpread$1(_objectSpread$1({}, this.config), {}, {
3164
+ endpoint: activeEndpoint
3165
+ }), objectKey, this.config.signedUrlExpiresIn);
3166
+ case 12:
3167
+ _t = _context.sent;
3168
+ case 13:
3169
+ signedUrl = _t;
3170
+ return _context.abrupt("return", {
3171
+ objectKey: objectKey,
3172
+ url: this.config.returnMode === "signed-url" ? signedUrl || publicUrl : publicUrl,
3173
+ signedUrl: this.config.returnMode === "both" || this.config.returnMode === "signed-url" ? signedUrl : undefined
3174
+ });
3175
+ case 14:
3176
+ case "end":
3177
+ return _context.stop();
3178
+ }
3179
+ }, _callee, this);
3180
+ }));
3181
+ function upload(_x14) {
3182
+ return _upload.apply(this, arguments);
3183
+ }
3184
+ return upload;
3185
+ }()
3186
+ }]);
3187
+ }();
3188
+ var ossUploadService = null;
3189
+ function initializeOssUpload(config) {
3190
+ ossUploadService = new OssUploadService(config);
3191
+ return ossUploadService;
3192
+ }
3193
+ function getOssUploadService() {
3194
+ if (!ossUploadService) {
3195
+ throw new OssUploadError("OSS upload is not initialized. Call initializeOssUpload(config) before registering upload routes.", 500);
3196
+ }
3197
+ return ossUploadService;
3198
+ }
3199
+
3200
+ var ADMIN_REGISTRY_TABLE = "_cms_admin_registry";
3201
+ var ensured = false;
3202
+ function normalizeSessionId(sessionId) {
3203
+ // 统一将连字符转换为下划线,确保 UUID 格式一致性
3204
+ // 例如:1047aab4-eecb-4538-ad8d-b5847e762f30 和 1047aab4_eecb_4538_ad8d_b5847e762f30 被视为相同
3205
+ return (sessionId || "").trim().replace(/-/g, "_");
3206
+ }
3207
+ /**
3208
+ * 从前端传来的 auth tableName 中提取 session_id
3209
+ * 约定:auth tableName 形如 `${sessionId}_cms_users`;无前缀则为 `cms_users`
3210
+ */
3211
+ function extractSessionIdFromAuthTableName(tableName) {
3212
+ var name = (tableName || "").trim();
3213
+ if (!name) return "";
3214
+ if (name === "cms_users") return "";
3215
+ if (name.endsWith("_cms_users")) return name.slice(0, -"_cms_users".length);
3216
+ // 兼容:如果传入的不是 cms_users,也允许把最后一个 "_cms_users" 前缀当作 session
3217
+ var idx = name.lastIndexOf("_cms_users");
3218
+ if (idx > 0) return name.slice(0, idx);
3219
+ return "";
3220
+ }
3221
+ function ensureAdminRegistryTable(_x) {
3222
+ return _ensureAdminRegistryTable.apply(this, arguments);
3223
+ }
3224
+ function _ensureAdminRegistryTable() {
3225
+ _ensureAdminRegistryTable = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(supabase) {
3226
+ var _yield$supabase$from$, error;
3227
+ return _regeneratorRuntime.wrap(function (_context) {
3228
+ while (1) switch (_context.prev = _context.next) {
3229
+ case 0:
3230
+ if (!ensured) {
3231
+ _context.next = 1;
3232
+ break;
3233
+ }
3234
+ return _context.abrupt("return", true);
3235
+ case 1:
3236
+ _context.prev = 1;
3237
+ _context.next = 2;
3238
+ return supabase.from(ADMIN_REGISTRY_TABLE).select("session_id").limit(1);
3239
+ case 2:
3240
+ _yield$supabase$from$ = _context.sent;
3241
+ error = _yield$supabase$from$.error;
3242
+ if (error) {
3243
+ _context.next = 3;
3244
+ break;
3245
+ }
3246
+ ensured = true;
3247
+ return _context.abrupt("return", true);
3248
+ case 3:
3249
+ _context.next = 5;
3250
+ break;
3251
+ case 4:
3252
+ _context.prev = 4;
3253
+ _context["catch"](1);
3254
+ case 5:
3255
+ return _context.abrupt("return", false);
3256
+ case 6:
3257
+ case "end":
3258
+ return _context.stop();
3259
+ }
3260
+ }, _callee, null, [[1, 4]]);
3261
+ }));
3262
+ return _ensureAdminRegistryTable.apply(this, arguments);
3263
+ }
3264
+ function getSessionAdminRow(_x2, _x3) {
3265
+ return _getSessionAdminRow.apply(this, arguments);
3266
+ }
3267
+ function _getSessionAdminRow() {
3268
+ _getSessionAdminRow = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(supabase, sessionId) {
3269
+ var sid, _yield$supabase$from$2, data, error;
3270
+ return _regeneratorRuntime.wrap(function (_context2) {
3271
+ while (1) switch (_context2.prev = _context2.next) {
3272
+ case 0:
3273
+ sid = normalizeSessionId(sessionId);
3274
+ _context2.next = 1;
3275
+ return supabase.from(ADMIN_REGISTRY_TABLE).select("session_id,user_id,email").eq("session_id", sid).maybeSingle();
3276
+ case 1:
3277
+ _yield$supabase$from$2 = _context2.sent;
3278
+ data = _yield$supabase$from$2.data;
3279
+ error = _yield$supabase$from$2.error;
3280
+ if (!(error || !data)) {
3281
+ _context2.next = 2;
3282
+ break;
3283
+ }
3284
+ return _context2.abrupt("return", null);
3285
+ case 2:
3286
+ return _context2.abrupt("return", data);
3287
+ case 3:
3288
+ case "end":
3289
+ return _context2.stop();
3290
+ }
3291
+ }, _callee2);
3292
+ }));
3293
+ return _getSessionAdminRow.apply(this, arguments);
3294
+ }
3295
+ function isUserSessionAdmin(_x4, _x5, _x6) {
3296
+ return _isUserSessionAdmin.apply(this, arguments);
3297
+ }
3298
+ function _isUserSessionAdmin() {
3299
+ _isUserSessionAdmin = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(supabase, sessionId, userId) {
3300
+ var row;
3301
+ return _regeneratorRuntime.wrap(function (_context3) {
3302
+ while (1) switch (_context3.prev = _context3.next) {
3303
+ case 0:
3304
+ _context3.next = 1;
3305
+ return getSessionAdminRow(supabase, sessionId);
3306
+ case 1:
3307
+ row = _context3.sent;
3308
+ if (row) {
3309
+ _context3.next = 2;
3310
+ break;
3311
+ }
3312
+ return _context3.abrupt("return", false);
3313
+ case 2:
3314
+ return _context3.abrupt("return", row.user_id === userId);
3315
+ case 3:
3316
+ case "end":
3317
+ return _context3.stop();
3318
+ }
3319
+ }, _callee3);
3320
+ }));
3321
+ return _isUserSessionAdmin.apply(this, arguments);
3322
+ }
3323
+
3324
+ function _createForOfIteratorHelper$1(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray$2(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
3325
+ function _unsupportedIterableToArray$2(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray$2(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray$2(r, a) : void 0; } }
3326
+ function _arrayLikeToArray$2(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
3327
+ var RESERVED_STATUS_FIELD = "status";
3328
+ var PUBLISH_STATUS_VALUES = new Set(["draft", "published"]);
2687
3329
  // 初始化Supabase连接和CMS系统
2688
3330
  function initializeSystem() {
2689
3331
  return _initializeSystem.apply(this, arguments);
2690
- } // GET - 获取所有模型
3332
+ }
2691
3333
  function _initializeSystem() {
2692
3334
  _initializeSystem = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
2693
3335
  var _t;
@@ -2718,13 +3360,72 @@ function _initializeSystem() {
2718
3360
  }));
2719
3361
  return _initializeSystem.apply(this, arguments);
2720
3362
  }
3363
+ function validateReservedFields(jsonSchema) {
3364
+ if (!(jsonSchema !== null && jsonSchema !== void 0 && jsonSchema.fields) || !Array.isArray(jsonSchema.fields)) {
3365
+ return "json_schema 必须包含 fields 数组";
3366
+ }
3367
+ var _iterator = _createForOfIteratorHelper$1(jsonSchema.fields),
3368
+ _step;
3369
+ try {
3370
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
3371
+ var field = _step.value;
3372
+ if ((field === null || field === void 0 ? void 0 : field.name) !== RESERVED_STATUS_FIELD) {
3373
+ continue;
3374
+ }
3375
+ if (field.type !== "string") {
3376
+ return '字段 "status" 是保留字段,类型必须为 string。若这是业务状态,请改名为 category_status、order_status 等更具体的字段名。';
3377
+ }
3378
+ var configuredValues = new Set();
3379
+ if (field.defaultValue !== undefined && field.defaultValue !== null) {
3380
+ configuredValues.add(String(field.defaultValue));
3381
+ }
3382
+ if (Array.isArray(field["enum"])) {
3383
+ var _iterator2 = _createForOfIteratorHelper$1(field["enum"]),
3384
+ _step2;
3385
+ try {
3386
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
3387
+ var enumValue = _step2.value;
3388
+ configuredValues.add(String(enumValue));
3389
+ }
3390
+ } catch (err) {
3391
+ _iterator2.e(err);
3392
+ } finally {
3393
+ _iterator2.f();
3394
+ }
3395
+ }
3396
+ if (configuredValues.size === 0) {
3397
+ return '字段 "status" 是保留发布状态字段。请显式将其配置为 draft/published;如果你需要业务状态,请改名为 category_status、order_status、user_status 等。';
3398
+ }
3399
+ var _iterator3 = _createForOfIteratorHelper$1(configuredValues),
3400
+ _step3;
3401
+ try {
3402
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
3403
+ var value = _step3.value;
3404
+ if (!PUBLISH_STATUS_VALUES.has(value)) {
3405
+ return "\u5B57\u6BB5 \"status\" \u4EC5\u5141\u8BB8\u8868\u793A\u53D1\u5E03\u72B6\u6001\uFF0C\u652F\u6301\u7684\u503C\u53EA\u6709 draft/published\u3002\u68C0\u6D4B\u5230\u975E\u6CD5\u503C \"".concat(value, "\"\u3002\u5982\u679C\u8FD9\u662F\u4E1A\u52A1\u72B6\u6001\uFF0C\u8BF7\u6539\u540D\u4E3A category_status\u3001order_status\u3001user_status \u7B49\u3002");
3406
+ }
3407
+ }
3408
+ } catch (err) {
3409
+ _iterator3.e(err);
3410
+ } finally {
3411
+ _iterator3.f();
3412
+ }
3413
+ }
3414
+ } catch (err) {
3415
+ _iterator.e(err);
3416
+ } finally {
3417
+ _iterator.f();
3418
+ }
3419
+ return null;
3420
+ }
3421
+ // GET - 获取所有模型
2721
3422
  function getModels(_x) {
2722
3423
  return _getModels.apply(this, arguments);
2723
3424
  }
2724
3425
  // POST - 创建新模型
2725
3426
  function _getModels() {
2726
3427
  _getModels = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(c) {
2727
- var cmsModelService, page, limit, name, models, total, offset, paginatedModels, response, _response, _t2;
3428
+ var cmsModelService, page, limit, name, sessionId, models, tablePrefix, total, offset, paginatedModels, response, _response, _t2;
2728
3429
  return _regeneratorRuntime.wrap(function (_context2) {
2729
3430
  while (1) switch (_context2.prev = _context2.next) {
2730
3431
  case 0:
@@ -2735,11 +3436,19 @@ function _getModels() {
2735
3436
  cmsModelService = getCmsModelService();
2736
3437
  page = parseInt(c.req.query("page") || "1");
2737
3438
  limit = parseInt(c.req.query("limit") || "10");
2738
- name = c.req.query("name"); // 获取所有模型
3439
+ name = c.req.query("name"); // 获取当前请求的 session_id
3440
+ sessionId = normalizeSessionId(c.req.header("X-Session-Id") || c.req.header("x-session-id")); // 获取所有模型
2739
3441
  _context2.next = 2;
2740
3442
  return cmsModelService.findAll();
2741
3443
  case 2:
2742
3444
  models = _context2.sent;
3445
+ // 根据 session_id 过滤模型(只返回属于当前 session 的表)
3446
+ if (sessionId) {
3447
+ tablePrefix = sessionId + "_";
3448
+ models = models.filter(function (model) {
3449
+ return model.table_name.startsWith(tablePrefix);
3450
+ });
3451
+ }
2743
3452
  // 如果有名称过滤
2744
3453
  if (name) {
2745
3454
  models = models.filter(function (model) {
@@ -2787,7 +3496,7 @@ function createModel(_x2) {
2787
3496
  // PUT - 更新模型
2788
3497
  function _createModel() {
2789
3498
  _createModel = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(c) {
2790
- var cmsModelService, dynamicTableService, body, name, table_name, json_schema, _response2, _response3, existingModel, _response4, allModels, nameExists, _response5, tableExists, _response6, tableCreated, _response7, newModel, response, _response8, _t3;
3499
+ var cmsModelService, dynamicTableService, body, name, table_name, json_schema, _response2, schemaValidationError, _response3, existingModel, _response4, allModels, nameExists, _response5, tableExists, _response6, tableCreated, _response7, newModel, response, _response8, _t3;
2791
3500
  return _regeneratorRuntime.wrap(function (_context3) {
2792
3501
  while (1) switch (_context3.prev = _context3.next) {
2793
3502
  case 0:
@@ -2812,13 +3521,15 @@ function _createModel() {
2812
3521
  };
2813
3522
  return _context3.abrupt("return", c.json(_response2, 200));
2814
3523
  case 3:
2815
- if (!(!json_schema.fields || !Array.isArray(json_schema.fields))) {
3524
+ // 验证 JSON 模式格式和保留字段规则
3525
+ schemaValidationError = validateReservedFields(json_schema);
3526
+ if (!schemaValidationError) {
2816
3527
  _context3.next = 4;
2817
3528
  break;
2818
3529
  }
2819
3530
  _response3 = {
2820
3531
  success: false,
2821
- message: "json_schema 必须包含 fields 数组"
3532
+ message: schemaValidationError
2822
3533
  };
2823
3534
  return _context3.abrupt("return", c.json(_response3, 200));
2824
3535
  case 4:
@@ -2919,7 +3630,7 @@ function updateModel(_x3) {
2919
3630
  // DELETE - 删除模型
2920
3631
  function _updateModel() {
2921
3632
  _updateModel = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(c) {
2922
- var cmsModelService, body, id, name, json_schema, _response9, model, _response0, updateData, updatedModel, response, _response1, _t4;
3633
+ var cmsModelService, body, id, name, json_schema, _response9, model, _response0, schemaValidationError, _response1, updateData, updatedModel, response, _response10, _t4;
2923
3634
  return _regeneratorRuntime.wrap(function (_context4) {
2924
3635
  while (1) switch (_context4.prev = _context4.next) {
2925
3636
  case 0:
@@ -2957,13 +3668,28 @@ function _updateModel() {
2957
3668
  };
2958
3669
  return _context4.abrupt("return", c.json(_response0, 200));
2959
3670
  case 5:
3671
+ if (!json_schema) {
3672
+ _context4.next = 6;
3673
+ break;
3674
+ }
3675
+ schemaValidationError = validateReservedFields(json_schema);
3676
+ if (!schemaValidationError) {
3677
+ _context4.next = 6;
3678
+ break;
3679
+ }
3680
+ _response1 = {
3681
+ success: false,
3682
+ message: schemaValidationError
3683
+ };
3684
+ return _context4.abrupt("return", c.json(_response1, 200));
3685
+ case 6:
2960
3686
  // 更新模型信息(不允许修改表名)
2961
3687
  updateData = {};
2962
3688
  if (name) updateData.name = name;
2963
3689
  if (json_schema) updateData.json_schema = json_schema;
2964
- _context4.next = 6;
3690
+ _context4.next = 7;
2965
3691
  return cmsModelService.update(id, updateData);
2966
- case 6:
3692
+ case 7:
2967
3693
  updatedModel = _context4.sent;
2968
3694
  response = {
2969
3695
  success: true,
@@ -2971,21 +3697,21 @@ function _updateModel() {
2971
3697
  data: updatedModel
2972
3698
  };
2973
3699
  return _context4.abrupt("return", c.json(response));
2974
- case 7:
2975
- _context4.prev = 7;
3700
+ case 8:
3701
+ _context4.prev = 8;
2976
3702
  _t4 = _context4["catch"](0);
2977
3703
  console.error("更新模型失败:", _t4);
2978
- _response1 = {
3704
+ _response10 = {
2979
3705
  success: false,
2980
3706
  message: "更新模型失败",
2981
3707
  error: _t4 instanceof Error ? _t4.message : "未知错误"
2982
3708
  };
2983
- return _context4.abrupt("return", c.json(_response1, 500));
2984
- case 8:
3709
+ return _context4.abrupt("return", c.json(_response10, 500));
3710
+ case 9:
2985
3711
  case "end":
2986
3712
  return _context4.stop();
2987
3713
  }
2988
- }, _callee4, null, [[0, 7]]);
3714
+ }, _callee4, null, [[0, 8]]);
2989
3715
  }));
2990
3716
  return _updateModel.apply(this, arguments);
2991
3717
  }
@@ -2994,7 +3720,7 @@ function deleteModel(_x4) {
2994
3720
  }
2995
3721
  function _deleteModel() {
2996
3722
  _deleteModel = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(c) {
2997
- var cmsModelService, dynamicTableService, idStr, _response10, id, model, _response11, tableDropped, _response12, response, _response13, _t5;
3723
+ var cmsModelService, dynamicTableService, idStr, _response11, id, model, _response12, tableDropped, _response13, response, _response14, _t5;
2998
3724
  return _regeneratorRuntime.wrap(function (_context5) {
2999
3725
  while (1) switch (_context5.prev = _context5.next) {
3000
3726
  case 0:
@@ -3009,11 +3735,11 @@ function _deleteModel() {
3009
3735
  _context5.next = 2;
3010
3736
  break;
3011
3737
  }
3012
- _response10 = {
3738
+ _response11 = {
3013
3739
  success: false,
3014
3740
  message: "缺少模型 ID"
3015
3741
  };
3016
- return _context5.abrupt("return", c.json(_response10, 200));
3742
+ return _context5.abrupt("return", c.json(_response11, 200));
3017
3743
  case 2:
3018
3744
  id = parseInt(idStr);
3019
3745
  _context5.next = 3;
@@ -3024,11 +3750,11 @@ function _deleteModel() {
3024
3750
  _context5.next = 4;
3025
3751
  break;
3026
3752
  }
3027
- _response11 = {
3753
+ _response12 = {
3028
3754
  success: false,
3029
3755
  message: "模型不存在"
3030
3756
  };
3031
- return _context5.abrupt("return", c.json(_response11, 200));
3757
+ return _context5.abrupt("return", c.json(_response12, 200));
3032
3758
  case 4:
3033
3759
  _context5.next = 5;
3034
3760
  return dynamicTableService.dropTable(model.table_name);
@@ -3038,11 +3764,11 @@ function _deleteModel() {
3038
3764
  _context5.next = 6;
3039
3765
  break;
3040
3766
  }
3041
- _response12 = {
3767
+ _response13 = {
3042
3768
  success: false,
3043
3769
  message: "删除数据表失败"
3044
3770
  };
3045
- return _context5.abrupt("return", c.json(_response12, 200));
3771
+ return _context5.abrupt("return", c.json(_response13, 200));
3046
3772
  case 6:
3047
3773
  _context5.next = 7;
3048
3774
  return cmsModelService["delete"](id);
@@ -3056,12 +3782,12 @@ function _deleteModel() {
3056
3782
  _context5.prev = 8;
3057
3783
  _t5 = _context5["catch"](0);
3058
3784
  console.error("删除模型失败:", _t5);
3059
- _response13 = {
3785
+ _response14 = {
3060
3786
  success: false,
3061
3787
  message: "删除模型失败",
3062
3788
  error: _t5 instanceof Error ? _t5.message : "未知错误"
3063
3789
  };
3064
- return _context5.abrupt("return", c.json(_response13, 500));
3790
+ return _context5.abrupt("return", c.json(_response14, 500));
3065
3791
  case 9:
3066
3792
  case "end":
3067
3793
  return _context5.stop();
@@ -3071,28 +3797,6 @@ function _deleteModel() {
3071
3797
  return _deleteModel.apply(this, arguments);
3072
3798
  }
3073
3799
 
3074
- function _objectWithoutPropertiesLoose(r, e) {
3075
- if (null == r) return {};
3076
- var t = {};
3077
- for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
3078
- if (-1 !== e.indexOf(n)) continue;
3079
- t[n] = r[n];
3080
- }
3081
- return t;
3082
- }
3083
-
3084
- function _objectWithoutProperties(e, t) {
3085
- if (null == e) return {};
3086
- var o,
3087
- r,
3088
- i = _objectWithoutPropertiesLoose(e, t);
3089
- if (Object.getOwnPropertySymbols) {
3090
- var n = Object.getOwnPropertySymbols(e);
3091
- for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
3092
- }
3093
- return i;
3094
- }
3095
-
3096
3800
  function _arrayWithHoles(r) {
3097
3801
  if (Array.isArray(r)) return r;
3098
3802
  }
@@ -4199,130 +4903,6 @@ var AuthUtils = /*#__PURE__*/function () {
4199
4903
  }]);
4200
4904
  }();
4201
4905
 
4202
- var ADMIN_REGISTRY_TABLE = "_cms_admin_registry";
4203
- var ensured = false;
4204
- function normalizeSessionId(sessionId) {
4205
- // 统一将连字符转换为下划线,确保 UUID 格式一致性
4206
- // 例如:1047aab4-eecb-4538-ad8d-b5847e762f30 和 1047aab4_eecb_4538_ad8d_b5847e762f30 被视为相同
4207
- return (sessionId || "").trim().replace(/-/g, "_");
4208
- }
4209
- /**
4210
- * 从前端传来的 auth tableName 中提取 session_id
4211
- * 约定:auth tableName 形如 `${sessionId}_cms_users`;无前缀则为 `cms_users`
4212
- */
4213
- function extractSessionIdFromAuthTableName(tableName) {
4214
- var name = (tableName || "").trim();
4215
- if (!name) return "";
4216
- if (name === "cms_users") return "";
4217
- if (name.endsWith("_cms_users")) return name.slice(0, -"_cms_users".length);
4218
- // 兼容:如果传入的不是 cms_users,也允许把最后一个 "_cms_users" 前缀当作 session
4219
- var idx = name.lastIndexOf("_cms_users");
4220
- if (idx > 0) return name.slice(0, idx);
4221
- return "";
4222
- }
4223
- function ensureAdminRegistryTable(_x) {
4224
- return _ensureAdminRegistryTable.apply(this, arguments);
4225
- }
4226
- function _ensureAdminRegistryTable() {
4227
- _ensureAdminRegistryTable = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(supabase) {
4228
- var _yield$supabase$from$, error;
4229
- return _regeneratorRuntime.wrap(function (_context) {
4230
- while (1) switch (_context.prev = _context.next) {
4231
- case 0:
4232
- if (!ensured) {
4233
- _context.next = 1;
4234
- break;
4235
- }
4236
- return _context.abrupt("return", true);
4237
- case 1:
4238
- _context.prev = 1;
4239
- _context.next = 2;
4240
- return supabase.from(ADMIN_REGISTRY_TABLE).select("session_id").limit(1);
4241
- case 2:
4242
- _yield$supabase$from$ = _context.sent;
4243
- error = _yield$supabase$from$.error;
4244
- if (error) {
4245
- _context.next = 3;
4246
- break;
4247
- }
4248
- ensured = true;
4249
- return _context.abrupt("return", true);
4250
- case 3:
4251
- _context.next = 5;
4252
- break;
4253
- case 4:
4254
- _context.prev = 4;
4255
- _context["catch"](1);
4256
- case 5:
4257
- return _context.abrupt("return", false);
4258
- case 6:
4259
- case "end":
4260
- return _context.stop();
4261
- }
4262
- }, _callee, null, [[1, 4]]);
4263
- }));
4264
- return _ensureAdminRegistryTable.apply(this, arguments);
4265
- }
4266
- function getSessionAdminRow(_x2, _x3) {
4267
- return _getSessionAdminRow.apply(this, arguments);
4268
- }
4269
- function _getSessionAdminRow() {
4270
- _getSessionAdminRow = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(supabase, sessionId) {
4271
- var sid, _yield$supabase$from$2, data, error;
4272
- return _regeneratorRuntime.wrap(function (_context2) {
4273
- while (1) switch (_context2.prev = _context2.next) {
4274
- case 0:
4275
- sid = normalizeSessionId(sessionId);
4276
- _context2.next = 1;
4277
- return supabase.from(ADMIN_REGISTRY_TABLE).select("session_id,user_id,email").eq("session_id", sid).maybeSingle();
4278
- case 1:
4279
- _yield$supabase$from$2 = _context2.sent;
4280
- data = _yield$supabase$from$2.data;
4281
- error = _yield$supabase$from$2.error;
4282
- if (!(error || !data)) {
4283
- _context2.next = 2;
4284
- break;
4285
- }
4286
- return _context2.abrupt("return", null);
4287
- case 2:
4288
- return _context2.abrupt("return", data);
4289
- case 3:
4290
- case "end":
4291
- return _context2.stop();
4292
- }
4293
- }, _callee2);
4294
- }));
4295
- return _getSessionAdminRow.apply(this, arguments);
4296
- }
4297
- function isUserSessionAdmin(_x4, _x5, _x6) {
4298
- return _isUserSessionAdmin.apply(this, arguments);
4299
- }
4300
- function _isUserSessionAdmin() {
4301
- _isUserSessionAdmin = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(supabase, sessionId, userId) {
4302
- var row;
4303
- return _regeneratorRuntime.wrap(function (_context3) {
4304
- while (1) switch (_context3.prev = _context3.next) {
4305
- case 0:
4306
- _context3.next = 1;
4307
- return getSessionAdminRow(supabase, sessionId);
4308
- case 1:
4309
- row = _context3.sent;
4310
- if (row) {
4311
- _context3.next = 2;
4312
- break;
4313
- }
4314
- return _context3.abrupt("return", false);
4315
- case 2:
4316
- return _context3.abrupt("return", row.user_id === userId);
4317
- case 3:
4318
- case "end":
4319
- return _context3.stop();
4320
- }
4321
- }, _callee3);
4322
- }));
4323
- return _isUserSessionAdmin.apply(this, arguments);
4324
- }
4325
-
4326
4906
  function getRoleFromSupabaseUser$2(user) {
4327
4907
  var _user$app_metadata, _user$user_metadata;
4328
4908
  var appRole = user === null || user === void 0 || (_user$app_metadata = user.app_metadata) === null || _user$app_metadata === void 0 ? void 0 : _user$app_metadata.role;
@@ -4938,6 +5518,81 @@ function requireAuth(handler) {
4938
5518
  }();
4939
5519
  }
4940
5520
 
5521
+ function readTextField(formData, fieldName) {
5522
+ var value = formData.get(fieldName);
5523
+ return typeof value === "string" ? value.trim() : "";
5524
+ }
5525
+ function isFileLike(value) {
5526
+ return !!value && typeof value !== "string" && typeof value.arrayBuffer === "function";
5527
+ }
5528
+ function uploadToOss(_x) {
5529
+ return _uploadToOss.apply(this, arguments);
5530
+ }
5531
+ function _uploadToOss() {
5532
+ _uploadToOss = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(c) {
5533
+ var formData, file, uploadService, result, status, _t, _t2, _t3, _t4, _t5, _t6;
5534
+ return _regeneratorRuntime.wrap(function (_context) {
5535
+ while (1) switch (_context.prev = _context.next) {
5536
+ case 0:
5537
+ _context.prev = 0;
5538
+ _context.next = 1;
5539
+ return c.req.raw.formData();
5540
+ case 1:
5541
+ formData = _context.sent;
5542
+ file = formData.get("file");
5543
+ if (isFileLike(file)) {
5544
+ _context.next = 2;
5545
+ break;
5546
+ }
5547
+ return _context.abrupt("return", c.json({
5548
+ success: false,
5549
+ message: "Missing file in multipart request"
5550
+ }, 400));
5551
+ case 2:
5552
+ uploadService = getOssUploadService();
5553
+ _t = uploadService;
5554
+ _context.next = 3;
5555
+ return file.arrayBuffer();
5556
+ case 3:
5557
+ _t2 = _context.sent;
5558
+ _t3 = file.type || "application/octet-stream";
5559
+ _t4 = readTextField(formData, "directory");
5560
+ _t5 = file.name || "upload.bin";
5561
+ _context.next = 4;
5562
+ return _t.upload.call(_t, {
5563
+ buffer: _t2,
5564
+ contentType: _t3,
5565
+ directory: _t4,
5566
+ originalName: _t5
5567
+ });
5568
+ case 4:
5569
+ result = _context.sent;
5570
+ return _context.abrupt("return", c.json({
5571
+ success: true,
5572
+ url: result.url,
5573
+ signedUrl: result.signedUrl,
5574
+ objectKey: result.objectKey,
5575
+ fieldName: readTextField(formData, "fieldName"),
5576
+ tableName: readTextField(formData, "tableName")
5577
+ }, 200));
5578
+ case 5:
5579
+ _context.prev = 5;
5580
+ _t6 = _context["catch"](0);
5581
+ status = _t6 instanceof OssUploadError ? _t6.status : 500;
5582
+ return _context.abrupt("return", c.json({
5583
+ success: false,
5584
+ message: "Upload failed",
5585
+ error: _t6 instanceof Error ? _t6.message : "Unknown upload error"
5586
+ }, status));
5587
+ case 6:
5588
+ case "end":
5589
+ return _context.stop();
5590
+ }
5591
+ }, _callee, null, [[0, 5]]);
5592
+ }));
5593
+ return _uploadToOss.apply(this, arguments);
5594
+ }
5595
+
4941
5596
  function getRoleFromSupabaseUser$1(user) {
4942
5597
  var _user$app_metadata, _user$user_metadata;
4943
5598
  var appRole = user === null || user === void 0 || (_user$app_metadata = user.app_metadata) === null || _user$app_metadata === void 0 ? void 0 : _user$app_metadata.role;
@@ -5418,6 +6073,10 @@ function createAuthRoute(app, tableName) {
5418
6073
  });
5419
6074
  return app;
5420
6075
  }
6076
+ function createOssUploadRoute(app) {
6077
+ app.post("/upload", requireJwtAuth, requireAdminRole, uploadToOss);
6078
+ return app;
6079
+ }
5421
6080
  // 一键创建所有CMS路由
5422
6081
  function createCmsRoutes(app) {
5423
6082
  createModelRoute(app);
@@ -5426,5 +6085,5 @@ function createCmsRoutes(app) {
5426
6085
  return app;
5427
6086
  }
5428
6087
 
5429
- export { AuthService, getCmsModelService as CmsModel, CmsModelService, DynamicTableService, closeSupabase as closeDatabase, closeSupabase, createAuthRoute, createCmsRoutes, createDataRoute, createDynamicAuthRoute, createDynamicDataRoute, createModel, createModelRoute, createTableData, deleteModel, deleteTableData, dropForeignKeys, executeSupabaseSetup, getAuthService, getCmsModelService, getCurrentUser, getSupabase as getDatabase, getDynamicTableService, getModels, getRelationOptions, getSupabase, getSupabaseSetupSQL, getTableData, getTableDataWithRelations, initializeCmsModel, initializeCmsSystem, initializeSupabase as initializeDatabase, initializeSupabase, login, requireAuth, signup, signupStatus, initializeCmsSystem as syncDatabase, testConnection, updateModel, updateTableData, verifyAuth };
6088
+ export { AuthService, getCmsModelService as CmsModel, CmsModelService, DynamicTableService, OssUploadError, OssUploadService, closeSupabase as closeDatabase, closeSupabase, createAuthRoute, createCmsRoutes, createDataRoute, createDynamicAuthRoute, createDynamicDataRoute, createModel, createModelRoute, createOssUploadRoute, createTableData, deleteModel, deleteTableData, dropForeignKeys, executeSupabaseSetup, getAuthService, getCmsModelService, getCurrentUser, getSupabase as getDatabase, getDynamicTableService, getModels, getOssUploadService, getRelationOptions, getSupabase, getSupabaseSetupSQL, getTableData, getTableDataWithRelations, initializeCmsModel, initializeCmsSystem, initializeSupabase as initializeDatabase, initializeOssUpload, initializeSupabase, login, requireAuth, signup, signupStatus, initializeCmsSystem as syncDatabase, testConnection, updateModel, updateTableData, uploadToOss, verifyAuth };
5430
6089
  //# sourceMappingURL=index.esm.js.map