@wecode-team/cms-supabase-api 0.1.53 → 0.1.54
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.d.ts +1 -0
- package/dist/index.esm.js +91 -38
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +91 -38
- package/dist/index.js.map +1 -1
- package/dist/utils/route-helpers.d.ts +9 -6
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -14,5 +14,6 @@ export { getConfig, updateConfig, } from "./handlers/configs";
|
|
|
14
14
|
export type { SchemaField, JsonSchema, CmsModelAttributes, CmsModelCreationAttributes, ApiResponse, PaginatedResponse, SupabaseConfig, DatabaseConfig, TableDataOptions, SupabaseFilter, FieldTypeMapping, RelationType, RelationConfig, RelationOption, GetRelationOptionsParams, } from "./types";
|
|
15
15
|
export type { User, UserInfo, LoginRequest, ForgotPasswordRequest, ResetPasswordRequest, LoginResponse, } from "./handlers/auth";
|
|
16
16
|
export { createCmsRoutes, createModelRoute, createDynamicDataRoute, createDynamicAuthRoute, createDataRoute, createAuthRoute, createOssUploadRoute, createConfigRoute, } from "./utils/route-helpers";
|
|
17
|
+
export type { CmsRouteOptions, } from "./utils/route-helpers";
|
|
17
18
|
export { notifyCmsCrudErrorToFeishu, reportCmsCrudErrorToFeishu, } from "./utils/feishu-alert";
|
|
18
19
|
export type { OssUploadProvider, OssUploadReturnMode, OssUploadConfig, NormalizedOssUploadConfig, OssUploadInput, OssUploadResult, UploadRouteResponse, } from "./types/upload";
|
package/dist/index.esm.js
CHANGED
|
@@ -7532,64 +7532,117 @@ function _supabaseCurrentUser() {
|
|
|
7532
7532
|
return _supabaseCurrentUser.apply(this, arguments);
|
|
7533
7533
|
}
|
|
7534
7534
|
|
|
7535
|
+
function isSkipAuthRequest(c) {
|
|
7536
|
+
return c.req.header("X-CMS-Skip-Auth") === "true";
|
|
7537
|
+
}
|
|
7538
|
+
function withAdmin() {
|
|
7539
|
+
return [(/*#__PURE__*/function () {
|
|
7540
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(c, next) {
|
|
7541
|
+
return _regeneratorRuntime.wrap(function (_context) {
|
|
7542
|
+
while (1) switch (_context.prev = _context.next) {
|
|
7543
|
+
case 0:
|
|
7544
|
+
if (!isSkipAuthRequest(c)) {
|
|
7545
|
+
_context.next = 2;
|
|
7546
|
+
break;
|
|
7547
|
+
}
|
|
7548
|
+
_context.next = 1;
|
|
7549
|
+
return next();
|
|
7550
|
+
case 1:
|
|
7551
|
+
return _context.abrupt("return");
|
|
7552
|
+
case 2:
|
|
7553
|
+
return _context.abrupt("return", requireJwtAuth(c, next));
|
|
7554
|
+
case 3:
|
|
7555
|
+
case "end":
|
|
7556
|
+
return _context.stop();
|
|
7557
|
+
}
|
|
7558
|
+
}, _callee);
|
|
7559
|
+
}));
|
|
7560
|
+
return function (_x, _x2) {
|
|
7561
|
+
return _ref.apply(this, arguments);
|
|
7562
|
+
};
|
|
7563
|
+
}()), (/*#__PURE__*/function () {
|
|
7564
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(c, next) {
|
|
7565
|
+
return _regeneratorRuntime.wrap(function (_context2) {
|
|
7566
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
7567
|
+
case 0:
|
|
7568
|
+
if (!isSkipAuthRequest(c)) {
|
|
7569
|
+
_context2.next = 2;
|
|
7570
|
+
break;
|
|
7571
|
+
}
|
|
7572
|
+
_context2.next = 1;
|
|
7573
|
+
return next();
|
|
7574
|
+
case 1:
|
|
7575
|
+
return _context2.abrupt("return");
|
|
7576
|
+
case 2:
|
|
7577
|
+
return _context2.abrupt("return", requireAdminRole(c, next));
|
|
7578
|
+
case 3:
|
|
7579
|
+
case "end":
|
|
7580
|
+
return _context2.stop();
|
|
7581
|
+
}
|
|
7582
|
+
}, _callee2);
|
|
7583
|
+
}));
|
|
7584
|
+
return function (_x3, _x4) {
|
|
7585
|
+
return _ref2.apply(this, arguments);
|
|
7586
|
+
};
|
|
7587
|
+
}())];
|
|
7588
|
+
}
|
|
7535
7589
|
// 创建模型路由处理器
|
|
7536
7590
|
function createModelRoute(app) {
|
|
7537
|
-
|
|
7538
|
-
app.
|
|
7539
|
-
app.
|
|
7540
|
-
app.
|
|
7541
|
-
app["delete"]("/models", requireJwtAuth, requireAdminRole, deleteModel);
|
|
7591
|
+
app.get.apply(app, ["/models"].concat(_toConsumableArray(withAdmin()), [getModels]));
|
|
7592
|
+
app.post.apply(app, ["/models"].concat(_toConsumableArray(withAdmin()), [createModel]));
|
|
7593
|
+
app.put.apply(app, ["/models"].concat(_toConsumableArray(withAdmin()), [updateModel]));
|
|
7594
|
+
app["delete"].apply(app, ["/models"].concat(_toConsumableArray(withAdmin()), [deleteModel]));
|
|
7542
7595
|
return app;
|
|
7543
7596
|
}
|
|
7544
7597
|
// 创建数据表路由处理器(固定表名)
|
|
7545
7598
|
function createDataRoute(app, tableName) {
|
|
7546
|
-
app.get("/data/".concat(tableName),
|
|
7599
|
+
app.get.apply(app, ["/data/".concat(tableName)].concat(_toConsumableArray(withAdmin()), [function (c) {
|
|
7547
7600
|
return getTableData(c, tableName);
|
|
7548
|
-
});
|
|
7549
|
-
app.post("/data/".concat(tableName),
|
|
7601
|
+
}]));
|
|
7602
|
+
app.post.apply(app, ["/data/".concat(tableName)].concat(_toConsumableArray(withAdmin()), [function (c) {
|
|
7550
7603
|
return createTableData(c, tableName);
|
|
7551
|
-
});
|
|
7552
|
-
app.put("/data/".concat(tableName),
|
|
7604
|
+
}]));
|
|
7605
|
+
app.put.apply(app, ["/data/".concat(tableName)].concat(_toConsumableArray(withAdmin()), [function (c) {
|
|
7553
7606
|
return updateTableData(c, tableName);
|
|
7554
|
-
});
|
|
7555
|
-
app["delete"]("/data/".concat(tableName),
|
|
7607
|
+
}]));
|
|
7608
|
+
app["delete"].apply(app, ["/data/".concat(tableName)].concat(_toConsumableArray(withAdmin()), [function (c) {
|
|
7556
7609
|
return deleteTableData(c, tableName);
|
|
7557
|
-
});
|
|
7610
|
+
}]));
|
|
7558
7611
|
return app;
|
|
7559
7612
|
}
|
|
7560
7613
|
// 动态创建数据表路由处理器(从URL参数获取表名)
|
|
7561
7614
|
function createDynamicDataRoute(app) {
|
|
7562
7615
|
// 获取关联表选项(放在 :tableName 路由之前,避免被匹配)
|
|
7563
|
-
app.get("/relation/:tableName/options",
|
|
7564
|
-
var tableName = c.req.param("tableName");
|
|
7616
|
+
app.get.apply(app, ["/relation/:tableName/options"].concat(_toConsumableArray(withAdmin()), [function (c) {
|
|
7617
|
+
var tableName = c.req.param("tableName") || "";
|
|
7565
7618
|
return getRelationOptions(c, tableName);
|
|
7566
|
-
});
|
|
7619
|
+
}]));
|
|
7567
7620
|
// 获取带关联数据的表数据
|
|
7568
|
-
app.get("/data/:tableName/with-relations",
|
|
7569
|
-
var tableName = c.req.param("tableName");
|
|
7621
|
+
app.get.apply(app, ["/data/:tableName/with-relations"].concat(_toConsumableArray(withAdmin()), [function (c) {
|
|
7622
|
+
var tableName = c.req.param("tableName") || "";
|
|
7570
7623
|
return getTableDataWithRelations(c, tableName);
|
|
7571
|
-
});
|
|
7572
|
-
app.get("/data/:tableName",
|
|
7573
|
-
var tableName = c.req.param("tableName");
|
|
7624
|
+
}]));
|
|
7625
|
+
app.get.apply(app, ["/data/:tableName"].concat(_toConsumableArray(withAdmin()), [function (c) {
|
|
7626
|
+
var tableName = c.req.param("tableName") || "";
|
|
7574
7627
|
return getTableData(c, tableName);
|
|
7575
|
-
});
|
|
7576
|
-
app.post("/data/:tableName",
|
|
7577
|
-
var tableName = c.req.param("tableName");
|
|
7628
|
+
}]));
|
|
7629
|
+
app.post.apply(app, ["/data/:tableName"].concat(_toConsumableArray(withAdmin()), [function (c) {
|
|
7630
|
+
var tableName = c.req.param("tableName") || "";
|
|
7578
7631
|
return createTableData(c, tableName);
|
|
7579
|
-
});
|
|
7580
|
-
app.put("/data/:tableName",
|
|
7581
|
-
var tableName = c.req.param("tableName");
|
|
7632
|
+
}]));
|
|
7633
|
+
app.put.apply(app, ["/data/:tableName"].concat(_toConsumableArray(withAdmin()), [function (c) {
|
|
7634
|
+
var tableName = c.req.param("tableName") || "";
|
|
7582
7635
|
return updateTableData(c, tableName);
|
|
7583
|
-
});
|
|
7584
|
-
app["delete"]("/data/:tableName",
|
|
7585
|
-
var tableName = c.req.param("tableName");
|
|
7636
|
+
}]));
|
|
7637
|
+
app["delete"].apply(app, ["/data/:tableName"].concat(_toConsumableArray(withAdmin()), [function (c) {
|
|
7638
|
+
var tableName = c.req.param("tableName") || "";
|
|
7586
7639
|
return deleteTableData(c, tableName);
|
|
7587
|
-
});
|
|
7640
|
+
}]));
|
|
7588
7641
|
// 删除表的所有外键约束(用于解决外键引用错误表的问题)
|
|
7589
|
-
app["delete"]("/data/:tableName/foreign-keys",
|
|
7590
|
-
var tableName = c.req.param("tableName");
|
|
7642
|
+
app["delete"].apply(app, ["/data/:tableName/foreign-keys"].concat(_toConsumableArray(withAdmin()), [function (c) {
|
|
7643
|
+
var tableName = c.req.param("tableName") || "";
|
|
7591
7644
|
return dropForeignKeys(c, tableName);
|
|
7592
|
-
});
|
|
7645
|
+
}]));
|
|
7593
7646
|
return app;
|
|
7594
7647
|
}
|
|
7595
7648
|
// 动态创建认证路由处理器(从URL参数获取表名)
|
|
@@ -7672,14 +7725,14 @@ function createAuthRoute(app, tableName) {
|
|
|
7672
7725
|
return app;
|
|
7673
7726
|
}
|
|
7674
7727
|
function createOssUploadRoute(app) {
|
|
7675
|
-
app.post("/upload",
|
|
7728
|
+
app.post.apply(app, ["/upload"].concat(_toConsumableArray(withAdmin()), [uploadToOss]));
|
|
7676
7729
|
return app;
|
|
7677
7730
|
}
|
|
7678
7731
|
function createConfigRoute(app) {
|
|
7679
|
-
app.get("/configs",
|
|
7680
|
-
app.put("/configs/:namespace",
|
|
7732
|
+
app.get.apply(app, ["/configs"].concat(_toConsumableArray(withAdmin()), [getConfig]));
|
|
7733
|
+
app.put.apply(app, ["/configs/:namespace"].concat(_toConsumableArray(withAdmin()), [function (c) {
|
|
7681
7734
|
return updateConfig(c);
|
|
7682
|
-
});
|
|
7735
|
+
}]));
|
|
7683
7736
|
return app;
|
|
7684
7737
|
}
|
|
7685
7738
|
// 一键创建所有CMS路由
|