skyeye-svc-common-utils 2.0.0-dev0.2 → 2.0.0-dev0.20

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 (366) hide show
  1. package/package.json +27 -24
  2. package/src/index.ts +10 -7
  3. package/src/lib/azure/azureKeyVault.ts +44 -0
  4. package/src/lib/azure/cognitiveSearch/QueryType.ts +8 -0
  5. package/src/lib/azure/cognitiveSearch/SearchClient.ts +149 -0
  6. package/src/lib/azure/cognitiveSearch/SearchFacets.ts +16 -0
  7. package/src/lib/azure/cognitiveSearch/SearchFilter.ts +140 -0
  8. package/src/lib/azure/cognitiveSearch/SearchMode.ts +9 -0
  9. package/src/lib/azure/cognitiveSearch/SearchOption.ts +155 -0
  10. package/src/lib/azure/cognitiveSearch/SearchOrder.ts +9 -0
  11. package/src/lib/azure/cognitiveSearch/index.ts +7 -0
  12. package/src/lib/azure/index.ts +7 -0
  13. package/src/lib/fetch/index.ts +2 -0
  14. package/src/lib/fetch/sendRequest.ts +10 -0
  15. package/src/lib/fetch/sendRequestWithTimeout.ts +38 -0
  16. package/src/lib/httpClient.ts +27 -26
  17. package/src/lib/index.ts +3 -0
  18. package/src/lib/teams/broadcastLogMessage.ts +70 -0
  19. package/src/lib/teams/index.ts +2 -0
  20. package/src/lib/teams/logMessage.ts +55 -0
  21. package/src/utils/appConfig.ts +2 -2
  22. package/src/utils/appConst.ts +64 -0
  23. package/src/utils/baseClass/appDataSource.ts +23 -0
  24. package/src/utils/baseClass/baseController.ts +9 -9
  25. package/src/utils/index.ts +2 -0
  26. package/src/utils/logger/morganLogger.ts +2 -2
  27. package/src/utils/middleware/loadConfig.ts +150 -0
  28. package/.env +0 -3
  29. package/dist/index.d.ts +0 -29
  30. package/dist/index.js +0 -46
  31. package/dist/index.js.map +0 -1
  32. package/dist/interfaces/apiResponse.d.ts +0 -7
  33. package/dist/interfaces/apiResponse.js +0 -3
  34. package/dist/interfaces/apiResponse.js.map +0 -1
  35. package/dist/interfaces/grpcListRequest.d.ts +0 -6
  36. package/dist/interfaces/grpcListRequest.js +0 -3
  37. package/dist/interfaces/grpcListRequest.js.map +0 -1
  38. package/dist/interfaces/grpcServiceResponse.d.ts +0 -8
  39. package/dist/interfaces/grpcServiceResponse.js +0 -3
  40. package/dist/interfaces/grpcServiceResponse.js.map +0 -1
  41. package/dist/interfaces/index.d.ts +0 -10
  42. package/dist/interfaces/index.js +0 -26
  43. package/dist/interfaces/index.js.map +0 -1
  44. package/dist/interfaces/internalHttp/request/index.d.ts +0 -1
  45. package/dist/interfaces/internalHttp/request/index.js +0 -18
  46. package/dist/interfaces/internalHttp/request/index.js.map +0 -1
  47. package/dist/interfaces/internalHttp/request/search.d.ts +0 -9
  48. package/dist/interfaces/internalHttp/request/search.js +0 -3
  49. package/dist/interfaces/internalHttp/request/search.js.map +0 -1
  50. package/dist/interfaces/internalHttp/response/index.d.ts +0 -1
  51. package/dist/interfaces/internalHttp/response/index.js +0 -18
  52. package/dist/interfaces/internalHttp/response/index.js.map +0 -1
  53. package/dist/interfaces/internalHttp/response/search.d.ts +0 -10
  54. package/dist/interfaces/internalHttp/response/search.js +0 -3
  55. package/dist/interfaces/internalHttp/response/search.js.map +0 -1
  56. package/dist/interfaces/pagination.d.ts +0 -6
  57. package/dist/interfaces/pagination.js +0 -12
  58. package/dist/interfaces/pagination.js.map +0 -1
  59. package/dist/interfaces/serviceResponse.d.ts +0 -8
  60. package/dist/interfaces/serviceResponse.js +0 -3
  61. package/dist/interfaces/serviceResponse.js.map +0 -1
  62. package/dist/interfaces/subcriptionFeaturePermissionModel.d.ts +0 -8
  63. package/dist/interfaces/subcriptionFeaturePermissionModel.js +0 -14
  64. package/dist/interfaces/subcriptionFeaturePermissionModel.js.map +0 -1
  65. package/dist/interfaces/userInfo.d.ts +0 -17
  66. package/dist/interfaces/userInfo.js +0 -21
  67. package/dist/interfaces/userInfo.js.map +0 -1
  68. package/dist/lib/azure/azureBlobStorage.d.ts +0 -4
  69. package/dist/lib/azure/azureBlobStorage.js +0 -137
  70. package/dist/lib/azure/azureBlobStorage.js.map +0 -1
  71. package/dist/lib/azure/azureKeyVault.d.ts +0 -1
  72. package/dist/lib/azure/azureKeyVault.js +0 -27
  73. package/dist/lib/azure/azureKeyVault.js.map +0 -1
  74. package/dist/lib/azure/azureServiceBusClient.d.ts +0 -47
  75. package/dist/lib/azure/azureServiceBusClient.js +0 -139
  76. package/dist/lib/azure/azureServiceBusClient.js.map +0 -1
  77. package/dist/lib/azure/azureServiceBusQueue.d.ts +0 -1
  78. package/dist/lib/azure/azureServiceBusQueue.js +0 -42
  79. package/dist/lib/azure/azureServiceBusQueue.js.map +0 -1
  80. package/dist/lib/azure/azureStorageQueue.d.ts +0 -1
  81. package/dist/lib/azure/azureStorageQueue.js +0 -26
  82. package/dist/lib/azure/azureStorageQueue.js.map +0 -1
  83. package/dist/lib/azure/azureTableStorage.d.ts +0 -4
  84. package/dist/lib/azure/azureTableStorage.js +0 -67
  85. package/dist/lib/azure/azureTableStorage.js.map +0 -1
  86. package/dist/lib/httpClient.d.ts +0 -3
  87. package/dist/lib/httpClient.js +0 -51
  88. package/dist/lib/httpClient.js.map +0 -1
  89. package/dist/lib/redisClient.d.ts +0 -45
  90. package/dist/lib/redisClient.js +0 -153
  91. package/dist/lib/redisClient.js.map +0 -1
  92. package/dist/lib/sendGridClient.d.ts +0 -27
  93. package/dist/lib/sendGridClient.js +0 -62
  94. package/dist/lib/sendGridClient.js.map +0 -1
  95. package/dist/models/baseControllerParameter.d.ts +0 -9
  96. package/dist/models/baseControllerParameter.js +0 -24
  97. package/dist/models/baseControllerParameter.js.map +0 -1
  98. package/dist/models/campaign/grpcCampaignEventModel.d.ts +0 -18
  99. package/dist/models/campaign/grpcCampaignEventModel.js +0 -24
  100. package/dist/models/campaign/grpcCampaignEventModel.js.map +0 -1
  101. package/dist/models/campaign/grpcCampaignEventUserModel.d.ts +0 -13
  102. package/dist/models/campaign/grpcCampaignEventUserModel.js +0 -19
  103. package/dist/models/campaign/grpcCampaignEventUserModel.js.map +0 -1
  104. package/dist/models/campaign/grpcCampaignUserModel.d.ts +0 -12
  105. package/dist/models/campaign/grpcCampaignUserModel.js +0 -16
  106. package/dist/models/campaign/grpcCampaignUserModel.js.map +0 -1
  107. package/dist/models/campaign/index.d.ts +0 -4
  108. package/dist/models/campaign/index.js +0 -10
  109. package/dist/models/campaign/index.js.map +0 -1
  110. package/dist/models/emailtemplate/grpcEmailTemplateModel.d.ts +0 -10
  111. package/dist/models/emailtemplate/grpcEmailTemplateModel.js +0 -16
  112. package/dist/models/emailtemplate/grpcEmailTemplateModel.js.map +0 -1
  113. package/dist/models/emailtemplate/index.d.ts +0 -2
  114. package/dist/models/emailtemplate/index.js +0 -6
  115. package/dist/models/emailtemplate/index.js.map +0 -1
  116. package/dist/models/index.d.ts +0 -10
  117. package/dist/models/index.js +0 -28
  118. package/dist/models/index.js.map +0 -1
  119. package/dist/models/organisation/grpcOrganisationModel.d.ts +0 -15
  120. package/dist/models/organisation/grpcOrganisationModel.js +0 -21
  121. package/dist/models/organisation/grpcOrganisationModel.js.map +0 -1
  122. package/dist/models/organisation/index.d.ts +0 -2
  123. package/dist/models/organisation/index.js +0 -6
  124. package/dist/models/organisation/index.js.map +0 -1
  125. package/dist/models/rbac/grpcRoleModel.d.ts +0 -9
  126. package/dist/models/rbac/grpcRoleModel.js +0 -15
  127. package/dist/models/rbac/grpcRoleModel.js.map +0 -1
  128. package/dist/models/rbac/index.d.ts +0 -2
  129. package/dist/models/rbac/index.js +0 -6
  130. package/dist/models/rbac/index.js.map +0 -1
  131. package/dist/models/scoutai/grpcAIDETrainingResultListModel.d.ts +0 -8
  132. package/dist/models/scoutai/grpcAIDETrainingResultListModel.js +0 -14
  133. package/dist/models/scoutai/grpcAIDETrainingResultListModel.js.map +0 -1
  134. package/dist/models/scoutai/grpcNerlCorrectionModel.d.ts +0 -11
  135. package/dist/models/scoutai/grpcNerlCorrectionModel.js +0 -16
  136. package/dist/models/scoutai/grpcNerlCorrectionModel.js.map +0 -1
  137. package/dist/models/scoutai/grpcScoutAIListReq.d.ts +0 -12
  138. package/dist/models/scoutai/grpcScoutAIListReq.js +0 -17
  139. package/dist/models/scoutai/grpcScoutAIListReq.js.map +0 -1
  140. package/dist/models/scoutai/grpcScoutAIModel.d.ts +0 -10
  141. package/dist/models/scoutai/grpcScoutAIModel.js +0 -16
  142. package/dist/models/scoutai/grpcScoutAIModel.js.map +0 -1
  143. package/dist/models/scoutai/grpcScoutAIResult.d.ts +0 -10
  144. package/dist/models/scoutai/grpcScoutAIResult.js +0 -16
  145. package/dist/models/scoutai/grpcScoutAIResult.js.map +0 -1
  146. package/dist/models/scoutai/grpcTaasConfigAIModel.d.ts +0 -6
  147. package/dist/models/scoutai/grpcTaasConfigAIModel.js +0 -12
  148. package/dist/models/scoutai/grpcTaasConfigAIModel.js.map +0 -1
  149. package/dist/models/scoutai/grpcTaasConfigModel.d.ts +0 -11
  150. package/dist/models/scoutai/grpcTaasConfigModel.js +0 -15
  151. package/dist/models/scoutai/grpcTaasConfigModel.js.map +0 -1
  152. package/dist/models/scoutai/grpcTaasConfigUserModel.d.ts +0 -8
  153. package/dist/models/scoutai/grpcTaasConfigUserModel.js +0 -14
  154. package/dist/models/scoutai/grpcTaasConfigUserModel.js.map +0 -1
  155. package/dist/models/scoutai/grpcTagItemModel.d.ts +0 -9
  156. package/dist/models/scoutai/grpcTagItemModel.js +0 -15
  157. package/dist/models/scoutai/grpcTagItemModel.js.map +0 -1
  158. package/dist/models/scoutai/grpcVisualisationModel.d.ts +0 -11
  159. package/dist/models/scoutai/grpcVisualisationModel.js +0 -15
  160. package/dist/models/scoutai/grpcVisualisationModel.js.map +0 -1
  161. package/dist/models/scoutai/grpcVisualisationPositionModel.d.ts +0 -6
  162. package/dist/models/scoutai/grpcVisualisationPositionModel.js +0 -11
  163. package/dist/models/scoutai/grpcVisualisationPositionModel.js.map +0 -1
  164. package/dist/models/scoutai/index.d.ts +0 -10
  165. package/dist/models/scoutai/index.js +0 -22
  166. package/dist/models/scoutai/index.js.map +0 -1
  167. package/dist/models/search/grpcAggregation.d.ts +0 -9
  168. package/dist/models/search/grpcAggregation.js +0 -14
  169. package/dist/models/search/grpcAggregation.js.map +0 -1
  170. package/dist/models/search/grpcCmsModel.d.ts +0 -5
  171. package/dist/models/search/grpcCmsModel.js +0 -11
  172. package/dist/models/search/grpcCmsModel.js.map +0 -1
  173. package/dist/models/search/grpcCommonModels.d.ts +0 -109
  174. package/dist/models/search/grpcCommonModels.js +0 -80
  175. package/dist/models/search/grpcCommonModels.js.map +0 -1
  176. package/dist/models/search/grpcCompanyAggregation.d.ts +0 -14
  177. package/dist/models/search/grpcCompanyAggregation.js +0 -16
  178. package/dist/models/search/grpcCompanyAggregation.js.map +0 -1
  179. package/dist/models/search/grpcCompanyConnectModel.d.ts +0 -14
  180. package/dist/models/search/grpcCompanyConnectModel.js +0 -18
  181. package/dist/models/search/grpcCompanyConnectModel.js.map +0 -1
  182. package/dist/models/search/grpcCompanyListReq.d.ts +0 -36
  183. package/dist/models/search/grpcCompanyListReq.js +0 -42
  184. package/dist/models/search/grpcCompanyListReq.js.map +0 -1
  185. package/dist/models/search/grpcCompanyModel.d.ts +0 -43
  186. package/dist/models/search/grpcCompanyModel.js +0 -46
  187. package/dist/models/search/grpcCompanyModel.js.map +0 -1
  188. package/dist/models/search/grpcCompanyNewsCountModel.d.ts +0 -9
  189. package/dist/models/search/grpcCompanyNewsCountModel.js +0 -14
  190. package/dist/models/search/grpcCompanyNewsCountModel.js.map +0 -1
  191. package/dist/models/search/grpcCompanyPeriodMentionModel.d.ts +0 -18
  192. package/dist/models/search/grpcCompanyPeriodMentionModel.js +0 -22
  193. package/dist/models/search/grpcCompanyPeriodMentionModel.js.map +0 -1
  194. package/dist/models/search/grpcCompanyPreviewModel.d.ts +0 -26
  195. package/dist/models/search/grpcCompanyPreviewModel.js +0 -31
  196. package/dist/models/search/grpcCompanyPreviewModel.js.map +0 -1
  197. package/dist/models/search/grpcContentAggregation.d.ts +0 -8
  198. package/dist/models/search/grpcContentAggregation.js +0 -7
  199. package/dist/models/search/grpcContentAggregation.js.map +0 -1
  200. package/dist/models/search/grpcContentListReq.d.ts +0 -16
  201. package/dist/models/search/grpcContentListReq.js +0 -22
  202. package/dist/models/search/grpcContentListReq.js.map +0 -1
  203. package/dist/models/search/grpcContentModel.d.ts +0 -32
  204. package/dist/models/search/grpcContentModel.js +0 -37
  205. package/dist/models/search/grpcContentModel.js.map +0 -1
  206. package/dist/models/search/grpcContentPreviewModel.d.ts +0 -28
  207. package/dist/models/search/grpcContentPreviewModel.js +0 -33
  208. package/dist/models/search/grpcContentPreviewModel.js.map +0 -1
  209. package/dist/models/search/grpcContentTabsModel.d.ts +0 -10
  210. package/dist/models/search/grpcContentTabsModel.js +0 -15
  211. package/dist/models/search/grpcContentTabsModel.js.map +0 -1
  212. package/dist/models/search/grpcCountryModel.d.ts +0 -13
  213. package/dist/models/search/grpcCountryModel.js +0 -19
  214. package/dist/models/search/grpcCountryModel.js.map +0 -1
  215. package/dist/models/search/grpcFinancialModel.d.ts +0 -292
  216. package/dist/models/search/grpcFinancialModel.js +0 -7
  217. package/dist/models/search/grpcFinancialModel.js.map +0 -1
  218. package/dist/models/search/grpcMarketModel.d.ts +0 -16
  219. package/dist/models/search/grpcMarketModel.js +0 -6
  220. package/dist/models/search/grpcMarketModel.js.map +0 -1
  221. package/dist/models/search/grpcMentionContentCountModel.d.ts +0 -5
  222. package/dist/models/search/grpcMentionContentCountModel.js +0 -7
  223. package/dist/models/search/grpcMentionContentCountModel.js.map +0 -1
  224. package/dist/models/search/index.d.ts +0 -16
  225. package/dist/models/search/index.js +0 -44
  226. package/dist/models/search/index.js.map +0 -1
  227. package/dist/models/subscription/applicationFeatureModel.d.ts +0 -7
  228. package/dist/models/subscription/applicationFeatureModel.js +0 -12
  229. package/dist/models/subscription/applicationFeatureModel.js.map +0 -1
  230. package/dist/models/subscription/featureModel.d.ts +0 -7
  231. package/dist/models/subscription/featureModel.js +0 -13
  232. package/dist/models/subscription/featureModel.js.map +0 -1
  233. package/dist/models/subscription/grpcSubscriptionModel.d.ts +0 -6
  234. package/dist/models/subscription/grpcSubscriptionModel.js +0 -12
  235. package/dist/models/subscription/grpcSubscriptionModel.js.map +0 -1
  236. package/dist/models/subscription/index.d.ts +0 -10
  237. package/dist/models/subscription/index.js +0 -22
  238. package/dist/models/subscription/index.js.map +0 -1
  239. package/dist/models/subscription/licenseModel.d.ts +0 -6
  240. package/dist/models/subscription/licenseModel.js +0 -12
  241. package/dist/models/subscription/licenseModel.js.map +0 -1
  242. package/dist/models/subscription/licenseUserModel.d.ts +0 -5
  243. package/dist/models/subscription/licenseUserModel.js +0 -11
  244. package/dist/models/subscription/licenseUserModel.js.map +0 -1
  245. package/dist/models/subscription/subscriptionFeatureModel.d.ts +0 -6
  246. package/dist/models/subscription/subscriptionFeatureModel.js +0 -12
  247. package/dist/models/subscription/subscriptionFeatureModel.js.map +0 -1
  248. package/dist/models/subscription/subscriptionModel.d.ts +0 -14
  249. package/dist/models/subscription/subscriptionModel.js +0 -19
  250. package/dist/models/subscription/subscriptionModel.js.map +0 -1
  251. package/dist/models/subscription/subscriptionPlanFeatureModel.d.ts +0 -5
  252. package/dist/models/subscription/subscriptionPlanFeatureModel.js +0 -11
  253. package/dist/models/subscription/subscriptionPlanFeatureModel.js.map +0 -1
  254. package/dist/models/subscription/subscriptionPlanModel.d.ts +0 -15
  255. package/dist/models/subscription/subscriptionPlanModel.js +0 -20
  256. package/dist/models/subscription/subscriptionPlanModel.js.map +0 -1
  257. package/dist/models/user/grpcAccountInfoModel.d.ts +0 -5
  258. package/dist/models/user/grpcAccountInfoModel.js +0 -7
  259. package/dist/models/user/grpcAccountInfoModel.js.map +0 -1
  260. package/dist/models/user/grpcAppUserModel.d.ts +0 -15
  261. package/dist/models/user/grpcAppUserModel.js +0 -20
  262. package/dist/models/user/grpcAppUserModel.js.map +0 -1
  263. package/dist/models/user/grpcAppUserOrganisationStatistic.d.ts +0 -6
  264. package/dist/models/user/grpcAppUserOrganisationStatistic.js +0 -12
  265. package/dist/models/user/grpcAppUserOrganisationStatistic.js.map +0 -1
  266. package/dist/models/user/grpcAppUserRoleModel.d.ts +0 -5
  267. package/dist/models/user/grpcAppUserRoleModel.js +0 -11
  268. package/dist/models/user/grpcAppUserRoleModel.js.map +0 -1
  269. package/dist/models/user/grpcBrowseHistoryModel.d.ts +0 -8
  270. package/dist/models/user/grpcBrowseHistoryModel.js +0 -14
  271. package/dist/models/user/grpcBrowseHistoryModel.js.map +0 -1
  272. package/dist/models/user/grpcDailyDigestUserModel.d.ts +0 -10
  273. package/dist/models/user/grpcDailyDigestUserModel.js +0 -15
  274. package/dist/models/user/grpcDailyDigestUserModel.js.map +0 -1
  275. package/dist/models/user/grpcNotificationSettingModel.d.ts +0 -11
  276. package/dist/models/user/grpcNotificationSettingModel.js +0 -17
  277. package/dist/models/user/grpcNotificationSettingModel.js.map +0 -1
  278. package/dist/models/user/grpcSavedSearchModel.d.ts +0 -8
  279. package/dist/models/user/grpcSavedSearchModel.js +0 -14
  280. package/dist/models/user/grpcSavedSearchModel.js.map +0 -1
  281. package/dist/models/user/grpcSearchHistoryModel.d.ts +0 -7
  282. package/dist/models/user/grpcSearchHistoryModel.js +0 -13
  283. package/dist/models/user/grpcSearchHistoryModel.js.map +0 -1
  284. package/dist/models/user/grpcTargetListEntityModel.d.ts +0 -5
  285. package/dist/models/user/grpcTargetListEntityModel.js +0 -7
  286. package/dist/models/user/grpcTargetListEntityModel.js.map +0 -1
  287. package/dist/models/user/grpcTargetListExportModel.d.ts +0 -8
  288. package/dist/models/user/grpcTargetListExportModel.js +0 -14
  289. package/dist/models/user/grpcTargetListExportModel.js.map +0 -1
  290. package/dist/models/user/grpcTargetListItemModel.d.ts +0 -7
  291. package/dist/models/user/grpcTargetListItemModel.js +0 -13
  292. package/dist/models/user/grpcTargetListItemModel.js.map +0 -1
  293. package/dist/models/user/grpcTargetListModel.d.ts +0 -9
  294. package/dist/models/user/grpcTargetListModel.js +0 -14
  295. package/dist/models/user/grpcTargetListModel.js.map +0 -1
  296. package/dist/models/user/index.d.ts +0 -14
  297. package/dist/models/user/index.js +0 -30
  298. package/dist/models/user/index.js.map +0 -1
  299. package/dist/utils/appConfig.d.ts +0 -45
  300. package/dist/utils/appConfig.js +0 -57
  301. package/dist/utils/appConfig.js.map +0 -1
  302. package/dist/utils/appConst.d.ts +0 -139
  303. package/dist/utils/appConst.js +0 -159
  304. package/dist/utils/appConst.js.map +0 -1
  305. package/dist/utils/authentication/auth.d.ts +0 -2
  306. package/dist/utils/authentication/auth.js +0 -163
  307. package/dist/utils/authentication/auth.js.map +0 -1
  308. package/dist/utils/authentication/role.d.ts +0 -7
  309. package/dist/utils/authentication/role.js +0 -139
  310. package/dist/utils/authentication/role.js.map +0 -1
  311. package/dist/utils/baseClass/baseController.d.ts +0 -12
  312. package/dist/utils/baseClass/baseController.js +0 -176
  313. package/dist/utils/baseClass/baseController.js.map +0 -1
  314. package/dist/utils/baseClass/baseService.d.ts +0 -7
  315. package/dist/utils/baseClass/baseService.js +0 -11
  316. package/dist/utils/baseClass/baseService.js.map +0 -1
  317. package/dist/utils/baseClass/dataSourceManager.d.ts +0 -11
  318. package/dist/utils/baseClass/dataSourceManager.js +0 -54
  319. package/dist/utils/baseClass/dataSourceManager.js.map +0 -1
  320. package/dist/utils/commonUtils/appConfigKeyRetriever.d.ts +0 -7
  321. package/dist/utils/commonUtils/appConfigKeyRetriever.js +0 -43
  322. package/dist/utils/commonUtils/appConfigKeyRetriever.js.map +0 -1
  323. package/dist/utils/commonUtils/appUtils.d.ts +0 -41
  324. package/dist/utils/commonUtils/appUtils.js +0 -236
  325. package/dist/utils/commonUtils/appUtils.js.map +0 -1
  326. package/dist/utils/commonUtils/cronUtils.d.ts +0 -9
  327. package/dist/utils/commonUtils/cronUtils.js +0 -32
  328. package/dist/utils/commonUtils/cronUtils.js.map +0 -1
  329. package/dist/utils/commonUtils/index.d.ts +0 -6
  330. package/dist/utils/commonUtils/index.js +0 -23
  331. package/dist/utils/commonUtils/index.js.map +0 -1
  332. package/dist/utils/commonUtils/jwtUtils.d.ts +0 -3
  333. package/dist/utils/commonUtils/jwtUtils.js +0 -83
  334. package/dist/utils/commonUtils/jwtUtils.js.map +0 -1
  335. package/dist/utils/commonUtils/responseUtils.d.ts +0 -7
  336. package/dist/utils/commonUtils/responseUtils.js +0 -131
  337. package/dist/utils/commonUtils/responseUtils.js.map +0 -1
  338. package/dist/utils/commonUtils/validation.d.ts +0 -6
  339. package/dist/utils/commonUtils/validation.js +0 -92
  340. package/dist/utils/commonUtils/validation.js.map +0 -1
  341. package/dist/utils/documentation/swagger.d.ts +0 -1
  342. package/dist/utils/documentation/swagger.js +0 -44
  343. package/dist/utils/documentation/swagger.js.map +0 -1
  344. package/dist/utils/logger/logger.d.ts +0 -1
  345. package/dist/utils/logger/logger.js +0 -58
  346. package/dist/utils/logger/logger.js.map +0 -1
  347. package/dist/utils/logger/morganLogger.d.ts +0 -4
  348. package/dist/utils/logger/morganLogger.js +0 -41
  349. package/dist/utils/logger/morganLogger.js.map +0 -1
  350. package/dist/utils/middleware/handleError.d.ts +0 -2
  351. package/dist/utils/middleware/handleError.js +0 -12
  352. package/dist/utils/middleware/handleError.js.map +0 -1
  353. package/dist/utils/middleware/isPublicUser.d.ts +0 -2
  354. package/dist/utils/middleware/isPublicUser.js +0 -35
  355. package/dist/utils/middleware/isPublicUser.js.map +0 -1
  356. package/dist/utils/middleware/overwriteConst.d.ts +0 -1
  357. package/dist/utils/middleware/overwriteConst.js +0 -84
  358. package/dist/utils/middleware/overwriteConst.js.map +0 -1
  359. package/dist/utils/middleware/startdbConnection.d.ts +0 -1
  360. package/dist/utils/middleware/startdbConnection.js +0 -30
  361. package/dist/utils/middleware/startdbConnection.js.map +0 -1
  362. package/dist/utils/monitoring/apm.d.ts +0 -6
  363. package/dist/utils/monitoring/apm.js +0 -99
  364. package/dist/utils/monitoring/apm.js.map +0 -1
  365. package/src/utils/baseClass/dataSourceManager.ts +0 -44
  366. package/src/utils/middleware/startdbConnection.ts +0 -20
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "skyeye-svc-common-utils",
3
- "version": "2.0.0-dev0.2",
3
+ "version": "2.0.0-dev0.20",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {
8
8
  "build": "tsc -p ./tsconfig.json",
9
- "clean": "rm -rf node_modules log",
9
+ "clean": "rm -rf node_modules package-lock.json dist log",
10
10
  "cleanPublish": "npm i && npm run build && npm run clean && npm publish"
11
11
  },
