midway-fatcms 0.0.2 → 0.0.3

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.
Files changed (396) hide show
  1. package/.eslintrc.json +14 -14
  2. package/.prettierrc.js +4 -4
  3. package/README.md +406 -406
  4. package/dist/config/config.default.d.ts +3 -3
  5. package/dist/config/config.default.js +177 -177
  6. package/dist/config/utils.d.ts +1 -1
  7. package/dist/config/utils.js +23 -23
  8. package/dist/configuration.d.ts +7 -7
  9. package/dist/configuration.js +113 -113
  10. package/dist/controller/base/BaseApiController.d.ts +49 -49
  11. package/dist/controller/base/BaseApiController.js +198 -198
  12. package/dist/controller/gateway/AnyApiGatewayController.d.ts +13 -13
  13. package/dist/controller/gateway/AnyApiGatewayController.js +55 -55
  14. package/dist/controller/gateway/AsyncTaskController.d.ts +20 -20
  15. package/dist/controller/gateway/AsyncTaskController.js +181 -181
  16. package/dist/controller/gateway/CrudMtdGatewayController.d.ts +21 -21
  17. package/dist/controller/gateway/CrudMtdGatewayController.js +122 -122
  18. package/dist/controller/gateway/CrudStdGatewayController.d.ts +39 -39
  19. package/dist/controller/gateway/CrudStdGatewayController.js +149 -149
  20. package/dist/controller/gateway/DocGatewayController.d.ts +27 -27
  21. package/dist/controller/gateway/DocGatewayController.js +181 -181
  22. package/dist/controller/gateway/FileController.d.ts +32 -32
  23. package/dist/controller/gateway/FileController.js +160 -160
  24. package/dist/controller/gateway/FlowInstanceController.d.ts +16 -16
  25. package/dist/controller/gateway/FlowInstanceController.js +48 -48
  26. package/dist/controller/gateway/ProxyApiGatewayController.d.ts +18 -18
  27. package/dist/controller/gateway/ProxyApiGatewayController.js +78 -78
  28. package/dist/controller/gateway/PublicApiController.d.ts +33 -33
  29. package/dist/controller/gateway/PublicApiController.js +194 -194
  30. package/dist/controller/gateway/StaticController.d.ts +23 -23
  31. package/dist/controller/gateway/StaticController.js +280 -280
  32. package/dist/controller/helpers.controller.d.ts +36 -36
  33. package/dist/controller/helpers.controller.js +187 -187
  34. package/dist/controller/home.controller.d.ts +9 -9
  35. package/dist/controller/home.controller.js +78 -78
  36. package/dist/controller/manage/AnyApiMangeApi.d.ts +10 -10
  37. package/dist/controller/manage/AnyApiMangeApi.js +98 -98
  38. package/dist/controller/manage/AppLogMangeApi.d.ts +10 -10
  39. package/dist/controller/manage/AppLogMangeApi.js +88 -88
  40. package/dist/controller/manage/AppMangeApi.d.ts +12 -12
  41. package/dist/controller/manage/AppMangeApi.js +101 -101
  42. package/dist/controller/manage/AppPageMangeApi.d.ts +10 -10
  43. package/dist/controller/manage/AppPageMangeApi.js +87 -87
  44. package/dist/controller/manage/AppSchemaHistoryApi.d.ts +10 -10
  45. package/dist/controller/manage/AppSchemaHistoryApi.js +83 -83
  46. package/dist/controller/manage/CrudMethodsMangeApi.d.ts +10 -10
  47. package/dist/controller/manage/CrudMethodsMangeApi.js +84 -84
  48. package/dist/controller/manage/CrudStandardDesignApi.d.ts +46 -46
  49. package/dist/controller/manage/CrudStandardDesignApi.js +367 -367
  50. package/dist/controller/manage/DataDictManageApi.d.ts +17 -17
  51. package/dist/controller/manage/DataDictManageApi.js +165 -165
  52. package/dist/controller/manage/DeployManageApi.d.ts +21 -21
  53. package/dist/controller/manage/DeployManageApi.js +203 -203
  54. package/dist/controller/manage/DocLibManageApi.d.ts +10 -10
  55. package/dist/controller/manage/DocLibManageApi.js +104 -104
  56. package/dist/controller/manage/DocManageApi.d.ts +11 -11
  57. package/dist/controller/manage/DocManageApi.js +130 -130
  58. package/dist/controller/manage/FileManageApi.d.ts +13 -13
  59. package/dist/controller/manage/FileManageApi.js +77 -77
  60. package/dist/controller/manage/FlowConfigManageApi.d.ts +12 -12
  61. package/dist/controller/manage/FlowConfigManageApi.js +109 -109
  62. package/dist/controller/manage/LowCodeTplManageApi.d.ts +13 -13
  63. package/dist/controller/manage/LowCodeTplManageApi.js +86 -86
  64. package/dist/controller/manage/MenuManageApi.d.ts +11 -11
  65. package/dist/controller/manage/MenuManageApi.js +104 -104
  66. package/dist/controller/manage/ProxyApiMangeApi.d.ts +10 -10
  67. package/dist/controller/manage/ProxyApiMangeApi.js +87 -87
  68. package/dist/controller/manage/SuperAdminManageApi.d.ts +24 -24
  69. package/dist/controller/manage/SuperAdminManageApi.js +153 -153
  70. package/dist/controller/manage/SysConfigMangeApi.d.ts +12 -12
  71. package/dist/controller/manage/SysConfigMangeApi.js +133 -133
  72. package/dist/controller/manage/SystemInfoManageApi.d.ts +12 -12
  73. package/dist/controller/manage/SystemInfoManageApi.js +82 -82
  74. package/dist/controller/manage/UserAccountManageApi.d.ts +16 -16
  75. package/dist/controller/manage/UserAccountManageApi.js +153 -153
  76. package/dist/controller/manage/WorkbenchMangeApi.d.ts +11 -11
  77. package/dist/controller/manage/WorkbenchMangeApi.js +106 -106
  78. package/dist/controller/myinfo/AuthController.d.ts +37 -37
  79. package/dist/controller/myinfo/AuthController.js +157 -157
  80. package/dist/controller/myinfo/MyInfoController.d.ts +13 -13
  81. package/dist/controller/myinfo/MyInfoController.js +51 -51
  82. package/dist/controller/render/AppRenderController.d.ts +12 -12
  83. package/dist/controller/render/AppRenderController.js +93 -93
  84. package/dist/controller/test.controller.d.ts +8 -8
  85. package/dist/controller/test.controller.js +51 -51
  86. package/dist/filter/default.filter.d.ts +7 -7
  87. package/dist/filter/default.filter.js +23 -23
  88. package/dist/filter/notfound.filter.d.ts +5 -5
  89. package/dist/filter/notfound.filter.js +20 -20
  90. package/dist/index.d.ts +111 -111
  91. package/dist/index.js +129 -129
  92. package/dist/interface.d.ts +30 -30
  93. package/dist/interface.js +3 -3
  94. package/dist/libs/crud-pro/CrudPro.d.ts +37 -37
  95. package/dist/libs/crud-pro/CrudPro.js +146 -146
  96. package/dist/libs/crud-pro/defaultConfigs.d.ts +4 -4
  97. package/dist/libs/crud-pro/defaultConfigs.js +15 -15
  98. package/dist/libs/crud-pro/exceptions.d.ts +106 -106
  99. package/dist/libs/crud-pro/exceptions.js +119 -119
  100. package/dist/libs/crud-pro/interfaces.d.ts +175 -175
  101. package/dist/libs/crud-pro/interfaces.js +12 -12
  102. package/dist/libs/crud-pro/models/ExecuteContext.d.ts +50 -50
  103. package/dist/libs/crud-pro/models/ExecuteContext.js +87 -87
  104. package/dist/libs/crud-pro/models/ExecuteContextFunc.d.ts +38 -38
  105. package/dist/libs/crud-pro/models/ExecuteContextFunc.js +72 -72
  106. package/dist/libs/crud-pro/models/FuncContext.d.ts +18 -18
  107. package/dist/libs/crud-pro/models/FuncContext.js +6 -6
  108. package/dist/libs/crud-pro/models/RequestCfgModel.d.ts +65 -65
  109. package/dist/libs/crud-pro/models/RequestCfgModel.js +81 -81
  110. package/dist/libs/crud-pro/models/RequestModel.d.ts +25 -25
  111. package/dist/libs/crud-pro/models/RequestModel.js +113 -113
  112. package/dist/libs/crud-pro/models/ResModel.d.ts +20 -20
  113. package/dist/libs/crud-pro/models/ResModel.js +2 -2
  114. package/dist/libs/crud-pro/models/ServiceHub.d.ts +20 -20
  115. package/dist/libs/crud-pro/models/ServiceHub.js +2 -2
  116. package/dist/libs/crud-pro/models/SqlCfgModel.d.ts +23 -23
  117. package/dist/libs/crud-pro/models/SqlCfgModel.js +40 -40
  118. package/dist/libs/crud-pro/models/SqlSegArg.d.ts +6 -6
  119. package/dist/libs/crud-pro/models/SqlSegArg.js +12 -12
  120. package/dist/libs/crud-pro/models/Transaction.d.ts +50 -50
  121. package/dist/libs/crud-pro/models/Transaction.js +184 -179
  122. package/dist/libs/crud-pro/models/TransactionMySQL.d.ts +19 -19
  123. package/dist/libs/crud-pro/models/TransactionMySQL.js +48 -48
  124. package/dist/libs/crud-pro/models/TransactionPostgres.d.ts +19 -19
  125. package/dist/libs/crud-pro/models/TransactionPostgres.js +64 -64
  126. package/dist/libs/crud-pro/models/TransactionSqlServer.d.ts +9 -9
  127. package/dist/libs/crud-pro/models/TransactionSqlServer.js +61 -61
  128. package/dist/libs/crud-pro/models/keys.d.ts +111 -110
  129. package/dist/libs/crud-pro/models/keys.js +156 -154
  130. package/dist/libs/crud-pro/services/CrudProCachedCfgService.d.ts +11 -11
  131. package/dist/libs/crud-pro/services/CrudProCachedCfgService.js +73 -73
  132. package/dist/libs/crud-pro/services/CrudProExecuteFuncService.d.ts +9 -9
  133. package/dist/libs/crud-pro/services/CrudProExecuteFuncService.js +125 -125
  134. package/dist/libs/crud-pro/services/CrudProExecuteSqlService.d.ts +17 -17
  135. package/dist/libs/crud-pro/services/CrudProExecuteSqlService.js +224 -224
  136. package/dist/libs/crud-pro/services/CrudProFieldUpdateService.d.ts +9 -9
  137. package/dist/libs/crud-pro/services/CrudProFieldUpdateService.js +51 -51
  138. package/dist/libs/crud-pro/services/CrudProFieldValidateService.d.ts +13 -13
  139. package/dist/libs/crud-pro/services/CrudProFieldValidateService.js +148 -148
  140. package/dist/libs/crud-pro/services/CrudProGenSqlCondition.d.ts +25 -24
  141. package/dist/libs/crud-pro/services/CrudProGenSqlCondition.js +385 -355
  142. package/dist/libs/crud-pro/services/CrudProGenSqlService.d.ts +25 -25
  143. package/dist/libs/crud-pro/services/CrudProGenSqlService.js +165 -165
  144. package/dist/libs/crud-pro/services/CrudProOriginToExecuteSql.d.ts +32 -32
  145. package/dist/libs/crud-pro/services/CrudProOriginToExecuteSql.js +339 -339
  146. package/dist/libs/crud-pro/services/CrudProServiceBase.d.ts +24 -24
  147. package/dist/libs/crud-pro/services/CrudProServiceBase.js +88 -88
  148. package/dist/libs/crud-pro/services/CrudProTableMetaService.d.ts +9 -9
  149. package/dist/libs/crud-pro/services/CrudProTableMetaService.js +72 -72
  150. package/dist/libs/crud-pro/services/CurdProServiceHub.d.ts +32 -32
  151. package/dist/libs/crud-pro/services/CurdProServiceHub.js +64 -64
  152. package/dist/libs/crud-pro/utils/CompareUtils.d.ts +9 -9
  153. package/dist/libs/crud-pro/utils/CompareUtils.js +25 -25
  154. package/dist/libs/crud-pro/utils/CrudMonitor.d.ts +9 -9
  155. package/dist/libs/crud-pro/utils/CrudMonitor.js +12 -12
  156. package/dist/libs/crud-pro/utils/DatabaseName.d.ts +9 -9
  157. package/dist/libs/crud-pro/utils/DatabaseName.js +50 -50
  158. package/dist/libs/crud-pro/utils/DateTimeUtils.d.ts +7 -7
  159. package/dist/libs/crud-pro/utils/DateTimeUtils.js +21 -21
  160. package/dist/libs/crud-pro/utils/MemoryRefreshCache.d.ts +19 -19
  161. package/dist/libs/crud-pro/utils/MemoryRefreshCache.js +47 -47
  162. package/dist/libs/crud-pro/utils/MessageParseUtils.d.ts +5 -5
  163. package/dist/libs/crud-pro/utils/MessageParseUtils.js +33 -33
  164. package/dist/libs/crud-pro/utils/MixinUtils.d.ts +40 -40
  165. package/dist/libs/crud-pro/utils/MixinUtils.js +259 -258
  166. package/dist/libs/crud-pro/utils/ModelUtils.d.ts +11 -11
  167. package/dist/libs/crud-pro/utils/ModelUtils.js +54 -54
  168. package/dist/libs/crud-pro/utils/MultiKeyMap.d.ts +11 -11
  169. package/dist/libs/crud-pro/utils/MultiKeyMap.js +63 -63
  170. package/dist/libs/crud-pro/utils/SqlFuncUtils.d.ts +5 -5
  171. package/dist/libs/crud-pro/utils/SqlFuncUtils.js +29 -29
  172. package/dist/libs/crud-pro/utils/TypeUtils.d.ts +40 -40
  173. package/dist/libs/crud-pro/utils/TypeUtils.js +166 -166
  174. package/dist/libs/crud-pro/utils/ValidateUtils.d.ts +3 -3
  175. package/dist/libs/crud-pro/utils/ValidateUtils.js +165 -165
  176. package/dist/libs/crud-pro/utils/pool/MySQLUtils.d.ts +3 -3
  177. package/dist/libs/crud-pro/utils/pool/MySQLUtils.js +19 -19
  178. package/dist/libs/crud-pro/utils/pool/PostgresUtils.d.ts +3 -3
  179. package/dist/libs/crud-pro/utils/pool/PostgresUtils.js +20 -20
  180. package/dist/libs/crud-pro/utils/pool/SqlServerUtils.d.ts +3 -3
  181. package/dist/libs/crud-pro/utils/pool/SqlServerUtils.js +20 -20
  182. package/dist/libs/crud-pro/utils/sqlConvert/convertColumnName.d.ts +4 -4
  183. package/dist/libs/crud-pro/utils/sqlConvert/convertColumnName.js +35 -35
  184. package/dist/libs/crud-pro/utils/sqlConvert/convertMix.js +24 -24
  185. package/dist/libs/crud-pro/utils/sqlConvert/convertMsSql.d.ts +2 -2
  186. package/dist/libs/crud-pro/utils/sqlConvert/convertMsSql.js +14 -14
  187. package/dist/libs/crud-pro/utils/sqlConvert/convertPgSql.d.ts +2 -2
  188. package/dist/libs/crud-pro/utils/sqlConvert/convertPgSql.js +14 -14
  189. package/dist/libs/global-config/global-config.d.ts +71 -71
  190. package/dist/libs/global-config/global-config.js +38 -38
  191. package/dist/libs/utils/AsymmetricCrypto.d.ts +76 -76
  192. package/dist/libs/utils/AsymmetricCrypto.js +261 -261
  193. package/dist/libs/utils/base64.d.ts +9 -9
  194. package/dist/libs/utils/base64.js +42 -42
  195. package/dist/libs/utils/common-dto.d.ts +18 -18
  196. package/dist/libs/utils/common-dto.js +40 -40
  197. package/dist/libs/utils/crypto-utils.d.ts +3 -3
  198. package/dist/libs/utils/crypto-utils.js +55 -55
  199. package/dist/libs/utils/errorToString.d.ts +20 -20
  200. package/dist/libs/utils/errorToString.js +79 -79
  201. package/dist/libs/utils/fatcms-request.d.ts +45 -45
  202. package/dist/libs/utils/fatcms-request.js +161 -161
  203. package/dist/libs/utils/format-url.d.ts +17 -17
  204. package/dist/libs/utils/format-url.js +30 -30
  205. package/dist/libs/utils/functions.d.ts +11 -11
  206. package/dist/libs/utils/functions.js +99 -99
  207. package/dist/libs/utils/ordernum-utils.d.ts +22 -22
  208. package/dist/libs/utils/ordernum-utils.js +35 -35
  209. package/dist/libs/utils/parseConfig.d.ts +8 -8
  210. package/dist/libs/utils/parseConfig.js +47 -47
  211. package/dist/libs/utils/parseCreateSql.d.ts +10 -10
  212. package/dist/libs/utils/parseCreateSql.js +87 -87
  213. package/dist/libs/utils/render-utils.d.ts +40 -40
  214. package/dist/libs/utils/render-utils.js +158 -158
  215. package/dist/middleware/forbidden.middleware.d.ts +74 -74
  216. package/dist/middleware/forbidden.middleware.js +318 -307
  217. package/dist/middleware/global.middleware.d.ts +40 -40
  218. package/dist/middleware/global.middleware.js +310 -310
  219. package/dist/middleware/permission.middleware.d.ts +88 -88
  220. package/dist/middleware/permission.middleware.js +145 -145
  221. package/dist/middleware/rediscache.middleware.d.ts +28 -28
  222. package/dist/middleware/rediscache.middleware.js +114 -114
  223. package/dist/middleware/redislock.middleware.d.ts +29 -29
  224. package/dist/middleware/redislock.middleware.js +106 -106
  225. package/dist/middleware/tx.middleware.d.ts +55 -55
  226. package/dist/middleware/tx.middleware.js +83 -83
  227. package/dist/models/AsyncTaskModel.d.ts +74 -74
  228. package/dist/models/AsyncTaskModel.js +31 -31
  229. package/dist/models/FlowModel.d.ts +227 -227
  230. package/dist/models/FlowModel.js +53 -53
  231. package/dist/models/RedisKeys.d.ts +15 -15
  232. package/dist/models/RedisKeys.js +18 -18
  233. package/dist/models/SystemEntities.d.ts +118 -117
  234. package/dist/models/SystemEntities.js +18 -17
  235. package/dist/models/SystemPerm.d.ts +96 -96
  236. package/dist/models/SystemPerm.js +101 -101
  237. package/dist/models/SystemTables.d.ts +25 -25
  238. package/dist/models/SystemTables.js +28 -28
  239. package/dist/models/WorkbenchInfoTools.d.ts +7 -7
  240. package/dist/models/WorkbenchInfoTools.js +20 -20
  241. package/dist/models/bizmodels.d.ts +150 -150
  242. package/dist/models/bizmodels.js +62 -62
  243. package/dist/models/contextLogger.d.ts +27 -27
  244. package/dist/models/contextLogger.js +119 -119
  245. package/dist/models/devops.d.ts +12 -12
  246. package/dist/models/devops.js +19 -19
  247. package/dist/models/userSession.d.ts +67 -67
  248. package/dist/models/userSession.js +179 -179
  249. package/dist/schedule/anonymousContext.d.ts +15 -15
  250. package/dist/schedule/anonymousContext.js +74 -74
  251. package/dist/schedule/index.d.ts +4 -4
  252. package/dist/schedule/index.js +10 -10
  253. package/dist/schedule/runSchedule.d.ts +12 -12
  254. package/dist/schedule/runSchedule.js +68 -68
  255. package/dist/schedule/scheduleNames.d.ts +15 -15
  256. package/dist/schedule/scheduleNames.js +19 -19
  257. package/dist/service/AuthService.d.ts +56 -56
  258. package/dist/service/AuthService.js +251 -248
  259. package/dist/service/EnumInfoService.d.ts +30 -30
  260. package/dist/service/EnumInfoService.js +97 -97
  261. package/dist/service/FileCenterService.d.ts +64 -64
  262. package/dist/service/FileCenterService.js +422 -422
  263. package/dist/service/SysAppService.d.ts +15 -15
  264. package/dist/service/SysAppService.js +108 -108
  265. package/dist/service/SysConfigService.d.ts +10 -10
  266. package/dist/service/SysConfigService.js +64 -64
  267. package/dist/service/SysDictDataService.d.ts +9 -9
  268. package/dist/service/SysDictDataService.js +72 -72
  269. package/dist/service/SysMenuService.d.ts +51 -51
  270. package/dist/service/SysMenuService.js +58 -58
  271. package/dist/service/UserAccountService.d.ts +23 -23
  272. package/dist/service/UserAccountService.js +107 -107
  273. package/dist/service/UserSessionService.d.ts +43 -43
  274. package/dist/service/UserSessionService.js +163 -163
  275. package/dist/service/VisitStatService.d.ts +14 -14
  276. package/dist/service/VisitStatService.js +161 -161
  277. package/dist/service/WorkbenchService.d.ts +59 -59
  278. package/dist/service/WorkbenchService.js +249 -249
  279. package/dist/service/anyapi/AnyApiSandboxService.d.ts +15 -15
  280. package/dist/service/anyapi/AnyApiSandboxService.js +110 -110
  281. package/dist/service/anyapi/AnyApiService.d.ts +27 -27
  282. package/dist/service/anyapi/AnyApiService.js +181 -181
  283. package/dist/service/asyncTask/AsyncTaskRunnerService.d.ts +50 -50
  284. package/dist/service/asyncTask/AsyncTaskRunnerService.js +287 -287
  285. package/dist/service/asyncTask/AsyncTaskService.d.ts +7 -7
  286. package/dist/service/asyncTask/AsyncTaskService.js +34 -34
  287. package/dist/service/asyncTask/handler/ExcelInfoModel.d.ts +10 -10
  288. package/dist/service/asyncTask/handler/ExcelInfoModel.js +2 -2
  289. package/dist/service/asyncTask/handler/ExportExcelAsyncTaskHandler.d.ts +7 -7
  290. package/dist/service/asyncTask/handler/ExportExcelAsyncTaskHandler.js +216 -216
  291. package/dist/service/asyncTask/handler/ExportExcelByInnerHttpHandler.d.ts +36 -36
  292. package/dist/service/asyncTask/handler/ExportExcelByInnerHttpHandler.js +141 -141
  293. package/dist/service/asyncTask/handler/ExportExcelByStdCrudHandler.d.ts +46 -46
  294. package/dist/service/asyncTask/handler/ExportExcelByStdCrudHandler.js +135 -135
  295. package/dist/service/base/ApiBaseService.d.ts +22 -22
  296. package/dist/service/base/ApiBaseService.js +60 -60
  297. package/dist/service/base/ApiRateLimiter.d.ts +10 -10
  298. package/dist/service/base/ApiRateLimiter.js +51 -51
  299. package/dist/service/base/BaseService.d.ts +46 -45
  300. package/dist/service/base/BaseService.js +131 -127
  301. package/dist/service/base/cache/CacheServiceFactory.d.ts +26 -26
  302. package/dist/service/base/cache/CacheServiceFactory.js +122 -122
  303. package/dist/service/base/cache/CtxCache.d.ts +18 -18
  304. package/dist/service/base/cache/CtxCache.js +37 -37
  305. package/dist/service/base/cache/DiskCache.d.ts +19 -19
  306. package/dist/service/base/cache/DiskCache.js +81 -81
  307. package/dist/service/base/cache/MemoryCache.d.ts +12 -12
  308. package/dist/service/base/cache/MemoryCache.js +58 -58
  309. package/dist/service/base/cache/NoneCache.d.ts +10 -10
  310. package/dist/service/base/cache/NoneCache.js +19 -19
  311. package/dist/service/base/cache/RedisCache.d.ts +14 -14
  312. package/dist/service/base/cache/RedisCache.js +31 -31
  313. package/dist/service/crudstd/CrudStdActionService.d.ts +17 -17
  314. package/dist/service/crudstd/CrudStdActionService.js +32 -32
  315. package/dist/service/crudstd/CrudStdConstant.d.ts +58 -58
  316. package/dist/service/crudstd/CrudStdConstant.js +64 -64
  317. package/dist/service/crudstd/CrudStdRelationService.d.ts +11 -11
  318. package/dist/service/crudstd/CrudStdRelationService.js +179 -179
  319. package/dist/service/crudstd/CrudStdService.d.ts +59 -59
  320. package/dist/service/crudstd/CrudStdService.js +348 -348
  321. package/dist/service/curd/CrudProQuick.d.ts +60 -60
  322. package/dist/service/curd/CrudProQuick.js +167 -167
  323. package/dist/service/curd/CurdMixByAccountService.d.ts +14 -14
  324. package/dist/service/curd/CurdMixByAccountService.js +166 -166
  325. package/dist/service/curd/CurdMixByDictService.d.ts +12 -12
  326. package/dist/service/curd/CurdMixByDictService.js +114 -114
  327. package/dist/service/curd/CurdMixByLinkToCustomService.d.ts +30 -30
  328. package/dist/service/curd/CurdMixByLinkToCustomService.js +209 -209
  329. package/dist/service/curd/CurdMixBySysConfigService.d.ts +13 -13
  330. package/dist/service/curd/CurdMixBySysConfigService.js +116 -116
  331. package/dist/service/curd/CurdMixByWorkbenchService.d.ts +11 -11
  332. package/dist/service/curd/CurdMixByWorkbenchService.js +80 -80
  333. package/dist/service/curd/CurdMixService.d.ts +28 -28
  334. package/dist/service/curd/CurdMixService.js +100 -100
  335. package/dist/service/curd/CurdMixUtils.d.ts +57 -57
  336. package/dist/service/curd/CurdMixUtils.js +331 -331
  337. package/dist/service/curd/CurdProService.d.ts +32 -32
  338. package/dist/service/curd/CurdProService.js +215 -215
  339. package/dist/service/curd/fixCfgModel.d.ts +3 -3
  340. package/dist/service/curd/fixCfgModel.js +104 -104
  341. package/dist/service/curd/fixSoftDelete.d.ts +6 -6
  342. package/dist/service/curd/fixSoftDelete.js +43 -43
  343. package/dist/service/flow/FlowConfigService.d.ts +41 -41
  344. package/dist/service/flow/FlowConfigService.js +95 -95
  345. package/dist/service/flow/FlowInstanceCrudService.d.ts +35 -35
  346. package/dist/service/flow/FlowInstanceCrudService.js +257 -257
  347. package/dist/service/flow/FlowInstanceService.d.ts +88 -88
  348. package/dist/service/flow/FlowInstanceService.js +451 -451
  349. package/dist/service/proxyapi/ProxyApiLoadService.d.ts +21 -21
  350. package/dist/service/proxyapi/ProxyApiLoadService.js +167 -167
  351. package/dist/service/proxyapi/ProxyApiService.d.ts +61 -61
  352. package/dist/service/proxyapi/ProxyApiService.js +317 -297
  353. package/dist/service/proxyapi/ProxyApiUtils.d.ts +15 -15
  354. package/dist/service/proxyapi/ProxyApiUtils.js +34 -34
  355. package/dist/service/proxyapi/RouteHandler.d.ts +6 -5
  356. package/dist/service/proxyapi/RouteHandler.js +9 -9
  357. package/dist/service/proxyapi/RouteTrie.d.ts +12 -12
  358. package/dist/service/proxyapi/RouteTrie.js +64 -63
  359. package/dist/service/proxyapi/WeightedRandom.d.ts +9 -9
  360. package/dist/service/proxyapi/WeightedRandom.js +31 -31
  361. package/dist/service/proxyapi/WeightedRoundRobin.d.ts +8 -8
  362. package/dist/service/proxyapi/WeightedRoundRobin.js +33 -32
  363. package/index.d.ts +10 -10
  364. package/package.json +87 -87
  365. package/src/libs/crud-pro/models/Transaction.ts +5 -1
  366. package/src/libs/crud-pro/models/keys.ts +6 -2
  367. package/src/libs/crud-pro/services/CrudProGenSqlCondition.ts +37 -0
  368. package/src/libs/crud-pro/utils/CrudMonitor.ts +13 -13
  369. package/src/libs/crud-pro/utils/MixinUtils.ts +11 -10
  370. package/src/libs/utils/AsymmetricCrypto.ts +307 -307
  371. package/src/libs/utils/format-url.ts +29 -29
  372. package/src/libs/utils/render-utils.ts +223 -223
  373. package/src/middleware/forbidden.middleware.ts +17 -7
  374. package/src/middleware/global.middleware.ts +1 -1
  375. package/src/models/SystemEntities.ts +1 -0
  376. package/src/models/WorkbenchInfoTools.ts +19 -19
  377. package/src/service/AuthService.ts +3 -0
  378. package/src/service/SysAppService.ts +103 -103
  379. package/src/service/SysDictDataService.ts +63 -63
  380. package/src/service/SysMenuService.ts +87 -87
  381. package/src/service/WorkbenchService.ts +279 -279
  382. package/src/service/base/BaseService.ts +5 -0
  383. package/src/service/base/cache/CacheServiceFactory.ts +135 -135
  384. package/src/service/base/cache/CtxCache.ts +45 -45
  385. package/src/service/base/cache/DiskCache.ts +90 -90
  386. package/src/service/base/cache/MemoryCache.ts +68 -68
  387. package/src/service/base/cache/NoneCache.ts +24 -24
  388. package/src/service/base/cache/RedisCache.ts +41 -41
  389. package/src/service/crudstd/CrudStdService.ts +2 -1
  390. package/src/service/curd/CurdMixByAccountService.ts +177 -177
  391. package/src/service/curd/fixSoftDelete.ts +58 -58
  392. package/src/service/proxyapi/ProxyApiService.ts +22 -1
  393. package/src/service/proxyapi/RouteHandler.ts +4 -2
  394. package/src/service/proxyapi/RouteTrie.ts +1 -1
  395. package/src/service/proxyapi/WeightedRoundRobin.ts +2 -1
  396. package/tsconfig.json +32 -32
