skyeye-svc-common-utils 2.0.0-dev0.8 → 2.0.0

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 (111) hide show
  1. package/dist/index.d.ts +10 -7
  2. package/dist/index.js +10 -7
  3. package/dist/index.js.map +1 -1
  4. package/dist/lib/azure/azureKeyVault.d.ts +10 -0
  5. package/dist/lib/azure/azureKeyVault.js +39 -1
  6. package/dist/lib/azure/azureKeyVault.js.map +1 -1
  7. package/dist/lib/azure/cognitiveSearch/QueryType.d.ts +8 -0
  8. package/dist/lib/azure/cognitiveSearch/QueryType.js +13 -0
  9. package/dist/lib/azure/cognitiveSearch/QueryType.js.map +1 -0
  10. package/dist/lib/azure/cognitiveSearch/SearchClient.d.ts +42 -0
  11. package/dist/lib/azure/cognitiveSearch/SearchClient.js +161 -0
  12. package/dist/lib/azure/cognitiveSearch/SearchClient.js.map +1 -0
  13. package/dist/lib/azure/cognitiveSearch/SearchFacets.d.ts +16 -0
  14. package/dist/lib/azure/cognitiveSearch/SearchFacets.js +3 -0
  15. package/dist/lib/azure/cognitiveSearch/SearchFacets.js.map +1 -0
  16. package/dist/lib/azure/cognitiveSearch/SearchFilter.d.ts +68 -0
  17. package/dist/lib/azure/cognitiveSearch/SearchFilter.js +125 -0
  18. package/dist/lib/azure/cognitiveSearch/SearchFilter.js.map +1 -0
  19. package/dist/lib/azure/cognitiveSearch/SearchMode.d.ts +9 -0
  20. package/dist/lib/azure/cognitiveSearch/SearchMode.js +14 -0
  21. package/dist/lib/azure/cognitiveSearch/SearchMode.js.map +1 -0
  22. package/dist/lib/azure/cognitiveSearch/SearchOption.d.ts +88 -0
  23. package/dist/lib/azure/cognitiveSearch/SearchOption.js +104 -0
  24. package/dist/lib/azure/cognitiveSearch/SearchOption.js.map +1 -0
  25. package/dist/lib/azure/cognitiveSearch/SearchOrder.d.ts +9 -0
  26. package/dist/lib/azure/cognitiveSearch/SearchOrder.js +3 -0
  27. package/dist/lib/azure/cognitiveSearch/SearchOrder.js.map +1 -0
  28. package/dist/lib/azure/cognitiveSearch/index.d.ts +7 -0
  29. package/dist/lib/azure/cognitiveSearch/index.js +24 -0
  30. package/dist/lib/azure/cognitiveSearch/index.js.map +1 -0
  31. package/dist/lib/azure/index.d.ts +7 -0
  32. package/dist/lib/azure/index.js +24 -0
  33. package/dist/lib/azure/index.js.map +1 -0
  34. package/dist/lib/fetch/index.d.ts +2 -0
  35. package/dist/lib/fetch/index.js +19 -0
  36. package/dist/lib/fetch/index.js.map +1 -0
  37. package/dist/lib/fetch/sendRequest.d.ts +8 -0
  38. package/dist/lib/fetch/sendRequest.js +25 -0
  39. package/dist/lib/fetch/sendRequest.js.map +1 -0
  40. package/dist/lib/fetch/sendRequestWithTimeout.d.ts +9 -0
  41. package/dist/lib/fetch/sendRequestWithTimeout.js +53 -0
  42. package/dist/lib/fetch/sendRequestWithTimeout.js.map +1 -0
  43. package/dist/lib/httpClient.d.ts +1 -0
  44. package/dist/lib/httpClient.js +18 -14
  45. package/dist/lib/httpClient.js.map +1 -1
  46. package/dist/lib/index.d.ts +3 -0
  47. package/dist/lib/index.js +20 -0
  48. package/dist/lib/index.js.map +1 -0
  49. package/dist/lib/teams/broadcastLogMessage.d.ts +8 -0
  50. package/dist/lib/teams/broadcastLogMessage.js +81 -0
  51. package/dist/lib/teams/broadcastLogMessage.js.map +1 -0
  52. package/dist/lib/teams/index.d.ts +2 -0
  53. package/dist/lib/teams/index.js +19 -0
  54. package/dist/lib/teams/index.js.map +1 -0
  55. package/dist/lib/teams/logMessage.d.ts +51 -0
  56. package/dist/lib/teams/logMessage.js +33 -0
  57. package/dist/lib/teams/logMessage.js.map +1 -0
  58. package/dist/utils/appConst.d.ts +57 -0
  59. package/dist/utils/appConst.js +56 -1
  60. package/dist/utils/appConst.js.map +1 -1
  61. package/dist/utils/baseClass/appDataSource.d.ts +7 -0
  62. package/dist/utils/baseClass/appDataSource.js +31 -0
  63. package/dist/utils/baseClass/appDataSource.js.map +1 -0
  64. package/dist/utils/baseClass/baseController.d.ts +0 -3
  65. package/dist/utils/baseClass/baseController.js +27 -85
  66. package/dist/utils/baseClass/baseController.js.map +1 -1
  67. package/dist/utils/index.d.ts +2 -0
  68. package/dist/utils/index.js +19 -0
  69. package/dist/utils/index.js.map +1 -0
  70. package/dist/utils/logger/morganLogger.d.ts +4 -4
  71. package/dist/utils/logger/morganLogger.js +7 -7
  72. package/dist/utils/logger/morganLogger.js.map +1 -1
  73. package/dist/utils/middleware/loadConfig.d.ts +128 -0
  74. package/dist/utils/middleware/loadConfig.js +143 -0
  75. package/dist/utils/middleware/loadConfig.js.map +1 -0
  76. package/package.json +34 -45
  77. package/src/index.ts +10 -7
  78. package/src/lib/azure/azureKeyVault.ts +44 -0
  79. package/src/lib/azure/cognitiveSearch/QueryType.ts +8 -0
  80. package/src/lib/azure/cognitiveSearch/SearchClient.ts +149 -0
  81. package/src/lib/azure/cognitiveSearch/SearchFacets.ts +16 -0
  82. package/src/lib/azure/cognitiveSearch/SearchFilter.ts +140 -0
  83. package/src/lib/azure/cognitiveSearch/SearchMode.ts +9 -0
  84. package/src/lib/azure/cognitiveSearch/SearchOption.ts +155 -0
  85. package/src/lib/azure/cognitiveSearch/SearchOrder.ts +9 -0
  86. package/src/lib/azure/cognitiveSearch/index.ts +7 -0
  87. package/src/lib/azure/index.ts +7 -0
  88. package/src/lib/fetch/index.ts +2 -0
  89. package/src/lib/fetch/sendRequest.ts +10 -0
  90. package/src/lib/fetch/sendRequestWithTimeout.ts +38 -0
  91. package/src/lib/httpClient.ts +27 -26
  92. package/src/lib/index.ts +3 -0
  93. package/src/lib/teams/broadcastLogMessage.ts +70 -0
  94. package/src/lib/teams/index.ts +2 -0
  95. package/src/lib/teams/logMessage.ts +55 -0
  96. package/src/utils/appConfig.ts +2 -2
  97. package/src/utils/appConst.ts +64 -0
  98. package/src/utils/baseClass/appDataSource.ts +23 -0
  99. package/src/utils/baseClass/baseController.ts +28 -88
  100. package/src/utils/index.ts +2 -0
  101. package/src/utils/logger/morganLogger.ts +28 -29
  102. package/src/utils/middleware/loadConfig.ts +150 -0
  103. package/.env +0 -3
  104. package/dist/utils/baseClass/dataSourceManager.d.ts +0 -11
  105. package/dist/utils/baseClass/dataSourceManager.js +0 -57
  106. package/dist/utils/baseClass/dataSourceManager.js.map +0 -1
  107. package/dist/utils/middleware/startdbConnection.d.ts +0 -1
  108. package/dist/utils/middleware/startdbConnection.js +0 -30
  109. package/dist/utils/middleware/startdbConnection.js.map +0 -1
  110. package/src/utils/baseClass/dataSourceManager.ts +0 -47
  111. package/src/utils/middleware/startdbConnection.ts +0 -20