12
12
  "repository": {
@@ -21,20 +21,14 @@
21
21
  "homepage": "https://github.com/HandshakesByDC/SkyEye-SVC-Common-Utils#readme",
22
22
  "dependencies": {
23
23
  "@azure/data-tables": "^13.2.2",
24
- "@azure/identity": "latest",
25
- "@azure/keyvault-secrets": "latest",
26
- "@azure/service-bus": "7.9.1",
24
+ "@azure/identity": "^4.0.1",
25
+ "@azure/keyvault-secrets": "^4.8.0",
26
+ "@azure/service-bus": "^7.9.4",
27
27
  "@azure/storage-blob": "^12.1.2",
28
28
  "@azure/storage-queue": "^12.0.2",
29
+ "@azure/search-documents": "11.2.1",
30
+ "@azure/abort-controller": "1.0.4",
29
31
  "@sendgrid/mail": "^7.7.0",
30
- "@types/chai": "^4.2.11",
31
- "@types/express": "4.17.14",
32
- "@types/express-serve-static-core": "4.17.30",
33
- "@types/google-protobuf": "^3.7.2",
34
- "@types/jsonwebtoken": "^9.0.0",
35
- "@types/lodash": "4.14.182",
36
- "@types/swagger-jsdoc": "^3.0.2",
37
- "@types/swagger-ui-express": "^4.1.1",
38
32
  "async-mutex": "^0.3.2",
39
33
  "cron-parser": "4.8.1",
40
34
  "dateformat": "^3.0.3",
@@ -45,30 +39,39 @@
45
39
  "http-errors": "^1.7.3",
46
40
  "https": "^1.0.0",
47
41
  "ioredis": "^5.0.4",
48
- "jsonwebtoken": "^9.0.0",
42
+ "jsonwebtoken": "^9.0.2",
43
+ "lodash": "^4.17.21",
49
44
  "logform": "2.4.2",
50
45
  "moment": "^2.24.0",
51
46
  "morgan": "^1.9.1",
52
47
  "node-fetch": "^2.6.0",
53
48
  "nyc": "^15.1.0",
54
- "rotating-file-stream": "^1.4.6",
49
+ "rotating-file-stream": "^3.2.1",
55
50
  "skyeye-common-const": "1.0.42",
56
51
  "swagger-jsdoc": "^3.5.0",
57
52
  "swagger-ui-express": "^4.1.3",
58
53
  "ts-node": "^10.7.0",
59
54
  "typeorm": "^0.3.17",
60
55
  "typescript": "^5.3.3",
61
- "uuid": "^3.3.3",
62
56
  "winston": "^3.2.1",
63
- "winston-daily-rotate-file": "^4.2.1"
57
+ "winston-daily-rotate-file": "^4.2.1",
58
+ "abort-controller": "3.0.0",
59
+ "zod": "3.22.3"
64
60
  },
65
61
  "devDependencies": {
66
- "@types/dateformat": "^3.0.1",
67
- "@types/debug": "~4.1.5",
68
- "@types/http-errors": "~1.6.1",
69
- "@types/morgan": "~1.7.37",
70
- "@types/node": "^14.0.27",
71
- "@types/node-fetch": "^2.5.3",
72
- "@types/uuid": "^3.4.6"
62
+ "@types/dateformat": "^5.0.2",
63
+ "@types/debug": "^4.1.12",
64
+ "@types/http-errors": "~2.0.4",
65
+ "@types/morgan": "~1.9.9",
66
+ "@types/node": "^20.11.19",
67
+ "@types/node-fetch": "^2.6.11",
68
+ "@types/chai": "^4.3.11",
69
+ "@types/express": "^4.17.21",
70
+ "@types/express-serve-static-core": "^4.17.43",
71
+ "@types/google-protobuf": "^3.15.12",
72
+ "@types/jsonwebtoken": "^9.0.6",
73
+ "@types/lodash": "^4.14.202",
74
+ "@types/swagger-jsdoc": "^6.0.4",
75
+ "@types/swagger-ui-express": "^4.1.6"
73
76
  }
74
77
  }
