@wecode-team/cms-supabase-api 0.1.47 → 0.1.48
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/config/feishu-alert.d.ts +4 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.esm.js +203 -251
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +205 -253
- package/dist/index.js.map +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/utils/feishu-alert.d.ts +13 -0
- package/dist/utils/route-helpers.d.ts +0 -1
- package/package.json +1 -1
- package/supabase-setup.sql +1 -26
- package/dist/handlers/analytics.d.ts +0 -11
- package/dist/handlers/configs.d.ts +0 -23
package/dist/index.js
CHANGED
|
@@ -695,6 +695,10 @@ function getSupabaseSetupSQL() {
|
|
|
695
695
|
return "-- Supabase Setup SQL for we0-cms-supabase-hono-api\n-- \u8BF7\u5728 Supabase SQL \u7F16\u8F91\u5668\u4E2D\u6267\u884C\u4EE5\u4E0B\u5B8C\u6574\u811A\u672C\n\n-- Function to execute SQL queries\nCREATE OR REPLACE FUNCTION execute_sql(sql_query text)\nRETURNS json\nLANGUAGE plpgsql\nSECURITY DEFINER\nAS $$\nDECLARE\n result json;\n row_count integer;\nBEGIN\n EXECUTE sql_query;\n GET DIAGNOSTICS row_count = ROW_COUNT;\n RETURN json_build_object('success', true, 'rows_affected', row_count);\nEXCEPTION\n WHEN OTHERS THEN\n RETURN json_build_object('success', false, 'error', SQLERRM);\nEND;\n$$;\n\n-- Function to execute SQL with parameters (simplified version)\nCREATE OR REPLACE FUNCTION execute_sql_with_params(sql_query text, params json)\nRETURNS json\nLANGUAGE plpgsql\nSECURITY DEFINER\nAS $$\nDECLARE\n result json;\n row_count integer;\nBEGIN\n -- Note: This is a simplified version for basic use cases\n -- In production, you might want more sophisticated parameter binding\n EXECUTE sql_query;\n GET DIAGNOSTICS row_count = ROW_COUNT;\n RETURN json_build_object('success', true, 'rows_affected', row_count);\nEXCEPTION\n WHEN OTHERS THEN\n RETURN json_build_object('success', false, 'error', SQLERRM);\nEND;\n$$;\n\n-- Function to check if table exists\nCREATE OR REPLACE FUNCTION check_table_exists(input_table_name text)\nRETURNS boolean\nLANGUAGE plpgsql\nSECURITY DEFINER\nAS $$\nBEGIN\n RETURN EXISTS (\n SELECT 1 FROM information_schema.tables\n WHERE table_schema = 'public' \n AND table_name = input_table_name\n );\nEND;\n$$;\n\n-- Function to get table structure\nCREATE OR REPLACE FUNCTION get_table_structure(table_name text)\nRETURNS json\nLANGUAGE plpgsql\nSECURITY DEFINER\nAS $$\nDECLARE\n result json;\nBEGIN\n SELECT json_agg(\n json_build_object(\n 'column_name', column_name,\n 'data_type', data_type,\n 'is_nullable', is_nullable,\n 'column_default', column_default,\n 'character_maximum_length', character_maximum_length\n )\n ) INTO result\n FROM information_schema.columns\n WHERE table_schema = 'public' AND table_name = $1\n ORDER BY ordinal_position;\n \n RETURN COALESCE(result, '[]'::json);\nEND;\n$$;\n\n-- Function to create CMS models table if not exists\nCREATE OR REPLACE FUNCTION create_cms_models_table_if_not_exists()\nRETURNS json\nLANGUAGE plpgsql\nSECURITY DEFINER\nAS $$\nBEGIN\n -- Create the CMS models table\n CREATE TABLE IF NOT EXISTS \"_cms_models\" (\n id SERIAL PRIMARY KEY,\n name VARCHAR(100) NOT NULL,\n table_name VARCHAR(100) NOT NULL UNIQUE,\n json_schema JSONB NOT NULL,\n created_at TIMESTAMPTZ DEFAULT NOW(),\n updated_at TIMESTAMPTZ DEFAULT NOW()\n );\n \n -- Create or replace the trigger function for updating timestamps\n CREATE OR REPLACE FUNCTION update_updated_at_column()\n RETURNS TRIGGER AS $trigger$\n BEGIN\n NEW.updated_at = NOW();\n RETURN NEW;\n END;\n $trigger$ language 'plpgsql';\n \n -- Drop existing trigger if it exists and create new one\n DROP TRIGGER IF EXISTS update_cms_models_updated_at ON \"_cms_models\";\n CREATE TRIGGER update_cms_models_updated_at\n BEFORE UPDATE ON \"_cms_models\"\n FOR EACH ROW\n EXECUTE FUNCTION update_updated_at_column();\n \n RETURN json_build_object('success', true, 'message', 'CMS models table created successfully');\nEXCEPTION\n WHEN OTHERS THEN\n RETURN json_build_object('success', false, 'error', SQLERRM);\nEND;\n$$;\n\n-- Initialize the CMS models table\nSELECT create_cms_models_table_if_not_exists();\n\n-- Grant necessary permissions (adjust as needed for your security requirements)\n-- Note: Be careful with these permissions in production\nGRANT USAGE ON SCHEMA public TO anon, authenticated;\nGRANT ALL ON ALL TABLES IN SCHEMA public TO anon, authenticated;\nGRANT ALL ON ALL SEQUENCES IN SCHEMA public TO anon, authenticated;\nGRANT ALL ON ALL FUNCTIONS IN SCHEMA public TO anon, authenticated;\n\n-- Create RLS policies for the CMS models table (optional, adjust as needed)\nALTER TABLE \"_cms_models\" ENABLE ROW LEVEL SECURITY;\n\n-- Allow all operations for all users (development environment)\nCREATE POLICY \"Allow all operations\" ON \"_cms_models\"\n FOR ALL USING (true);\n\nCOMMENT ON TABLE \"_cms_models\" IS 'CMS models configuration table for we0-cms-supabase-hono-api';\nCOMMENT ON FUNCTION execute_sql(text) IS 'Execute SQL queries for dynamic table management';\nCOMMENT ON FUNCTION check_table_exists(text) IS 'Check if a table exists in the public schema';\nCOMMENT ON FUNCTION get_table_structure(text) IS 'Get the structure of a table';";
|
|
696
696
|
}
|
|
697
697
|
|
|
698
|
+
var feishuAlertConfig = {
|
|
699
|
+
crudErrorWebhookUrls: ["https://open.feishu.cn/open-apis/bot/v2/hook/784e9470-c1fd-4e38-97a2-b9a1856c00b1"]
|
|
700
|
+
};
|
|
701
|
+
|
|
698
702
|
function _classCallCheck(a, n) {
|
|
699
703
|
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
|
|
700
704
|
}
|
|
@@ -1029,8 +1033,8 @@ function _defineProperty(e, r, t) {
|
|
|
1029
1033
|
}) : e[r] = t, e;
|
|
1030
1034
|
}
|
|
1031
1035
|
|
|
1032
|
-
function ownKeys$
|
|
1033
|
-
function _objectSpread$
|
|
1036
|
+
function ownKeys$4(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; }
|
|
1037
|
+
function _objectSpread$4(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$4(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$4(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
1034
1038
|
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; } } }; }
|
|
1035
1039
|
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; } }
|
|
1036
1040
|
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; }
|
|
@@ -1038,6 +1042,7 @@ function _arrayLikeToArray$3(r, a) { (null == a || a > r.length) && (a = r.lengt
|
|
|
1038
1042
|
var fieldTypeMapping = {
|
|
1039
1043
|
string: "text",
|
|
1040
1044
|
text: "text",
|
|
1045
|
+
richText: "text",
|
|
1041
1046
|
integer: "int4",
|
|
1042
1047
|
"float": "float8",
|
|
1043
1048
|
"boolean": "bool",
|
|
@@ -2085,7 +2090,7 @@ var DynamicTableService = /*#__PURE__*/function () {
|
|
|
2085
2090
|
throw error;
|
|
2086
2091
|
case 2:
|
|
2087
2092
|
return _context14.abrupt("return", (data || []).map(function (item) {
|
|
2088
|
-
return _objectSpread$
|
|
2093
|
+
return _objectSpread$4({
|
|
2089
2094
|
id: item.id,
|
|
2090
2095
|
label: item[displayField] || "ID: ".concat(item.id)
|
|
2091
2096
|
}, item);
|
|
@@ -2198,8 +2203,8 @@ function getDynamicTableService() {
|
|
|
2198
2203
|
return defaultService$1;
|
|
2199
2204
|
}
|
|
2200
2205
|
|
|
2201
|
-
function ownKeys$
|
|
2202
|
-
function _objectSpread$
|
|
2206
|
+
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; }
|
|
2207
|
+
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; }
|
|
2203
2208
|
var AuthService = /*#__PURE__*/function () {
|
|
2204
2209
|
function AuthService() {
|
|
2205
2210
|
_classCallCheck(this, AuthService);
|
|
@@ -2376,7 +2381,7 @@ var AuthService = /*#__PURE__*/function () {
|
|
|
2376
2381
|
return _regeneratorRuntime.wrap(function (_context4) {
|
|
2377
2382
|
while (1) switch (_context4.prev = _context4.next) {
|
|
2378
2383
|
case 0:
|
|
2379
|
-
finalUserData = _objectSpread$
|
|
2384
|
+
finalUserData = _objectSpread$3({
|
|
2380
2385
|
tableName: this.defaultTableName
|
|
2381
2386
|
}, userData);
|
|
2382
2387
|
_context4.prev = 1;
|
|
@@ -2434,7 +2439,7 @@ var AuthService = /*#__PURE__*/function () {
|
|
|
2434
2439
|
case 0:
|
|
2435
2440
|
updateData = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : {};
|
|
2436
2441
|
// 设置默认值
|
|
2437
|
-
finalUpdateData = _objectSpread$
|
|
2442
|
+
finalUpdateData = _objectSpread$3({
|
|
2438
2443
|
tableName: this.defaultTableName
|
|
2439
2444
|
}, updateData);
|
|
2440
2445
|
_context5.prev = 1;
|
|
@@ -2842,8 +2847,8 @@ function _toConsumableArray(r) {
|
|
|
2842
2847
|
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray$2(r) || _nonIterableSpread();
|
|
2843
2848
|
}
|
|
2844
2849
|
|
|
2845
|
-
function ownKeys$
|
|
2846
|
-
function _objectSpread$
|
|
2850
|
+
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; }
|
|
2851
|
+
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; }
|
|
2847
2852
|
function _callSuper$1(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct$1() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
2848
2853
|
function _isNativeReflectConstruct$1() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$1 = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
2849
2854
|
// src/error.ts
|
|
@@ -3371,7 +3376,7 @@ var DEFAULT_LIMITS = {
|
|
|
3371
3376
|
other: 10 * 1024 * 1024
|
|
3372
3377
|
};
|
|
3373
3378
|
function getSizeLimit(fileName, limits) {
|
|
3374
|
-
var merged = _objectSpread$
|
|
3379
|
+
var merged = _objectSpread$2(_objectSpread$2({}, DEFAULT_LIMITS), limits);
|
|
3375
3380
|
if (isImage(fileName)) return merged.image;
|
|
3376
3381
|
if (isVideo(fileName)) return merged.video;
|
|
3377
3382
|
return merged.other;
|
|
@@ -3399,7 +3404,7 @@ function _compressImageBlob() {
|
|
|
3399
3404
|
return _regeneratorRuntime.wrap(function (_context10) {
|
|
3400
3405
|
while (1) switch (_context10.prev = _context10.next) {
|
|
3401
3406
|
case 0:
|
|
3402
|
-
opts = _objectSpread$
|
|
3407
|
+
opts = _objectSpread$2(_objectSpread$2({}, DEFAULT_COMPRESS), options);
|
|
3403
3408
|
if (!(typeof createImageBitmap === "undefined" || typeof OffscreenCanvas === "undefined")) {
|
|
3404
3409
|
_context10.next = 1;
|
|
3405
3410
|
break;
|
|
@@ -3465,7 +3470,7 @@ function _processFile() {
|
|
|
3465
3470
|
return _regeneratorRuntime.wrap(function (_context11) {
|
|
3466
3471
|
while (1) switch (_context11.prev = _context11.next) {
|
|
3467
3472
|
case 0:
|
|
3468
|
-
opts = _objectSpread$
|
|
3473
|
+
opts = _objectSpread$2(_objectSpread$2({}, DEFAULT_COMPRESS), compress);
|
|
3469
3474
|
if (!(opts.enabled && isImage(fileName))) {
|
|
3470
3475
|
_context11.next = 2;
|
|
3471
3476
|
break;
|
|
@@ -3529,7 +3534,7 @@ function createOssClient() {
|
|
|
3529
3534
|
var allowedExtensions = options.allowedExtensions;
|
|
3530
3535
|
function mergeRetry(override) {
|
|
3531
3536
|
if (!defaultRetry && !override) return void 0;
|
|
3532
|
-
return _objectSpread$
|
|
3537
|
+
return _objectSpread$2(_objectSpread$2({}, defaultRetry), override);
|
|
3533
3538
|
}
|
|
3534
3539
|
function resolveCompress(override) {
|
|
3535
3540
|
if (override === false) return {
|
|
@@ -3539,7 +3544,7 @@ function createOssClient() {
|
|
|
3539
3544
|
enabled: false
|
|
3540
3545
|
};
|
|
3541
3546
|
var base = _typeof$1(defaultCompress) === "object" ? defaultCompress : {};
|
|
3542
|
-
return override ? _objectSpread$
|
|
3547
|
+
return override ? _objectSpread$2(_objectSpread$2({}, base), override) : Object.keys(base).length ? base : void 0;
|
|
3543
3548
|
}
|
|
3544
3549
|
function uploadOne(_x25, _x26, _x27, _x28) {
|
|
3545
3550
|
return _uploadOne.apply(this, arguments);
|
|
@@ -3625,7 +3630,7 @@ function createOssClient() {
|
|
|
3625
3630
|
var i = index++;
|
|
3626
3631
|
var item = files[i];
|
|
3627
3632
|
running++;
|
|
3628
|
-
var fileOpts = _objectSpread$
|
|
3633
|
+
var fileOpts = _objectSpread$2({
|
|
3629
3634
|
retry: opts === null || opts === void 0 ? void 0 : opts.retry,
|
|
3630
3635
|
compress: opts === null || opts === void 0 ? void 0 : opts.compress
|
|
3631
3636
|
}, item.options);
|
|
@@ -4070,6 +4075,141 @@ function _isUserSessionAdmin() {
|
|
|
4070
4075
|
return _isUserSessionAdmin.apply(this, arguments);
|
|
4071
4076
|
}
|
|
4072
4077
|
|
|
4078
|
+
var ACTION_LABELS = {
|
|
4079
|
+
create: "创建",
|
|
4080
|
+
read: "查询",
|
|
4081
|
+
update: "更新",
|
|
4082
|
+
"delete": "删除"
|
|
4083
|
+
};
|
|
4084
|
+
var TARGET_LABELS = {
|
|
4085
|
+
data: "数据",
|
|
4086
|
+
model: "模型"
|
|
4087
|
+
};
|
|
4088
|
+
function getWebhookUrls() {
|
|
4089
|
+
return feishuAlertConfig.crudErrorWebhookUrls.map(function (item) {
|
|
4090
|
+
return item.trim();
|
|
4091
|
+
}).filter(Boolean);
|
|
4092
|
+
}
|
|
4093
|
+
function getErrorMessage(error) {
|
|
4094
|
+
if (error instanceof Error) {
|
|
4095
|
+
return error.message;
|
|
4096
|
+
}
|
|
4097
|
+
return String(error);
|
|
4098
|
+
}
|
|
4099
|
+
function getErrorStack(error) {
|
|
4100
|
+
if (error instanceof Error) {
|
|
4101
|
+
return error.stack || "";
|
|
4102
|
+
}
|
|
4103
|
+
return "";
|
|
4104
|
+
}
|
|
4105
|
+
function buildRequestSummary(c) {
|
|
4106
|
+
var url = new URL(c.req.url);
|
|
4107
|
+
return ["method: ".concat(c.req.method), "path: ".concat(url.pathname), "query: ".concat(url.search || "-"), "userAgent: ".concat(c.req.header("user-agent") || "-")].join("\n");
|
|
4108
|
+
}
|
|
4109
|
+
function getSessionId(c) {
|
|
4110
|
+
return c.req.header("X-Session-Id") || c.req.header("x-session-id") || "-";
|
|
4111
|
+
}
|
|
4112
|
+
function buildAlertText(c, options) {
|
|
4113
|
+
var _options$modelId, _options$recordId;
|
|
4114
|
+
var actionLabel = ACTION_LABELS[options.action];
|
|
4115
|
+
var targetLabel = TARGET_LABELS[options.target];
|
|
4116
|
+
var lines = ["\u5305\u540D: @wecode-team/cms-supabase-api", "\u5BBF\u4E3B\u9879\u76EE\u6807\u8BC6(sessionId): ".concat(getSessionId(c)), "\u64CD\u4F5C\u5BF9\u8C61: ".concat(targetLabel), "\u64CD\u4F5C\u7C7B\u578B: ".concat(actionLabel), "\u6570\u636E\u8868\u540D: ".concat(options.tableName || "-"), "\u6A21\u578B ID: ".concat((_options$modelId = options.modelId) !== null && _options$modelId !== void 0 ? _options$modelId : "-"), "\u8BB0\u5F55 ID: ".concat((_options$recordId = options.recordId) !== null && _options$recordId !== void 0 ? _options$recordId : "-"), "\u65F6\u95F4: ".concat(new Date().toISOString()), "\u9519\u8BEF\u4FE1\u606F: ".concat(getErrorMessage(options.error)), "\u8BF7\u6C42\u4FE1\u606F:\n".concat(buildRequestSummary(c))];
|
|
4117
|
+
var stack = getErrorStack(options.error);
|
|
4118
|
+
if (stack) {
|
|
4119
|
+
lines.push("\u9519\u8BEF\u5806\u6808:\n".concat(stack));
|
|
4120
|
+
}
|
|
4121
|
+
return lines.join("\n\n");
|
|
4122
|
+
}
|
|
4123
|
+
function postWebhook(_x, _x2) {
|
|
4124
|
+
return _postWebhook.apply(this, arguments);
|
|
4125
|
+
}
|
|
4126
|
+
function _postWebhook() {
|
|
4127
|
+
_postWebhook = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(webhook, body) {
|
|
4128
|
+
var response;
|
|
4129
|
+
return _regeneratorRuntime.wrap(function (_context) {
|
|
4130
|
+
while (1) switch (_context.prev = _context.next) {
|
|
4131
|
+
case 0:
|
|
4132
|
+
_context.next = 1;
|
|
4133
|
+
return fetch(webhook, {
|
|
4134
|
+
method: "POST",
|
|
4135
|
+
headers: {
|
|
4136
|
+
"Content-Type": "application/json"
|
|
4137
|
+
},
|
|
4138
|
+
body: JSON.stringify(body)
|
|
4139
|
+
});
|
|
4140
|
+
case 1:
|
|
4141
|
+
response = _context.sent;
|
|
4142
|
+
if (response.ok) {
|
|
4143
|
+
_context.next = 2;
|
|
4144
|
+
break;
|
|
4145
|
+
}
|
|
4146
|
+
throw new Error("\u98DE\u4E66\u62A5\u8B66\u53D1\u9001\u5931\u8D25: ".concat(response.status, " ").concat(response.statusText));
|
|
4147
|
+
case 2:
|
|
4148
|
+
case "end":
|
|
4149
|
+
return _context.stop();
|
|
4150
|
+
}
|
|
4151
|
+
}, _callee);
|
|
4152
|
+
}));
|
|
4153
|
+
return _postWebhook.apply(this, arguments);
|
|
4154
|
+
}
|
|
4155
|
+
function notifyCmsCrudErrorToFeishu(_x3, _x4) {
|
|
4156
|
+
return _notifyCmsCrudErrorToFeishu.apply(this, arguments);
|
|
4157
|
+
}
|
|
4158
|
+
function _notifyCmsCrudErrorToFeishu() {
|
|
4159
|
+
_notifyCmsCrudErrorToFeishu = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(c, options) {
|
|
4160
|
+
var webhookUrls, body, results, failed;
|
|
4161
|
+
return _regeneratorRuntime.wrap(function (_context2) {
|
|
4162
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
4163
|
+
case 0:
|
|
4164
|
+
webhookUrls = getWebhookUrls();
|
|
4165
|
+
if (!(webhookUrls.length === 0)) {
|
|
4166
|
+
_context2.next = 1;
|
|
4167
|
+
break;
|
|
4168
|
+
}
|
|
4169
|
+
return _context2.abrupt("return");
|
|
4170
|
+
case 1:
|
|
4171
|
+
body = {
|
|
4172
|
+
msg_type: "post",
|
|
4173
|
+
content: {
|
|
4174
|
+
post: {
|
|
4175
|
+
zh_cn: {
|
|
4176
|
+
title: "[cms-supabase-api] ".concat(TARGET_LABELS[options.target]).concat(ACTION_LABELS[options.action], "\u5F02\u5E38"),
|
|
4177
|
+
content: [[{
|
|
4178
|
+
tag: "text",
|
|
4179
|
+
text: buildAlertText(c, options)
|
|
4180
|
+
}]]
|
|
4181
|
+
}
|
|
4182
|
+
}
|
|
4183
|
+
}
|
|
4184
|
+
};
|
|
4185
|
+
_context2.next = 2;
|
|
4186
|
+
return Promise.allSettled(webhookUrls.map(function (url) {
|
|
4187
|
+
return postWebhook(url, body);
|
|
4188
|
+
}));
|
|
4189
|
+
case 2:
|
|
4190
|
+
results = _context2.sent;
|
|
4191
|
+
failed = results.find(function (result) {
|
|
4192
|
+
return result.status === "rejected";
|
|
4193
|
+
});
|
|
4194
|
+
if (!((failed === null || failed === void 0 ? void 0 : failed.status) === "rejected")) {
|
|
4195
|
+
_context2.next = 3;
|
|
4196
|
+
break;
|
|
4197
|
+
}
|
|
4198
|
+
throw failed.reason;
|
|
4199
|
+
case 3:
|
|
4200
|
+
case "end":
|
|
4201
|
+
return _context2.stop();
|
|
4202
|
+
}
|
|
4203
|
+
}, _callee2);
|
|
4204
|
+
}));
|
|
4205
|
+
return _notifyCmsCrudErrorToFeishu.apply(this, arguments);
|
|
4206
|
+
}
|
|
4207
|
+
function reportCmsCrudErrorToFeishu(c, options) {
|
|
4208
|
+
void notifyCmsCrudErrorToFeishu(c, options)["catch"](function (feishuError) {
|
|
4209
|
+
console.error("飞书报警发送失败:", feishuError);
|
|
4210
|
+
});
|
|
4211
|
+
}
|
|
4212
|
+
|
|
4073
4213
|
function _createForOfIteratorHelper$1(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray$1(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; } } }; }
|
|
4074
4214
|
function _unsupportedIterableToArray$1(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray$1(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$1(r, a) : void 0; } }
|
|
4075
4215
|
function _arrayLikeToArray$1(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; }
|
|
@@ -4371,6 +4511,11 @@ function _createModel() {
|
|
|
4371
4511
|
_context3.prev = 15;
|
|
4372
4512
|
_t3 = _context3["catch"](0);
|
|
4373
4513
|
console.error("创建模型失败:", _t3);
|
|
4514
|
+
reportCmsCrudErrorToFeishu(c, {
|
|
4515
|
+
action: "create",
|
|
4516
|
+
target: "model",
|
|
4517
|
+
error: _t3
|
|
4518
|
+
});
|
|
4374
4519
|
_response9 = {
|
|
4375
4520
|
success: false,
|
|
4376
4521
|
message: "创建模型失败",
|
|
@@ -4462,6 +4607,11 @@ function _updateModel() {
|
|
|
4462
4607
|
_context4.prev = 8;
|
|
4463
4608
|
_t4 = _context4["catch"](0);
|
|
4464
4609
|
console.error("更新模型失败:", _t4);
|
|
4610
|
+
reportCmsCrudErrorToFeishu(c, {
|
|
4611
|
+
action: "update",
|
|
4612
|
+
target: "model",
|
|
4613
|
+
error: _t4
|
|
4614
|
+
});
|
|
4465
4615
|
_response11 = {
|
|
4466
4616
|
success: false,
|
|
4467
4617
|
message: "更新模型失败",
|
|
@@ -4543,6 +4693,11 @@ function _deleteModel() {
|
|
|
4543
4693
|
_context5.prev = 8;
|
|
4544
4694
|
_t5 = _context5["catch"](0);
|
|
4545
4695
|
console.error("删除模型失败:", _t5);
|
|
4696
|
+
reportCmsCrudErrorToFeishu(c, {
|
|
4697
|
+
action: "delete",
|
|
4698
|
+
target: "model",
|
|
4699
|
+
error: _t5
|
|
4700
|
+
});
|
|
4546
4701
|
_response15 = {
|
|
4547
4702
|
success: false,
|
|
4548
4703
|
message: "删除模型失败",
|
|
@@ -4604,8 +4759,8 @@ var _excluded = ["id", "created_at", "updated_at"],
|
|
|
4604
4759
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n2 = 0, F = function F() {}; return { s: F, n: function n() { return _n2 >= r.length ? { done: !0 } : { done: !1, value: r[_n2++] }; }, 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; } } }; }
|
|
4605
4760
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(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(r, a) : void 0; } }
|
|
4606
4761
|
function _arrayLikeToArray(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; }
|
|
4607
|
-
function ownKeys$
|
|
4608
|
-
function _objectSpread$
|
|
4762
|
+
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; }
|
|
4763
|
+
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; }
|
|
4609
4764
|
function normalizeJsonLikeFields(schemaFields, payload) {
|
|
4610
4765
|
if (!schemaFields || schemaFields.length === 0) return payload;
|
|
4611
4766
|
var jsonLikeFieldNames = new Set(schemaFields.filter(function (f) {
|
|
@@ -4614,7 +4769,7 @@ function normalizeJsonLikeFields(schemaFields, payload) {
|
|
|
4614
4769
|
return f.name;
|
|
4615
4770
|
}));
|
|
4616
4771
|
if (jsonLikeFieldNames.size === 0) return payload;
|
|
4617
|
-
var normalized = _objectSpread$
|
|
4772
|
+
var normalized = _objectSpread$1({}, payload);
|
|
4618
4773
|
for (var _i = 0, _Object$entries = Object.entries(payload); _i < _Object$entries.length; _i++) {
|
|
4619
4774
|
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
4620
4775
|
key = _Object$entries$_i[0],
|
|
@@ -4909,7 +5064,7 @@ function _getTableData() {
|
|
|
4909
5064
|
}
|
|
4910
5065
|
// 找到所有文本类型的字段
|
|
4911
5066
|
searchableFields = schemaFields.filter(function (field) {
|
|
4912
|
-
return field.type === 'string' || field.type === 'text';
|
|
5067
|
+
return field.type === 'string' || field.type === 'text' || field.type === 'richText';
|
|
4913
5068
|
}).map(function (field) {
|
|
4914
5069
|
return field.name;
|
|
4915
5070
|
});
|
|
@@ -4954,6 +5109,12 @@ function _getTableData() {
|
|
|
4954
5109
|
_context.prev = 16;
|
|
4955
5110
|
_t2 = _context["catch"](0);
|
|
4956
5111
|
console.error("获取表数据失败:", _t2);
|
|
5112
|
+
reportCmsCrudErrorToFeishu(c, {
|
|
5113
|
+
action: "read",
|
|
5114
|
+
target: "data",
|
|
5115
|
+
tableName: tableName,
|
|
5116
|
+
error: _t2
|
|
5117
|
+
});
|
|
4957
5118
|
_response3 = {
|
|
4958
5119
|
success: false,
|
|
4959
5120
|
message: "获取表数据失败",
|
|
@@ -5040,6 +5201,12 @@ function _createTableData() {
|
|
|
5040
5201
|
_context2.prev = 8;
|
|
5041
5202
|
_t4 = _context2["catch"](0);
|
|
5042
5203
|
console.error("创建数据失败:", _t4);
|
|
5204
|
+
reportCmsCrudErrorToFeishu(c, {
|
|
5205
|
+
action: "create",
|
|
5206
|
+
target: "data",
|
|
5207
|
+
tableName: tableName,
|
|
5208
|
+
error: _t4
|
|
5209
|
+
});
|
|
5043
5210
|
_response5 = {
|
|
5044
5211
|
success: false,
|
|
5045
5212
|
message: "创建数据失败",
|
|
@@ -5171,6 +5338,12 @@ function _updateTableData() {
|
|
|
5171
5338
|
_context3.prev = 13;
|
|
5172
5339
|
_t6 = _context3["catch"](0);
|
|
5173
5340
|
console.error("更新数据失败:", _t6);
|
|
5341
|
+
reportCmsCrudErrorToFeishu(c, {
|
|
5342
|
+
action: "update",
|
|
5343
|
+
target: "data",
|
|
5344
|
+
tableName: tableName,
|
|
5345
|
+
error: _t6
|
|
5346
|
+
});
|
|
5174
5347
|
_response1 = {
|
|
5175
5348
|
success: false,
|
|
5176
5349
|
message: "更新数据失败",
|
|
@@ -5254,6 +5427,12 @@ function _deleteTableData() {
|
|
|
5254
5427
|
_context4.prev = 7;
|
|
5255
5428
|
_t7 = _context4["catch"](0);
|
|
5256
5429
|
console.error("删除数据失败:", _t7);
|
|
5430
|
+
reportCmsCrudErrorToFeishu(c, {
|
|
5431
|
+
action: "delete",
|
|
5432
|
+
target: "data",
|
|
5433
|
+
tableName: tableName,
|
|
5434
|
+
error: _t7
|
|
5435
|
+
});
|
|
5257
5436
|
_response13 = {
|
|
5258
5437
|
success: false,
|
|
5259
5438
|
message: "删除数据失败",
|
|
@@ -5710,8 +5889,8 @@ var AuthUtils = /*#__PURE__*/function () {
|
|
|
5710
5889
|
}]);
|
|
5711
5890
|
}();
|
|
5712
5891
|
|
|
5713
|
-
function ownKeys
|
|
5714
|
-
function _objectSpread
|
|
5892
|
+
function ownKeys(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; }
|
|
5893
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
5715
5894
|
function getRoleFromSupabaseUser$2(user) {
|
|
5716
5895
|
var _user$app_metadata, _user$user_metadata;
|
|
5717
5896
|
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;
|
|
@@ -5737,7 +5916,7 @@ function toSupabaseEmail(account, sessionId) {
|
|
|
5737
5916
|
return "".concat(sid, "_").concat(localPart, "@").concat(domain);
|
|
5738
5917
|
}
|
|
5739
5918
|
function buildAdminMetadata(existingMetadata, sessionId, account) {
|
|
5740
|
-
return _objectSpread
|
|
5919
|
+
return _objectSpread(_objectSpread({}, existingMetadata || {}), {}, {
|
|
5741
5920
|
role: "admin",
|
|
5742
5921
|
session_id: normalizeSessionId(sessionId),
|
|
5743
5922
|
original_username: account
|
|
@@ -6540,7 +6719,7 @@ function _resolveUploadMaxSize() {
|
|
|
6540
6719
|
return _resolveUploadMaxSize.apply(this, arguments);
|
|
6541
6720
|
}
|
|
6542
6721
|
function readSessionId(c) {
|
|
6543
|
-
return c.req.header("X-Session-Id") || c.req.header("x-session-id") || '';
|
|
6722
|
+
return normalizeSessionId(c.req.header("X-Session-Id") || c.req.header("x-session-id")) || '';
|
|
6544
6723
|
}
|
|
6545
6724
|
function uploadToOss(_x3) {
|
|
6546
6725
|
return _uploadToOss.apply(this, arguments);
|
|
@@ -6619,225 +6798,6 @@ function _uploadToOss() {
|
|
|
6619
6798
|
return _uploadToOss.apply(this, arguments);
|
|
6620
6799
|
}
|
|
6621
6800
|
|
|
6622
|
-
function ownKeys(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; }
|
|
6623
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
6624
|
-
var CONFIG_NAMESPACE_RE = /^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/;
|
|
6625
|
-
var CONFIG_SESSION_RE = /^[a-zA-Z0-9_]{1,128}$/;
|
|
6626
|
-
function getConfigSessionId(c) {
|
|
6627
|
-
return normalizeSessionId(c.req.header("X-Session-Id") || c.req.header("x-session-id"));
|
|
6628
|
-
}
|
|
6629
|
-
function validateConfigSessionId(sessionId) {
|
|
6630
|
-
if (!sessionId) return "缺少 X-Session-Id,无法访问配置中心";
|
|
6631
|
-
if (!CONFIG_SESSION_RE.test(sessionId)) {
|
|
6632
|
-
return "X-Session-Id 格式不合法";
|
|
6633
|
-
}
|
|
6634
|
-
return null;
|
|
6635
|
-
}
|
|
6636
|
-
function getConfigsTableName(sessionId) {
|
|
6637
|
-
return "".concat(sessionId.replace('-', '_'), "__config__");
|
|
6638
|
-
}
|
|
6639
|
-
function normalizeValues(values) {
|
|
6640
|
-
if (!values || _typeof$1(values) !== "object" || Array.isArray(values)) {
|
|
6641
|
-
return {};
|
|
6642
|
-
}
|
|
6643
|
-
return values;
|
|
6644
|
-
}
|
|
6645
|
-
function buildFieldStatus(values) {
|
|
6646
|
-
return Object.fromEntries(Object.entries(values).map(function (_ref) {
|
|
6647
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
|
6648
|
-
key = _ref2[0],
|
|
6649
|
-
value = _ref2[1];
|
|
6650
|
-
return [key, {
|
|
6651
|
-
configured: value !== null && value !== undefined && String(value).trim() !== ""
|
|
6652
|
-
}];
|
|
6653
|
-
}));
|
|
6654
|
-
}
|
|
6655
|
-
function validateNamespace(namespace) {
|
|
6656
|
-
if (!namespace) return "缺少 namespace";
|
|
6657
|
-
if (!CONFIG_NAMESPACE_RE.test(namespace)) {
|
|
6658
|
-
return "namespace 只能包含字母、数字、下划线和连字符,且必须以字母开头";
|
|
6659
|
-
}
|
|
6660
|
-
return null;
|
|
6661
|
-
}
|
|
6662
|
-
function toConfigResponse(row, fallbackNamespace) {
|
|
6663
|
-
var values = normalizeValues(row === null || row === void 0 ? void 0 : row.values);
|
|
6664
|
-
return {
|
|
6665
|
-
id: row === null || row === void 0 ? void 0 : row.id,
|
|
6666
|
-
namespace: (row === null || row === void 0 ? void 0 : row.namespace) || fallbackNamespace,
|
|
6667
|
-
values: values,
|
|
6668
|
-
fields: buildFieldStatus(values),
|
|
6669
|
-
created_at: row === null || row === void 0 ? void 0 : row.created_at,
|
|
6670
|
-
updated_at: row === null || row === void 0 ? void 0 : row.updated_at
|
|
6671
|
-
};
|
|
6672
|
-
}
|
|
6673
|
-
function getConfig(_x) {
|
|
6674
|
-
return _getConfig.apply(this, arguments);
|
|
6675
|
-
}
|
|
6676
|
-
function _getConfig() {
|
|
6677
|
-
_getConfig = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(c) {
|
|
6678
|
-
var namespace, namespaceError, _response, sessionId, sessionError, _response2, tableName, supabase, _yield$supabase$from$, data, error, response, _response3, _t;
|
|
6679
|
-
return _regeneratorRuntime.wrap(function (_context) {
|
|
6680
|
-
while (1) switch (_context.prev = _context.next) {
|
|
6681
|
-
case 0:
|
|
6682
|
-
_context.prev = 0;
|
|
6683
|
-
namespace = (c.req.query("namespace") || "").trim();
|
|
6684
|
-
namespaceError = validateNamespace(namespace);
|
|
6685
|
-
if (!namespaceError) {
|
|
6686
|
-
_context.next = 1;
|
|
6687
|
-
break;
|
|
6688
|
-
}
|
|
6689
|
-
_response = {
|
|
6690
|
-
success: false,
|
|
6691
|
-
message: namespaceError
|
|
6692
|
-
};
|
|
6693
|
-
return _context.abrupt("return", c.json(_response, 200));
|
|
6694
|
-
case 1:
|
|
6695
|
-
sessionId = getConfigSessionId(c);
|
|
6696
|
-
sessionError = validateConfigSessionId(sessionId);
|
|
6697
|
-
if (!sessionError) {
|
|
6698
|
-
_context.next = 2;
|
|
6699
|
-
break;
|
|
6700
|
-
}
|
|
6701
|
-
_response2 = {
|
|
6702
|
-
success: false,
|
|
6703
|
-
message: sessionError
|
|
6704
|
-
};
|
|
6705
|
-
return _context.abrupt("return", c.json(_response2, 200));
|
|
6706
|
-
case 2:
|
|
6707
|
-
tableName = getConfigsTableName(sessionId); // await ensureConfigsTable(tableName)
|
|
6708
|
-
supabase = getSupabase();
|
|
6709
|
-
_context.next = 3;
|
|
6710
|
-
return supabase.from(tableName).select("*").eq("namespace", namespace).maybeSingle();
|
|
6711
|
-
case 3:
|
|
6712
|
-
_yield$supabase$from$ = _context.sent;
|
|
6713
|
-
data = _yield$supabase$from$.data;
|
|
6714
|
-
error = _yield$supabase$from$.error;
|
|
6715
|
-
if (!error) {
|
|
6716
|
-
_context.next = 4;
|
|
6717
|
-
break;
|
|
6718
|
-
}
|
|
6719
|
-
throw error;
|
|
6720
|
-
case 4:
|
|
6721
|
-
response = {
|
|
6722
|
-
success: true,
|
|
6723
|
-
data: toConfigResponse(data, namespace)
|
|
6724
|
-
};
|
|
6725
|
-
return _context.abrupt("return", c.json(response, 200));
|
|
6726
|
-
case 5:
|
|
6727
|
-
_context.prev = 5;
|
|
6728
|
-
_t = _context["catch"](0);
|
|
6729
|
-
console.error("获取配置失败:", _t);
|
|
6730
|
-
_response3 = {
|
|
6731
|
-
success: false,
|
|
6732
|
-
message: "获取配置失败",
|
|
6733
|
-
error: _t.message
|
|
6734
|
-
};
|
|
6735
|
-
return _context.abrupt("return", c.json(_response3, 500));
|
|
6736
|
-
case 6:
|
|
6737
|
-
case "end":
|
|
6738
|
-
return _context.stop();
|
|
6739
|
-
}
|
|
6740
|
-
}, _callee, null, [[0, 5]]);
|
|
6741
|
-
}));
|
|
6742
|
-
return _getConfig.apply(this, arguments);
|
|
6743
|
-
}
|
|
6744
|
-
function updateConfig(_x2) {
|
|
6745
|
-
return _updateConfig.apply(this, arguments);
|
|
6746
|
-
}
|
|
6747
|
-
function _updateConfig() {
|
|
6748
|
-
_updateConfig = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(c) {
|
|
6749
|
-
var namespace, namespaceError, _response4, body, values, sessionId, sessionError, _response5, tableName, supabase, _yield$supabase$from$2, existing, existingError, nextValues, _yield$supabase$from$3, data, error, response, _response6, _t2;
|
|
6750
|
-
return _regeneratorRuntime.wrap(function (_context2) {
|
|
6751
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
6752
|
-
case 0:
|
|
6753
|
-
_context2.prev = 0;
|
|
6754
|
-
namespace = (c.req.param("namespace") || "").trim();
|
|
6755
|
-
namespaceError = validateNamespace(namespace);
|
|
6756
|
-
if (!namespaceError) {
|
|
6757
|
-
_context2.next = 1;
|
|
6758
|
-
break;
|
|
6759
|
-
}
|
|
6760
|
-
_response4 = {
|
|
6761
|
-
success: false,
|
|
6762
|
-
message: namespaceError
|
|
6763
|
-
};
|
|
6764
|
-
return _context2.abrupt("return", c.json(_response4, 200));
|
|
6765
|
-
case 1:
|
|
6766
|
-
_context2.next = 2;
|
|
6767
|
-
return c.req.json();
|
|
6768
|
-
case 2:
|
|
6769
|
-
body = _context2.sent;
|
|
6770
|
-
values = normalizeValues(body === null || body === void 0 ? void 0 : body.values);
|
|
6771
|
-
sessionId = getConfigSessionId(c);
|
|
6772
|
-
sessionError = validateConfigSessionId(sessionId);
|
|
6773
|
-
if (!sessionError) {
|
|
6774
|
-
_context2.next = 3;
|
|
6775
|
-
break;
|
|
6776
|
-
}
|
|
6777
|
-
_response5 = {
|
|
6778
|
-
success: false,
|
|
6779
|
-
message: sessionError
|
|
6780
|
-
};
|
|
6781
|
-
return _context2.abrupt("return", c.json(_response5, 200));
|
|
6782
|
-
case 3:
|
|
6783
|
-
tableName = getConfigsTableName(sessionId); // await ensureConfigsTable(tableName)
|
|
6784
|
-
supabase = getSupabase();
|
|
6785
|
-
_context2.next = 4;
|
|
6786
|
-
return supabase.from(tableName).select("values").eq("namespace", namespace).maybeSingle();
|
|
6787
|
-
case 4:
|
|
6788
|
-
_yield$supabase$from$2 = _context2.sent;
|
|
6789
|
-
existing = _yield$supabase$from$2.data;
|
|
6790
|
-
existingError = _yield$supabase$from$2.error;
|
|
6791
|
-
if (!existingError) {
|
|
6792
|
-
_context2.next = 5;
|
|
6793
|
-
break;
|
|
6794
|
-
}
|
|
6795
|
-
throw existingError;
|
|
6796
|
-
case 5:
|
|
6797
|
-
nextValues = _objectSpread(_objectSpread({}, normalizeValues(existing === null || existing === void 0 ? void 0 : existing.values)), values);
|
|
6798
|
-
_context2.next = 6;
|
|
6799
|
-
return supabase.from(tableName).upsert({
|
|
6800
|
-
namespace: namespace,
|
|
6801
|
-
values: nextValues,
|
|
6802
|
-
updated_at: new Date().toISOString()
|
|
6803
|
-
}, {
|
|
6804
|
-
onConflict: "namespace"
|
|
6805
|
-
}).select("*").single();
|
|
6806
|
-
case 6:
|
|
6807
|
-
_yield$supabase$from$3 = _context2.sent;
|
|
6808
|
-
data = _yield$supabase$from$3.data;
|
|
6809
|
-
error = _yield$supabase$from$3.error;
|
|
6810
|
-
if (!error) {
|
|
6811
|
-
_context2.next = 7;
|
|
6812
|
-
break;
|
|
6813
|
-
}
|
|
6814
|
-
throw error;
|
|
6815
|
-
case 7:
|
|
6816
|
-
response = {
|
|
6817
|
-
success: true,
|
|
6818
|
-
message: "配置保存成功",
|
|
6819
|
-
data: toConfigResponse(data, namespace)
|
|
6820
|
-
};
|
|
6821
|
-
return _context2.abrupt("return", c.json(response, 200));
|
|
6822
|
-
case 8:
|
|
6823
|
-
_context2.prev = 8;
|
|
6824
|
-
_t2 = _context2["catch"](0);
|
|
6825
|
-
console.error("保存配置失败:", _t2);
|
|
6826
|
-
_response6 = {
|
|
6827
|
-
success: false,
|
|
6828
|
-
message: "保存配置失败",
|
|
6829
|
-
error: _t2.message
|
|
6830
|
-
};
|
|
6831
|
-
return _context2.abrupt("return", c.json(_response6, 500));
|
|
6832
|
-
case 9:
|
|
6833
|
-
case "end":
|
|
6834
|
-
return _context2.stop();
|
|
6835
|
-
}
|
|
6836
|
-
}, _callee2, null, [[0, 8]]);
|
|
6837
|
-
}));
|
|
6838
|
-
return _updateConfig.apply(this, arguments);
|
|
6839
|
-
}
|
|
6840
|
-
|
|
6841
6801
|
var AUTH_REQUIRED = "CMS_AUTH_REQUIRED";
|
|
6842
6802
|
var AUTH_INVALID = "CMS_AUTH_INVALID";
|
|
6843
6803
|
var CMS_FORBIDDEN = "CMS_FORBIDDEN";
|
|
@@ -7333,17 +7293,9 @@ function createOssUploadRoute(app) {
|
|
|
7333
7293
|
app.post("/upload", requireJwtAuth, requireAdminRole, uploadToOss);
|
|
7334
7294
|
return app;
|
|
7335
7295
|
}
|
|
7336
|
-
function createConfigRoute(app) {
|
|
7337
|
-
app.get("/configs", requireAdminRole, getConfig);
|
|
7338
|
-
app.put("/configs/:namespace", requireAdminRole, function (c) {
|
|
7339
|
-
return updateConfig(c);
|
|
7340
|
-
});
|
|
7341
|
-
return app;
|
|
7342
|
-
}
|
|
7343
7296
|
// 一键创建所有CMS路由
|
|
7344
7297
|
function createCmsRoutes(app) {
|
|
7345
7298
|
createModelRoute(app);
|
|
7346
|
-
createConfigRoute(app);
|
|
7347
7299
|
createDynamicDataRoute(app);
|
|
7348
7300
|
createDynamicAuthRoute(app);
|
|
7349
7301
|
return app;
|
|
@@ -7359,7 +7311,6 @@ exports.closeDatabase = closeSupabase;
|
|
|
7359
7311
|
exports.closeSupabase = closeSupabase;
|
|
7360
7312
|
exports.createAuthRoute = createAuthRoute;
|
|
7361
7313
|
exports.createCmsRoutes = createCmsRoutes;
|
|
7362
|
-
exports.createConfigRoute = createConfigRoute;
|
|
7363
7314
|
exports.createDataRoute = createDataRoute;
|
|
7364
7315
|
exports.createDynamicAuthRoute = createDynamicAuthRoute;
|
|
7365
7316
|
exports.createDynamicDataRoute = createDynamicDataRoute;
|
|
@@ -7371,9 +7322,9 @@ exports.deleteModel = deleteModel;
|
|
|
7371
7322
|
exports.deleteTableData = deleteTableData;
|
|
7372
7323
|
exports.dropForeignKeys = dropForeignKeys;
|
|
7373
7324
|
exports.executeSupabaseSetup = executeSupabaseSetup;
|
|
7325
|
+
exports.feishuAlertConfig = feishuAlertConfig;
|
|
7374
7326
|
exports.getAuthService = getAuthService;
|
|
7375
7327
|
exports.getCmsModelService = getCmsModelService;
|
|
7376
|
-
exports.getConfig = getConfig;
|
|
7377
7328
|
exports.getCurrentUser = getCurrentUser;
|
|
7378
7329
|
exports.getDatabase = getSupabase;
|
|
7379
7330
|
exports.getDynamicTableService = getDynamicTableService;
|
|
@@ -7390,12 +7341,13 @@ exports.initializeDatabase = initializeSupabase;
|
|
|
7390
7341
|
exports.initializeOssUpload = initializeOssUpload;
|
|
7391
7342
|
exports.initializeSupabase = initializeSupabase;
|
|
7392
7343
|
exports.login = login;
|
|
7344
|
+
exports.notifyCmsCrudErrorToFeishu = notifyCmsCrudErrorToFeishu;
|
|
7345
|
+
exports.reportCmsCrudErrorToFeishu = reportCmsCrudErrorToFeishu;
|
|
7393
7346
|
exports.requireAuth = requireAuth;
|
|
7394
7347
|
exports.signup = signup;
|
|
7395
7348
|
exports.signupStatus = signupStatus;
|
|
7396
7349
|
exports.syncDatabase = initializeCmsSystem;
|
|
7397
7350
|
exports.testConnection = testConnection;
|
|
7398
|
-
exports.updateConfig = updateConfig;
|
|
7399
7351
|
exports.updateModel = updateModel;
|
|
7400
7352
|
exports.updateTableData = updateTableData;
|
|
7401
7353
|
exports.uploadToOss = uploadToOss;
|