@@ -1,297 +1,317 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.ProxyApiService = void 0;
13
- const core_1 = require("@midwayjs/core");
14
- const _ = require("lodash");
15
- const RouteTrie_1 = require("./RouteTrie");
16
- const exceptions_1 = require("../../libs/crud-pro/exceptions");
17
- const devops_1 = require("../../models/devops");
18
- const CurdProService_1 = require("../curd/CurdProService");
19
- const SystemEntities_1 = require("../../models/SystemEntities");
20
- const axios_1 = require("axios");
21
- const fatcms_request_1 = require("../../libs/utils/fatcms-request");
22
- const ProxyApiUtils_1 = require("./ProxyApiUtils");
23
- const ProxyApiLoadService_1 = require("./ProxyApiLoadService");
24
- const ApiBaseService_1 = require("../base/ApiBaseService");
25
- const base64_1 = require("../../libs/utils/base64");
26
- /**
27
- * 接口代理
28
- */
29
- let ProxyApiService = class ProxyApiService extends ApiBaseService_1.ApiBaseService {
30
- /**
31
- * 转发请求
32
- * @param current_workbench_code 当前站点
33
- * @param upstream_path : 形如/[upstream_code]/[api_path]
34
- */
35
- async handleProxyRequest(current_workbench_code, upstream_path) {
36
- const routeTrie = (0, RouteTrie_1.getRouteTrie)(current_workbench_code);
37
- const ss = routeTrie.findLongestMatch(upstream_path);
38
- if (!ss) {
39
- throw new devops_1.BizException('路径没有匹配到', exceptions_1.Exceptions.CFG_NOT_FOUND);
40
- }
41
- const handler = _.get(ss, 'handler');
42
- const cfgInfo = handler === null || handler === void 0 ? void 0 : handler.cfgInfo;
43
- if (!cfgInfo) {
44
- throw new devops_1.BizException('路径配置没有匹配到', exceptions_1.Exceptions.CFG_NOT_FOUND);
45
- }
46
- return this._handleProxyRequestForCfg(cfgInfo, upstream_path);
47
- }
48
- /**
49
- * 转发请求
50
- * @param proxyApiEntity
51
- * @param upstream_path
52
- * @private
53
- */
54
- async _handleProxyRequestForCfg(proxyApiEntity, upstream_path) {
55
- await super.beforeCheckApiAccessibility(ApiBaseService_1.API_BASE_TYPE.PROXY_API, proxyApiEntity);
56
- const targetList = proxyApiEntity.targetList;
57
- if (!Array.isArray(targetList) || targetList.length === 0) {
58
- throw new devops_1.BizException('目标服务器找不到', exceptions_1.Exceptions.CFG_NOT_FOUND);
59
- }
60
- const ctx = this.ctx;
61
- const targetBaseUrl = this.selectTargetByBalanceStrategy(proxyApiEntity, ctx);
62
- if (!targetBaseUrl) {
63
- throw new devops_1.BizException('目标服务器找不到', exceptions_1.Exceptions.CFG_NOT_FOUND);
64
- }
65
- const newPath = this.toNewPathByMapping(upstream_path, proxyApiEntity);
66
- const targetUrl = new URL(newPath, targetBaseUrl);
67
- targetUrl.search = new URLSearchParams(ctx.query).toString();
68
- // const response_type: ResponseType = (proxyApiEntity.response_type || 'stream') as any;
69
- const response_type = 'stream';
70
- try {
71
- const headers = {
72
- ...ctx.headers,
73
- host: targetUrl.host, // 设置正确的 host
74
- };
75
- delete headers['content-length'];
76
- this.setRequestHeaders(headers, proxyApiEntity);
77
- const axiosParams = {
78
- method: ctx.method,
79
- url: targetUrl.toString(),
80
- data: ctx.request.body,
81
- headers: headers,
82
- responseType: response_type,
83
- timeout: Number(proxyApiEntity.timeout_ms) || 5 * 60 * 1000,
84
- validateStatus: () => true,
85
- };
86
- const response = await (0, axios_1.default)(axiosParams);
87
- ctx.status = response.status;
88
- const resHeaders = this.toResHeaders(response.headers);
89
- ctx.set({
90
- ...resHeaders,
91
- 'cache-control': 'no-store',
92
- 'x-proxy-server': 'fatcms-server', // 添加代理标识
93
- });
94
- if (response_type === 'stream') {
95
- return this.handleResponseTypeStream(response, ctx);
96
- }
97
- else if (response_type === 'json') {
98
- return this.handleResponseTypeJSON(response, ctx);
99
- }
100
- else {
101
- this.ctx.body = response.data;
102
- return null;
103
- }
104
- }
105
- catch (e) {
106
- ctx.contextLogger.error('Proxy request failed ', e);
107
- ctx.status = 500;
108
- ctx.body = { success: false, message: 'Proxy request failed => ' + e.message };
109
- }
110
- return null;
111
- }
112
- /**
113
- * 处理JSON响应
114
- * @param response
115
- * @param ctx
116
- * @private
117
- */
118
- handleResponseTypeJSON(response, ctx) {
119
- return Promise.resolve(response.data);
120
- }
121
- /**
122
- * 处理stream响应
123
- * @param response
124
- * @param ctx
125
- * @private
126
- */
127
- handleResponseTypeStream(response, ctx) {
128
- // 流式传输处理
129
- return new Promise((resolve, reject) => {
130
- response.data
131
- .on('data', chunk => {
132
- ctx.res.write(chunk);
133
- })
134
- .on('end', () => {
135
- ctx.res.end();
136
- resolve();
137
- })
138
- .on('error', err => {
139
- ctx.res.destroy(err);
140
- reject(err);
141
- });
142
- // 处理客户端断开连接
143
- ctx.req.on('close', () => {
144
- response.data.destroy();
145
- reject(new Error('Client disconnected'));
146
- });
147
- });
148
- }
149
- /**
150
- * 获取响应的headers数据
151
- * @param headers
152
- * @private
153
- */
154
- toResHeaders(headers) {
155
- if (!headers) {
156
- return {};
157
- }
158
- if (typeof headers.toJSON === 'function') {
159
- return headers.toJSON(false);
160
- }
161
- return headers;
162
- }
163
- /**
164
- * 获取转发到目的服务器的路径
165
- * @param upstream_path
166
- * @param proxyApiEntity
167
- * @private
168
- */
169
- toNewPathByMapping(upstream_path, proxyApiEntity) {
170
- const result = upstream_path.substring(proxyApiEntity.upstream_code.length + 1);
171
- this.logInfo('toNewPathByMapping', { upstream_path, result });
172
- return result;
173
- }
174
- /**
175
- * 根据负载均衡策略,选择目标服务器
176
- * @param proxyApiEntity
177
- * @param ctx
178
- * @private
179
- */
180
- selectTargetByBalanceStrategy(proxyApiEntity, ctx) {
181
- const targetList = proxyApiEntity.targetList;
182
- const strategy = proxyApiEntity.balanceStrategy;
183
- if ((0, fatcms_request_1.isEnableDebug)(ctx)) {
184
- // 在调试模式下,可以强制指定某台机器。
185
- const targetOrigin = (0, fatcms_request_1.getDebugProxyTarget)(ctx);
186
- if (typeof targetOrigin === 'string' && targetOrigin.startsWith('http')) {
187
- return targetOrigin;
188
- }
189
- }
190
- if (!targetList || targetList.length === 0) {
191
- return null;
192
- }
193
- if (strategy === ProxyApiUtils_1.BALANCE_STRATEGY.WEIGHTED_RANDOM) {
194
- const weightedRandom = proxyApiEntity.weightedRandom;
195
- const ss = weightedRandom.next();
196
- return ss ? ss.origin : null;
197
- }
198
- else if (strategy === ProxyApiUtils_1.BALANCE_STRATEGY.WEIGHTED_ROUND_ROBIN) {
199
- const weightedRoundRobin = proxyApiEntity.weightedRoundRobin;
200
- const ss = weightedRoundRobin.next();
201
- return ss ? ss.origin : null;
202
- }
203
- else if (strategy === ProxyApiUtils_1.BALANCE_STRATEGY.USER_SESSION_HASH) {
204
- // 根据用户sessionId hash
205
- const sessionId = ctx.userSession.getSessionValue('sessionId') || `random_${Math.random()}`;
206
- proxyApiEntity.targetIndex = (0, ProxyApiUtils_1.stringHashMod)(`${sessionId}`, targetList.length);
207
- }
208
- else if (strategy === ProxyApiUtils_1.BALANCE_STRATEGY.USER_ACCOUNT_HASH) {
209
- // 根据用户accountId hash
210
- const accountId = ctx.userSession.getSessionValue('accountId') || `random_${Math.random()}`;
211
- proxyApiEntity.targetIndex = (0, ProxyApiUtils_1.stringHashMod)(`${accountId}`, targetList.length);
212
- }
213
- else if (strategy === ProxyApiUtils_1.BALANCE_STRATEGY.IP_HASH) {
214
- // 根据用户IP地址hash
215
- const ip = (0, fatcms_request_1.getRealIpSafe)(ctx);
216
- proxyApiEntity.targetIndex = (0, ProxyApiUtils_1.stringHashMod)(ip, targetList.length);
217
- }
218
- else if (strategy === ProxyApiUtils_1.BALANCE_STRATEGY.RANDOM) {
219
- // 随机
220
- proxyApiEntity.targetIndex = (0, ProxyApiUtils_1.stringHashMod)(`${Math.random()}`, targetList.length);
221
- }
222
- else {
223
- // 默认,轮询
224
- proxyApiEntity.targetIndex = (proxyApiEntity.targetIndex + 1) % targetList.length;
225
- }
226
- const ss = targetList[proxyApiEntity.targetIndex];
227
- return ss ? ss.origin : null;
228
- }
229
- setRequestHeaders(headers, proxyApiEntity) {
230
- const ctx = this.ctx;
231
- // 转发IP
232
- if (proxyApiEntity.pass_real_ip) {
233
- const realIp = (0, fatcms_request_1.getRealIpSafe)(ctx);
234
- headers['x-real-ip'] = realIp;
235
- // 保留原始的 x-forwarded-for,或者创建新的
236
- const existingForwarded = ctx.headers['x-forwarded-for'];
237
- headers['x-forwarded-for'] = existingForwarded ? `${existingForwarded}, ${realIp}` : realIp;
238
- }
239
- // 转发用户上下文
240
- const userContextHeader = this.buildUserContextHeader(proxyApiEntity);
241
- if (userContextHeader) {
242
- headers['x-fatcms-usercontext'] = userContextHeader;
243
- }
244
- else {
245
- delete headers['x-fatcms-usercontext']; // 只有自己构建的才能被转发。前面传过来的,不要转发。
246
- }
247
- if (proxyApiEntity.change_host && proxyApiEntity.change_host.length > 0) {
248
- headers.host = proxyApiEntity.change_host;
249
- }
250
- if (proxyApiEntity.change_origin && proxyApiEntity.change_origin.length > 0) {
251
- headers.origin = proxyApiEntity.change_origin;
252
- }
253
- }
254
- buildUserContextHeader(proxyApiEntity) {
255
- var _a, _b;
256
- // 传递整个用户上下文
257
- if (proxyApiEntity.user_context === SystemEntities_1.ProxyUserContextEnum.SESSION_INFO) {
258
- const isLogin = this.ctx.userSession.isLogin();
259
- const sessionInfo = this.ctx.userSession.getSessionInfo();
260
- const workbenchCode = (_a = this.ctx.workbenchInfo) === null || _a === void 0 ? void 0 : _a.workbench_code;
261
- return (0, base64_1.toBase64)({ ...sessionInfo, isLogin, workbenchCode });
262
- }
263
- // 只传递用户基本信息
264
- if (proxyApiEntity.user_context === SystemEntities_1.ProxyUserContextEnum.BASIC_INFO) {
265
- const isLogin = this.ctx.userSession.isLogin();
266
- const sessionInfo = this.ctx.userSession.getSessionInfo();
267
- const workbenchCode = (_b = this.ctx.workbenchInfo) === null || _b === void 0 ? void 0 : _b.workbench_code;
268
- const userBasicInfo = { isLogin };
269
- if (sessionInfo && isLogin) {
270
- userBasicInfo.loginName = sessionInfo.loginName;
271
- userBasicInfo.sessionId = sessionInfo.sessionId;
272
- userBasicInfo.accountId = sessionInfo.accountId;
273
- userBasicInfo.workbenchCode = sessionInfo.workbenchCode;
274
- userBasicInfo.accountType = sessionInfo.accountType;
275
- }
276
- userBasicInfo.workbenchCode = workbenchCode;
277
- return (0, base64_1.toBase64)(userBasicInfo);
278
- }
279
- return null;
280
- }
281
- };
282
- __decorate([
283
- (0, core_1.Inject)(),
284
- __metadata("design:type", Object)
285
- ], ProxyApiService.prototype, "ctx", void 0);
286
- __decorate([
287
- (0, core_1.Inject)(),
288
- __metadata("design:type", CurdProService_1.CurdProService)
289
- ], ProxyApiService.prototype, "curdProService", void 0);
290
- __decorate([
291
- (0, core_1.Inject)(),
292
- __metadata("design:type", ProxyApiLoadService_1.ProxyApiLoadService)
293
- ], ProxyApiService.prototype, "proxyApiLoadService", void 0);
294
- ProxyApiService = __decorate([
295
- (0, core_1.Provide)()
296
- ], ProxyApiService);
297
- exports.ProxyApiService = ProxyApiService;
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ProxyApiService = void 0;
13
+ const core_1 = require("@midwayjs/core");
14
+ const _ = require("lodash");
15
+ const RouteTrie_1 = require("./RouteTrie");
16
+ const exceptions_1 = require("../../libs/crud-pro/exceptions");
17
+ const devops_1 = require("../../models/devops");
18
+ const CurdProService_1 = require("../curd/CurdProService");
19
+ const SystemEntities_1 = require("../../models/SystemEntities");
20
+ const axios_1 = require("axios");
21
+ const fatcms_request_1 = require("../../libs/utils/fatcms-request");
22
+ const ProxyApiUtils_1 = require("./ProxyApiUtils");
23
+ const ProxyApiLoadService_1 = require("./ProxyApiLoadService");
24
+ const ApiBaseService_1 = require("../base/ApiBaseService");
25
+ const base64_1 = require("../../libs/utils/base64");
26
+ /**
27
+ * 接口代理
28
+ */
29
+ let ProxyApiService = class ProxyApiService extends ApiBaseService_1.ApiBaseService {
30
+ /**
31
+ * 转发请求
32
+ * @param current_workbench_code 当前站点
33
+ * @param upstream_path : 形如/[upstream_code]/[api_path]
34
+ */
35
+ async handleProxyRequest(current_workbench_code, upstream_path) {
36
+ const routeTrie = (0, RouteTrie_1.getRouteTrie)(current_workbench_code);
37
+ const ss = routeTrie.findLongestMatch(upstream_path);
38
+ if (!ss) {
39
+ throw new devops_1.BizException('路径没有匹配到', exceptions_1.Exceptions.CFG_NOT_FOUND);
40
+ }
41
+ const handler = _.get(ss, 'handler');
42
+ const cfgInfo = handler === null || handler === void 0 ? void 0 : handler.cfgInfo;
43
+ if (!cfgInfo) {
44
+ throw new devops_1.BizException('路径配置没有匹配到', exceptions_1.Exceptions.CFG_NOT_FOUND);
45
+ }
46
+ const proxyApiEntity = JSON.parse(JSON.stringify(cfgInfo));
47
+ return this._handleProxyRequestForCfg(proxyApiEntity, upstream_path);
48
+ }
49
+ /**
50
+ * 转发请求
51
+ * @param proxyApiEntity
52
+ * @param upstream_path
53
+ * @private
54
+ */
55
+ async _handleProxyRequestForCfg(proxyApiEntity, upstream_path) {
56
+ await super.beforeCheckApiAccessibility(ApiBaseService_1.API_BASE_TYPE.PROXY_API, proxyApiEntity);
57
+ const targetList = proxyApiEntity.targetList;
58
+ if (!Array.isArray(targetList) || targetList.length === 0) {
59
+ throw new devops_1.BizException('目标服务器找不到', exceptions_1.Exceptions.CFG_NOT_FOUND);
60
+ }
61
+ const ctx = this.ctx;
62
+ const targetBaseUrl = this.selectTargetByBalanceStrategy(proxyApiEntity, ctx);
63
+ if (!targetBaseUrl) {
64
+ throw new devops_1.BizException('目标服务器找不到', exceptions_1.Exceptions.CFG_NOT_FOUND);
65
+ }
66
+ const newPath = this.toNewPathByMapping(upstream_path, proxyApiEntity);
67
+ const targetUrl = new URL(newPath, targetBaseUrl);
68
+ targetUrl.search = new URLSearchParams(ctx.query).toString();
69
+ // const response_type: ResponseType = (proxyApiEntity.response_type || 'stream') as any;
70
+ const response_type = 'stream';
71
+ try {
72
+ const headers = {
73
+ ...ctx.headers,
74
+ host: targetUrl.host, // 设置正确的 host
75
+ };
76
+ delete headers['content-length'];
77
+ this.setRequestHeaders(headers, proxyApiEntity);
78
+ const axiosParams = {
79
+ method: ctx.method,
80
+ url: targetUrl.toString(),
81
+ data: ctx.request.body,
82
+ headers: headers,
83
+ responseType: response_type,
84
+ timeout: Number(proxyApiEntity.timeout_ms) || 5 * 60 * 1000,
85
+ validateStatus: () => true,
86
+ };
87
+ const response = await (0, axios_1.default)(axiosParams);
88
+ ctx.status = response.status;
89
+ const resHeaders = this.toResHeaders(response.headers);
90
+ ctx.set({
91
+ ...resHeaders,
92
+ 'cache-control': 'no-store',
93
+ 'x-proxy-server': 'fatcms-server', // 添加代理标识
94
+ });
95
+ if (response_type === 'stream') {
96
+ return this.handleResponseTypeStream(response, ctx);
97
+ }
98
+ else if (response_type === 'json') {
99
+ return this.handleResponseTypeJSON(response, ctx);
100
+ }
101
+ else {
102
+ this.ctx.body = response.data;
103
+ return null;
104
+ }
105
+ }
106
+ catch (e) {
107
+ ctx.contextLogger.error('Proxy request failed ', e);
108
+ ctx.status = 500;
109
+ ctx.body = { success: false, message: 'Proxy request failed => ' + e.message };
110
+ }
111
+ return null;
112
+ }
113
+ /**
114
+ * 处理JSON响应
115
+ * @param response
116
+ * @param ctx
117
+ * @private
118
+ */
119
+ handleResponseTypeJSON(response, ctx) {
120
+ return Promise.resolve(response.data);
121
+ }
122
+ /**
123
+ * 处理stream响应
124
+ * @param response
125
+ * @param ctx
126
+ * @private
127
+ */
128
+ handleResponseTypeStream(response, ctx) {
129
+ // 流式传输处理
130
+ return new Promise((resolve, reject) => {
131
+ response.data
132
+ .on('data', chunk => {
133
+ ctx.res.write(chunk);
134
+ })
135
+ .on('end', () => {
136
+ ctx.res.end();
137
+ resolve();
138
+ })
139
+ .on('error', err => {
140
+ ctx.res.destroy(err);
141
+ reject(err);
142
+ });
143
+ // 处理客户端断开连接
144
+ ctx.req.on('close', () => {
145
+ response.data.destroy();
146
+ reject(new Error('Client disconnected'));
147
+ });
148
+ });
149
+ }
150
+ /**
151
+ * 获取响应的headers数据
152
+ * @param headers
153
+ * @private
154
+ */
155
+ toResHeaders(headers) {
156
+ if (!headers) {
157
+ return {};
158
+ }
159
+ if (typeof headers.toJSON === 'function') {
160
+ return headers.toJSON(false);
161
+ }
162
+ return headers;
163
+ }
164
+ /**
165
+ * 获取转发到目的服务器的路径
166
+ * @param upstream_path
167
+ * @param proxyApiEntity
168
+ * @private
169
+ */
170
+ toNewPathByMapping(upstream_path, proxyApiEntity) {
171
+ const result = upstream_path.substring(proxyApiEntity.upstream_code.length + 1);
172
+ this.logInfo('toNewPathByMapping', { upstream_path, result });
173
+ return result;
174
+ }
175
+ /**
176
+ * 根据负载均衡策略,选择目标服务器
177
+ * @param proxyApiEntity
178
+ * @param ctx
179
+ * @private
180
+ */
181
+ selectTargetByBalanceStrategy(proxyApiEntity, ctx) {
182
+ const targetList = proxyApiEntity.targetList;
183
+ const strategy = proxyApiEntity.balanceStrategy;
184
+ if ((0, fatcms_request_1.isEnableDebug)(ctx)) {
185
+ // 在调试模式下,可以强制指定某台机器。
186
+ const targetOrigin = (0, fatcms_request_1.getDebugProxyTarget)(ctx);
187
+ if (typeof targetOrigin === 'string' && targetOrigin.startsWith('http')) {
188
+ return targetOrigin;
189
+ }
190
+ }
191
+ if (!targetList || targetList.length === 0) {
192
+ return null;
193
+ }
194
+ if (strategy === ProxyApiUtils_1.BALANCE_STRATEGY.WEIGHTED_RANDOM) {
195
+ const weightedRandom = proxyApiEntity.weightedRandom;
196
+ const ss = weightedRandom.next();
197
+ return ss ? ss.origin : null;
198
+ }
199
+ else if (strategy === ProxyApiUtils_1.BALANCE_STRATEGY.WEIGHTED_ROUND_ROBIN) {
200
+ const weightedRoundRobin = proxyApiEntity.weightedRoundRobin;
201
+ const ss = weightedRoundRobin.next();
202
+ return ss ? ss.origin : null;
203
+ }
204
+ else if (strategy === ProxyApiUtils_1.BALANCE_STRATEGY.USER_SESSION_HASH) {
205
+ // 根据用户sessionId hash
206
+ const sessionId = ctx.userSession.getSessionValue('sessionId') || `random_${Math.random()}`;
207
+ proxyApiEntity.targetIndex = (0, ProxyApiUtils_1.stringHashMod)(`${sessionId}`, targetList.length);
208
+ }
209
+ else if (strategy === ProxyApiUtils_1.BALANCE_STRATEGY.USER_ACCOUNT_HASH) {
210
+ // 根据用户accountId hash
211
+ const accountId = ctx.userSession.getSessionValue('accountId') || `random_${Math.random()}`;
212
+ proxyApiEntity.targetIndex = (0, ProxyApiUtils_1.stringHashMod)(`${accountId}`, targetList.length);
213
+ }
214
+ else if (strategy === ProxyApiUtils_1.BALANCE_STRATEGY.IP_HASH) {
215
+ // 根据用户IP地址hash
216
+ const ip = (0, fatcms_request_1.getRealIpSafe)(ctx);
217
+ proxyApiEntity.targetIndex = (0, ProxyApiUtils_1.stringHashMod)(ip, targetList.length);
218
+ }
219
+ else if (strategy === ProxyApiUtils_1.BALANCE_STRATEGY.RANDOM) {
220
+ // 随机
221
+ proxyApiEntity.targetIndex = (0, ProxyApiUtils_1.stringHashMod)(`${Math.random()}`, targetList.length);
222
+ }
223
+ else {
224
+ // 默认,轮询
225
+ proxyApiEntity.targetIndex = (proxyApiEntity.targetIndex + 1) % targetList.length;
226
+ }
227
+ const ss = targetList[proxyApiEntity.targetIndex];
228
+ return ss ? ss.origin : null;
229
+ }
230
+ setRequestHeaders(headers, proxyApiEntity) {
231
+ const ctx = this.ctx;
232
+ // 转发IP
233
+ if (proxyApiEntity.pass_real_ip) {
234
+ const realIp = (0, fatcms_request_1.getRealIpSafe)(ctx);
235
+ headers['x-real-ip'] = realIp;
236
+ // 保留原始的 x-forwarded-for,或者创建新的
237
+ const existingForwarded = ctx.headers['x-forwarded-for'];
238
+ headers['x-forwarded-for'] = existingForwarded ? `${existingForwarded}, ${realIp}` : realIp;
239
+ }
240
+ // 转发用户上下文
241
+ const userContextHeader = this.buildUserContextHeader(proxyApiEntity);
242
+ if (userContextHeader) {
243
+ headers['x-fatcms-usercontext'] = userContextHeader;
244
+ }
245
+ else {
246
+ delete headers['x-fatcms-usercontext']; // 只有自己构建的才能被转发。前面传过来的,不要转发。
247
+ }
248
+ if (proxyApiEntity.change_host && proxyApiEntity.change_host.length > 0) {
249
+ headers.host = proxyApiEntity.change_host;
250
+ }
251
+ if (proxyApiEntity.change_origin && proxyApiEntity.change_origin.length > 0) {
252
+ headers.origin = proxyApiEntity.change_origin;
253
+ }
254
+ }
255
+ buildUserContextHeader(proxyApiEntity) {
256
+ var _a, _b, _c;
257
+ // 传递整个用户上下文
258
+ if (proxyApiEntity.user_context === SystemEntities_1.ProxyUserContextEnum.SESSION_INFO) {
259
+ const isLogin = this.ctx.userSession.isLogin();
260
+ const sessionInfo = this.ctx.userSession.getSessionInfo();
261
+ const workbenchCode = (_a = this.ctx.workbenchInfo) === null || _a === void 0 ? void 0 : _a.workbench_code;
262
+ return (0, base64_1.toBase64)({ ...sessionInfo, isLogin, workbenchCode });
263
+ }
264
+ // 只传递用户基本信息
265
+ if (proxyApiEntity.user_context === SystemEntities_1.ProxyUserContextEnum.BASIC_INFO) {
266
+ const isLogin = this.ctx.userSession.isLogin();
267
+ const sessionInfo = this.ctx.userSession.getSessionInfo();
268
+ const workbenchCode = (_b = this.ctx.workbenchInfo) === null || _b === void 0 ? void 0 : _b.workbench_code;
269
+ const userBasicInfo = { isLogin };
270
+ if (sessionInfo && isLogin) {
271
+ userBasicInfo.nickName = sessionInfo.nickName;
272
+ userBasicInfo.loginName = sessionInfo.loginName;
273
+ userBasicInfo.sessionId = sessionInfo.sessionId;
274
+ userBasicInfo.accountId = sessionInfo.accountId;
275
+ userBasicInfo.workbenchCode = sessionInfo.workbenchCode;
276
+ userBasicInfo.accountType = sessionInfo.accountType;
277
+ }
278
+ userBasicInfo.workbenchCode = workbenchCode;
279
+ return (0, base64_1.toBase64)(userBasicInfo);
280
+ }
281
+ // 传递用户基本信息和BizExt
282
+ if (proxyApiEntity.user_context === SystemEntities_1.ProxyUserContextEnum.BASIC_INFO_BIZ_EXT) {
283
+ const isLogin = this.ctx.userSession.isLogin();
284
+ const sessionInfo = this.ctx.userSession.getSessionInfo();
285
+ const workbenchCode = (_c = this.ctx.workbenchInfo) === null || _c === void 0 ? void 0 : _c.workbench_code;
286
+ const userBasicInfo = { isLogin };
287
+ if (sessionInfo && isLogin) {
288
+ userBasicInfo.nickName = sessionInfo.nickName;
289
+ userBasicInfo.loginName = sessionInfo.loginName;
290
+ userBasicInfo.sessionId = sessionInfo.sessionId;
291
+ userBasicInfo.accountId = sessionInfo.accountId;
292
+ userBasicInfo.workbenchCode = sessionInfo.workbenchCode;
293
+ userBasicInfo.accountType = sessionInfo.accountType;
294
+ userBasicInfo.bizExt = sessionInfo.bizExt; // 多了一个bizExt
295
+ }
296
+ userBasicInfo.workbenchCode = workbenchCode;
297
+ return (0, base64_1.toBase64)(userBasicInfo);
298
+ }
299
+ return null;
300
+ }
301
+ };
302
+ __decorate([
303
+ (0, core_1.Inject)(),
304
+ __metadata("design:type", Object)
305
+ ], ProxyApiService.prototype, "ctx", void 0);
306
+ __decorate([
307
+ (0, core_1.Inject)(),
308
+ __metadata("design:type", CurdProService_1.CurdProService)
309
+ ], ProxyApiService.prototype, "curdProService", void 0);
310
+ __decorate([
311
+ (0, core_1.Inject)(),
312
+ __metadata("design:type", ProxyApiLoadService_1.ProxyApiLoadService)
313
+ ], ProxyApiService.prototype, "proxyApiLoadService", void 0);
314
+ ProxyApiService = __decorate([
315
+ (0, core_1.Provide)()
316
+ ], ProxyApiService);
317
+ exports.ProxyApiService = ProxyApiService;