package/src/index.ts CHANGED
@@ -7,23 +7,26 @@ export * from './utils/logger/morganLogger';
7
7
  export * from './utils/middleware/handleError';
8
8
  export * from './utils/middleware/isPublicUser';
9
9
  export * from './utils/middleware/overwriteConst';
10
- export * from './utils/middleware/startdbConnection';
10
+ export * from './utils/middleware/loadConfig';
11
11
  export * from './utils/baseClass/baseController';
12
12
  export * from './utils/baseClass/baseService';
13
- export * from './interfaces/index';
13
+ export * from './utils/baseClass/appDataSource';
14
+ export * from './utils/monitoring/apm';
15
+ export * from './utils/commonUtils/appConfigKeyRetriever';
16
+ export * from './utils/documentation/swagger';
14
17
  export * from './lib/azure/azureKeyVault';
15
18
  export * from './lib/azure/azureServiceBusClient';
16
19
  export * from './lib/azure/azureStorageQueue';
17
20
  export * from './lib/azure/azureServiceBusQueue';
18
21
  export * from './lib/azure/azureTableStorage';
19
22
  export * from './lib/azure/azureBlobStorage';
20
- export * from './utils/documentation/swagger';
23
+ export * from './lib/azure/cognitiveSearch';
24
+ export * from './lib/fetch';
21
25
  export * from './lib/httpClient';
