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.
- package/package.json +27 -24
- package/src/index.ts +10 -7
- package/src/lib/azure/azureKeyVault.ts +44 -0
- package/src/lib/azure/cognitiveSearch/QueryType.ts +8 -0
- package/src/lib/azure/cognitiveSearch/SearchClient.ts +149 -0
- package/src/lib/azure/cognitiveSearch/SearchFacets.ts +16 -0
- package/src/lib/azure/cognitiveSearch/SearchFilter.ts +140 -0
- package/src/lib/azure/cognitiveSearch/SearchMode.ts +9 -0
- package/src/lib/azure/cognitiveSearch/SearchOption.ts +155 -0
- package/src/lib/azure/cognitiveSearch/SearchOrder.ts +9 -0
- package/src/lib/azure/cognitiveSearch/index.ts +7 -0
- package/src/lib/azure/index.ts +7 -0
- package/src/lib/fetch/index.ts +2 -0
- package/src/lib/fetch/sendRequest.ts +10 -0
- package/src/lib/fetch/sendRequestWithTimeout.ts +38 -0
- package/src/lib/httpClient.ts +27 -26
- package/src/lib/index.ts +3 -0
- package/src/lib/teams/broadcastLogMessage.ts +70 -0
- package/src/lib/teams/index.ts +2 -0
- package/src/lib/teams/logMessage.ts +55 -0
- package/src/utils/appConfig.ts +2 -2
- package/src/utils/appConst.ts +64 -0
- package/src/utils/baseClass/appDataSource.ts +23 -0
- package/src/utils/baseClass/baseController.ts +9 -9
- package/src/utils/index.ts +2 -0
- package/src/utils/logger/morganLogger.ts +2 -2
- package/src/utils/middleware/loadConfig.ts +150 -0
- package/.env +0 -3
- package/dist/index.d.ts +0 -29
- package/dist/index.js +0 -46
- package/dist/index.js.map +0 -1
- package/dist/interfaces/apiResponse.d.ts +0 -7
- package/dist/interfaces/apiResponse.js +0 -3
- package/dist/interfaces/apiResponse.js.map +0 -1
- package/dist/interfaces/grpcListRequest.d.ts +0 -6
- package/dist/interfaces/grpcListRequest.js +0 -3
- package/dist/interfaces/grpcListRequest.js.map +0 -1
- package/dist/interfaces/grpcServiceResponse.d.ts +0 -8
- package/dist/interfaces/grpcServiceResponse.js +0 -3
- package/dist/interfaces/grpcServiceResponse.js.map +0 -1
- package/dist/interfaces/index.d.ts +0 -10
- package/dist/interfaces/index.js +0 -26
- package/dist/interfaces/index.js.map +0 -1
- package/dist/interfaces/internalHttp/request/index.d.ts +0 -1
- package/dist/interfaces/internalHttp/request/index.js +0 -18
- package/dist/interfaces/internalHttp/request/index.js.map +0 -1
- package/dist/interfaces/internalHttp/request/search.d.ts +0 -9
- package/dist/interfaces/internalHttp/request/search.js +0 -3
- package/dist/interfaces/internalHttp/request/search.js.map +0 -1
- package/dist/interfaces/internalHttp/response/index.d.ts +0 -1
- package/dist/interfaces/internalHttp/response/index.js +0 -18
- package/dist/interfaces/internalHttp/response/index.js.map +0 -1
- package/dist/interfaces/internalHttp/response/search.d.ts +0 -10
- package/dist/interfaces/internalHttp/response/search.js +0 -3
- package/dist/interfaces/internalHttp/response/search.js.map +0 -1
- package/dist/interfaces/pagination.d.ts +0 -6
- package/dist/interfaces/pagination.js +0 -12
- package/dist/interfaces/pagination.js.map +0 -1
- package/dist/interfaces/serviceResponse.d.ts +0 -8
- package/dist/interfaces/serviceResponse.js +0 -3
- package/dist/interfaces/serviceResponse.js.map +0 -1
- package/dist/interfaces/subcriptionFeaturePermissionModel.d.ts +0 -8
- package/dist/interfaces/subcriptionFeaturePermissionModel.js +0 -14
- package/dist/interfaces/subcriptionFeaturePermissionModel.js.map +0 -1
- package/dist/interfaces/userInfo.d.ts +0 -17
- package/dist/interfaces/userInfo.js +0 -21
- package/dist/interfaces/userInfo.js.map +0 -1
- package/dist/lib/azure/azureBlobStorage.d.ts +0 -4
- package/dist/lib/azure/azureBlobStorage.js +0 -137
- package/dist/lib/azure/azureBlobStorage.js.map +0 -1
- package/dist/lib/azure/azureKeyVault.d.ts +0 -1
- package/dist/lib/azure/azureKeyVault.js +0 -27
- package/dist/lib/azure/azureKeyVault.js.map +0 -1
- package/dist/lib/azure/azureServiceBusClient.d.ts +0 -47
- package/dist/lib/azure/azureServiceBusClient.js +0 -139
- package/dist/lib/azure/azureServiceBusClient.js.map +0 -1
- package/dist/lib/azure/azureServiceBusQueue.d.ts +0 -1
- package/dist/lib/azure/azureServiceBusQueue.js +0 -42
- package/dist/lib/azure/azureServiceBusQueue.js.map +0 -1
- package/dist/lib/azure/azureStorageQueue.d.ts +0 -1
- package/dist/lib/azure/azureStorageQueue.js +0 -26
- package/dist/lib/azure/azureStorageQueue.js.map +0 -1
- package/dist/lib/azure/azureTableStorage.d.ts +0 -4
- package/dist/lib/azure/azureTableStorage.js +0 -67
- package/dist/lib/azure/azureTableStorage.js.map +0 -1
- package/dist/lib/httpClient.d.ts +0 -3
- package/dist/lib/httpClient.js +0 -51
- package/dist/lib/httpClient.js.map +0 -1
- package/dist/lib/redisClient.d.ts +0 -45
- package/dist/lib/redisClient.js +0 -153
- package/dist/lib/redisClient.js.map +0 -1
- package/dist/lib/sendGridClient.d.ts +0 -27
- package/dist/lib/sendGridClient.js +0 -62
- package/dist/lib/sendGridClient.js.map +0 -1
- package/dist/models/baseControllerParameter.d.ts +0 -9
- package/dist/models/baseControllerParameter.js +0 -24
- package/dist/models/baseControllerParameter.js.map +0 -1
- package/dist/models/campaign/grpcCampaignEventModel.d.ts +0 -18
- package/dist/models/campaign/grpcCampaignEventModel.js +0 -24
- package/dist/models/campaign/grpcCampaignEventModel.js.map +0 -1
- package/dist/models/campaign/grpcCampaignEventUserModel.d.ts +0 -13
- package/dist/models/campaign/grpcCampaignEventUserModel.js +0 -19
- package/dist/models/campaign/grpcCampaignEventUserModel.js.map +0 -1
- package/dist/models/campaign/grpcCampaignUserModel.d.ts +0 -12
- package/dist/models/campaign/grpcCampaignUserModel.js +0 -16
- package/dist/models/campaign/grpcCampaignUserModel.js.map +0 -1
- package/dist/models/campaign/index.d.ts +0 -4
- package/dist/models/campaign/index.js +0 -10
- package/dist/models/campaign/index.js.map +0 -1
- package/dist/models/emailtemplate/grpcEmailTemplateModel.d.ts +0 -10
- package/dist/models/emailtemplate/grpcEmailTemplateModel.js +0 -16
- package/dist/models/emailtemplate/grpcEmailTemplateModel.js.map +0 -1
- package/dist/models/emailtemplate/index.d.ts +0 -2
- package/dist/models/emailtemplate/index.js +0 -6
- package/dist/models/emailtemplate/index.js.map +0 -1
- package/dist/models/index.d.ts +0 -10
- package/dist/models/index.js +0 -28
- package/dist/models/index.js.map +0 -1
- package/dist/models/organisation/grpcOrganisationModel.d.ts +0 -15
- package/dist/models/organisation/grpcOrganisationModel.js +0 -21
- package/dist/models/organisation/grpcOrganisationModel.js.map +0 -1
- package/dist/models/organisation/index.d.ts +0 -2
- package/dist/models/organisation/index.js +0 -6
- package/dist/models/organisation/index.js.map +0 -1
- package/dist/models/rbac/grpcRoleModel.d.ts +0 -9
- package/dist/models/rbac/grpcRoleModel.js +0 -15
- package/dist/models/rbac/grpcRoleModel.js.map +0 -1
- package/dist/models/rbac/index.d.ts +0 -2
- package/dist/models/rbac/index.js +0 -6
- package/dist/models/rbac/index.js.map +0 -1
- package/dist/models/scoutai/grpcAIDETrainingResultListModel.d.ts +0 -8
- package/dist/models/scoutai/grpcAIDETrainingResultListModel.js +0 -14
- package/dist/models/scoutai/grpcAIDETrainingResultListModel.js.map +0 -1
- package/dist/models/scoutai/grpcNerlCorrectionModel.d.ts +0 -11
- package/dist/models/scoutai/grpcNerlCorrectionModel.js +0 -16
- package/dist/models/scoutai/grpcNerlCorrectionModel.js.map +0 -1
- package/dist/models/scoutai/grpcScoutAIListReq.d.ts +0 -12
- package/dist/models/scoutai/grpcScoutAIListReq.js +0 -17
- package/dist/models/scoutai/grpcScoutAIListReq.js.map +0 -1
- package/dist/models/scoutai/grpcScoutAIModel.d.ts +0 -10
- package/dist/models/scoutai/grpcScoutAIModel.js +0 -16
- package/dist/models/scoutai/grpcScoutAIModel.js.map +0 -1
- package/dist/models/scoutai/grpcScoutAIResult.d.ts +0 -10
- package/dist/models/scoutai/grpcScoutAIResult.js +0 -16
- package/dist/models/scoutai/grpcScoutAIResult.js.map +0 -1
- package/dist/models/scoutai/grpcTaasConfigAIModel.d.ts +0 -6
- package/dist/models/scoutai/grpcTaasConfigAIModel.js +0 -12
- package/dist/models/scoutai/grpcTaasConfigAIModel.js.map +0 -1
- package/dist/models/scoutai/grpcTaasConfigModel.d.ts +0 -11
- package/dist/models/scoutai/grpcTaasConfigModel.js +0 -15
- package/dist/models/scoutai/grpcTaasConfigModel.js.map +0 -1
- package/dist/models/scoutai/grpcTaasConfigUserModel.d.ts +0 -8
- package/dist/models/scoutai/grpcTaasConfigUserModel.js +0 -14
- package/dist/models/scoutai/grpcTaasConfigUserModel.js.map +0 -1
- package/dist/models/scoutai/grpcTagItemModel.d.ts +0 -9
- package/dist/models/scoutai/grpcTagItemModel.js +0 -15
- package/dist/models/scoutai/grpcTagItemModel.js.map +0 -1
- package/dist/models/scoutai/grpcVisualisationModel.d.ts +0 -11
- package/dist/models/scoutai/grpcVisualisationModel.js +0 -15
- package/dist/models/scoutai/grpcVisualisationModel.js.map +0 -1
- package/dist/models/scoutai/grpcVisualisationPositionModel.d.ts +0 -6
- package/dist/models/scoutai/grpcVisualisationPositionModel.js +0 -11
- package/dist/models/scoutai/grpcVisualisationPositionModel.js.map +0 -1
- package/dist/models/scoutai/index.d.ts +0 -10
- package/dist/models/scoutai/index.js +0 -22
- package/dist/models/scoutai/index.js.map +0 -1
- package/dist/models/search/grpcAggregation.d.ts +0 -9
- package/dist/models/search/grpcAggregation.js +0 -14
- package/dist/models/search/grpcAggregation.js.map +0 -1
- package/dist/models/search/grpcCmsModel.d.ts +0 -5
- package/dist/models/search/grpcCmsModel.js +0 -11
- package/dist/models/search/grpcCmsModel.js.map +0 -1
- package/dist/models/search/grpcCommonModels.d.ts +0 -109
- package/dist/models/search/grpcCommonModels.js +0 -80
- package/dist/models/search/grpcCommonModels.js.map +0 -1
- package/dist/models/search/grpcCompanyAggregation.d.ts +0 -14
- package/dist/models/search/grpcCompanyAggregation.js +0 -16
- package/dist/models/search/grpcCompanyAggregation.js.map +0 -1
- package/dist/models/search/grpcCompanyConnectModel.d.ts +0 -14
- package/dist/models/search/grpcCompanyConnectModel.js +0 -18
- package/dist/models/search/grpcCompanyConnectModel.js.map +0 -1
- package/dist/models/search/grpcCompanyListReq.d.ts +0 -36
- package/dist/models/search/grpcCompanyListReq.js +0 -42
- package/dist/models/search/grpcCompanyListReq.js.map +0 -1
- package/dist/models/search/grpcCompanyModel.d.ts +0 -43
- package/dist/models/search/grpcCompanyModel.js +0 -46
- package/dist/models/search/grpcCompanyModel.js.map +0 -1
- package/dist/models/search/grpcCompanyNewsCountModel.d.ts +0 -9
- package/dist/models/search/grpcCompanyNewsCountModel.js +0 -14
- package/dist/models/search/grpcCompanyNewsCountModel.js.map +0 -1
- package/dist/models/search/grpcCompanyPeriodMentionModel.d.ts +0 -18
- package/dist/models/search/grpcCompanyPeriodMentionModel.js +0 -22
- package/dist/models/search/grpcCompanyPeriodMentionModel.js.map +0 -1
- package/dist/models/search/grpcCompanyPreviewModel.d.ts +0 -26
- package/dist/models/search/grpcCompanyPreviewModel.js +0 -31
- package/dist/models/search/grpcCompanyPreviewModel.js.map +0 -1
- package/dist/models/search/grpcContentAggregation.d.ts +0 -8
- package/dist/models/search/grpcContentAggregation.js +0 -7
- package/dist/models/search/grpcContentAggregation.js.map +0 -1
- package/dist/models/search/grpcContentListReq.d.ts +0 -16
- package/dist/models/search/grpcContentListReq.js +0 -22
- package/dist/models/search/grpcContentListReq.js.map +0 -1
- package/dist/models/search/grpcContentModel.d.ts +0 -32
- package/dist/models/search/grpcContentModel.js +0 -37
- package/dist/models/search/grpcContentModel.js.map +0 -1
- package/dist/models/search/grpcContentPreviewModel.d.ts +0 -28
- package/dist/models/search/grpcContentPreviewModel.js +0 -33
- package/dist/models/search/grpcContentPreviewModel.js.map +0 -1
- package/dist/models/search/grpcContentTabsModel.d.ts +0 -10
- package/dist/models/search/grpcContentTabsModel.js +0 -15
- package/dist/models/search/grpcContentTabsModel.js.map +0 -1
- package/dist/models/search/grpcCountryModel.d.ts +0 -13
- package/dist/models/search/grpcCountryModel.js +0 -19
- package/dist/models/search/grpcCountryModel.js.map +0 -1
- package/dist/models/search/grpcFinancialModel.d.ts +0 -292
- package/dist/models/search/grpcFinancialModel.js +0 -7
- package/dist/models/search/grpcFinancialModel.js.map +0 -1
- package/dist/models/search/grpcMarketModel.d.ts +0 -16
- package/dist/models/search/grpcMarketModel.js +0 -6
- package/dist/models/search/grpcMarketModel.js.map +0 -1
- package/dist/models/search/grpcMentionContentCountModel.d.ts +0 -5
- package/dist/models/search/grpcMentionContentCountModel.js +0 -7
- package/dist/models/search/grpcMentionContentCountModel.js.map +0 -1
- package/dist/models/search/index.d.ts +0 -16
- package/dist/models/search/index.js +0 -44
- package/dist/models/search/index.js.map +0 -1
- package/dist/models/subscription/applicationFeatureModel.d.ts +0 -7
- package/dist/models/subscription/applicationFeatureModel.js +0 -12
- package/dist/models/subscription/applicationFeatureModel.js.map +0 -1
- package/dist/models/subscription/featureModel.d.ts +0 -7
- package/dist/models/subscription/featureModel.js +0 -13
- package/dist/models/subscription/featureModel.js.map +0 -1
- package/dist/models/subscription/grpcSubscriptionModel.d.ts +0 -6
- package/dist/models/subscription/grpcSubscriptionModel.js +0 -12
- package/dist/models/subscription/grpcSubscriptionModel.js.map +0 -1
- package/dist/models/subscription/index.d.ts +0 -10
- package/dist/models/subscription/index.js +0 -22
- package/dist/models/subscription/index.js.map +0 -1
- package/dist/models/subscription/licenseModel.d.ts +0 -6
- package/dist/models/subscription/licenseModel.js +0 -12
- package/dist/models/subscription/licenseModel.js.map +0 -1
- package/dist/models/subscription/licenseUserModel.d.ts +0 -5
- package/dist/models/subscription/licenseUserModel.js +0 -11
- package/dist/models/subscription/licenseUserModel.js.map +0 -1
- package/dist/models/subscription/subscriptionFeatureModel.d.ts +0 -6
- package/dist/models/subscription/subscriptionFeatureModel.js +0 -12
- package/dist/models/subscription/subscriptionFeatureModel.js.map +0 -1
- package/dist/models/subscription/subscriptionModel.d.ts +0 -14
- package/dist/models/subscription/subscriptionModel.js +0 -19
- package/dist/models/subscription/subscriptionModel.js.map +0 -1
- package/dist/models/subscription/subscriptionPlanFeatureModel.d.ts +0 -5
- package/dist/models/subscription/subscriptionPlanFeatureModel.js +0 -11
- package/dist/models/subscription/subscriptionPlanFeatureModel.js.map +0 -1
- package/dist/models/subscription/subscriptionPlanModel.d.ts +0 -15
- package/dist/models/subscription/subscriptionPlanModel.js +0 -20
- package/dist/models/subscription/subscriptionPlanModel.js.map +0 -1
- package/dist/models/user/grpcAccountInfoModel.d.ts +0 -5
- package/dist/models/user/grpcAccountInfoModel.js +0 -7
- package/dist/models/user/grpcAccountInfoModel.js.map +0 -1
- package/dist/models/user/grpcAppUserModel.d.ts +0 -15
- package/dist/models/user/grpcAppUserModel.js +0 -20
- package/dist/models/user/grpcAppUserModel.js.map +0 -1
- package/dist/models/user/grpcAppUserOrganisationStatistic.d.ts +0 -6
- package/dist/models/user/grpcAppUserOrganisationStatistic.js +0 -12
- package/dist/models/user/grpcAppUserOrganisationStatistic.js.map +0 -1
- package/dist/models/user/grpcAppUserRoleModel.d.ts +0 -5
- package/dist/models/user/grpcAppUserRoleModel.js +0 -11
- package/dist/models/user/grpcAppUserRoleModel.js.map +0 -1
- package/dist/models/user/grpcBrowseHistoryModel.d.ts +0 -8
- package/dist/models/user/grpcBrowseHistoryModel.js +0 -14
- package/dist/models/user/grpcBrowseHistoryModel.js.map +0 -1
- package/dist/models/user/grpcDailyDigestUserModel.d.ts +0 -10
- package/dist/models/user/grpcDailyDigestUserModel.js +0 -15
- package/dist/models/user/grpcDailyDigestUserModel.js.map +0 -1
- package/dist/models/user/grpcNotificationSettingModel.d.ts +0 -11
- package/dist/models/user/grpcNotificationSettingModel.js +0 -17
- package/dist/models/user/grpcNotificationSettingModel.js.map +0 -1
- package/dist/models/user/grpcSavedSearchModel.d.ts +0 -8
- package/dist/models/user/grpcSavedSearchModel.js +0 -14
- package/dist/models/user/grpcSavedSearchModel.js.map +0 -1
- package/dist/models/user/grpcSearchHistoryModel.d.ts +0 -7
- package/dist/models/user/grpcSearchHistoryModel.js +0 -13
- package/dist/models/user/grpcSearchHistoryModel.js.map +0 -1
- package/dist/models/user/grpcTargetListEntityModel.d.ts +0 -5
- package/dist/models/user/grpcTargetListEntityModel.js +0 -7
- package/dist/models/user/grpcTargetListEntityModel.js.map +0 -1
- package/dist/models/user/grpcTargetListExportModel.d.ts +0 -8
- package/dist/models/user/grpcTargetListExportModel.js +0 -14
- package/dist/models/user/grpcTargetListExportModel.js.map +0 -1
- package/dist/models/user/grpcTargetListItemModel.d.ts +0 -7
- package/dist/models/user/grpcTargetListItemModel.js +0 -13
- package/dist/models/user/grpcTargetListItemModel.js.map +0 -1
- package/dist/models/user/grpcTargetListModel.d.ts +0 -9
- package/dist/models/user/grpcTargetListModel.js +0 -14
- package/dist/models/user/grpcTargetListModel.js.map +0 -1
- package/dist/models/user/index.d.ts +0 -14
- package/dist/models/user/index.js +0 -30
- package/dist/models/user/index.js.map +0 -1
- package/dist/utils/appConfig.d.ts +0 -45
- package/dist/utils/appConfig.js +0 -57
- package/dist/utils/appConfig.js.map +0 -1
- package/dist/utils/appConst.d.ts +0 -139
- package/dist/utils/appConst.js +0 -159
- package/dist/utils/appConst.js.map +0 -1
- package/dist/utils/authentication/auth.d.ts +0 -2
- package/dist/utils/authentication/auth.js +0 -163
- package/dist/utils/authentication/auth.js.map +0 -1
- package/dist/utils/authentication/role.d.ts +0 -7
- package/dist/utils/authentication/role.js +0 -139
- package/dist/utils/authentication/role.js.map +0 -1
- package/dist/utils/baseClass/baseController.d.ts +0 -12
- package/dist/utils/baseClass/baseController.js +0 -176
- package/dist/utils/baseClass/baseController.js.map +0 -1
- package/dist/utils/baseClass/baseService.d.ts +0 -7
- package/dist/utils/baseClass/baseService.js +0 -11
- package/dist/utils/baseClass/baseService.js.map +0 -1
- package/dist/utils/baseClass/dataSourceManager.d.ts +0 -11
- package/dist/utils/baseClass/dataSourceManager.js +0 -54
- package/dist/utils/baseClass/dataSourceManager.js.map +0 -1
- package/dist/utils/commonUtils/appConfigKeyRetriever.d.ts +0 -7
- package/dist/utils/commonUtils/appConfigKeyRetriever.js +0 -43
- package/dist/utils/commonUtils/appConfigKeyRetriever.js.map +0 -1
- package/dist/utils/commonUtils/appUtils.d.ts +0 -41
- package/dist/utils/commonUtils/appUtils.js +0 -236
- package/dist/utils/commonUtils/appUtils.js.map +0 -1
- package/dist/utils/commonUtils/cronUtils.d.ts +0 -9
- package/dist/utils/commonUtils/cronUtils.js +0 -32
- package/dist/utils/commonUtils/cronUtils.js.map +0 -1
- package/dist/utils/commonUtils/index.d.ts +0 -6
- package/dist/utils/commonUtils/index.js +0 -23
- package/dist/utils/commonUtils/index.js.map +0 -1
- package/dist/utils/commonUtils/jwtUtils.d.ts +0 -3
- package/dist/utils/commonUtils/jwtUtils.js +0 -83
- package/dist/utils/commonUtils/jwtUtils.js.map +0 -1
- package/dist/utils/commonUtils/responseUtils.d.ts +0 -7
- package/dist/utils/commonUtils/responseUtils.js +0 -131
- package/dist/utils/commonUtils/responseUtils.js.map +0 -1
- package/dist/utils/commonUtils/validation.d.ts +0 -6
- package/dist/utils/commonUtils/validation.js +0 -92
- package/dist/utils/commonUtils/validation.js.map +0 -1
- package/dist/utils/documentation/swagger.d.ts +0 -1
- package/dist/utils/documentation/swagger.js +0 -44
- package/dist/utils/documentation/swagger.js.map +0 -1
- package/dist/utils/logger/logger.d.ts +0 -1
- package/dist/utils/logger/logger.js +0 -58
- package/dist/utils/logger/logger.js.map +0 -1
- package/dist/utils/logger/morganLogger.d.ts +0 -4
- package/dist/utils/logger/morganLogger.js +0 -41
- package/dist/utils/logger/morganLogger.js.map +0 -1
- package/dist/utils/middleware/handleError.d.ts +0 -2
- package/dist/utils/middleware/handleError.js +0 -12
- package/dist/utils/middleware/handleError.js.map +0 -1
- package/dist/utils/middleware/isPublicUser.d.ts +0 -2
- package/dist/utils/middleware/isPublicUser.js +0 -35
- package/dist/utils/middleware/isPublicUser.js.map +0 -1
- package/dist/utils/middleware/overwriteConst.d.ts +0 -1
- package/dist/utils/middleware/overwriteConst.js +0 -84
- package/dist/utils/middleware/overwriteConst.js.map +0 -1
- package/dist/utils/middleware/startdbConnection.d.ts +0 -1
- package/dist/utils/middleware/startdbConnection.js +0 -30
- package/dist/utils/middleware/startdbConnection.js.map +0 -1
- package/dist/utils/monitoring/apm.d.ts +0 -6
- package/dist/utils/monitoring/apm.js +0 -99
- package/dist/utils/monitoring/apm.js.map +0 -1
- package/src/utils/baseClass/dataSourceManager.ts +0 -44
- package/src/utils/middleware/startdbConnection.ts +0 -20
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './cognitiveSearch';
|
|
2
|
+
export * from './azureBlobStorage';
|
|
3
|
+
export * from './azureKeyVault';
|
|
4
|
+
export * from './azureServiceBusClient';
|
|
5
|
+
export * from './azureServiceBusQueue';
|
|
6
|
+
export * from './azureStorageQueue';
|
|
7
|
+
export * from './azureTableStorage';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import fetch from 'node-fetch';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @description wrapper of node-fetch
|
|
6
|
+
* @param {string} url - request endpoint
|
|
7
|
+
* @param {any} options - fetch options
|
|
8
|
+
* @returns {any} response
|
|
9
|
+
*/
|
|
10
|
+
export const sendRequest = async (url: string, options: any) => await fetch(url, options);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import fetch from 'node-fetch';
|
|
2
|
+
import { AbortController } from '@azure/abort-controller';
|
|
3
|
+
import { thirdPartyRegulation } from '../../utils/appConst';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @description to store the current processing request, it should only be called
|
|
8
|
+
* by function sendRequestWithTimeout
|
|
9
|
+
*/
|
|
10
|
+
const abortedSet: Set<string> = new Set<string>();
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @description send a request which will automatically abort within a given time
|
|
14
|
+
* if the request is not response yet
|
|
15
|
+
* @param {string} url - url of request endpoint
|
|
16
|
+
* @param {any} options - fetch option
|
|
17
|
+
* @param {number} abortWithinMs - automatically abort after given millisecond
|
|
18
|
+
* @returns {any} response
|
|
19
|
+
*/
|
|
20
|
+
export async function sendRequestWithTimeout(
|
|
21
|
+
url: string,
|
|
22
|
+
options: any,
|
|
23
|
+
abortWithinMs: number = thirdPartyRegulation.requestLimitationMsec
|
|
24
|
+
): Promise<any> {
|
|
25
|
+
const controller = new AbortController();
|
|
26
|
+
const timeout = setTimeout(() => {
|
|
27
|
+
abortedSet.add(url);
|
|
28
|
+
controller.abort();
|
|
29
|
+
}, abortWithinMs);
|
|
30
|
+
try {
|
|
31
|
+
const response = await fetch(url, { signal: controller.signal, ...options});
|
|
32
|
+
clearTimeout(timeout);
|
|
33
|
+
return response;
|
|
34
|
+
} catch (err) {
|
|
35
|
+
if (abortedSet.has(url) && (err as Error).name === 'AbortError') { abortedSet.delete(url); }
|
|
36
|
+
throw err;
|
|
37
|
+
}
|
|
38
|
+
}
|
package/src/lib/httpClient.ts
CHANGED
|
@@ -1,36 +1,37 @@
|
|
|
1
|
+
import fetch, { Response, RequestInit } from 'node-fetch';
|
|
1
2
|
import { UserInfo } from '../interfaces';
|
|
2
3
|
import { getInternalClient, userInfoSimplifier } from '../utils/commonUtils';
|
|
3
4
|
import { generateJWT } from '../utils/commonUtils';
|
|
4
5
|
import {commonAppConst, jsonContentTypeHeaders } from '../utils/appConst';
|
|
5
|
-
|
|
6
|
+
import { logger } from '../utils/logger/logger';
|
|
6
7
|
|
|
7
8
|
export async function httpRequest(method: string, url : string, data: any = null, headers : any = jsonContentTypeHeaders()): Promise<Response> {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
method: method,
|
|
15
|
-
cache: "no-cache",
|
|
16
|
-
headers: headers,
|
|
17
|
-
body: JSON.stringify(data)
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
return fetch(url, init);
|
|
9
|
+
const init: RequestInit = {
|
|
10
|
+
method,
|
|
11
|
+
headers,
|
|
12
|
+
body: data === null ? undefined : JSON.stringify(data)
|
|
13
|
+
}
|
|
14
|
+
return fetch(url, init);
|
|
21
15
|
}
|
|
22
16
|
|
|
23
17
|
export async function sendInternalHttpRequest(userInfo:UserInfo, client: string, endpoint: string, data: any = null, method?: string, select?:string[]) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
18
|
+
method = method ?? commonAppConst.httpMethod.POST;
|
|
19
|
+
const internalClient = await getInternalClient(client)
|
|
20
|
+
const url = internalClient + endpoint;
|
|
21
|
+
let headers:any = jsonContentTypeHeaders();
|
|
22
|
+
if(userInfo){
|
|
23
|
+
userInfo = await userInfoSimplifier(userInfo, select)
|
|
24
|
+
let token: string = `${commonAppConst.httpHeader.BEARER} ${await generateJWT(userInfo)}`;
|
|
25
|
+
headers[commonAppConst.httpHeader.AUTHORIZATION] = token;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let response: Response;
|
|
29
|
+
try {
|
|
30
|
+
response = await httpRequest(method, url, data, headers);
|
|
31
|
+
return response.json();
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
logger.error(`Error while sending internal http request, receiving response: ${response}`);
|
|
35
|
+
throw new Error(`${err}`);
|
|
36
|
+
}
|
|
36
37
|
}
|
package/src/lib/index.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { LogLevel, LogMessage } from './logMessage';
|
|
2
|
+
import { appConfig, loadConfig } from '../../utils/middleware/loadConfig';
|
|
3
|
+
import { sendRequestWithTimeout } from '../fetch';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @description broadcast log message to specific Microsoft Teams channels
|
|
8
|
+
* @param {LogLevel} level - level of the log
|
|
9
|
+
* @param {string} message - log message
|
|
10
|
+
* @returns {void} the function is deposable, thus it won't return any of information
|
|
11
|
+
*/
|
|
12
|
+
export async function broadcastLogMessage(level: LogLevel, message: string) {
|
|
13
|
+
// we only broadcast two levels of log.
|
|
14
|
+
if (level !== 'error' && level !== 'warn') { return; }
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* When the keyVaultName is empty, loadConfig() should be called in order to fetch the value as possible
|
|
18
|
+
* since we are not using lazy-loading here. It would be better to transform into a lazy-loading mechanism.
|
|
19
|
+
*/
|
|
20
|
+
if (appConfig === undefined) {
|
|
21
|
+
try {
|
|
22
|
+
await loadConfig();
|
|
23
|
+
} catch (err) {
|
|
24
|
+
throw err;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const time = new Date().toISOString();
|
|
29
|
+
const logMessage: LogMessage = {
|
|
30
|
+
level,
|
|
31
|
+
message,
|
|
32
|
+
time,
|
|
33
|
+
environment: appConfig.environment,
|
|
34
|
+
appName: appConfig.appName,
|
|
35
|
+
version: appConfig.version
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const messageCard: Object = ((): Object => {
|
|
39
|
+
return {
|
|
40
|
+
'@type': 'MessageCard',
|
|
41
|
+
'@context': 'http://schema.org/extensions',
|
|
42
|
+
'summary': 'Teams broadcasting of Logs',
|
|
43
|
+
'sections': [{
|
|
44
|
+
'activityTitle': `# ***Service Error Log - ${logMessage.level}***`,
|
|
45
|
+
'facts': [
|
|
46
|
+
{ 'name': 'Time', 'value': logMessage.time },
|
|
47
|
+
{ 'name': 'Environment', 'value': logMessage.environment },
|
|
48
|
+
{ 'name': 'Service', 'value': logMessage.appName },
|
|
49
|
+
{ 'name': 'Version', 'value': logMessage.version },
|
|
50
|
+
{ 'name': 'Message', 'value': logMessage.message }
|
|
51
|
+
],
|
|
52
|
+
'markdown': true
|
|
53
|
+
}],
|
|
54
|
+
'potentialAction': [
|
|
55
|
+
{
|
|
56
|
+
'@type': 'OpenUri',
|
|
57
|
+
'name': 'View Documentation',
|
|
58
|
+
'targets': [ { 'os': 'default', 'uri': '' } ]
|
|
59
|
+
}
|
|
60
|
+
]
|
|
61
|
+
}
|
|
62
|
+
})();
|
|
63
|
+
|
|
64
|
+
const url = level === 'error' ?
|
|
65
|
+
appConfig.telemetry.teamsChannelWebHook.errorChannel
|
|
66
|
+
:
|
|
67
|
+
appConfig.telemetry.teamsChannelWebHook.warnChannel;
|
|
68
|
+
|
|
69
|
+
await sendRequestWithTimeout(url, { method: 'POST', body: JSON.stringify(messageCard) });
|
|
70
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Environment } from '../../utils';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @description we classified the logs into 4 levels and one supporting level:
|
|
7
|
+
* - `verbose`: The most fine-grained information only used in rare cases where
|
|
8
|
+
* you need the full visibility of what is happening in your application
|
|
9
|
+
* and inside the third-party libraries that you use
|
|
10
|
+
* - `info`: The standard log level indicating that something happened;
|
|
11
|
+
* the application entered a certain state. It should be purely informative and
|
|
12
|
+
* not looking into them on a regular basis
|
|
13
|
+
* - `warn`: the log level that indicates that something unexpected happened in
|
|
14
|
+
* the application, a problem, or a situation that might disturb one of the
|
|
15
|
+
* processes. But that doesn’t mean that the application failed
|
|
16
|
+
* - `error`: error, states as `FATAL` in the modern log leveling to alleviate DRY.
|
|
17
|
+
* It tells that the application encountered an event or entered a state in which
|
|
18
|
+
* one of the crucial business functionality is no longer working
|
|
19
|
+
* - `disabled`: supporting enum for disabling the functionality of logger
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```markdown
|
|
23
|
+
* - verbose: annotate each step in the algorithm or each individual query
|
|
24
|
+
* with parameters in your code
|
|
25
|
+
* - info: request of authorization API which states whether a user sign-on success or not
|
|
26
|
+
* - warn`: a parsing error occurred that resulted in a certain document not being processed
|
|
27
|
+
* - error: when the application is not able to connect to a crucial data store like a database
|
|
28
|
+
* or one of the sub-service is unavailable
|
|
29
|
+
* ```
|
|
30
|
+
* @see https://sematext.com/blog/logging-levels/
|
|
31
|
+
*/
|
|
32
|
+
export const zLogLevel = z.enum(['verbose', 'info', 'warn', 'error', 'disabled']);
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @description typedef of `zLogLevel`
|
|
36
|
+
*/
|
|
37
|
+
export type LogLevel = z.infer<typeof zLogLevel>;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @description definition of the context that a log should contains
|
|
41
|
+
* @property {LogLevel} level - log level
|
|
42
|
+
* @property {string} time - when does the log be generated
|
|
43
|
+
* @property {string} appName - the service which generates the logs
|
|
44
|
+
* @property {Environment} environment - log happened in which environment
|
|
45
|
+
* @property {string} message - log message
|
|
46
|
+
* @property {string} version - current app version
|
|
47
|
+
*/
|
|
48
|
+
export type LogMessage = {
|
|
49
|
+
level: LogLevel;
|
|
50
|
+
time: string;
|
|
51
|
+
appName: string;
|
|
52
|
+
environment: Environment;
|
|
53
|
+
message: string;
|
|
54
|
+
version: string;
|
|
55
|
+
}
|
package/src/utils/appConfig.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import dotenv from 'dotenv';
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
if (process.env.NODE_ENV !== undefined) {
|
|
4
4
|
dotenv.config({ path: `${process.env.NODE_ENV}.env` });
|
|
5
5
|
}
|
|
@@ -49,4 +49,4 @@ export const commonAppConfig = {
|
|
|
49
49
|
DailyDigest: process.env.DAILYDIGEST_CLIENT,
|
|
50
50
|
Announcement: process.env.ANNOUNCEMENT_CLIENT,
|
|
51
51
|
APIM: process.env.APIM_CLIENT,
|
|
52
|
-
}
|
|
52
|
+
}
|
package/src/utils/appConst.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
1
3
|
export const commonAppConst = {
|
|
2
4
|
emptyGuid: '00000000-0000-0000-0000-000000000000',
|
|
3
5
|
sampleStatus: {
|
|
@@ -155,3 +157,65 @@ export const exitErrorMessage:Record<string, string> = {
|
|
|
155
157
|
SQLQueryRunner: `Requests can only be made in the LoggedIn state, not the SentClientRequest state`,
|
|
156
158
|
UnknownTimeout: `operation timed out for an unknown reason`
|
|
157
159
|
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* @description environment cuts some of the functionalities, including log levels
|
|
163
|
+
* and local-env file location, to optimize our services.
|
|
164
|
+
* @enum {string}
|
|
165
|
+
*/
|
|
166
|
+
export const zEnvironment = z.enum(['test', 'dev', 'development', 'preview', 'staging', 'beta', 'production']);
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* @description typedef of `zEnvironment`
|
|
170
|
+
*/
|
|
171
|
+
export type Environment = z.infer<typeof zEnvironment>;
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* @description const to regulate, control the third parties' usage
|
|
175
|
+
* @property {number} requestLimitationMsec - default request abort time
|
|
176
|
+
* @property {number} requestDefaultRetry - default retry times if the request is failed
|
|
177
|
+
*/
|
|
178
|
+
export const thirdPartyRegulation = {
|
|
179
|
+
requestLimitationMsec: 5000,
|
|
180
|
+
requestDefaultRetry: 2
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* @description settings for logger
|
|
185
|
+
* @property {string} path - local storage path of log files
|
|
186
|
+
* @property {boolean} teamsChannelDisabled - when the log level is `warn`/`error`,
|
|
187
|
+
* the messages will be delivered to the Teams channel
|
|
188
|
+
*/
|
|
189
|
+
export const loggerSettings = {
|
|
190
|
+
path: './log/',
|
|
191
|
+
teamsChannelDisabled: true
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* @description Index of Azure Cognitive Search
|
|
196
|
+
* @enum {string}
|
|
197
|
+
*/
|
|
198
|
+
export enum AzureSearchIndex {
|
|
199
|
+
news = 'news',
|
|
200
|
+
company = 'company',
|
|
201
|
+
market = 'market',
|
|
202
|
+
financial = 'financial',
|
|
203
|
+
ott = 'ott',
|
|
204
|
+
nerl = 'nerl',
|
|
205
|
+
people = 'people',
|
|
206
|
+
relationship = 'relationship'
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* @description configuration of Azure Cognitive Search
|
|
211
|
+
* @property {number} queryRetryDefault - default retry times for query
|
|
212
|
+
* @property {number} retryIntervalSecond - retry after waiting given second
|
|
213
|
+
* @property {string} credentialSecretName - credential secret name saved in Azure Key Vault
|
|
214
|
+
* @property {string} indexSecretName - index secret name saved in Azure Key Vault
|
|
215
|
+
*/
|
|
216
|
+
export const AzureSearchConfig = {
|
|
217
|
+
queryRetryDefault: 3,
|
|
218
|
+
retryIntervalSecond: 1,
|
|
219
|
+
credentialSecretName: 'SkyEye-SVC-Search-Credential',
|
|
220
|
+
indexSecretName: 'SkyEye-SVC-Search-Index'
|
|
221
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { DataSource, DataSourceOptions } from 'typeorm';
|
|
2
|
+
import { logger } from '../logger/logger';
|
|
3
|
+
|
|
4
|
+
export class AppDataSource {
|
|
5
|
+
|
|
6
|
+
private static instance: DataSource;
|
|
7
|
+
|
|
8
|
+
private constructor() {}
|
|
9
|
+
|
|
10
|
+
public static getInstance() {
|
|
11
|
+
return AppDataSource.instance;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public static async startConnection(options: DataSourceOptions) {
|
|
15
|
+
if (!AppDataSource.instance) {
|
|
16
|
+
AppDataSource.instance = new DataSource(options);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (!AppDataSource.instance.isInitialized) {
|
|
20
|
+
await AppDataSource.instance.initialize();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -7,7 +7,7 @@ import { QueryRunner } from 'typeorm';
|
|
|
7
7
|
import { commonAppConst } from '../appConst';
|
|
8
8
|
import { commonAppConfig } from '../appConfig';
|
|
9
9
|
import { Mutex } from 'async-mutex';
|
|
10
|
-
import {
|
|
10
|
+
import { AppDataSource } from './appDataSource';
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
export abstract class BaseController {
|
|
@@ -18,8 +18,8 @@ export abstract class BaseController {
|
|
|
18
18
|
let queryRunner: QueryRunner;
|
|
19
19
|
|
|
20
20
|
try {
|
|
21
|
-
|
|
22
|
-
queryRunner =
|
|
21
|
+
// Use queryRunner if transaction is needed
|
|
22
|
+
queryRunner = AppDataSource.getInstance().createQueryRunner();
|
|
23
23
|
await queryRunner.startTransaction();
|
|
24
24
|
|
|
25
25
|
return Promise.resolve(queryRunner);
|
|
@@ -59,12 +59,12 @@ export abstract class BaseController {
|
|
|
59
59
|
} catch (err) {
|
|
60
60
|
logger.error(`BaseController/endTransaction: ${err}`);
|
|
61
61
|
} finally {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
} catch (err) {
|
|
66
|
-
logger.error(`BaseController/endTransaction Release Error: ${err}`);
|
|
62
|
+
try {
|
|
63
|
+
if (!baseControllerParameter.queryRunner.isReleased) {
|
|
64
|
+
await baseControllerParameter.queryRunner.release();
|
|
67
65
|
}
|
|
66
|
+
} catch (err) {
|
|
67
|
+
logger.error(`BaseController/endTransaction Release Error: ${err}`);
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
}
|
|
@@ -149,7 +149,7 @@ export abstract class BaseController {
|
|
|
149
149
|
baseControllerParameter.serviceResponse.isSuccess = false;
|
|
150
150
|
baseControllerParameter.serviceResponse.error = true;
|
|
151
151
|
baseControllerParameter.serviceResponse.message = err.message;
|
|
152
|
-
|
|
152
|
+
|
|
153
153
|
throw err;
|
|
154
154
|
});
|
|
155
155
|
}
|
|
@@ -7,7 +7,7 @@ import dateformat from 'dateformat';
|
|
|
7
7
|
// ensure log directory exists
|
|
8
8
|
fs.existsSync(commonAppConfig.LogPath) || fs.mkdirSync(commonAppConfig.LogPath)
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
const FileNameGenerator = (time: number | Date, index: number) =>{
|
|
11
11
|
if (!time)
|
|
12
12
|
{
|
|
13
13
|
time = new Date();
|
|
@@ -18,7 +18,7 @@ function FileNameGenerator(time:Date, index:number){
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
// create a rotating write stream
|
|
21
|
-
var accessLogStream = rfs(FileNameGenerator, {
|
|
21
|
+
var accessLogStream = rfs.createStream(FileNameGenerator, {
|
|
22
22
|
interval: '1d', // rotate daily
|
|
23
23
|
path: commonAppConfig.LogPath
|
|
24
24
|
})
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import dotenv from 'dotenv';
|
|
2
|
+
import { getKeyVault } from '../../lib';
|
|
3
|
+
import { logger } from '../logger/logger';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { zEnvironment, Environment } from '../appConst';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @description
|
|
9
|
+
* @property {string} appName - service's app name from package.json
|
|
10
|
+
* @property {string} version - service's version from package.json
|
|
11
|
+
* @property {enum} environment - current environment
|
|
12
|
+
* @property {string} keyVaultName - Azure key vault name
|
|
13
|
+
* @property {string} keyVaultSecretName - secret name of Azure key vault
|
|
14
|
+
* @todo migration to single typedef
|
|
15
|
+
*/
|
|
16
|
+
const zEnvFileAppConfig = z.object({
|
|
17
|
+
appName: z.string(),
|
|
18
|
+
version: z.string(),
|
|
19
|
+
environment: zEnvironment,
|
|
20
|
+
keyVaultName: z.string(),
|
|
21
|
+
keyVaultSecretName: z.string()
|
|
22
|
+
}).strict();
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @description typedef of environment File App Config
|
|
26
|
+
*/
|
|
27
|
+
type EnvFileAppConfig = z.infer<typeof zEnvFileAppConfig>;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @todo migration to single typedef
|
|
31
|
+
*/
|
|
32
|
+
const zElasticKeyVault = z.object({
|
|
33
|
+
secretToken: z.string(),
|
|
34
|
+
serverUrl: z.string()
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @todo migration to single typedef
|
|
39
|
+
*/
|
|
40
|
+
const zTeamsChannelWebHook = z.object({
|
|
41
|
+
errorChannel: z.string(),
|
|
42
|
+
warnChannel: z.string()
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @todo migration to single typedef
|
|
47
|
+
*/
|
|
48
|
+
const zTelemetry = z.object({
|
|
49
|
+
teamsChannelWebHook: zTeamsChannelWebHook,
|
|
50
|
+
elasticKeyVault: zElasticKeyVault
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @todo migration to single typedef
|
|
55
|
+
*/
|
|
56
|
+
const zSecretFileAppConfig = z.object({
|
|
57
|
+
telemetry: zTelemetry,
|
|
58
|
+
serviceConfig: z.any().nullable()
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @description typedef of secret file
|
|
63
|
+
*/
|
|
64
|
+
type SecretFileAppConfig = z.infer<typeof zSecretFileAppConfig>;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @todo migration to single typedef
|
|
68
|
+
*/
|
|
69
|
+
type AppConfig = EnvFileAppConfig & SecretFileAppConfig;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @description configuration carrier (or, instance). We can classified all the configurations into 2 categories:
|
|
73
|
+
* - Environment File App Config: configuration from the environment file (.env) and some other settings
|
|
74
|
+
* - Secret File App Config: loaded from the Azure Key Vault
|
|
75
|
+
*/
|
|
76
|
+
export let appConfig: AppConfig;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @todo move to loadConfig since all the environment fields should be loaded from appConfig
|
|
80
|
+
*/
|
|
81
|
+
export const environment: Environment = (process.env.NODE_ENV as Environment) ?? 'development';
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @description preload for app configuration, once it is been called, the appConfig will be loaded and be freezed
|
|
85
|
+
* @param packagePath - optional, path of `package.json` in order to load app name and version
|
|
86
|
+
*/
|
|
87
|
+
export const loadConfig = async (packagePath?: string) => {
|
|
88
|
+
logger.verbose('start /appConfig/preload()');
|
|
89
|
+
|
|
90
|
+
// load environment file
|
|
91
|
+
dotenv.config({ path: `${environment}.env` });
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* To load the appName and the version, we read the package information in the following order:
|
|
95
|
+
* 1. check if the environment value is defined directly
|
|
96
|
+
* 2. check if environment given from npm is defined
|
|
97
|
+
* 3. check if value in package.json is defined
|
|
98
|
+
*/
|
|
99
|
+
const pkg = require(packagePath ?? `${process.env.PWD}/package.json`);
|
|
100
|
+
|
|
101
|
+
const appName: string = ((): string => {
|
|
102
|
+
if (!!process.env.APP_NAME) { return process.env.APP_NAME; }
|
|
103
|
+
if (!!process.env.npm_package_name) { return process.env.npm_package_name; }
|
|
104
|
+
if (!!pkg.name) { return pkg.name; }
|
|
105
|
+
return 'default-app-name';
|
|
106
|
+
})();
|
|
107
|
+
|
|
108
|
+
const version: string = ((): string => {
|
|
109
|
+
if (!!process.env.VERSION) { return process.env.VERSION; }
|
|
110
|
+
if (!!process.env.npm_package_version) { return process.env.npm_package_version; }
|
|
111
|
+
if (!!pkg.version) { return pkg.version; }
|
|
112
|
+
return '0.0.0';
|
|
113
|
+
})();
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* check the env which suppose to be hide as possible as it can,
|
|
117
|
+
* which is not allowed to define in-memory.
|
|
118
|
+
*/
|
|
119
|
+
if (process.env.AZURE_TENANT_ID === undefined || process.env.AZURE_CLIENT_ID === undefined || process.env.AZURE_CLIENT_SECRET === undefined) {
|
|
120
|
+
throw new Error('/appConfig/preload: missing Azure configuration');
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const envFileAppConfig: EnvFileAppConfig = {
|
|
124
|
+
appName,
|
|
125
|
+
version,
|
|
126
|
+
environment,
|
|
127
|
+
keyVaultName: process.env.KEYVAULT_NAME,
|
|
128
|
+
keyVaultSecretName: process.env.LIBRARY_KEY_VAULT_SECRET_NAME
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// check envFileAppConfig
|
|
132
|
+
const envTypeCheck = zEnvFileAppConfig.safeParse(envFileAppConfig);
|
|
133
|
+
if (!envTypeCheck.success) {
|
|
134
|
+
throw new Error('/appConfig/preload: invalid schema of envFileAppConfig');
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// check secretFileAppConfig
|
|
138
|
+
const rawSecretResp = await getKeyVault(envFileAppConfig.keyVaultName, envFileAppConfig.keyVaultSecretName);
|
|
139
|
+
if (!rawSecretResp.isSuccess) { throw new Error(rawSecretResp.message); }
|
|
140
|
+
const secretFileAppConfig: SecretFileAppConfig = rawSecretResp.data;
|
|
141
|
+
const secretFileTypeCheck = zSecretFileAppConfig.safeParse(secretFileAppConfig);
|
|
142
|
+
if (!secretFileTypeCheck.success) {
|
|
143
|
+
throw new Error('/appConfig/preload: invalid schema of secretFileAppConfig');
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
appConfig = { ...envFileAppConfig, ...secretFileAppConfig };
|
|
147
|
+
Object.freeze(appConfig);
|
|
148
|
+
|
|
149
|
+
logger.verbose('end /appConfig/preload()');
|
|
150
|
+
};
|
package/.env
DELETED
package/dist/index.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
export * from './utils/appConfig';
|
|
2
|
-
export * from './utils/appConst';
|
|
3
|
-
export * from './utils/commonUtils';
|
|
4
|
-
export * from './utils/authentication/auth';
|
|
5
|
-
export * from './utils/logger/logger';
|
|
6
|
-
export * from './utils/logger/morganLogger';
|
|
7
|
-
export * from './utils/middleware/handleError';
|
|
8
|
-
export * from './utils/middleware/isPublicUser';
|
|
9
|
-
export * from './utils/middleware/overwriteConst';
|
|
10
|
-
export * from './utils/middleware/startdbConnection';
|
|
11
|
-
export * from './utils/baseClass/baseController';
|
|
12
|
-
export * from './utils/baseClass/baseService';
|
|
13
|
-
export * from './interfaces/index';
|
|
14
|
-
export * from './lib/azure/azureKeyVault';
|
|
15
|
-
export * from './lib/azure/azureServiceBusClient';
|
|
16
|
-
export * from './lib/azure/azureStorageQueue';
|
|
17
|
-
export * from './lib/azure/azureServiceBusQueue';
|
|
18
|
-
export * from './lib/azure/azureTableStorage';
|
|
19
|
-
export * from './lib/azure/azureBlobStorage';
|
|
20
|
-
export * from './utils/documentation/swagger';
|
|
21
|
-
export * from './lib/httpClient';
|
|
22
|
-
export * from './utils/monitoring/apm';
|
|
23
|
-
export * from './models/baseControllerParameter';
|
|
24
|
-
export * from './models';
|
|
25
|
-
export * from './lib/redisClient';
|
|
26
|
-
export * from './lib/sendGridClient';
|
|
27
|
-
export * from './interfaces/grpcServiceResponse';
|
|
28
|
-
export * from './interfaces/grpcListRequest';
|
|
29
|
-
export * from './utils/commonUtils/appConfigKeyRetriever';
|