@platform-x/hep-push-notification-client 1.0.0 → 1.0.1
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/README.md +39 -5
- package/dist/src/PushNotificationManager.d.ts +9 -9
- package/dist/src/PushNotificationManager.js +55 -55
- package/dist/src/common/util/commonUtil.d.ts +12 -6
- package/dist/src/common/util/commonUtil.js +67 -42
- package/dist/src/common/util/errorHandler.d.ts +41 -41
- package/dist/src/common/util/errorHandler.js +80 -80
- package/dist/src/common/util/logger.d.ts +68 -68
- package/dist/src/common/util/logger.js +192 -192
- package/dist/src/common/util/requestTracer.d.ts +2 -2
- package/dist/src/common/util/requestTracer.js +16 -16
- package/dist/src/config/index.d.ts +22 -22
- package/dist/src/config/index.js +31 -31
- package/dist/src/index.d.ts +4 -4
- package/dist/src/index.js +35 -33
- package/dist/src/platform-x/constants/index.d.ts +41 -41
- package/dist/src/platform-x/constants/index.js +44 -44
- package/dist/src/platform-x/database/connection.d.ts +10 -8
- package/dist/src/platform-x/database/connection.js +72 -53
- package/dist/src/platform-x/database/dao/site_domain.dao.d.ts +10 -10
- package/dist/src/platform-x/database/dao/site_domain.dao.js +44 -44
- package/dist/src/platform-x/database/index.d.ts +16 -14
- package/dist/src/platform-x/database/index.js +9 -9
- package/dist/src/platform-x/database/interfaces/site_domain.interface.d.ts +33 -33
- package/dist/src/platform-x/database/interfaces/site_domain.interface.js +2 -2
- package/dist/src/platform-x/database/models/site_domain.model.d.ts +9 -9
- package/dist/src/platform-x/database/models/site_domain.model.js +47 -47
- package/dist/src/platform-x/services/fcmservices.d.ts +18 -18
- package/dist/src/platform-x/services/fcmservices.js +187 -187
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,10 +1,44 @@
|
|
|
1
|
-
|
|
1
|
+
# @platform-x/hep-push-notification-client
|
|
2
2
|
Provide module to push notifications to the users.
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
## Installation
|
|
5
5
|
|
|
6
|
+
```bash
|
|
6
7
|
npm install @platform-x/hep-push-notification-client
|
|
8
|
+
```
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
## Quick Start
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
import {
|
|
14
|
+
initPushNotificationWithExternalMongo,
|
|
15
|
+
initPushNotificationSecrets,
|
|
16
|
+
pushNotificationManager
|
|
17
|
+
} from '@platform-x/hep-push-notification-client';
|
|
18
|
+
import mongoose from 'mongoose';
|
|
19
|
+
|
|
20
|
+
// Initialize with your existing mongoose connection
|
|
21
|
+
initPushNotificationWithExternalMongo(mongoose);
|
|
22
|
+
|
|
23
|
+
// Initialize secrets
|
|
24
|
+
initPushNotificationSecrets(yourSecretService);
|
|
25
|
+
|
|
26
|
+
// Use the notification manager
|
|
27
|
+
const manager = new pushNotificationManager();
|
|
28
|
+
const client = await manager.pushNotificationProvider('sitename');
|
|
29
|
+
await client.fetchTopics(type);
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## MongoDB Integration
|
|
33
|
+
|
|
34
|
+
**Important**: This package requires MongoDB connection initialization to avoid duplicate connections when used in services that already have MongoDB setup.
|
|
35
|
+
|
|
36
|
+
📖 **See [MONGODB_INTEGRATION.md](./MONGODB_INTEGRATION.md) for detailed MongoDB integration guide**
|
|
37
|
+
|
|
38
|
+
## Usage
|
|
39
|
+
|
|
40
|
+
import the modules and implement:
|
|
41
|
+
```typescript
|
|
42
|
+
const fcmClient: any = new pushNotificationProvider(sitename);
|
|
43
|
+
await fcmClient.fetchTopics(type);
|
|
44
|
+
```
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Push Notification Manager - supports multiple providers
|
|
3
|
-
* Currently implemented: FCM
|
|
4
|
-
* Future providers: SAP_EMARSYS
|
|
5
|
-
*/
|
|
6
|
-
export declare class pushNotificationManager {
|
|
7
|
-
private notificationProvider;
|
|
8
|
-
pushNotificationProvider(sitename: string): Promise<any>;
|
|
9
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Push Notification Manager - supports multiple providers
|
|
3
|
+
* Currently implemented: FCM
|
|
4
|
+
* Future providers: SAP_EMARSYS
|
|
5
|
+
*/
|
|
6
|
+
export declare class pushNotificationManager {
|
|
7
|
+
private notificationProvider;
|
|
8
|
+
pushNotificationProvider(sitename: string): Promise<any>;
|
|
9
|
+
}
|
|
@@ -1,56 +1,56 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.pushNotificationManager = void 0;
|
|
16
|
-
const logger_1 = require("./common/util/logger");
|
|
17
|
-
const constants_1 = require("./platform-x/constants");
|
|
18
|
-
const fcmservices_1 = require("./platform-x/services/fcmservices");
|
|
19
|
-
const site_domain_dao_1 = __importDefault(require("./platform-x/database/dao/site_domain.dao"));
|
|
20
|
-
/**
|
|
21
|
-
* Push Notification Manager - supports multiple providers
|
|
22
|
-
* Currently implemented: FCM
|
|
23
|
-
* Future providers: SAP_EMARSYS
|
|
24
|
-
*/
|
|
25
|
-
class pushNotificationManager {
|
|
26
|
-
pushNotificationProvider(sitename) {
|
|
27
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
-
var _a, _b, _c;
|
|
29
|
-
try {
|
|
30
|
-
logger_1.Logger.info('pushNotificationManager: Reached pushNotificationProvider', 'pushNotificationProvider');
|
|
31
|
-
let pushConfig = yield new site_domain_dao_1.default().details({ sitename });
|
|
32
|
-
let pushNotifyProvider = (_c = (_b = (_a = pushConfig === null || pushConfig === void 0 ? void 0 : pushConfig.providers) === null || _a === void 0 ? void 0 : _a.notification) === null || _b === void 0 ? void 0 : _b.active) !== null && _c !== void 0 ? _c : constants_1.PROVIDERS.FCM;
|
|
33
|
-
logger_1.Logger.info(`pushNotificationManager: Initializing the provider for client ${sitename}`, '');
|
|
34
|
-
switch (pushNotifyProvider) {
|
|
35
|
-
case constants_1.PROVIDERS.FCM:
|
|
36
|
-
this.notificationProvider = yield fcmservices_1.FcmClient.fcmClientObject(sitename);
|
|
37
|
-
logger_1.Logger.info('pushNotificationManager: Initialized with FCM provider', 'constructor');
|
|
38
|
-
break;
|
|
39
|
-
case constants_1.PROVIDERS.SAP_EMARSYS:
|
|
40
|
-
// Implement the SAP emarsys client initialization here
|
|
41
|
-
logger_1.Logger.info('pushNotificationManager: Initialized with SAP_EMARSYS provider', 'constructor');
|
|
42
|
-
break;
|
|
43
|
-
default:
|
|
44
|
-
throw new Error(`Unsupported provider: ${pushNotifyProvider}. Supported providers: ${Object.values(constants_1.PROVIDERS).join(', ')}`);
|
|
45
|
-
}
|
|
46
|
-
return this.notificationProvider;
|
|
47
|
-
}
|
|
48
|
-
catch (err) {
|
|
49
|
-
logger_1.Logger.error('pushNotificationManager: Error in pushNotificationManager', 'pushNotificationManager', err);
|
|
50
|
-
throw err;
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
exports.pushNotificationManager = pushNotificationManager;
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.pushNotificationManager = void 0;
|
|
16
|
+
const logger_1 = require("./common/util/logger");
|
|
17
|
+
const constants_1 = require("./platform-x/constants");
|
|
18
|
+
const fcmservices_1 = require("./platform-x/services/fcmservices");
|
|
19
|
+
const site_domain_dao_1 = __importDefault(require("./platform-x/database/dao/site_domain.dao"));
|
|
20
|
+
/**
|
|
21
|
+
* Push Notification Manager - supports multiple providers
|
|
22
|
+
* Currently implemented: FCM
|
|
23
|
+
* Future providers: SAP_EMARSYS
|
|
24
|
+
*/
|
|
25
|
+
class pushNotificationManager {
|
|
26
|
+
pushNotificationProvider(sitename) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
var _a, _b, _c;
|
|
29
|
+
try {
|
|
30
|
+
logger_1.Logger.info('pushNotificationManager: Reached pushNotificationProvider', 'pushNotificationProvider');
|
|
31
|
+
let pushConfig = yield new site_domain_dao_1.default().details({ sitename });
|
|
32
|
+
let pushNotifyProvider = (_c = (_b = (_a = pushConfig === null || pushConfig === void 0 ? void 0 : pushConfig.providers) === null || _a === void 0 ? void 0 : _a.notification) === null || _b === void 0 ? void 0 : _b.active) !== null && _c !== void 0 ? _c : constants_1.PROVIDERS.FCM;
|
|
33
|
+
logger_1.Logger.info(`pushNotificationManager: Initializing the provider for client ${sitename}`, '');
|
|
34
|
+
switch (pushNotifyProvider) {
|
|
35
|
+
case constants_1.PROVIDERS.FCM:
|
|
36
|
+
this.notificationProvider = yield fcmservices_1.FcmClient.fcmClientObject(sitename);
|
|
37
|
+
logger_1.Logger.info('pushNotificationManager: Initialized with FCM provider', 'constructor');
|
|
38
|
+
break;
|
|
39
|
+
case constants_1.PROVIDERS.SAP_EMARSYS:
|
|
40
|
+
// Implement the SAP emarsys client initialization here
|
|
41
|
+
logger_1.Logger.info('pushNotificationManager: Initialized with SAP_EMARSYS provider', 'constructor');
|
|
42
|
+
break;
|
|
43
|
+
default:
|
|
44
|
+
throw new Error(`Unsupported provider: ${pushNotifyProvider}. Supported providers: ${Object.values(constants_1.PROVIDERS).join(', ')}`);
|
|
45
|
+
}
|
|
46
|
+
return this.notificationProvider;
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
logger_1.Logger.error('pushNotificationManager: Error in pushNotificationManager', 'pushNotificationManager', err);
|
|
50
|
+
throw err;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.pushNotificationManager = pushNotificationManager;
|
|
56
56
|
//# sourceMappingURL=PushNotificationManager.js.map
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* base64ToString - to convert base64 into string
|
|
3
|
-
* @param {string} toDecode- string base64 request
|
|
4
|
-
*/
|
|
5
|
-
export declare const base64ToString: (toDecode: string) => string;
|
|
6
|
-
export declare function getDynamicSecretdata(sitename: any, providerName: any, secretKey: any): Promise<string>;
|
|
1
|
+
/**
|
|
2
|
+
* base64ToString - to convert base64 into string
|
|
3
|
+
* @param {string} toDecode- string base64 request
|
|
4
|
+
*/
|
|
5
|
+
export declare const base64ToString: (toDecode: string) => string;
|
|
6
|
+
export declare function getDynamicSecretdata(sitename: any, providerName: any, secretKey: any): Promise<string>;
|
|
7
|
+
/**
|
|
8
|
+
* Validate that MongoDB connection is properly initialized for server startup
|
|
9
|
+
* If no external MongoDB connection is found, it will initialize its own connection
|
|
10
|
+
* Call this during your server startup to ensure proper MongoDB configuration
|
|
11
|
+
*/
|
|
12
|
+
export declare const validateMongoInitialization: () => Promise<boolean>;
|
|
@@ -1,43 +1,68 @@
|
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.validateMongoInitialization = exports.base64ToString = void 0;
|
|
16
|
+
exports.getDynamicSecretdata = getDynamicSecretdata;
|
|
17
|
+
const __1 = require("../..");
|
|
18
|
+
const constants_1 = require("../../platform-x/constants");
|
|
19
|
+
const logger_1 = require("./logger");
|
|
20
|
+
const connection_1 = __importDefault(require("../../platform-x/database/connection"));
|
|
21
|
+
/**
|
|
22
|
+
* base64ToString - to convert base64 into string
|
|
23
|
+
* @param {string} toDecode- string base64 request
|
|
24
|
+
*/
|
|
25
|
+
const base64ToString = (toDecode) => {
|
|
26
|
+
return Buffer.from(toDecode, 'base64').toString('ascii');
|
|
27
|
+
};
|
|
28
|
+
exports.base64ToString = base64ToString;
|
|
29
|
+
function getDynamicSecretdata(sitename, providerName, secretKey) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
logger_1.Logger.info(`commonUtils.ts : getDynamicSecretdata reached ${{ sitename, providerName, secretKey }}`, 'getDynamicSecretdata');
|
|
32
|
+
const secretValue = yield (0, __1.getPushNotificationSecrets)();
|
|
33
|
+
const defaultData = constants_1.DynamicValues === null || constants_1.DynamicValues === void 0 ? void 0 : constants_1.DynamicValues.DEFAULT;
|
|
34
|
+
const targetKey = `${sitename}_${providerName}_${secretKey}`.toUpperCase();
|
|
35
|
+
const fallbackKey = `${defaultData}_${providerName}_${secretKey}`.toUpperCase();
|
|
36
|
+
logger_1.Logger.info('Target Key: ', 'getDynamicSecretdata');
|
|
37
|
+
logger_1.Logger.info('Fallback Key: ', 'getDynamicSecretdata');
|
|
38
|
+
let finalValue = secretValue.hasOwnProperty(targetKey) ? secretValue[targetKey] : secretValue[fallbackKey];
|
|
39
|
+
if (!finalValue || finalValue == '') {
|
|
40
|
+
logger_1.Logger.info(`Target Key not found, using fallback key: ${fallbackKey}`, 'getDynamicSecretdata');
|
|
41
|
+
finalValue = secretValue[fallbackKey];
|
|
42
|
+
}
|
|
43
|
+
logger_1.Logger.info('Final Value fetched', 'getDynamicSecretdata');
|
|
44
|
+
return finalValue;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Validate that MongoDB connection is properly initialized for server startup
|
|
49
|
+
* If no external MongoDB connection is found, it will initialize its own connection
|
|
50
|
+
* Call this during your server startup to ensure proper MongoDB configuration
|
|
51
|
+
*/
|
|
52
|
+
const validateMongoInitialization = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
|
+
// Check if MongoDB connection exists and is connected
|
|
54
|
+
if (!connection_1.default.database || connection_1.default.database.readyState !== 1) {
|
|
55
|
+
// If no external connection, try to initialize own connection
|
|
56
|
+
if (!connection_1.default.isUsingExternalConnection()) {
|
|
57
|
+
logger_1.Logger.info('Push Notification Package: No external MongoDB connection found, initializing own connection', 'validatePackageInitialization');
|
|
58
|
+
yield connection_1.default.connect();
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
throw new Error('Push Notification Package: MongoDB connection not initialized. Please call initPushNotificationWithExternalMongo() or initPushNotificationWithOwnMongo() before starting the server.');
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
logger_1.Logger.info('Push Notification Package: MongoDB validation passed - package is properly initialized', 'validatePackageInitialization');
|
|
65
|
+
return true;
|
|
66
|
+
});
|
|
67
|
+
exports.validateMongoInitialization = validateMongoInitialization;
|
|
43
68
|
//# sourceMappingURL=commonUtil.js.map
|
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
export declare const enum HTTP_STATUS_CODE {
|
|
2
|
-
INTERNAL_SERVER_ERROR = 500
|
|
3
|
-
}
|
|
4
|
-
export declare const HTTP_STATUS_MAP: Map<number, string>;
|
|
5
|
-
export declare const enum HTTP_STATUS_TYPE {
|
|
6
|
-
INTERNAL_SERVER_ERROR = "Internal Server Error"
|
|
7
|
-
}
|
|
8
|
-
export declare class CommonErrorTemplate extends Error {
|
|
9
|
-
code: number;
|
|
10
|
-
type: string;
|
|
11
|
-
constructor(msg: string, code?: number);
|
|
12
|
-
toJSON(): {
|
|
13
|
-
code: number;
|
|
14
|
-
type: string;
|
|
15
|
-
message: string;
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
export declare class ApiError extends CommonErrorTemplate {
|
|
19
|
-
constructor(msg: string, code?: number);
|
|
20
|
-
}
|
|
21
|
-
export declare class CustomError {
|
|
22
|
-
code: number | undefined;
|
|
23
|
-
type: string | undefined;
|
|
24
|
-
message: string | undefined;
|
|
25
|
-
stack: string | undefined;
|
|
26
|
-
errorObj: Error | undefined | null;
|
|
27
|
-
constructor(errObj?: any, code?: number, type?: string, message?: string, stack?: string);
|
|
28
|
-
toJSON(): {
|
|
29
|
-
code: number | undefined;
|
|
30
|
-
type: string | undefined;
|
|
31
|
-
message: string | undefined;
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* errorMapper - to map error object to custom error
|
|
36
|
-
*/
|
|
37
|
-
export declare const errorMapper: (err: any, statusCode?: number, type?: string) => any;
|
|
38
|
-
/**
|
|
39
|
-
* throwError - to throw custome error
|
|
40
|
-
*/
|
|
41
|
-
export declare const throwError: (err: any, statusCode?: number, type?: string) => never;
|
|
1
|
+
export declare const enum HTTP_STATUS_CODE {
|
|
2
|
+
INTERNAL_SERVER_ERROR = 500
|
|
3
|
+
}
|
|
4
|
+
export declare const HTTP_STATUS_MAP: Map<number, string>;
|
|
5
|
+
export declare const enum HTTP_STATUS_TYPE {
|
|
6
|
+
INTERNAL_SERVER_ERROR = "Internal Server Error"
|
|
7
|
+
}
|
|
8
|
+
export declare class CommonErrorTemplate extends Error {
|
|
9
|
+
code: number;
|
|
10
|
+
type: string;
|
|
11
|
+
constructor(msg: string, code?: number);
|
|
12
|
+
toJSON(): {
|
|
13
|
+
code: number;
|
|
14
|
+
type: string;
|
|
15
|
+
message: string;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export declare class ApiError extends CommonErrorTemplate {
|
|
19
|
+
constructor(msg: string, code?: number);
|
|
20
|
+
}
|
|
21
|
+
export declare class CustomError {
|
|
22
|
+
code: number | undefined;
|
|
23
|
+
type: string | undefined;
|
|
24
|
+
message: string | undefined;
|
|
25
|
+
stack: string | undefined;
|
|
26
|
+
errorObj: Error | undefined | null;
|
|
27
|
+
constructor(errObj?: any, code?: number, type?: string, message?: string, stack?: string);
|
|
28
|
+
toJSON(): {
|
|
29
|
+
code: number | undefined;
|
|
30
|
+
type: string | undefined;
|
|
31
|
+
message: string | undefined;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* errorMapper - to map error object to custom error
|
|
36
|
+
*/
|
|
37
|
+
export declare const errorMapper: (err: any, statusCode?: number, type?: string) => any;
|
|
38
|
+
/**
|
|
39
|
+
* throwError - to throw custome error
|
|
40
|
+
*/
|
|
41
|
+
export declare const throwError: (err: any, statusCode?: number, type?: string) => never;
|
|
@@ -1,81 +1,81 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.throwError = exports.errorMapper = exports.CustomError = exports.ApiError = exports.CommonErrorTemplate = exports.HTTP_STATUS_MAP = void 0;
|
|
4
|
-
exports.HTTP_STATUS_MAP = new Map([
|
|
5
|
-
[500, 'Internal Server Error']
|
|
6
|
-
]);
|
|
7
|
-
class CommonErrorTemplate extends Error {
|
|
8
|
-
constructor(msg, code) {
|
|
9
|
-
super(msg);
|
|
10
|
-
this.code = code || 500 /* HTTP_STATUS_CODE.INTERNAL_SERVER_ERROR */;
|
|
11
|
-
this.type =
|
|
12
|
-
exports.HTTP_STATUS_MAP.get(this.code) || "Internal Server Error" /* HTTP_STATUS_TYPE.INTERNAL_SERVER_ERROR */;
|
|
13
|
-
}
|
|
14
|
-
toJSON() {
|
|
15
|
-
return {
|
|
16
|
-
code: this.code,
|
|
17
|
-
type: this.type,
|
|
18
|
-
message: this.message,
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
exports.CommonErrorTemplate = CommonErrorTemplate;
|
|
23
|
-
class ApiError extends CommonErrorTemplate {
|
|
24
|
-
constructor(msg, code) {
|
|
25
|
-
super(msg, code);
|
|
26
|
-
this.name = 'ApiError';
|
|
27
|
-
Error.captureStackTrace(this, ApiError);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
exports.ApiError = ApiError;
|
|
31
|
-
class CustomError {
|
|
32
|
-
constructor(errObj, code, type, message, stack) {
|
|
33
|
-
this.code = code;
|
|
34
|
-
this.type = type;
|
|
35
|
-
this.message = message;
|
|
36
|
-
this.stack = stack;
|
|
37
|
-
this.errorObj = errObj;
|
|
38
|
-
}
|
|
39
|
-
toJSON() {
|
|
40
|
-
// NOSONAR
|
|
41
|
-
return {
|
|
42
|
-
code: this.code,
|
|
43
|
-
type: this.type,
|
|
44
|
-
message: this.message,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
exports.CustomError = CustomError;
|
|
49
|
-
/**
|
|
50
|
-
* errorMapper - to map error object to custom error
|
|
51
|
-
*/
|
|
52
|
-
const errorMapper = (err, statusCode, type) => {
|
|
53
|
-
let error;
|
|
54
|
-
let customError;
|
|
55
|
-
let code = statusCode || 500 /* HTTP_STATUS_CODE.INTERNAL_SERVER_ERROR */;
|
|
56
|
-
let errorType = type || exports.HTTP_STATUS_MAP.get(code) || "Internal Server Error" /* HTTP_STATUS_TYPE.INTERNAL_SERVER_ERROR */;
|
|
57
|
-
if (typeof err === 'string') {
|
|
58
|
-
error = new Error(err);
|
|
59
|
-
customError = new CustomError(null, code, errorType, error.message, error.stack);
|
|
60
|
-
return customError;
|
|
61
|
-
}
|
|
62
|
-
else if (err.stack &&
|
|
63
|
-
err.message &&
|
|
64
|
-
!(err instanceof CustomError) &&
|
|
65
|
-
!err.toJSON) {
|
|
66
|
-
customError = new CustomError(null, code, errorType, err.message, err.stack);
|
|
67
|
-
return customError;
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
return err;
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
exports.errorMapper = errorMapper;
|
|
74
|
-
/**
|
|
75
|
-
* throwError - to throw custome error
|
|
76
|
-
*/
|
|
77
|
-
const throwError = (err, statusCode, type) => {
|
|
78
|
-
throw (0, exports.errorMapper)(err, statusCode, type);
|
|
79
|
-
};
|
|
80
|
-
exports.throwError = throwError;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.throwError = exports.errorMapper = exports.CustomError = exports.ApiError = exports.CommonErrorTemplate = exports.HTTP_STATUS_MAP = void 0;
|
|
4
|
+
exports.HTTP_STATUS_MAP = new Map([
|
|
5
|
+
[500, 'Internal Server Error']
|
|
6
|
+
]);
|
|
7
|
+
class CommonErrorTemplate extends Error {
|
|
8
|
+
constructor(msg, code) {
|
|
9
|
+
super(msg);
|
|
10
|
+
this.code = code || 500 /* HTTP_STATUS_CODE.INTERNAL_SERVER_ERROR */;
|
|
11
|
+
this.type =
|
|
12
|
+
exports.HTTP_STATUS_MAP.get(this.code) || "Internal Server Error" /* HTTP_STATUS_TYPE.INTERNAL_SERVER_ERROR */;
|
|
13
|
+
}
|
|
14
|
+
toJSON() {
|
|
15
|
+
return {
|
|
16
|
+
code: this.code,
|
|
17
|
+
type: this.type,
|
|
18
|
+
message: this.message,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.CommonErrorTemplate = CommonErrorTemplate;
|
|
23
|
+
class ApiError extends CommonErrorTemplate {
|
|
24
|
+
constructor(msg, code) {
|
|
25
|
+
super(msg, code);
|
|
26
|
+
this.name = 'ApiError';
|
|
27
|
+
Error.captureStackTrace(this, ApiError);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.ApiError = ApiError;
|
|
31
|
+
class CustomError {
|
|
32
|
+
constructor(errObj, code, type, message, stack) {
|
|
33
|
+
this.code = code;
|
|
34
|
+
this.type = type;
|
|
35
|
+
this.message = message;
|
|
36
|
+
this.stack = stack;
|
|
37
|
+
this.errorObj = errObj;
|
|
38
|
+
}
|
|
39
|
+
toJSON() {
|
|
40
|
+
// NOSONAR
|
|
41
|
+
return {
|
|
42
|
+
code: this.code,
|
|
43
|
+
type: this.type,
|
|
44
|
+
message: this.message,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.CustomError = CustomError;
|
|
49
|
+
/**
|
|
50
|
+
* errorMapper - to map error object to custom error
|
|
51
|
+
*/
|
|
52
|
+
const errorMapper = (err, statusCode, type) => {
|
|
53
|
+
let error;
|
|
54
|
+
let customError;
|
|
55
|
+
let code = statusCode || 500 /* HTTP_STATUS_CODE.INTERNAL_SERVER_ERROR */;
|
|
56
|
+
let errorType = type || exports.HTTP_STATUS_MAP.get(code) || "Internal Server Error" /* HTTP_STATUS_TYPE.INTERNAL_SERVER_ERROR */;
|
|
57
|
+
if (typeof err === 'string') {
|
|
58
|
+
error = new Error(err);
|
|
59
|
+
customError = new CustomError(null, code, errorType, error.message, error.stack);
|
|
60
|
+
return customError;
|
|
61
|
+
}
|
|
62
|
+
else if (err.stack &&
|
|
63
|
+
err.message &&
|
|
64
|
+
!(err instanceof CustomError) &&
|
|
65
|
+
!err.toJSON) {
|
|
66
|
+
customError = new CustomError(null, code, errorType, err.message, err.stack);
|
|
67
|
+
return customError;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
return err;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
exports.errorMapper = errorMapper;
|
|
74
|
+
/**
|
|
75
|
+
* throwError - to throw custome error
|
|
76
|
+
*/
|
|
77
|
+
const throwError = (err, statusCode, type) => {
|
|
78
|
+
throw (0, exports.errorMapper)(err, statusCode, type);
|
|
79
|
+
};
|
|
80
|
+
exports.throwError = throwError;
|
|
81
81
|
//# sourceMappingURL=errorHandler.js.map
|