22
- export * from './utils/monitoring/apm';
23
- export * from './models/baseControllerParameter';
24
- export * from './models';
25
26
  export * from './lib/redisClient';
26
27
  export * from './lib/sendGridClient';
28
+ export * from './models';
29
+ export * from './models/baseControllerParameter';
30
+ export * from './interfaces';
27
31
  export * from './interfaces/grpcServiceResponse';
28
32
  export * from './interfaces/grpcListRequest';
29
- export * from './utils/commonUtils/appConfigKeyRetriever';
@@ -1,6 +1,9 @@
1
1
  import { SecretClient } from "@azure/keyvault-secrets";
2
2
  import { DefaultAzureCredential } from "@azure/identity";
3
+ import { AbortController } from '@azure/abort-controller';
3
4
  import { commonAppConfig} from '../../utils/appConfig';
5
+ import { thirdPartyRegulation } from '../../utils/appConst';
6
+ import { ServiceResponse } from '../../interfaces';
4
7
 
5
8
  export async function getKey(secretName : string) : Promise<string>{
6
9
  const credential = new DefaultAzureCredential();
@@ -12,4 +15,45 @@ export async function getKey(secretName : string) : Promise<string>{
12
15
  const secret = await client.getSecret(secretName);
13
16
 
14
17
  return secret.value;
18
+ }
19
+
20
+ /**
21
+ * @description To retrieve secret from a given Azure Key Vault
22
+ * @param {string} keyVaultName - name of Azure Key Vault
23
+ * @param {string} secretName - secret name of Azure Key Vault
24
+ * @param {number} abortWithinMsec - automatically abort within given millisecond
25
+ * @param {number} retry - automatically retry with given times
26
+ * @returns {ServiceResponse}
27
+ */
28
+ export async function getKeyVault(
29
+ keyVaultName: string,
30
+ secretName : string,
31
+ abortWithinMsec: number = thirdPartyRegulation.requestLimitationMsec,
32
+ retry: number = thirdPartyRegulation.requestDefaultRetry
33
+ ): Promise<ServiceResponse> {
34
+ const resp: ServiceResponse = { isSuccess: false };
35
+
36
+ try {
37
+ const credential = new DefaultAzureCredential();
38
+ const url = `https://${keyVaultName}.vault.azure.net`;
39
+ const client = new SecretClient(url, credential);
40
+
41
+ let curTry = 0;
42
+ while (curTry <= retry) {
43
+ const signal = AbortController.timeout(abortWithinMsec);
44
+ const secret = await client.getSecret(secretName, { abortSignal: signal });
45
+ if (secret && secret.value) {
46
+ resp.data = JSON.parse(secret.value);
47
+ resp.isSuccess = true;
48
+ break;
49
+ }
50
+ if (curTry === retry) {
51
+ throw new Error(`/keyVault/getKeyVault(): failed fetch secret with retries (${retry})`);
52
+ }
53
+ }
54
+ } catch (err) {
55
+ resp.message = err as string;
56
+ }
57
+
58
+ return resp;
15
59
  }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @description Specifies whether simple or full of query type must be matched
3
+ * @see https://docs.microsoft.com/en-us/rest/api/searchservice/search-documents
4
+ */
5
+ export enum QueryType {
6
+ simple = 'simple',
7
+ full = 'full'
8
+ }
@@ -0,0 +1,149 @@
1
+ import { SearchClient as OfficialSearchClient, AzureKeyCredential } from '@azure/search-documents';
2
+ import { logger } from '../../../utils/logger/logger';
3
+ import { getKeyVault } from '../../azure/azureKeyVault';
4
+ import { ServiceResponse } from '../../../interfaces';
5
+ import { AzureSearchIndex, AzureSearchConfig } from '../../../utils';
6
+ import { appConfig, loadConfig } from '../../../utils/middleware/loadConfig';
7
+
8
+
9
+ /**
10
+ * @classdesc SearchClient as an adaptor to bind the third-party library
11
+ * (@azure/search-documents) with the internal application. That is to say, the
12
+ * class is aim to enhance dev's maintenance between lib and the exact usage.
13
+ * @property {SearchClient} instance - Singleton instance
14
+ * @property {string} endpoint - Azure cognitive search's request endpoint
15
+ * @property {string} credential - Azure cognitive search's API key
16
+ * @property {Semaphore} semaphore - to ensure not too many requests are sent to Azure cognitive search
17
+ * @property {Record<AzureSearchIndex, string>} indexMap - to store the index's alias
18
+ *
19
+ * @example
20
+ * const client = await SearchClient.getInstance();
21
+ * const searchOption = new SearchOption( { top: 1 });
22
+ * console.log(JSON.stringify(await client.query(AzureSearchIndex.company, '*', searchOption.value())));
23
+ */
24
+ export class SearchClient {
25
+ private static instance: SearchClient;
26
+ private static endpoint: string;
27
+ private static credential: string;
28
+ private static indexMap: Record<AzureSearchIndex, string>;
29
+
30
+ /**
31
+ * @description To retrieve the instance in the Singleton pattern
32
+ * @returns {SearchClient} the singleton instance of SearchClient
33
+ */
34
+ static async getInstance(): Promise<SearchClient> {
35
+ if (!!SearchClient.instance) { return SearchClient.instance; }
36
+
37
+ SearchClient.instance = new SearchClient();
38
+
39
+ /**
40
+ * When the keyVaultName is empty, loadConfig() should be called in order to fetch the value as possible
41
+ * since we are not using lazy-loading here. It would be better to transform into a lazy-loading mechanism.
42
+ */
43
+ if (appConfig === undefined) {
44
+ try {
45
+ await loadConfig();
46
+ if (appConfig.keyVaultName === undefined) {
47
+ throw new Error('SearchClient/getInstance: empty keyVaultName');
48
+ }
49
+ } catch (err) {
50
+ throw err;
51
+ }
52
+ }
53
+
54
+ const credentialResp = await getKeyVault(appConfig.keyVaultName, AzureSearchConfig.credentialSecretName);
55
+
56
+ if (credentialResp.isSuccess === false) {
57
+ throw new Error('/SearchClient/getInstance(): retrieve search credential failed');
58
+ }
59
+
60
+ const secret: { endpoint: string, credential: string } = credentialResp.data;
61
+
62
+ const indexMapResp = await getKeyVault(appConfig.keyVaultName, AzureSearchConfig.indexSecretName);
63
+
64
+ if (indexMapResp.isSuccess === false) {
65
+ throw new Error('/SearchClient/getInstance(): retrieve search indexMap failed');
66
+ }
67
+
68
+ SearchClient.indexMap = indexMapResp.data;
69
+ SearchClient.endpoint = secret.endpoint;
70
+ SearchClient.credential = secret.credential;
71
+ return SearchClient.instance;
72
+ }
73
+
74
+ /**
75
+ * @description To query the Azure cognitive search
76
+ * @param {AzureSearchIndex} index - to retrieve the document
77
+ * @param {string} keyword - as the prop 'search'
78
+ * @param {any} options - additional option for the search
79
+ * @param {number} retryTimes - specify how many times if Azure cognitive search returns a bad request
80
+ * @returns {ServiceResponse} a serviceResponse, noted that data is stated in `data.document`
81
+ */
82
+ async query(
83
+ index: AzureSearchIndex,
84
+ keyword: string = '*',
85
+ options?: any,
86
+ retryTimes: number = AzureSearchConfig.queryRetryDefault,
87
+ tracking: number = Math.floor(Math.random()*100000000000)
88
+ ): Promise<ServiceResponse> {
89
+ logger.verbose(`start SearchClient/query: ${tracking}`);
90
+ let serviceResponse: ServiceResponse = { isSuccess: false };
91
+ let searchResults: any;
92
+ let curRetry = 0;
93
+ try {
94
+
95
+ const client = new OfficialSearchClient(
96
+ SearchClient.endpoint,
97
+ SearchClient.indexMap[index],
98
+ new AzureKeyCredential(SearchClient.credential)
99
+ );
100
+
101
+ while (curRetry < retryTimes) {
102
+ try {
103
+ logger.verbose(`SearchClient/query before sending : ${curRetry}|${tracking}`);
104
+ searchResults = await client.search(keyword, options);
105
+ logger.verbose(`SearchClient/query after sending : ${curRetry}|${tracking}`);
106
+ serviceResponse.data = { document: [] };
107
+
108
+ for await (const result of searchResults.results) {
109
+ result.document.score = result.score;
110
+ result.document.highlights = result.highlights;
111
+ serviceResponse.data.document.push(result.document);
112
+ }
113
+ logger.verbose(`SearchClient/query after processing : ${curRetry}|${tracking}`);
114
+ if (!!searchResults.facets) {
115
+ serviceResponse.data.facets = searchResults.facets;
116
+ }
117
+
118
+ if (!!searchResults.count) {
119
+ serviceResponse.data.count = searchResults.count;
120
+ }
121
+
122
+ serviceResponse.isSuccess = true;
123
+ } catch (err) {
124
+ logger.error(`SearchClient/query: fail - ${err}`);
125
+ }
126
+
127
+ if (!serviceResponse.isSuccess) {
128
+ logger.info(`SearchClient/query: retry - ${curRetry}`);
129
+ ++curRetry;
130
+ await this.sleep(AzureSearchConfig.retryIntervalSecond * 1000);
131
+ } else {
132
+ break;
133
+ }
134
+ }
135
+ } catch (err) {
136
+ logger.error(`SearchClient/query: ${err}`);
137
+ }
138
+ logger.verbose(`end SearchClient/query : ${curRetry}|${serviceResponse.data.document.length}|${tracking}`);
139
+ return serviceResponse;
140
+ }
141
+
142
+ /**
143
+ * @description To postpone for specific millisecond
144
+ * @param {number} ms - millisecond to wait for
145
+ */
146
+ private async sleep(ms: number) {
147
+ await new Promise( _ => setTimeout(_, ms));
148
+ }
149
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @description SearchFacets as a type is to wrap facets for @azure/search-documents
3
+ * @see https://docs.microsoft.com/en-us/rest/api/searchservice/search-documents
4
+ * @property {string} attr - attribute/prop to reach
5
+ * @property {number} count - volume of the search
6
+ * @property {enum} sort - order
7
+ * @property {enum | number} interval - interval greater than 0 for numbers for date time values
8
+ * @property {string} timeoffset - specifying a dynamic set of facet entry values
9
+ */
10
+ export type SearchFacets = {
11
+ attr: string;
12
+ count?: number;
13
+ sort?: 'count' | '-count' | 'value' | '-value';
14
+ interval?: number | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year';
15
+ timeoffset?: string;
16
+ }
@@ -0,0 +1,140 @@
1
+ /**
2
+ * @classdesc SearchFilter is the object to construct the Filter when using Azure cognitive search
3
+ * @property {string} attr - the attribute, so called props, to be filtered by the condition
4
+ * @property {SearchFilterCondition} condition - the condition to filter, see enum @SearchFilter for more information
5
+ * @property {any} value - attr should under the condition with value
6
+ * @property {boolean} isCollection - true if the filed is defined as a collection in Azure Cognitive Search
7
+ * @property {'any' | 'all'} collectionOperation - collection search settings
8
+ * @see https://docs.microsoft.com/en-us/azure/search/search-query-understand-collection-filters
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * const primaryFilter = new SearchFilter('isPrimary', EQUAL, true);
13
+ * const mentionedCompanyListFilter = new SearchFilter('companyMentioned', CONTAINS, [...]);
14
+ * ```
15
+ */
16
+ export class SearchFilter {
17
+ attr: string;
18
+ condition: SearchFilterCondition;
19
+ value: any;
20
+ isCollection: boolean = false;
21
+ collectionOperation: 'any' | 'all' = 'any';
22
+
23
+ constructor(
24
+ attr: string,
25
+ condition: SearchFilterCondition,
26
+ value: any,
27
+ isCollection: boolean = false,
28
+ collectionOperation: 'any' | 'all' = 'any') {
29
+ this.attr = attr;
30
+ this.condition = condition;
31
+ this.value = value;
32
+ this.isCollection = isCollection;
33
+ this.collectionOperation = collectionOperation;
34
+ }
35
+
36
+ /**
37
+ * @description flatten is to compose the instance into a string when using Search
38
+ * @returns {string} the composite of the instance
39
+ */
40
+ flatten(): string {
41
+ if (this.isCollection) {
42
+ switch (this.condition) {
43
+ case CONTAINS:
44
+ return `${this.attr}/${this.collectionOperation}(i: search.in(i,'${this.value.toString()}', ','))`;
45
+ case EXCLUDE:
46
+ return `${this.attr}/${this.collectionOperation}(i: not search.in(i,'${this.value.toString()}', ','))`;
47
+ default:
48
+ throw new Error(`SearchFilter/flatten: Unknown condition for collection`);
49
+ }
50
+ } else {
51
+ switch (this.condition) {
52
+ case EQUAL:
53
+ case NOT_EQUAL:
54
+ case LESS_THAN_OR_EQUAL:
55
+ case GREATER_THAN_OR_EQUAL:
56
+ return `${this.attr} ${this.condition} ${ typeof(this.value) === 'string' ? `'${this.value}'` : this.value }`;
57
+ case CONTAINS:
58
+ return `search.in(${this.attr}, '${this.value.toString()}', ',')`;
59
+ case EXCLUDE:
60
+ return `${this.condition} search.in(${this.attr}, '${this.value.toString()}', ',')`;
61
+ default:
62
+ throw new Error(`SearchFilter/flatten: Unknown condition`);
63
+ }
64
+ }
65
+ }
66
+ }
67
+
68
+ /**
69
+ * @description The condition when filtering an params.
70
+ */
71
+ export enum SearchFilterCondition {
72
+ contains = '',
73
+ exclude = 'not',
74
+ equal = 'eq',
75
+ notEqual = 'ne',
76
+ lessThanOrEqual = 'le',
77
+ greaterThanOrEqual = 'ge'
78
+ }
79
+
80
+ /**
81
+ * @description The following const params is a easy-to-use type when implementing a SearchFilter,
82
+ * so that the developers no longer need to call the enum with the class reference
83
+ */
84
+ export const CONTAINS = SearchFilterCondition.contains;
85
+ export const EXCLUDE = SearchFilterCondition.exclude;
86
+ export const EQUAL = SearchFilterCondition.equal;
87
+ export const NOT_EQUAL = SearchFilterCondition.notEqual;
88
+ export const LESS_THAN_OR_EQUAL = SearchFilterCondition.lessThanOrEqual;
89
+ export const GREATER_THAN_OR_EQUAL = SearchFilterCondition.greaterThanOrEqual;
90
+
91
+ /**
92
+ * @description describe types of combination
93
+ */
94
+ export const enum CombinationType {
95
+ and = 'and',
96
+ or = 'or'
97
+ };
98
+
99
+ /**
100
+ * combination is a function ONLY be used for constructing two function: AND and OR,
101
+ * then it would be express into a string.
102
+ * @param {CombinationType} type - to indicate the combination type
103
+ * @param {Array<Array<string | SearchFilter>>} args - the arguments which need to be construct into string
104
+ * @returns {string} aggregation of the given args
105
+ */
106
+ const combination = (type: CombinationType, ...args: Array<string | SearchFilter>): string => {
107
+ if (args.length === 0) { return ''; }
108
+
109
+ function flatten(obj: string | SearchFilter): string {
110
+ return typeof(obj) === 'string' ? obj : obj.flatten();
111
+ }
112
+
113
+ let res: string = !!args[0] ? flatten(args[0]) : '';
114
+
115
+ for (let i = 1; i < args.length; ++i) {
116
+ if (!!args) {
117
+ res += ` ${type} ${flatten(args[i])}`;
118
+ }
119
+ }
120
+
121
+ return `(${res})`;
122
+ }
123
+
124
+ /**
125
+ * @description AND helps developers to compose a nested filter for condition AND.
126
+ * @param {Array<Array<string | SearchFilter>>} args - the arguments which need to be construct into string
127
+ * @returns {string} aggregation of the given args
128
+ */
129
+ export const AND = (...args: Array<string | SearchFilter>): string => {
130
+ return combination(CombinationType.and, ...args);
131
+ }
132
+
133
+ /**
134
+ * @description OR helps developers to compose a nested filter for condition OR.
135
+ * @param {Array<Array<string | SearchFilter>>} args - the arguments which need to be construct into string
136
+ * @returns {string} aggregation of the given args
137
+ */
138
+ export const OR = (...args: Array<string | SearchFilter>): string => {
139
+ return combination(CombinationType.or, ...args);
140
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @description Specifies whether any or all of the search terms must be matched
3
+ * in order to count the document as a match.
4
+ * @see https://docs.microsoft.com/en-us/rest/api/searchservice/search-documents
5
+ */
6
+ export enum SearchMode {
7
+ all = 'all',
8
+ any = 'any'
9
+ }
@@ -0,0 +1,155 @@
1
+ import { AND, OR, CombinationType, SearchFilter } from './SearchFilter';
2
+ import { SearchFacets } from './SearchFacets';
3
+ import { SearchOrder } from './SearchOrder';
4
+ import { SearchMode } from './SearchMode';
5
+ import { QueryType } from './QueryType';
6
+
7
+ /**
8
+ * @description SearchOptionType is the interface to connect with the library
9
+ * @azure/search-documents, it would only be initiated when creating an instance
10
+ * of class @SearchOption, none of the other functions should access this type declaration.
11
+ * @property {Array<string>} select - optional, to indicate the select attributes/props.
12
+ * @property {string | Array<string | SearchFilter>} filter - optional, search with the filter
13
+ * @property {CombinationType} filterCombinationType - optional, combination type of the filters
14
+ * @property {Array<SearchOrder>} orderBy - optional, return order
15
+ * @property {boolean} count - optional, if true, return with the count of the documents.
16
+ * @property {number} top - optional, total volume when retrieving the data
17
+ * @property {number} skip - optional, skip how many document
18
+ * @property {Array<SearchFacets>} facets - optional, retrieve data's facets
19
+ * @property {SearchMode} searchMode - required, different mode for search
20
+ */
21
+ type SearchOptionType = {
22
+ select?: string[],
23
+ filter?: string | Array<string | SearchFilter>,
24
+ filterCombinationType?: CombinationType,
25
+ orderBy?: SearchOrder[],
26
+ count?: boolean,
27
+ top?: number,
28
+ skip?: number,
29
+ facets?: SearchFacets[],
30
+ searchMode?: SearchMode,
31
+ searchFields?: string[],
32
+ scoringProfile?: string,
33
+ highlightFields?: string,
34
+ highlightPreTag?: string,
35
+ highlightPostTag?: string,
36
+ queryType?: QueryType
37
+ }
38
+
39
+ /**
40
+ * @classdesc the class is to wrap an option when retrieving the data from
41
+ * @azure/search-documents/query
42
+ * @property searchOptionType - to store the interface of the option, noted that
43
+ * when calling the query, you should use SearchOption.value() instead of using
44
+ * this attribute.
45
+ */
46
+ export class SearchOption {
47
+ searchOptionType?: SearchOptionType;
48
+
49
+ /**
50
+ * @description when initializing a SearchOption, the defaultSearchOption
51
+ * will override the undefined props
52
+ */
53
+ static defaultSearchOption: SearchOptionType = {
54
+ count: false,
55
+ top: 50,
56
+ skip: 0,
57
+ searchMode: SearchMode.all,
58
+ filterCombinationType: CombinationType.and
59
+ }
60
+
61
+ constructor(searchOptionType?: SearchOptionType) {
62
+ // override the default settings if the value is empty from the given OptionType
63
+ this.searchOptionType = { ...SearchOption.defaultSearchOption, ...searchOptionType };
64
+ }
65
+
66
+ /**
67
+ * @description to compose flatten-filter string for @azure/search-documents
68
+ * @returns {string} flatten-filter string
69
+ */
70
+ private composeFilter(): string {
71
+ if (typeof(this.searchOptionType.filter) === 'string') { return this.searchOptionType.filter; }
72
+ return this.searchOptionType.filterCombinationType === CombinationType.and ?
73
+ AND(...this.searchOptionType.filter)
74
+ :
75
+ OR(...this.searchOptionType.filter);
76
+ }
77
+
78
+ /**
79
+ * @description to compose flatten-order string for @azure/search-documents
80
+ * @returns {Array<string>} flatten-order string
81
+ */
82
+ private composeOrder(): string[] {
83
+ return this.searchOptionType.orderBy.map(
84
+ (s: SearchOrder) => `${s.attr} ${s.orderBy}`
85
+ );
86
+ }
87
+
88
+ /**
89
+ * @description to compose flatten-facets string for @azure/search-documents
90
+ * @returns {Array<string>} flatten-facets string
91
+ */
92
+ private composeFacets(): string[] {
93
+ return this.searchOptionType.facets.map((s: SearchFacets) => {
94
+ let res = `${s.attr}`;
95
+ if (s.count !== null && s.count !== undefined) { res+= `,count:${s.count}`; }
96
+ if (!!s.sort) { res += `,sort:${s.sort}`; }
97
+ if (s.interval !== null && s.interval !== undefined) { res += `,interval:${s.interval}`; }
98
+ if (!!s.timeoffset) { res += `,timeoffset:${s.timeoffset}`; }
99
+ return res;
100
+ });
101
+ }
102
+
103
+ /**
104
+ * @description as an adaptor to transform the type for @azure/search-documents
105
+ * @returns {Object} object which can be accepted by @azure/search-documents
106
+ */
107
+ value = () => {
108
+ let value: {
109
+ select?: string[],
110
+ filter?: string;
111
+ orderBy?: string[],
112
+ includeTotalCount?: boolean,
113
+ top?: number,
114
+ skip?: number,
115
+ facets?: string[],
116
+ searchMode?: string,
117
+ searchFields?: string[],
118
+ scoringProfile?: string,
119
+ highlightFields?: string,
120
+ highlightPreTag?: string,
121
+ highlightPostTag?: string,
122
+ queryType?:string
123
+ } = {};
124
+
125
+ value.includeTotalCount = this.searchOptionType.count;
126
+ value.select = this.searchOptionType.select;
127
+ value.skip = this.searchOptionType.skip;
128
+ value.top = this.searchOptionType.top;
129
+ value.searchMode = this.searchOptionType.searchMode;
130
+ value.searchFields = this.searchOptionType.searchFields;
131
+ value.scoringProfile = this.searchOptionType.scoringProfile;
132
+ value.highlightFields = this.searchOptionType.highlightFields;
133
+ value.highlightPreTag = this.searchOptionType.highlightPreTag;
134
+ value.highlightPostTag = this.searchOptionType.highlightPostTag;
135
+ value.queryType = this.searchOptionType.queryType;
136
+
137
+ if (!!this.searchOptionType.filter) {
138
+ value.filter = this.composeFilter();
139
+ }
140
+
141
+ if (!!this.searchOptionType.select && this.searchOptionType.select.length) {
142
+ value.select = this.searchOptionType.select;
143
+ }
144
+
145
+ if (!!this.searchOptionType.orderBy && this.searchOptionType.orderBy.length) {
146
+ value.orderBy = this.composeOrder();
147
+ }
148
+
149
+ if (!!this.searchOptionType.facets && this.searchOptionType.facets.length) {
150
+ value.facets = this.composeFacets();
151
+ }
152
+
153
+ return value;
154
+ }
155
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @description SearchOrder as a type to depict the orderBy props
3
+ * @property {string} attr - the search field which is used to be sorted
4
+ * @property {'desc' | 'asc'} orderBy - descent or ascent
5
+ */
6
+ export type SearchOrder = {
7
+ attr: string;
8
+ orderBy: 'desc' | 'asc';
9
+ }