@@ -6,24 +6,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.morganConsole = exports.morganFile = void 0;
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const morgan_1 = __importDefault(require("morgan"));
9
- const rotating_file_stream_1 = __importDefault(require("rotating-file-stream"));
9
+ const rotating_file_stream_1 = require("rotating-file-stream");
10
10
  const appConfig_1 = require("../appConfig");
11
11
  const dateformat_1 = __importDefault(require("dateformat"));
12
12
  // ensure log directory exists
13
13
  fs_1.default.existsSync(appConfig_1.commonAppConfig.LogPath) || fs_1.default.mkdirSync(appConfig_1.commonAppConfig.LogPath);
14
- function FileNameGenerator(time, index) {
14
+ const FileNameGenerator = (time, index) => {
15
15
  if (!time) {
16
16
  time = new Date();
17
17
  }
18
- let indexStr = index ? ("-" + JSON.stringify(index)) : "";
18
+ const indexStr = index ? ("-" + JSON.stringify(index)) : "";
19
19
  return `backend-access-${(0, dateformat_1.default)(time, 'yyyy-mm-dd')}${indexStr}.log`;
20
- }
20
+ };
21
21
  // create a rotating write stream
22
- var accessLogStream = (0, rotating_file_stream_1.default)(FileNameGenerator, {
22
+ const accessLogStream = (0, rotating_file_stream_1.createStream)(FileNameGenerator, {
23
23
  interval: '1d', // rotate daily
24
24
  path: appConfig_1.commonAppConfig.LogPath
25
25
  });
26
- const jsonFormat = function (tokens, req, res) {
26
+ const jsonFormat = (tokens, req, res) => {
27
27
  return JSON.stringify({
28
28
  "method": tokens.method(req, res),
29
29
  "url": tokens.url(req, res),
@@ -36,6 +36,6 @@ const jsonFormat = function (tokens, req, res) {
36
36
  });
37
37
  };
38
38
  // setup the logger
39
- exports.morganFile = (0, morgan_1.default)(jsonFormat, { stream: accessLogStream, });
39
+ exports.morganFile = (0, morgan_1.default)(jsonFormat, { stream: accessLogStream });
40
40
  exports.morganConsole = (0, morgan_1.default)(jsonFormat);
41
41
  //# sourceMappingURL=morganLogger.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"morganLogger.js","sourceRoot":"","sources":["../../../src/utils/logger/morganLogger.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,oDAA4B;AAC5B,gFAAuC;AACvC,4CAA6C;AAC7C,4DAAoC;AAEpC,8BAA8B;AAC9B,YAAE,CAAC,UAAU,CAAC,2BAAe,CAAC,OAAO,CAAC,IAAI,YAAE,CAAC,SAAS,CAAC,2BAAe,CAAC,OAAO,CAAC,CAAA;AAE/E,SAAS,iBAAiB,CAAC,IAAS,EAAE,KAAY;IAC9C,IAAI,CAAC,IAAI,EACT,CAAC;QACG,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;IACtB,CAAC;IACD,IAAI,QAAQ,GAAa,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAA,CAAC,CAAC,EAAE,CAAC;IACnE,OAAO,kBAAkB,IAAA,oBAAU,EAAC,IAAI,EAAC,YAAY,CAAC,GAAG,QAAQ,MAAM,CAAC;AAE5E,CAAC;AAED,iCAAiC;AACjC,IAAI,eAAe,GAAG,IAAA,8BAAG,EAAC,iBAAiB,EAAE;IAC3C,QAAQ,EAAE,IAAI,EAAE,eAAe;IAC/B,IAAI,EAAE,2BAAe,CAAC,OAAO;CAC9B,CAAC,CAAA;AAGF,MAAM,UAAU,GAAG,UAAU,M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C,UAAU,EAAE,EAAE,MAAM,EAAE,eAAe,EAAE,CAAC,CAAC;AAE7D,QAAA,aAAa,GAAG,IAAA,gBAAM,EAAC,UAAU,CAAC,CAAC"}
@@ -0,0 +1,128 @@
1
+ import { z } from 'zod';
2
+ import { Environment } from '../appConst';
3
+ /**
4
+ * @description
5
+ * @property {string} appName - service's app name from package.json
6
+ * @property {string} version - service's version from package.json
7
+ * @property {enum} environment - current environment
8
+ * @property {string} keyVaultName - Azure key vault name
9
+ * @property {string} keyVaultSecretName - secret name of Azure key vault
10
+ * @todo migration to single typedef
11
+ */
12
+ declare const zEnvFileAppConfig: z.ZodObject<{
13
+ appName: z.ZodString;
14
+ version: z.ZodString;
15
+ environment: z.ZodEnum<["test", "dev", "development", "preview", "staging", "beta", "production"]>;
16
+ keyVaultName: z.ZodString;
17
+ keyVaultSecretName: z.ZodString;
18
+ }, "strict", z.ZodTypeAny, {
19
+ appName?: string;
20
+ version?: string;
21
+ environment?: "dev" | "development" | "test" | "preview" | "staging" | "beta" | "production";
22
+ keyVaultName?: string;
23
+ keyVaultSecretName?: string;
24
+ }, {
25
+ appName?: string;
26
+ version?: string;
27
+ environment?: "dev" | "development" | "test" | "preview" | "staging" | "beta" | "production";
28
+ keyVaultName?: string;
29
+ keyVaultSecretName?: string;
30
+ }>;
31
+ /**
32
+ * @description typedef of environment File App Config
33
+ */
34
+ type EnvFileAppConfig = z.infer<typeof zEnvFileAppConfig>;
35
+ /**
36
+ * @todo migration to single typedef
37
+ */
38
+ declare const zSecretFileAppConfig: z.ZodObject<{
39
+ telemetry: z.ZodObject<{
40
+ teamsChannelWebHook: z.ZodObject<{
41
+ errorChannel: z.ZodString;
42
+ warnChannel: z.ZodString;
43
+ }, "strip", z.ZodTypeAny, {
44
+ errorChannel?: string;
45
+ warnChannel?: string;
46
+ }, {
47
+ errorChannel?: string;
48
+ warnChannel?: string;
49
+ }>;
50
+ elasticKeyVault: z.ZodObject<{
51
+ secretToken: z.ZodString;
52
+ serverUrl: z.ZodString;
53
+ }, "strip", z.ZodTypeAny, {
54
+ secretToken?: string;
55
+ serverUrl?: string;
56
+ }, {
57
+ secretToken?: string;
58
+ serverUrl?: string;
59
+ }>;
60
+ }, "strip", z.ZodTypeAny, {
61
+ teamsChannelWebHook?: {
62
+ errorChannel?: string;
63
+ warnChannel?: string;
64
+ };
65
+ elasticKeyVault?: {
66
+ secretToken?: string;
67
+ serverUrl?: string;
68
+ };
69
+ }, {
70
+ teamsChannelWebHook?: {
71
+ errorChannel?: string;
72
+ warnChannel?: string;
73
+ };
74
+ elasticKeyVault?: {
75
+ secretToken?: string;
76
+ serverUrl?: string;
77
+ };
78
+ }>;
79
+ serviceConfig: z.ZodNullable<z.ZodAny>;
80
+ }, "strip", z.ZodTypeAny, {
81
+ telemetry?: {
82
+ teamsChannelWebHook?: {
83
+ errorChannel?: string;
84
+ warnChannel?: string;
85
+ };
86
+ elasticKeyVault?: {
87
+ secretToken?: string;
88
+ serverUrl?: string;
89
+ };
90
+ };
91
+ serviceConfig?: any;
92
+ }, {
93
+ telemetry?: {
94
+ teamsChannelWebHook?: {
95
+ errorChannel?: string;
96
+ warnChannel?: string;
97
+ };
98
+ elasticKeyVault?: {
99
+ secretToken?: string;
100
+ serverUrl?: string;
101
+ };
102
+ };
103
+ serviceConfig?: any;
104
+ }>;
105
+ /**
106
+ * @description typedef of secret file
107
+ */
108
+ type SecretFileAppConfig = z.infer<typeof zSecretFileAppConfig>;
109
+ /**
110
+ * @todo migration to single typedef
111
+ */
112
+ type AppConfig = EnvFileAppConfig & SecretFileAppConfig;
113
+ /**
114
+ * @description configuration carrier (or, instance). We can classified all the configurations into 2 categories:
115
+ * - Environment File App Config: configuration from the environment file (.env) and some other settings
116
+ * - Secret File App Config: loaded from the Azure Key Vault
117
+ */
118
+ export declare let appConfig: AppConfig;
119
+ /**
120
+ * @todo move to loadConfig since all the environment fields should be loaded from appConfig
121
+ */
122
+ export declare const environment: Environment;
123
+ /**
124
+ * @description preload for app configuration, once it is been called, the appConfig will be loaded and be freezed
125
+ * @param packagePath - optional, path of `package.json` in order to load app name and version
126
+ */
127
+ export declare const loadConfig: (packagePath?: string) => Promise<void>;
128
+ export {};
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ var _a;
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.loadConfig = exports.environment = exports.appConfig = void 0;
17
+ const dotenv_1 = __importDefault(require("dotenv"));
18
+ const lib_1 = require("../../lib");
19
+ const logger_1 = require("../logger/logger");
20
+ const zod_1 = require("zod");
21
+ const appConst_1 = require("../appConst");
22
+ /**
23
+ * @description
24
+ * @property {string} appName - service's app name from package.json
25
+ * @property {string} version - service's version from package.json
26
+ * @property {enum} environment - current environment
27
+ * @property {string} keyVaultName - Azure key vault name
28
+ * @property {string} keyVaultSecretName - secret name of Azure key vault
29
+ * @todo migration to single typedef
30
+ */
31
+ const zEnvFileAppConfig = zod_1.z.object({
32
+ appName: zod_1.z.string(),
33
+ version: zod_1.z.string(),
34
+ environment: appConst_1.zEnvironment,
35
+ keyVaultName: zod_1.z.string(),
36
+ keyVaultSecretName: zod_1.z.string()
37
+ }).strict();
38
+ /**
39
+ * @todo migration to single typedef
40
+ */
41
+ const zElasticKeyVault = zod_1.z.object({
42
+ secretToken: zod_1.z.string(),
43
+ serverUrl: zod_1.z.string()
44
+ });
45
+ /**
46
+ * @todo migration to single typedef
47
+ */
48
+ const zTeamsChannelWebHook = zod_1.z.object({
49
+ errorChannel: zod_1.z.string(),
50
+ warnChannel: zod_1.z.string()
51
+ });
52
+ /**
53
+ * @todo migration to single typedef
54
+ */
55
+ const zTelemetry = zod_1.z.object({
56
+ teamsChannelWebHook: zTeamsChannelWebHook,
57
+ elasticKeyVault: zElasticKeyVault
58
+ });
59
+ /**
60
+ * @todo migration to single typedef
61
+ */
62
+ const zSecretFileAppConfig = zod_1.z.object({
63
+ telemetry: zTelemetry,
64
+ serviceConfig: zod_1.z.any().nullable()
65
+ });
66
+ /**
67
+ * @todo move to loadConfig since all the environment fields should be loaded from appConfig
68
+ */
69
+ exports.environment = (_a = process.env.NODE_ENV) !== null && _a !== void 0 ? _a : 'development';
70
+ /**
71
+ * @description preload for app configuration, once it is been called, the appConfig will be loaded and be freezed
72
+ * @param packagePath - optional, path of `package.json` in order to load app name and version
73
+ */
74
+ const loadConfig = (packagePath) => __awaiter(void 0, void 0, void 0, function* () {
75
+ logger_1.logger.verbose('start /appConfig/preload()');
76
+ // load environment file
77
+ dotenv_1.default.config({ path: `${exports.environment}.env` });
78
+ /**
79
+ * To load the appName and the version, we read the package information in the following order:
80
+ * 1. check if the environment value is defined directly
81
+ * 2. check if environment given from npm is defined
82
+ * 3. check if value in package.json is defined
83
+ */
84
+ const pkg = require(packagePath !== null && packagePath !== void 0 ? packagePath : `${process.env.PWD}/package.json`);
85
+ const appName = (() => {
86
+ if (!!process.env.APP_NAME) {
87
+ return process.env.APP_NAME;
88
+ }
89
+ if (!!process.env.npm_package_name) {
90
+ return process.env.npm_package_name;
91
+ }
92
+ if (!!pkg.name) {
93
+ return pkg.name;
94
+ }
95
+ return 'default-app-name';
96
+ })();
97
+ const version = (() => {
98
+ if (!!process.env.VERSION) {
99
+ return process.env.VERSION;
100
+ }
101
+ if (!!process.env.npm_package_version) {
102
+ return process.env.npm_package_version;
103
+ }
104
+ if (!!pkg.version) {
105
+ return pkg.version;
106
+ }
107
+ return '0.0.0';
108
+ })();
109
+ /**
110
+ * check the env which suppose to be hide as possible as it can,
111
+ * which is not allowed to define in-memory.
112
+ */
113
+ if (process.env.AZURE_TENANT_ID === undefined || process.env.AZURE_CLIENT_ID === undefined || process.env.AZURE_CLIENT_SECRET === undefined) {
114
+ throw new Error('/appConfig/preload: missing Azure configuration');
115
+ }
116
+ const envFileAppConfig = {
117
+ appName,
118
+ version,
119
+ environment: exports.environment,
120
+ keyVaultName: process.env.KEYVAULT_NAME,
121
+ keyVaultSecretName: process.env.LIBRARY_KEY_VAULT_SECRET_NAME
122
+ };
123
+ // check envFileAppConfig
124
+ const envTypeCheck = zEnvFileAppConfig.safeParse(envFileAppConfig);
125
+ if (!envTypeCheck.success) {
126
+ throw new Error('/appConfig/preload: invalid schema of envFileAppConfig');
127
+ }
128
+ // check secretFileAppConfig
129
+ const rawSecretResp = yield (0, lib_1.getKeyVault)(envFileAppConfig.keyVaultName, envFileAppConfig.keyVaultSecretName);
130
+ if (!rawSecretResp.isSuccess) {
131
+ throw new Error(rawSecretResp.message);
132
+ }
133
+ const secretFileAppConfig = rawSecretResp.data;
134
+ const secretFileTypeCheck = zSecretFileAppConfig.safeParse(secretFileAppConfig);
135
+ if (!secretFileTypeCheck.success) {
136
+ throw new Error('/appConfig/preload: invalid schema of secretFileAppConfig');
137
+ }
138
+ exports.appConfig = Object.assign(Object.assign({}, envFileAppConfig), secretFileAppConfig);
139
+ Object.freeze(exports.appConfig);
140
+ logger_1.logger.verbose('end /appConfig/preload()');
141
+ });
142
+ exports.loadConfig = loadConfig;
143
+ //# sourceMappingURL=loadConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loadConfig.js","sourceRoot":"","sources":["../../../src/utils/middleware/loadConfig.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAA4B;AAC5B,mCAAwC;AACxC,6CAA0C;AAC1C,6BAAwB;AACxB,0CAAwD;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svc-common-utils",
3
- "version": "2.0.0-dev0.8",
3
+ "version": "2.0.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -21,54 +21,43 @@
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",
27
- "@azure/storage-blob": "^12.1.2",
28
- "@azure/storage-queue": "^12.0.2",
29
- "@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
- "async-mutex": "^0.3.2",
39
- "cron-parser": "4.8.1",
40
- "dateformat": "^3.0.3",
41
- "debug": "^4.1.1",
42
- "dotenv": "^8.2.0",
43
- "elastic-apm-node": "^3.5.0",
44
- "express": "^4.17.1",
45
- "http-errors": "^1.7.3",
24
+ "@azure/identity": "^4.0.1",
25
+ "@azure/keyvault-secrets": "^4.8.0",
26
+ "@azure/service-bus": "^7.9.4",
27
+ "@azure/storage-blob": "^12.17.0",
28
+ "@azure/storage-queue": "^12.16.0",
29
+ "@azure/search-documents": "11.2.1",
30
+ "@azure/abort-controller": "1.0.4",
31
+ "@sendgrid/mail": "^8.1.1",
32
+ "cron-parser": "^4.9.0",
33
+ "dateformat": "^4.6.3",
34
+ "dotenv": "^16.4.5",
35
+ "elastic-apm-node": "^3.51.0",
36
+ "express": "^4.18.2",
46
37
  "https": "^1.0.0",
47
- "ioredis": "^5.0.4",
48
- "jsonwebtoken": "^9.0.0",
49
- "logform": "2.4.2",
50
- "moment": "^2.24.0",
51
- "morgan": "^1.9.1",
52
- "node-fetch": "^2.6.0",
53
- "nyc": "^15.1.0",
54
- "rotating-file-stream": "^1.4.6",
38
+ "ioredis": "^5.3.2",
39
+ "jsonwebtoken": "^9.0.2",
40
+ "lodash": "^4.17.21",
41
+ "moment": "^2.30.1",
42
+ "morgan": "^1.10.0",
43
+ "node-fetch": "^2.7.0",
44
+ "rotating-file-stream": "^3.2.1",
55
45
  "skyeye-common-const": "1.0.42",
56
- "swagger-jsdoc": "^3.5.0",
57
- "swagger-ui-express": "^4.1.3",
58
- "ts-node": "^10.7.0",
46
+ "swagger-jsdoc": "^6.2.8",
59
47
  "typeorm": "^0.3.17",
60
- "typescript": "^5.3.3",
61
- "uuid": "^3.3.3",
62
- "winston": "^3.2.1",
63
- "winston-daily-rotate-file": "^4.2.1"
48
+ "winston": "^3.11.0",
49
+ "winston-daily-rotate-file": "^4.7.1",
50
+ "abort-controller": "3.0.0",
51
+ "zod": "3.22.3",
52
+ "typescript": "^5.3.3"
64
53
  },
65
54
  "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"
55
+ "@types/dateformat": "^5.0.2",
56
+ "@types/morgan": "~1.9.9",
57
+ "@types/node-fetch": "^2.6.11",
58
+ "@types/express": "^4.17.21",
59
+ "@types/jsonwebtoken": "^9.0.6",
60
+ "@types/lodash": "^4.14.202",
61
+ "@types/swagger-jsdoc": "^6.0.4"
73
62
  }
74
63
  }
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
+ }