@wecode-team/cms-supabase-api 0.1.34 → 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,6 +2684,519 @@ 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
+
2687
3200
  var ADMIN_REGISTRY_TABLE = "_cms_admin_registry";
2688
3201
  var ensured = false;
2689
3202
  function normalizeSessionId(sessionId) {
@@ -2808,10 +3321,15 @@ function _isUserSessionAdmin() {
2808
3321
  return _isUserSessionAdmin.apply(this, arguments);
2809
3322
  }
2810
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"]);
2811
3329
  // 初始化Supabase连接和CMS系统
2812
3330
  function initializeSystem() {
2813
3331
  return _initializeSystem.apply(this, arguments);
2814
- } // GET - 获取所有模型
3332
+ }
2815
3333
  function _initializeSystem() {
2816
3334
  _initializeSystem = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
2817
3335
  var _t;
@@ -2842,6 +3360,65 @@ function _initializeSystem() {
2842
3360
  }));
2843
3361
  return _initializeSystem.apply(this, arguments);
2844
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 - 获取所有模型
2845
3422
  function getModels(_x) {
2846
3423
  return _getModels.apply(this, arguments);
2847
3424
  }
@@ -2919,7 +3496,7 @@ function createModel(_x2) {
2919
3496
  // PUT - 更新模型
2920
3497
  function _createModel() {
2921
3498
  _createModel = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(c) {
2922
- 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;
2923
3500
  return _regeneratorRuntime.wrap(function (_context3) {
2924
3501
  while (1) switch (_context3.prev = _context3.next) {
2925
3502
  case 0:
@@ -2944,13 +3521,15 @@ function _createModel() {
2944
3521
  };
2945
3522
  return _context3.abrupt("return", c.json(_response2, 200));
2946
3523
  case 3:
2947
- if (!(!json_schema.fields || !Array.isArray(json_schema.fields))) {
3524
+ // 验证 JSON 模式格式和保留字段规则
3525
+ schemaValidationError = validateReservedFields(json_schema);
3526
+ if (!schemaValidationError) {
2948
3527
  _context3.next = 4;
2949
3528
  break;
2950
3529
  }
2951
3530
  _response3 = {
2952
3531
  success: false,
2953
- message: "json_schema 必须包含 fields 数组"
3532
+ message: schemaValidationError
2954
3533
  };
2955
3534
  return _context3.abrupt("return", c.json(_response3, 200));
2956
3535
  case 4:
@@ -3051,7 +3630,7 @@ function updateModel(_x3) {
3051
3630
  // DELETE - 删除模型
3052
3631
  function _updateModel() {
3053
3632
  _updateModel = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(c) {
3054
- 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;
3055
3634
  return _regeneratorRuntime.wrap(function (_context4) {
3056
3635
  while (1) switch (_context4.prev = _context4.next) {
3057
3636
  case 0:
@@ -3089,13 +3668,28 @@ function _updateModel() {
3089
3668
  };
3090
3669
  return _context4.abrupt("return", c.json(_response0, 200));
3091
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:
3092
3686
  // 更新模型信息(不允许修改表名)
3093
3687
  updateData = {};
3094
3688
  if (name) updateData.name = name;
3095
3689
  if (json_schema) updateData.json_schema = json_schema;
3096
- _context4.next = 6;
3690
+ _context4.next = 7;
3097
3691
  return cmsModelService.update(id, updateData);
3098
- case 6:
3692
+ case 7:
3099
3693
  updatedModel = _context4.sent;
3100
3694
  response = {
3101
3695
  success: true,
@@ -3103,21 +3697,21 @@ function _updateModel() {
3103
3697
  data: updatedModel
3104
3698
  };
3105
3699
  return _context4.abrupt("return", c.json(response));
3106
- case 7:
3107
- _context4.prev = 7;
3700
+ case 8:
3701
+ _context4.prev = 8;
3108
3702
  _t4 = _context4["catch"](0);
3109
3703
  console.error("更新模型失败:", _t4);
3110
- _response1 = {
3704
+ _response10 = {
3111
3705
  success: false,
3112
3706
  message: "更新模型失败",
3113
3707
  error: _t4 instanceof Error ? _t4.message : "未知错误"
3114
3708
  };
3115
- return _context4.abrupt("return", c.json(_response1, 500));
3116
- case 8:
3709
+ return _context4.abrupt("return", c.json(_response10, 500));
3710
+ case 9:
3117
3711
  case "end":
3118
3712
  return _context4.stop();
3119
3713
  }
3120
- }, _callee4, null, [[0, 7]]);
3714
+ }, _callee4, null, [[0, 8]]);
3121
3715
  }));
3122
3716
  return _updateModel.apply(this, arguments);
3123
3717
  }
@@ -3126,7 +3720,7 @@ function deleteModel(_x4) {
3126
3720
  }
3127
3721
  function _deleteModel() {
3128
3722
  _deleteModel = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(c) {
3129
- 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;
3130
3724
  return _regeneratorRuntime.wrap(function (_context5) {
3131
3725
  while (1) switch (_context5.prev = _context5.next) {
3132
3726
  case 0:
@@ -3141,11 +3735,11 @@ function _deleteModel() {
3141
3735
  _context5.next = 2;
3142
3736
  break;
3143
3737
  }
3144
- _response10 = {
3738
+ _response11 = {
3145
3739
  success: false,
3146
3740
  message: "缺少模型 ID"
3147
3741
  };
3148
- return _context5.abrupt("return", c.json(_response10, 200));
3742
+ return _context5.abrupt("return", c.json(_response11, 200));
3149
3743
  case 2:
3150
3744
  id = parseInt(idStr);
3151
3745
  _context5.next = 3;
@@ -3156,11 +3750,11 @@ function _deleteModel() {
3156
3750
  _context5.next = 4;
3157
3751
  break;
3158
3752
  }
3159
- _response11 = {
3753
+ _response12 = {
3160
3754
  success: false,
3161
3755
  message: "模型不存在"
3162
3756
  };
3163
- return _context5.abrupt("return", c.json(_response11, 200));
3757
+ return _context5.abrupt("return", c.json(_response12, 200));
3164
3758
  case 4:
3165
3759
  _context5.next = 5;
3166
3760
  return dynamicTableService.dropTable(model.table_name);
@@ -3170,11 +3764,11 @@ function _deleteModel() {
3170
3764
  _context5.next = 6;
3171
3765
  break;
3172
3766
  }
3173
- _response12 = {
3767
+ _response13 = {
3174
3768
  success: false,
3175
3769
  message: "删除数据表失败"
3176
3770
  };
3177
- return _context5.abrupt("return", c.json(_response12, 200));
3771
+ return _context5.abrupt("return", c.json(_response13, 200));
3178
3772
  case 6:
3179
3773
  _context5.next = 7;
3180
3774
  return cmsModelService["delete"](id);
@@ -3188,12 +3782,12 @@ function _deleteModel() {
3188
3782
  _context5.prev = 8;
3189
3783
  _t5 = _context5["catch"](0);
3190
3784
  console.error("删除模型失败:", _t5);
3191
- _response13 = {
3785
+ _response14 = {
3192
3786
  success: false,
3193
3787
  message: "删除模型失败",
3194
3788
  error: _t5 instanceof Error ? _t5.message : "未知错误"
3195
3789
  };
3196
- return _context5.abrupt("return", c.json(_response13, 500));
3790
+ return _context5.abrupt("return", c.json(_response14, 500));
3197
3791
  case 9:
3198
3792
  case "end":
3199
3793
  return _context5.stop();
@@ -3203,28 +3797,6 @@ function _deleteModel() {
3203
3797
  return _deleteModel.apply(this, arguments);
3204
3798
  }
3205
3799
 
3206
- function _objectWithoutPropertiesLoose(r, e) {
3207
- if (null == r) return {};
3208
- var t = {};
3209
- for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
3210
- if (-1 !== e.indexOf(n)) continue;
3211
- t[n] = r[n];
3212
- }
3213
- return t;
3214
- }
3215
-
3216
- function _objectWithoutProperties(e, t) {
3217
- if (null == e) return {};
3218
- var o,
3219
- r,
3220
- i = _objectWithoutPropertiesLoose(e, t);
3221
- if (Object.getOwnPropertySymbols) {
3222
- var n = Object.getOwnPropertySymbols(e);
3223
- for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
3224
- }
3225
- return i;
3226
- }
3227
-
3228
3800
  function _arrayWithHoles(r) {
3229
3801
  if (Array.isArray(r)) return r;
3230
3802
  }
@@ -4946,6 +5518,81 @@ function requireAuth(handler) {
4946
5518
  }();
4947
5519
  }
4948
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
+
4949
5596
  function getRoleFromSupabaseUser$1(user) {
4950
5597
  var _user$app_metadata, _user$user_metadata;
4951
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;
@@ -5426,6 +6073,10 @@ function createAuthRoute(app, tableName) {
5426
6073
  });
5427
6074
  return app;
5428
6075
  }
6076
+ function createOssUploadRoute(app) {
6077
+ app.post("/upload", requireJwtAuth, requireAdminRole, uploadToOss);
6078
+ return app;
6079
+ }
5429
6080
  // 一键创建所有CMS路由
5430
6081
  function createCmsRoutes(app) {
5431
6082
  createModelRoute(app);
@@ -5434,5 +6085,5 @@ function createCmsRoutes(app) {
5434
6085
  return app;
5435
6086
  }
5436
6087
 
5437
- 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 };
5438
6089
  //# sourceMappingURL=index.esm.js.map