@6thbridge/utils 0.1.16
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/lib/actions/charge.action.d.ts +9 -0
- package/lib/actions/charge.action.js +74 -0
- package/lib/actions/charge.action.js.map +1 -0
- package/lib/actions/currency.action.d.ts +15 -0
- package/lib/actions/currency.action.js +57 -0
- package/lib/actions/currency.action.js.map +1 -0
- package/lib/actions/index.d.ts +9 -0
- package/lib/actions/index.js +33 -0
- package/lib/actions/index.js.map +1 -0
- package/lib/actions/phone-number.action.d.ts +23 -0
- package/lib/actions/phone-number.action.js +77 -0
- package/lib/actions/phone-number.action.js.map +1 -0
- package/lib/brokers/index.d.ts +6 -0
- package/lib/brokers/index.js +8 -0
- package/lib/brokers/index.js.map +1 -0
- package/lib/brokers/kafka.d.ts +84 -0
- package/lib/brokers/kafka.js +265 -0
- package/lib/brokers/kafka.js.map +1 -0
- package/lib/brokers/kafka.test.d.ts +1 -0
- package/lib/brokers/kafka.test.js +118 -0
- package/lib/brokers/kafka.test.js.map +1 -0
- package/lib/brokers/rabbitmq.d.ts +108 -0
- package/lib/brokers/rabbitmq.js +290 -0
- package/lib/brokers/rabbitmq.js.map +1 -0
- package/lib/cache/in-memory.d.ts +0 -0
- package/lib/cache/in-memory.js +2 -0
- package/lib/cache/in-memory.js.map +1 -0
- package/lib/cache/redis.d.ts +18 -0
- package/lib/cache/redis.js +58 -0
- package/lib/cache/redis.js.map +1 -0
- package/lib/database/MongoDBRepository.d.ts +23 -0
- package/lib/database/MongoDBRepository.js +90 -0
- package/lib/database/MongoDBRepository.js.map +1 -0
- package/lib/database/MongoDBTypeRepository.d.ts +26 -0
- package/lib/database/MongoDBTypeRepository.js +90 -0
- package/lib/database/MongoDBTypeRepository.js.map +1 -0
- package/lib/database/index.d.ts +4 -0
- package/lib/database/index.js +36 -0
- package/lib/database/index.js.map +1 -0
- package/lib/database/query.d.ts +16 -0
- package/lib/database/query.js +82 -0
- package/lib/database/query.js.map +1 -0
- package/lib/exceptions/custom.exception.d.ts +14 -0
- package/lib/exceptions/custom.exception.js +16 -0
- package/lib/exceptions/custom.exception.js.map +1 -0
- package/lib/helpers/errors.d.ts +2 -0
- package/lib/helpers/errors.js +46 -0
- package/lib/helpers/errors.js.map +1 -0
- package/lib/helpers/index.d.ts +51 -0
- package/lib/helpers/index.js +198 -0
- package/lib/helpers/index.js.map +1 -0
- package/lib/helpers/utils.d.ts +9 -0
- package/lib/helpers/utils.js +18 -0
- package/lib/helpers/utils.js.map +1 -0
- package/lib/http/axios.d.ts +0 -0
- package/lib/http/axios.js +2 -0
- package/lib/http/axios.js.map +1 -0
- package/lib/index.d.ts +17 -0
- package/lib/index.js +104 -0
- package/lib/index.js.map +1 -0
- package/lib/logger/index.d.ts +20 -0
- package/lib/logger/index.js +12 -0
- package/lib/logger/index.js.map +1 -0
- package/lib/logger/logger-test.d.ts +1 -0
- package/lib/logger/logger-test.js +40 -0
- package/lib/logger/logger-test.js.map +1 -0
- package/lib/logger/logger.d.ts +31 -0
- package/lib/logger/logger.js +106 -0
- package/lib/logger/logger.js.map +1 -0
- package/lib/logger/null-logger.d.ts +14 -0
- package/lib/logger/null-logger.js +29 -0
- package/lib/logger/null-logger.js.map +1 -0
- package/lib/logger/test.d.ts +1 -0
- package/lib/logger/test.js +45 -0
- package/lib/logger/test.js.map +1 -0
- package/lib/middlewares/common.d.ts +22 -0
- package/lib/middlewares/common.js +141 -0
- package/lib/middlewares/common.js.map +1 -0
- package/lib/middlewares/express.d.ts +4 -0
- package/lib/middlewares/express.js +99 -0
- package/lib/middlewares/express.js.map +1 -0
- package/lib/middlewares/fastify.d.ts +4 -0
- package/lib/middlewares/fastify.js +73 -0
- package/lib/middlewares/fastify.js.map +1 -0
- package/lib/middlewares/index.d.ts +4 -0
- package/lib/middlewares/index.js +34 -0
- package/lib/middlewares/index.js.map +1 -0
- package/lib/monitoring/index.d.ts +12 -0
- package/lib/monitoring/index.js +75 -0
- package/lib/monitoring/index.js.map +1 -0
- package/lib/responses/express.d.ts +26 -0
- package/lib/responses/express.js +98 -0
- package/lib/responses/express.js.map +1 -0
- package/lib/responses/fastify.d.ts +4 -0
- package/lib/responses/fastify.js +25 -0
- package/lib/responses/fastify.js.map +1 -0
- package/lib/responses/index.d.ts +3 -0
- package/lib/responses/index.js +31 -0
- package/lib/responses/index.js.map +1 -0
- package/lib/secrets/aws-secret.d.ts +4 -0
- package/lib/secrets/aws-secret.js +55 -0
- package/lib/secrets/aws-secret.js.map +1 -0
- package/lib/secrets/aws.d.ts +0 -0
- package/lib/secrets/aws.js +2 -0
- package/lib/secrets/aws.js.map +1 -0
- package/lib/secrets/index.d.ts +8 -0
- package/lib/secrets/index.js +18 -0
- package/lib/secrets/index.js.map +1 -0
- package/lib/test/actions/charge.action.test.d.ts +1 -0
- package/lib/test/actions/charge.action.test.js +86 -0
- package/lib/test/actions/charge.action.test.js.map +1 -0
- package/lib/test/database/test.spec.d.ts +1 -0
- package/lib/test/database/test.spec.js +74 -0
- package/lib/test/database/test.spec.js.map +1 -0
- package/lib/test/helpers/PhoneNumber.spec.d.ts +1 -0
- package/lib/test/helpers/PhoneNumber.spec.js +82 -0
- package/lib/test/helpers/PhoneNumber.spec.js.map +1 -0
- package/lib/test/logger/test.spec.d.ts +1 -0
- package/lib/test/logger/test.spec.js +37 -0
- package/lib/test/logger/test.spec.js.map +1 -0
- package/lib/test/types/context.entity.test.d.ts +1 -0
- package/lib/test/types/context.entity.test.js +29 -0
- package/lib/test/types/context.entity.test.js.map +1 -0
- package/lib/translations/index.d.ts +7 -0
- package/lib/translations/index.js +52 -0
- package/lib/translations/index.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/types/broker.entity.d.ts +15 -0
- package/lib/types/broker.entity.js +13 -0
- package/lib/types/broker.entity.js.map +1 -0
- package/lib/types/client.entity.d.ts +42 -0
- package/lib/types/client.entity.js +16 -0
- package/lib/types/client.entity.js.map +1 -0
- package/lib/types/context.entity.d.ts +43 -0
- package/lib/types/context.entity.js +105 -0
- package/lib/types/context.entity.js.map +1 -0
- package/lib/types/index.d.ts +82 -0
- package/lib/types/index.js +38 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/user.entity.d.ts +28 -0
- package/lib/types/user.entity.js +18 -0
- package/lib/types/user.entity.js.map +1 -0
- package/package.json +52 -0
- package/readme.md +66 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.registerLogger = exports.can = exports.internalOnly = void 0;
|
|
36
|
+
const response = __importStar(require("../responses/express"));
|
|
37
|
+
const common_1 = require("./common");
|
|
38
|
+
const logger_1 = require("../logger/logger");
|
|
39
|
+
function internalOnly(req, res, next) {
|
|
40
|
+
var _a;
|
|
41
|
+
try {
|
|
42
|
+
if (((_a = req.headers) === null || _a === void 0 ? void 0 : _a.source) !== "internal") {
|
|
43
|
+
console.log("===================Not internal request =============");
|
|
44
|
+
return response.failed(res, {
|
|
45
|
+
locale: { toLocale: req.headers["x-locale-id"] },
|
|
46
|
+
error: "You don't have permission to access this service. ",
|
|
47
|
+
statusCode: 403,
|
|
48
|
+
errorCode: "invalid_authorization"
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return next();
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
console.log(e.message);
|
|
55
|
+
return next();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.internalOnly = internalOnly;
|
|
59
|
+
const can = (supportedAuthenticationType, permissions, options = {
|
|
60
|
+
matchAll: true
|
|
61
|
+
}) => {
|
|
62
|
+
if (permissions.constructor.name === "IncomingMessage") {
|
|
63
|
+
throw new Error("It appears you have done something like `app.use(can)`, but it should be `app.use(can())`.");
|
|
64
|
+
}
|
|
65
|
+
return (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
66
|
+
const { error, data } = yield (0, common_1.getContext)(req, supportedAuthenticationType, permissions);
|
|
67
|
+
if (error) {
|
|
68
|
+
return response.failed(res, {
|
|
69
|
+
locale: { toLocale: req.headers["x-locale-id"] },
|
|
70
|
+
error: error || "You are not authorized to access this resource!!!",
|
|
71
|
+
statusCode: 403,
|
|
72
|
+
errorCode: "invalid_authorization"
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
res.locals = data;
|
|
76
|
+
res.setHeader("x-request-id", data.requestId);
|
|
77
|
+
return next();
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
exports.can = can;
|
|
81
|
+
const registerLogger = (req, res, next) => {
|
|
82
|
+
var _a;
|
|
83
|
+
if ((_a = res.locals) === null || _a === void 0 ? void 0 : _a.logger)
|
|
84
|
+
return next();
|
|
85
|
+
const params = {
|
|
86
|
+
requestId: req.header("x-request-id") || Math.random().toString(),
|
|
87
|
+
requestClientId: req.header('request-client-id') || req.header('client-id'),
|
|
88
|
+
contextClientId: req.header('context-client-id') || req.header('client-id'),
|
|
89
|
+
ip: req.headers["cf-connecting-ip"] || req.ip,
|
|
90
|
+
url: req.url,
|
|
91
|
+
locale: req.headers["x-locale-id"],
|
|
92
|
+
requestSource: req.header("source")
|
|
93
|
+
};
|
|
94
|
+
res.locals.logger = new logger_1.Logger(params);
|
|
95
|
+
res.setHeader("x-request-id", params.requestId);
|
|
96
|
+
return next();
|
|
97
|
+
};
|
|
98
|
+
exports.registerLogger = registerLogger;
|
|
99
|
+
//# sourceMappingURL=express.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"express.js","sourceRoot":"","sources":["../../src/middlewares/express.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEb,+DAAiD;AACjD,qCAAoC;AACpC,6CAAwC;AAExC,SAAgB,YAAY,CAAE,GAAY,EAAE,GAAa,EAAE,IAAkB;;IACzE,IAAI,CAAC;QACD,IAAG,CAAA,MAAA,GAAG,CAAC,OAAO,0CAAE,MAAM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object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.registerLogger = exports.can = void 0;
|
|
36
|
+
const response = __importStar(require("../responses/fastify"));
|
|
37
|
+
const common_1 = require("./common");
|
|
38
|
+
const logger_1 = require("../logger/logger");
|
|
39
|
+
const can = (supportedAuthenticationType = [], permissions = [], options = {
|
|
40
|
+
matchAll: true
|
|
41
|
+
}) => {
|
|
42
|
+
if (permissions.constructor.name === "IncomingMessage") {
|
|
43
|
+
throw new Error("It appears you have done something like `app.use(can)`, but it should be `app.use(can())`.");
|
|
44
|
+
}
|
|
45
|
+
return (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
+
const { error, data } = yield (0, common_1.getContext)(req, supportedAuthenticationType, permissions);
|
|
47
|
+
if (error) {
|
|
48
|
+
return response.error(res, error || "You are not authorized to access this resource!!!");
|
|
49
|
+
}
|
|
50
|
+
res.locals = data;
|
|
51
|
+
req.context = data;
|
|
52
|
+
res.header("x-request-id", data.requestId);
|
|
53
|
+
return;
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
exports.can = can;
|
|
57
|
+
const registerLogger = (req, res) => {
|
|
58
|
+
if (res.locals.logger)
|
|
59
|
+
return;
|
|
60
|
+
const params = {
|
|
61
|
+
requestId: req.header("x-request-id") || Math.random().toString(),
|
|
62
|
+
requestClientId: req.header('request-client-id') || req.header('client-id'),
|
|
63
|
+
contextClientId: req.header('context-client-id') || req.header('client-id'),
|
|
64
|
+
ip: req.headers["cf-connecting-ip"] || req.ip,
|
|
65
|
+
url: req.url,
|
|
66
|
+
requestSource: req.header("source")
|
|
67
|
+
};
|
|
68
|
+
res.locals.logger = new logger_1.Logger(params);
|
|
69
|
+
res.header("x-request-id", params.requestId);
|
|
70
|
+
return;
|
|
71
|
+
};
|
|
72
|
+
exports.registerLogger = registerLogger;
|
|
73
|
+
//# sourceMappingURL=fastify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fastify.js","sourceRoot":"","sources":["../../src/middlewares/fastify.ts"],"names":[],"mappings":"AAAA,Y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C;QAC3E,eAAe,EAAE,GAAG,CAAC,MAAM,CAAC,mBAAmB,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC;QAC3E,EAAE,EAAE,GAAG,CAAC,OAAO,CAAC,kBAAkB,CAAC,IAAI,GAAG,CAAC,EAAE;QAC7C,GAAG,EAAE,GAAG,CAAC,GAAG;QACZ,aAAa,EAAE,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC;KACtC,CAAC;IAEF,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,IAAI,eAAM,CAAC,MAAM,CAAC,CAAC;IACvC,GAAG,CAAC,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC;IAC7C,OAAO;AACX,CAAC,CAAA;AAhBY,QAAA,cAAc,kBAgB1B"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.apitoolkitMiddleware = exports.unless = exports.fastify = exports.express = void 0;
|
|
27
|
+
const express = __importStar(require("./express"));
|
|
28
|
+
exports.express = express;
|
|
29
|
+
const fastify = __importStar(require("./fastify"));
|
|
30
|
+
exports.fastify = fastify;
|
|
31
|
+
const common_1 = require("./common");
|
|
32
|
+
Object.defineProperty(exports, "unless", { enumerable: true, get: function () { return common_1.unless; } });
|
|
33
|
+
Object.defineProperty(exports, "apitoolkitMiddleware", { enumerable: true, get: function () { return common_1.apitoolkitMiddleware; } });
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/middlewares/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mDAAqC;AAMjC,0BAAO;AALX,mDAAqC;AAMjC,0BAAO;AALX,qCAAsD;AAMlD,uFANI,eAAM,OAMJ;AACN,qGAPY,6BAAoB,OAOZ"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AxiosInstance } from "axios";
|
|
2
|
+
type MonitoredAxiosOptions = {
|
|
3
|
+
apitoolkitApiKey: string;
|
|
4
|
+
urlWildcard?: string;
|
|
5
|
+
redactHeaders?: string[];
|
|
6
|
+
redactRequestBody?: string[];
|
|
7
|
+
redactResponseBody?: string[];
|
|
8
|
+
axiosInstance?: AxiosInstance;
|
|
9
|
+
};
|
|
10
|
+
export declare function getMonitoredAxios(options: MonitoredAxiosOptions): AxiosInstance;
|
|
11
|
+
export declare function reportAxiosError(error: any): Promise<void>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.reportAxiosError = exports.getMonitoredAxios = void 0;
|
|
39
|
+
const axios_1 = __importDefault(require("axios"));
|
|
40
|
+
const apitoolkit_express_1 = __importStar(require("apitoolkit-express"));
|
|
41
|
+
const logger_1 = require("../logger/logger");
|
|
42
|
+
let apitoolkit;
|
|
43
|
+
function getMonitoredAxios(options) {
|
|
44
|
+
var _a, _b;
|
|
45
|
+
const axiosInstance = options.axiosInstance || axios_1.default.create();
|
|
46
|
+
if (!options.apitoolkitApiKey)
|
|
47
|
+
return axiosInstance;
|
|
48
|
+
if (!apitoolkit)
|
|
49
|
+
apitoolkit = apitoolkit_express_1.default.NewClient({ apiKey: options.apitoolkitApiKey });
|
|
50
|
+
options.redactRequestBody = options.redactRequestBody || [];
|
|
51
|
+
options.redactResponseBody = options.redactResponseBody || [];
|
|
52
|
+
if ((_a = options === null || options === void 0 ? void 0 : options.redactResponseBody) === null || _a === void 0 ? void 0 : _a.length) {
|
|
53
|
+
options.redactResponseBody = options.redactResponseBody.map(field => `$.${field}`);
|
|
54
|
+
// console.log("redactResponseBody", options.redactResponseBody);
|
|
55
|
+
}
|
|
56
|
+
if ((_b = options === null || options === void 0 ? void 0 : options.redactRequestBody) === null || _b === void 0 ? void 0 : _b.length) {
|
|
57
|
+
// console.log("redactRequestBody", options?.redactRequestBody);
|
|
58
|
+
options.redactRequestBody = options.redactRequestBody.map(field => `$.${field}`);
|
|
59
|
+
// console.log("after redactRequestBody", options.redactRequestBody);
|
|
60
|
+
}
|
|
61
|
+
return apitoolkit.observeAxios(axiosInstance, options.urlWildcard, options.redactHeaders, options.redactRequestBody, options.redactResponseBody);
|
|
62
|
+
}
|
|
63
|
+
exports.getMonitoredAxios = getMonitoredAxios;
|
|
64
|
+
function reportAxiosError(error) {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
try {
|
|
67
|
+
(0, apitoolkit_express_1.ReportError)(error);
|
|
68
|
+
}
|
|
69
|
+
catch (e) {
|
|
70
|
+
logger_1.logger.exception(e);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
exports.reportAxiosError = reportAxiosError;
|
|
75
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/monitoring/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACb,kDAA2C;AAC3C,yEAA2D;AAE3D,6CAAwC;AAYxC,IAAI,UAAsB,CAAA;AAC1B,SAAgB,iBAAiB,CAAC,OAA8B;;IAC5D,MAAM,aAAa,GAAG,OAAO,CAAC,aAAa,IAAI,eAAK,CAAC,MAAM,EAAE,CAAC;IAE9D,IAAI,CAAC,OAAO,CAAC,gBAAgB;QAAE,OAAO,aAAa,CAAC;IAEpD,IAAG,CAAC,UAAU;QAAE,UAAU,GAAG,4BAAU,CAAC,SAAS,CAAC,EAAC,MAAM,EAAE,OAAO,CAAC,gBAAgB,EAAC,CAAC,CAAC;IAEtF,OAAO,CAAC,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,IAAI,EAAE,CAAC;IAC5D,OAAO,CAAC,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,IAAI,EAAE,CAAC;IAE9D,IAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,kBAAkB,0CAAE,MAAM,EAAC,CAAC;QACpC,OAAO,CAAC,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,KAAK,EAAE,CAAC,CAAC;QACnF,iEAAiE;IACrE,CAAC;IAED,IAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,iBAAiB,0CAAE,MAAM,EAAC,CAAC;QACnC,gEAAgE;QAChE,OAAO,CAAC,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,KAAK,EAAE,CAAC,CAAC;QACjF,qEAAqE;IACzE,CAAC;IAED,OAAO,UAAU,CAAC,YAAY,CAAC,aAAa,EAAE,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,iBAAiB,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC;AACrJ,CAAC;AAtBD,8CAsBC;AAGD,SAAsB,gBAAgB,CAAC,KAAU;;QAC7C,IAAG,CAAC;YACA,IAAA,gCAAW,EAAC,KAAK,CAAC,CAAC;QACvB,CAAC;QAAA,OAAO,CAAM,EAAC,CAAC;YACZ,eAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QACxB,CAAC;IACL,CAAC;CAAA;AAND,4CAMC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Response } from "express";
|
|
2
|
+
declare const success: (res: Response, data: any, code?: number) => Response<any, Record<string, any>>;
|
|
3
|
+
declare const paginated: (res: Response, data: any, code?: number) => Response<any, Record<string, any>>;
|
|
4
|
+
declare const error: (res: Response, error?: string | any, code?: number, errorCode?: string) => Response<any, Record<string, any>>;
|
|
5
|
+
export type OkResponse = {
|
|
6
|
+
data: any;
|
|
7
|
+
locale?: {
|
|
8
|
+
fromLocale?: string;
|
|
9
|
+
toLocale?: string;
|
|
10
|
+
fields?: string[];
|
|
11
|
+
};
|
|
12
|
+
statusCode?: number;
|
|
13
|
+
responseCode?: string;
|
|
14
|
+
};
|
|
15
|
+
export type ErrorResponse = {
|
|
16
|
+
error: string;
|
|
17
|
+
locale?: {
|
|
18
|
+
fromLocale?: string;
|
|
19
|
+
toLocale?: string;
|
|
20
|
+
};
|
|
21
|
+
statusCode?: number;
|
|
22
|
+
errorCode?: string;
|
|
23
|
+
};
|
|
24
|
+
declare const ok: (res: Response, response: OkResponse) => Promise<Response<any, Record<string, any>>>;
|
|
25
|
+
declare const failed: (res: Response, response: ErrorResponse) => Promise<Response<any, Record<string, any>>>;
|
|
26
|
+
export { error, paginated, success, ok, failed };
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.failed = exports.ok = exports.success = exports.paginated = exports.error = void 0;
|
|
36
|
+
const translations = __importStar(require("../translations"));
|
|
37
|
+
const lodash_1 = require("lodash");
|
|
38
|
+
const success = (res, data, code = 200) => {
|
|
39
|
+
return res.status(code).json({
|
|
40
|
+
statusCode: code,
|
|
41
|
+
data,
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
exports.success = success;
|
|
45
|
+
const paginated = (res, data, code = 200) => {
|
|
46
|
+
data.page = parseInt(data.page);
|
|
47
|
+
return res.status(code).json({
|
|
48
|
+
statusCode: code,
|
|
49
|
+
total: data.totalDocs || data.total || 0,
|
|
50
|
+
page: data.page || 1,
|
|
51
|
+
pages: data.totalPages || data.pages || 0,
|
|
52
|
+
limit: data.limit || 50,
|
|
53
|
+
data: data.docs
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
exports.paginated = paginated;
|
|
57
|
+
const error = (res, error = "Oops. An Error Occurred", code = 500, errorCode) => {
|
|
58
|
+
return res.status(code).json({
|
|
59
|
+
statusCode: code,
|
|
60
|
+
errorCode: errorCode || String(code),
|
|
61
|
+
error
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
exports.error = error;
|
|
65
|
+
const ok = (res, response) => __awaiter(void 0, void 0, void 0, function* () {
|
|
66
|
+
var _a, _b;
|
|
67
|
+
if (!(0, lodash_1.isEmpty)(response.locale)) {
|
|
68
|
+
response.locale.fields = response.locale.fields || [];
|
|
69
|
+
for (const field of response.locale.fields) {
|
|
70
|
+
const value = (0, lodash_1.get)(response.data, field);
|
|
71
|
+
if (!value)
|
|
72
|
+
continue;
|
|
73
|
+
const translatedString = yield translations.translate({
|
|
74
|
+
fromLanguage: response.locale.fromLocale,
|
|
75
|
+
toLanguage: ((_a = response.locale) === null || _a === void 0 ? void 0 : _a.toLocale) || ((_b = res.locals) === null || _b === void 0 ? void 0 : _b.locale),
|
|
76
|
+
text: value
|
|
77
|
+
});
|
|
78
|
+
(0, lodash_1.set)(response.data, field, translatedString);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
delete response.locale;
|
|
82
|
+
return res.status(response.statusCode || 200).json(response);
|
|
83
|
+
});
|
|
84
|
+
exports.ok = ok;
|
|
85
|
+
const failed = (res, response) => __awaiter(void 0, void 0, void 0, function* () {
|
|
86
|
+
var _c, _d;
|
|
87
|
+
if (!(0, lodash_1.isEmpty)(response.locale)) {
|
|
88
|
+
response.error = yield translations.translate({
|
|
89
|
+
fromLanguage: (response === null || response === void 0 ? void 0 : response.locale.fromLocale) || "en",
|
|
90
|
+
toLanguage: ((_c = response.locale) === null || _c === void 0 ? void 0 : _c.toLocale) || ((_d = res.locals) === null || _d === void 0 ? void 0 : _d.locale),
|
|
91
|
+
text: response.error
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
delete response.locale;
|
|
95
|
+
return res.status(response.statusCode || 500).json(response);
|
|
96
|
+
});
|
|
97
|
+
exports.failed = failed;
|
|
98
|
+
//# sourceMappingURL=express.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"express.js","sourceRoot":"","sources":["../../src/responses/express.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEb,8DAAgD;AAChD,mCAAyC;AAEzC,MAAM,OAAO,GAAG,CAAC,GAAa,EAAE,IAAS,EAAE,OAAe,GAAG,EAAE,EAAE;IAC7D,OAAO,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC;QACzB,UAAU,EAAE,IAAI;QAChB,IAAI;KACP,CAAC,CAAC;AACP,C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,GAAG,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AAClE,CAAC,CAAA,CAAA;AASG,wBAAM"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.success = exports.paginated = exports.error = void 0;
|
|
4
|
+
const success = (res, data, code = 200) => {
|
|
5
|
+
return res.status(code).send({ data });
|
|
6
|
+
};
|
|
7
|
+
exports.success = success;
|
|
8
|
+
const paginated = (res, data, code = 200) => {
|
|
9
|
+
data.page = parseInt(data.page);
|
|
10
|
+
return res.status(code).send({
|
|
11
|
+
total: data.totalDocs || data.total || 0,
|
|
12
|
+
page: data.page || 1,
|
|
13
|
+
pages: data.totalPages || data.pages || 0,
|
|
14
|
+
limit: data.limit || 50,
|
|
15
|
+
data: data.docs
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
exports.paginated = paginated;
|
|
19
|
+
const error = (res, error = "Oops. An Error Occurred", code = 500) => {
|
|
20
|
+
return res.status(code).send({
|
|
21
|
+
error
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
exports.error = error;
|
|
25
|
+
//# sourceMappingURL=fastify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fastify.js","sourceRoot":"","sources":["../../src/responses/fastify.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;AAEb,MAAM,OAAO,GAAG,CAAC,GAAQ,EAAE,IAAS,EAAE,OAAe,GAAG,EAAE,EAAE;IACxD,OAAO,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAAC,IAAI,EAAC,CAAC,CAAC;AACzC,CAAC,CAAC;AAuBE,0BAAO;AArBX,MAAM,SAAS,GAAG,CAAC,GAAQ,EAAE,IAAS,EAAE,OAAe,GAAG,EAAE,EAAE;IAC1D,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEhC,OAAO,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC;QACzB,KAAK,EAAE,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,KAAK,IAAI,CAAC;QACxC,IAAI,EAAG,IAAI,CAAC,IAAI,IAAI,CAAC;QACrB,KAAK,EAAE,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,KAAK,IAAI,CAAC;QACzC,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,EAAE;QACvB,IAAI,EAAE,IAAI,CAAC,IAAI;KAClB,CAAC,CAAC;AACP,CAAC,CAAC;AAUE,8BAAS;AAPb,MAAM,KAAK,GAAG,CAAC,GAAQ,EAAE,QAAsB,yBAAyB,EAAE,OAAe,GAAG,EAAE,EAAE;IAC5F,OAAO,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC;QACzB,KAAK;KACR,CAAC,CAAC;AACP,CAAC,CAAC;AAEE,sBAAK"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.fastify = exports.express = void 0;
|
|
27
|
+
const express = __importStar(require("./express"));
|
|
28
|
+
exports.express = express;
|
|
29
|
+
const fastify = __importStar(require("./fastify"));
|
|
30
|
+
exports.fastify = fastify;
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/responses/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mDAAqC;AAInC,0BAAO;AAHT,mDAAqC;AAInC,0BAAO"}
|
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.AWSSecrets = void 0;
|
|
13
|
+
const client_secrets_manager_1 = require("@aws-sdk/client-secrets-manager");
|
|
14
|
+
class AWSSecrets {
|
|
15
|
+
loadSecretsToEnv(props) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
let response;
|
|
18
|
+
try {
|
|
19
|
+
const client = new client_secrets_manager_1.SecretsManagerClient({
|
|
20
|
+
region: props.reqion || process.env.AWS_REGION || "us-east-1",
|
|
21
|
+
});
|
|
22
|
+
response = yield client.send(new client_secrets_manager_1.GetSecretValueCommand({
|
|
23
|
+
SecretId: props.secretName || process.env.AWS_SECRET_NAME,
|
|
24
|
+
VersionStage: "AWSCURRENT", // VersionStage defaults to AWSCURRENT if unspecified
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
// For a list of exceptions thrown, see
|
|
29
|
+
// https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_GetSecretValue.html
|
|
30
|
+
console.log("Error fetching secrets", error);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (!response.SecretString)
|
|
34
|
+
return;
|
|
35
|
+
const secrets = JSON.parse(response.SecretString);
|
|
36
|
+
for (const key in secrets) {
|
|
37
|
+
if (!process.env[key]) {
|
|
38
|
+
let val = secrets[key].trim();
|
|
39
|
+
if (val === 'false')
|
|
40
|
+
val = false;
|
|
41
|
+
if (val === 'true')
|
|
42
|
+
val = true;
|
|
43
|
+
process.env[key] = val;
|
|
44
|
+
console.log(`env ${key} loaded from AWS Secrets Manager`);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
console.log(`env ${key} loaded from AWS but not used because it is already set`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
console.log("loaded all config from AWS");
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.AWSSecrets = AWSSecrets;
|
|
55
|
+
//# sourceMappingURL=aws-secret.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aws-secret.js","sourceRoot":"","sources":["../../src/secrets/aws-secret.ts"],"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;qBACG,CAAC;oBACD,OAAO,CAAC,GAAG,CAAC,OAAO,GAAG,yDAAyD,CAAC,CAAA;gBACpF,CAAC;YACL,CAAC;YAED,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;QAC9C,CAAC;KAAA;CAEJ;AAzCD,gCAyCC"}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aws.js","sourceRoot":"","sources":["../../src/secrets/aws.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GetSecrets = exports.LoadSecretsProps = void 0;
|
|
4
|
+
const aws_secret_1 = require("./aws-secret");
|
|
5
|
+
class LoadSecretsProps {
|
|
6
|
+
}
|
|
7
|
+
exports.LoadSecretsProps = LoadSecretsProps;
|
|
8
|
+
const secretsImplementations = {
|
|
9
|
+
"aws": new aws_secret_1.AWSSecrets()
|
|
10
|
+
};
|
|
11
|
+
function GetSecrets(provider = "aws") {
|
|
12
|
+
const implementation = secretsImplementations[provider];
|
|
13
|
+
if (!implementation)
|
|
14
|
+
console.log("Oops, we are not able to find any implementation for the provider " + provider);
|
|
15
|
+
return implementation;
|
|
16
|
+
}
|
|
17
|
+
exports.GetSecrets = GetSecrets;
|
|
18
|
+
//# sourceMappingURL=index.js.map
|