@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,105 @@
|
|
|
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.ContextEntity = exports.INTERNAL_REQUEST_SOURCE = void 0;
|
|
27
|
+
const _ = __importStar(require("lodash"));
|
|
28
|
+
const crypto_1 = require("crypto");
|
|
29
|
+
const logger_1 = require("../logger/logger");
|
|
30
|
+
exports.INTERNAL_REQUEST_SOURCE = "internal";
|
|
31
|
+
class ContextEntity {
|
|
32
|
+
constructor() {
|
|
33
|
+
this.logger = new logger_1.Logger({});
|
|
34
|
+
}
|
|
35
|
+
static fromRequest(req) {
|
|
36
|
+
var _a, _b, _c, _d, _e;
|
|
37
|
+
const context = new ContextEntity();
|
|
38
|
+
context.requestSource = req.headers.source;
|
|
39
|
+
context.authenticationType = (req.headers["authentication-type"]);
|
|
40
|
+
context.clientId = (req.headers["client-id"] || req.headers["request-client-id"]);
|
|
41
|
+
context.requestClientId = (req.headers["request-client-id"] || req.headers["client-id"]);
|
|
42
|
+
context.contextClientId = (req.headers["context-client-id"] || req.headers["client-id"]);
|
|
43
|
+
context.userId = ((_a = req.params) === null || _a === void 0 ? void 0 : _a.userId) || ((_b = req.body) === null || _b === void 0 ? void 0 : _b.userId) || ((_c = req.query) === null || _c === void 0 ? void 0 : _c.userId);
|
|
44
|
+
context.requestId = req.headers["x-request-id"] || (0, crypto_1.randomUUID)();
|
|
45
|
+
context.ip = req.headers["cf-connecting-ip"] || req.ip;
|
|
46
|
+
context.os = req.headers.os;
|
|
47
|
+
context.platform = req.headers.platform;
|
|
48
|
+
context.version = req.headers.version;
|
|
49
|
+
context.request = req;
|
|
50
|
+
context.data = req.body;
|
|
51
|
+
context.currencyCode = req.headers["x-currency-code"];
|
|
52
|
+
context.countryCode = req.headers["x-country-code"];
|
|
53
|
+
context.locale = req.headers["x-locale-id"] || "en";
|
|
54
|
+
context.permissions = ((_d = req.headers.permissions) === null || _d === void 0 ? void 0 : _d.split(",")) || [];
|
|
55
|
+
context.features = ((_e = req.headers.features) === null || _e === void 0 ? void 0 : _e.split(",")) || [];
|
|
56
|
+
context.logger = new logger_1.Logger({
|
|
57
|
+
requestId: context.requestId,
|
|
58
|
+
requestClientId: context.requestClientId,
|
|
59
|
+
contextClientId: context.contextClientId,
|
|
60
|
+
userId: context.userId,
|
|
61
|
+
ip: context.ip,
|
|
62
|
+
url: context.request.originalUrl,
|
|
63
|
+
requestSource: context.requestSource
|
|
64
|
+
});
|
|
65
|
+
return context;
|
|
66
|
+
}
|
|
67
|
+
clone() {
|
|
68
|
+
return _.cloneDeep(this);
|
|
69
|
+
}
|
|
70
|
+
getClientId() {
|
|
71
|
+
return this.contextClientId || this.requestClientId || this.contextClientId;
|
|
72
|
+
}
|
|
73
|
+
createDefaultLogger() {
|
|
74
|
+
var _a;
|
|
75
|
+
this.logger = new logger_1.Logger({
|
|
76
|
+
requestId: this.requestId,
|
|
77
|
+
requestClientId: this.requestClientId,
|
|
78
|
+
contextClientId: this.contextClientId,
|
|
79
|
+
userId: this.userId,
|
|
80
|
+
ip: this.ip,
|
|
81
|
+
url: (_a = this.request) === null || _a === void 0 ? void 0 : _a.originalUrl,
|
|
82
|
+
requestSource: this.requestSource
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
hasPermission(permission) {
|
|
86
|
+
var _a;
|
|
87
|
+
return ((_a = this.permissions) === null || _a === void 0 ? void 0 : _a.includes(permission)) || false;
|
|
88
|
+
}
|
|
89
|
+
hasFeature(feature) {
|
|
90
|
+
var _a;
|
|
91
|
+
return ((_a = this.features) === null || _a === void 0 ? void 0 : _a.includes(feature)) || false;
|
|
92
|
+
}
|
|
93
|
+
getUserId() {
|
|
94
|
+
var _a, _b;
|
|
95
|
+
return ((_a = this === null || this === void 0 ? void 0 : this.contextUser) === null || _a === void 0 ? void 0 : _a.userId) || ((_b = this === null || this === void 0 ? void 0 : this.requestUser) === null || _b === void 0 ? void 0 : _b.userId) || (this === null || this === void 0 ? void 0 : this.userId) || "";
|
|
96
|
+
}
|
|
97
|
+
getRequestClientId() {
|
|
98
|
+
return this.requestClientId || this.clientId || "";
|
|
99
|
+
}
|
|
100
|
+
getContextClientId() {
|
|
101
|
+
return this.contextClientId || this.clientId || "";
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.ContextEntity = ContextEntity;
|
|
105
|
+
//# sourceMappingURL=context.entity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.entity.js","sourceRoot":"","sources":["../../src/types/context.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAA4B;AAK5B,mCAAkC;AAClC,6CAAwC;AAE3B,QAAA,uBAAuB,GAAG,UAAU,CAAC;AAElD,MAAa,aAAa;IA4BtB;QACI,IAAI,CAAC,MAAM,GAAI,IAAI,eAAM,CAAC,EAAE,CAAC,CAAC;IAClC,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,GAAoB;;QACnC,MAAM,OAAO,GAAG,IAAI,aAAa,EAAE,CAAC;QACpC,OAAO,CAAC,aAAa,GAAG,GAAG,CAAC,OAAO,CAAC,MAAgB,CAAC;QACrD,OAAO,CAAC,kBAAkB,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAW,CAAC;QAC5E,OAAO,CAAC,QAAQ,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAW,CAAC;QAC5F,OAAO,CAAC,eAAe,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,mBAAmB,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAW,CAAC;QACnG,OAAO,CAAC,eAAe,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,mBAAmB,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAW,CAAC;QACnG,OAAO,CAAC,MAAM,GAAG,CAAA,MAAA,GAAG,CAAC,MAAM,0CAAE,MAAM,MAAI,MAAA,GAAG,CAAC,IAAI,0CAAE,MAAM,CAAA,KAAI,MAAA,GAAG,CAAC,KAAK,0CAAE,MAAM,CAAA,CAAC;QAC7E,OAAO,CAAC,SAAS,GAAG,GAAG,CAA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AAC;IACD,kBAAkB;QACd,OAAO,IAAI,CAAC,eAAe,IAAI,IAAI,CAAC,QAAQ,IAAI,EAAE,CAAC;IACvD,CAAC;CACJ;AAnGD,sCAmGC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { ContextEntity, INTERNAL_REQUEST_SOURCE } from "./context.entity";
|
|
2
|
+
import { RequestUserEntity, UserEntity } from "./user.entity";
|
|
3
|
+
import { ClientEntity, RequestClientEntity } from "./client.entity";
|
|
4
|
+
import { BrokerDeadLetterPayloadEntity, BrokerRetryEntity } from "./broker.entity";
|
|
5
|
+
import { LoggerInterface } from "../logger";
|
|
6
|
+
import { OkResponse, ErrorResponse } from "../responses/express";
|
|
7
|
+
declare module "axios" {
|
|
8
|
+
interface InternalAxiosRequestConfig {
|
|
9
|
+
meta: any;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
type SaveActivityLogDTO = {
|
|
13
|
+
clientId: string;
|
|
14
|
+
userId: string;
|
|
15
|
+
service?: string;
|
|
16
|
+
reference?: string;
|
|
17
|
+
event: string;
|
|
18
|
+
timestamp: number;
|
|
19
|
+
message: string;
|
|
20
|
+
data: any;
|
|
21
|
+
};
|
|
22
|
+
declare class FunctionResponseDTO<T> {
|
|
23
|
+
error?: string;
|
|
24
|
+
statusCode?: number;
|
|
25
|
+
data?: T;
|
|
26
|
+
[x: string]: any;
|
|
27
|
+
}
|
|
28
|
+
declare enum TransactionChargeBearer {
|
|
29
|
+
merchant = "merchant",
|
|
30
|
+
customer = "customer"
|
|
31
|
+
}
|
|
32
|
+
declare class TransactionCharge {
|
|
33
|
+
chargeBearer?: TransactionChargeBearer;
|
|
34
|
+
platform?: {
|
|
35
|
+
percentage: number;
|
|
36
|
+
fixed: number;
|
|
37
|
+
};
|
|
38
|
+
provider?: {
|
|
39
|
+
percentage: number;
|
|
40
|
+
fixed: number;
|
|
41
|
+
};
|
|
42
|
+
tax?: {
|
|
43
|
+
percentage: number;
|
|
44
|
+
fixed: number;
|
|
45
|
+
};
|
|
46
|
+
cap?: {
|
|
47
|
+
minimum: number;
|
|
48
|
+
maximum: number;
|
|
49
|
+
};
|
|
50
|
+
custom?: {
|
|
51
|
+
percentage: number;
|
|
52
|
+
fixed: number;
|
|
53
|
+
};
|
|
54
|
+
VATOnChargeAndFees?: number;
|
|
55
|
+
providerPercentageFee?: number;
|
|
56
|
+
providerFixedFee?: number;
|
|
57
|
+
percentageAmount?: number;
|
|
58
|
+
fixedAmount?: number;
|
|
59
|
+
minimumCap?: number;
|
|
60
|
+
maximumCap?: number;
|
|
61
|
+
fixedTax?: number;
|
|
62
|
+
percentageTax?: number;
|
|
63
|
+
platformFixedAmount?: number;
|
|
64
|
+
platformPercentageAmount?: number;
|
|
65
|
+
chargeAmount?: number;
|
|
66
|
+
chargeType?: string;
|
|
67
|
+
[x: string]: any;
|
|
68
|
+
}
|
|
69
|
+
interface TransactionFee {
|
|
70
|
+
charge: number;
|
|
71
|
+
provider: number;
|
|
72
|
+
platform: number;
|
|
73
|
+
custom: number;
|
|
74
|
+
tax: number;
|
|
75
|
+
VAT: number;
|
|
76
|
+
cap?: number;
|
|
77
|
+
extra?: number;
|
|
78
|
+
total: number;
|
|
79
|
+
[x: string]: any;
|
|
80
|
+
}
|
|
81
|
+
export { INTERNAL_REQUEST_SOURCE, ContextEntity, RequestUserEntity, RequestClientEntity, SaveActivityLogDTO, ClientEntity, UserEntity, FunctionResponseDTO, BrokerRetryEntity, BrokerDeadLetterPayloadEntity, LoggerInterface, TransactionCharge, TransactionChargeBearer, TransactionFee, OkResponse, ErrorResponse, };
|
|
82
|
+
export { CountryCode } from "libphonenumber-js";
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TransactionChargeBearer = exports.TransactionCharge = exports.BrokerDeadLetterPayloadEntity = exports.BrokerRetryEntity = exports.FunctionResponseDTO = exports.UserEntity = exports.ClientEntity = exports.RequestUserEntity = exports.ContextEntity = exports.INTERNAL_REQUEST_SOURCE = void 0;
|
|
4
|
+
const context_entity_1 = require("./context.entity");
|
|
5
|
+
Object.defineProperty(exports, "ContextEntity", { enumerable: true, get: function () { return context_entity_1.ContextEntity; } });
|
|
6
|
+
Object.defineProperty(exports, "INTERNAL_REQUEST_SOURCE", { enumerable: true, get: function () { return context_entity_1.INTERNAL_REQUEST_SOURCE; } });
|
|
7
|
+
const user_entity_1 = require("./user.entity");
|
|
8
|
+
Object.defineProperty(exports, "RequestUserEntity", { enumerable: true, get: function () { return user_entity_1.RequestUserEntity; } });
|
|
9
|
+
Object.defineProperty(exports, "UserEntity", { enumerable: true, get: function () { return user_entity_1.UserEntity; } });
|
|
10
|
+
const client_entity_1 = require("./client.entity");
|
|
11
|
+
Object.defineProperty(exports, "ClientEntity", { enumerable: true, get: function () { return client_entity_1.ClientEntity; } });
|
|
12
|
+
const broker_entity_1 = require("./broker.entity");
|
|
13
|
+
Object.defineProperty(exports, "BrokerDeadLetterPayloadEntity", { enumerable: true, get: function () { return broker_entity_1.BrokerDeadLetterPayloadEntity; } });
|
|
14
|
+
Object.defineProperty(exports, "BrokerRetryEntity", { enumerable: true, get: function () { return broker_entity_1.BrokerRetryEntity; } });
|
|
15
|
+
class FunctionResponseDTO {
|
|
16
|
+
}
|
|
17
|
+
exports.FunctionResponseDTO = FunctionResponseDTO;
|
|
18
|
+
var TransactionChargeBearer;
|
|
19
|
+
(function (TransactionChargeBearer) {
|
|
20
|
+
TransactionChargeBearer["merchant"] = "merchant";
|
|
21
|
+
TransactionChargeBearer["customer"] = "customer";
|
|
22
|
+
})(TransactionChargeBearer || (exports.TransactionChargeBearer = TransactionChargeBearer = {}));
|
|
23
|
+
class TransactionCharge {
|
|
24
|
+
constructor() {
|
|
25
|
+
this.VATOnChargeAndFees = 0; //in percentage
|
|
26
|
+
this.providerPercentageFee = 0;
|
|
27
|
+
this.percentageAmount = 0; //deprecated
|
|
28
|
+
this.fixedAmount = 0; //deprecated
|
|
29
|
+
this.minimumCap = 0;
|
|
30
|
+
this.maximumCap = 0;
|
|
31
|
+
this.fixedTax = 0;
|
|
32
|
+
this.percentageTax = 0;
|
|
33
|
+
this.platformFixedAmount = 0;
|
|
34
|
+
this.platformPercentageAmount = 0;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.TransactionCharge = TransactionCharge;
|
|
38
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;AAAA,qDAAwE;AA+EpE,8FA/EI,8BAAa,OA+EJ;AADb,wGA9EmB,wCAAuB,OA8EnB;AA7E3B,+CAA4D;AA+ExD,kGA/EI,+BAAiB,OA+EJ;AAIjB,2FAnFuB,wBAAU,OAmFvB;AAlFd,mDAAkE;AAiF9D,6FAjFI,4BAAY,OAiFJ;AAhFhB,mDAAiF;AAoF7E,8GApFI,6CAA6B,OAoFJ;AAD7B,kGAnFmC,iCAAiB,OAmFnC;AA/DrB,MAAM,mBAAmB;CAKxB;AAyDG,kDAAmB;AAvDvB,IAAK,uBAGJ;AAHD,WAAK,uBAAuB;IACxB,gDAAqB,CAAA;IACrB,gDAAqB,CAAA;AACzB,CAAC,EAHI,uBAAuB,uCAAvB,uBAAuB,QAG3B;AAED,MAAM,iBAAiB;IAAvB;QAOI,uBAAkB,GAAY,CAAC,CAAA,CAAC,eAAe;QAG/C,0BAAqB,GAAY,CAAC,CAAA;QAElC,qBAAgB,GAAY,CAAC,CAAA,CAAC,YAAY;QAC1C,gBAAW,GAAY,CAAC,CAAA,CAAC,YAAY;QACrC,eAAU,GAAY,CAAC,CAAA;QACvB,eAAU,GAAY,CAAC,CAAA;QACvB,aAAQ,GAAY,CAAC,CAAA;QACrB,kBAAa,GAAY,CAAC,CAAA;QAC1B,wBAAmB,GAAY,CAAC,CAAA;QAChC,6BAAwB,GAAY,CAAC,CAAA;IAOzC,CAAC;CAAA;AA4BG,8CAAiB"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export declare class RequestUserEntity {
|
|
2
|
+
id: string;
|
|
3
|
+
clientId: string;
|
|
4
|
+
userId: string;
|
|
5
|
+
firstName?: string;
|
|
6
|
+
lastName?: string;
|
|
7
|
+
name: string;
|
|
8
|
+
email: string;
|
|
9
|
+
phoneNumber: string;
|
|
10
|
+
[key: string]: any;
|
|
11
|
+
}
|
|
12
|
+
export declare enum UserType {
|
|
13
|
+
user = "user",
|
|
14
|
+
customer = "customer"
|
|
15
|
+
}
|
|
16
|
+
export declare class UserEntity {
|
|
17
|
+
id: string;
|
|
18
|
+
type: UserType;
|
|
19
|
+
clientId: string;
|
|
20
|
+
userId: string;
|
|
21
|
+
firstName?: string;
|
|
22
|
+
lastName?: string;
|
|
23
|
+
name?: string;
|
|
24
|
+
email: string;
|
|
25
|
+
phoneNumber: string;
|
|
26
|
+
isInternalAdmin?: boolean;
|
|
27
|
+
[key: string]: any;
|
|
28
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UserEntity = exports.UserType = exports.RequestUserEntity = void 0;
|
|
4
|
+
class RequestUserEntity {
|
|
5
|
+
}
|
|
6
|
+
exports.RequestUserEntity = RequestUserEntity;
|
|
7
|
+
var UserType;
|
|
8
|
+
(function (UserType) {
|
|
9
|
+
UserType["user"] = "user";
|
|
10
|
+
UserType["customer"] = "customer";
|
|
11
|
+
})(UserType || (exports.UserType = UserType = {}));
|
|
12
|
+
class UserEntity {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.isInternalAdmin = false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.UserEntity = UserEntity;
|
|
18
|
+
//# sourceMappingURL=user.entity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user.entity.js","sourceRoot":"","sources":["../../src/types/user.entity.ts"],"names":[],"mappings":";;;AACA,MAAa,iBAAiB;CAU7B;AAVD,8CAUC;AAGD,IAAY,QAGX;AAHD,WAAY,QAAQ;IAClB,yBAAa,CAAA;IACb,iCAAqB,CAAA;AACvB,CAAC,EAHW,QAAQ,wBAAR,QAAQ,QAGnB;AAGD,MAAa,UAAU;IAAvB;QAUE,oBAAe,GAAa,KAAK,CAAC;IAEpC,CAAC;CAAA;AAZD,gCAYC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@6thbridge/utils",
|
|
3
|
+
"version": "0.1.16",
|
|
4
|
+
"description": "simple interface for the our commonly used functions",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib/**/*"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "jest --verbose -c jest.config.js",
|
|
12
|
+
"build": "tsc -p tsconfig.json",
|
|
13
|
+
"prepare": "npm run build",
|
|
14
|
+
"version": "npm run format && git add -A src",
|
|
15
|
+
"postversion": "git push && git push --tags"
|
|
16
|
+
},
|
|
17
|
+
"author": {
|
|
18
|
+
"name": "Micheal Akinwonmi",
|
|
19
|
+
"email": "michealakinwonmi@gmail.com"
|
|
20
|
+
},
|
|
21
|
+
"license": "ISC",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@aws-sdk/client-secrets-manager": "^3.504.0",
|
|
24
|
+
"amqp-connection-manager": "^4.1.14",
|
|
25
|
+
"amqplib": "^0.10.3",
|
|
26
|
+
"apitoolkit-express": "^2.2.4",
|
|
27
|
+
"axios": "^1.6.7",
|
|
28
|
+
"bignumber.js": "^9.1.2",
|
|
29
|
+
"dayjs": "^1.11.10",
|
|
30
|
+
"ioredis": "^5.3.2",
|
|
31
|
+
"joi": "^17.12.2",
|
|
32
|
+
"kafkajs": "^2.2.4",
|
|
33
|
+
"libphonenumber-js": "^1.10.57",
|
|
34
|
+
"lodash": "^4.17.21",
|
|
35
|
+
"mongoose-paginate-v2": "^1.8.0",
|
|
36
|
+
"node-cache": "^5.1.2",
|
|
37
|
+
"path-to-regexp": "^6.2.2",
|
|
38
|
+
"randomstring": "^1.3.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/express": "^4.17.13",
|
|
42
|
+
"@types/jest": "^29.5.12",
|
|
43
|
+
"@types/lodash": "^4.14.184",
|
|
44
|
+
"@types/randomstring": "^1.1.8",
|
|
45
|
+
"jest": "^29.7.0",
|
|
46
|
+
"ts-jest": "^29.1.2",
|
|
47
|
+
"typescript": "^5.4.3"
|
|
48
|
+
},
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": ">=14"
|
|
51
|
+
}
|
|
52
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
bridge-utils
|
|
2
|
+
===========
|
|
3
|
+
bridge-utils - This is a utility package for reused component
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
```json
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@6thbridge/utils": "^0.1.17" // see the "releases" section
|
|
9
|
+
}
|
|
10
|
+
```
|
|
11
|
+
```npm install @6thbridge/utils```
|
|
12
|
+
## Requirements
|
|
13
|
+
```javascript
|
|
14
|
+
const utils = require('bridge-mix');
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### Phone Number Formatter (Single)
|
|
18
|
+
- To format a single phone number
|
|
19
|
+
```javascript
|
|
20
|
+
let phoneNumber = "08012345678";
|
|
21
|
+
phoneNumber = utils.helpers.formatPhoneNumber(phoneNumber, "NG");
|
|
22
|
+
console.log(phoneNumber); //2348012345678
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Phone Number Formatter (Multiple)
|
|
26
|
+
- To format an array of phone numbers
|
|
27
|
+
```javascript
|
|
28
|
+
let phoneNumbers = ["08012345678", "08012345679"];
|
|
29
|
+
phoneNumbers = utils.helpers.formatPhoneNumberArray(phoneNumbers, "NG");
|
|
30
|
+
console.log(phoneNumbers); //['2348012345678','2348012345679']
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Remove Empty Fields from Data
|
|
34
|
+
- To format an array of phone numbers
|
|
35
|
+
```javascript
|
|
36
|
+
let data = {
|
|
37
|
+
"foo": "",
|
|
38
|
+
"bar": "value"
|
|
39
|
+
};
|
|
40
|
+
data = utils.helpers.removeFieldsWithEmptyValue(data);
|
|
41
|
+
console.log(data); //{"bar":"value"}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Logger
|
|
45
|
+
- Log data
|
|
46
|
+
```javascript
|
|
47
|
+
logger.error("This is an error from the package", {foo: "bar"}, new Error().stack);
|
|
48
|
+
logger.warn("This is an warning message from the package", {foo: "bar"}, new Error().stack);
|
|
49
|
+
logger.debug("This is an debug message from the package", {foo: "bar"}, new Error().stack);
|
|
50
|
+
logger.critical("This is a critical message from the package", {foo: "bar"}, new Error().stack);
|
|
51
|
+
logger.info("This is a info message from the package", {foo: "bar"}, new Error().stack);
|
|
52
|
+
logger.exception(new Error("Custom Error"), {foo: "bar"}, new Error().stack);
|
|
53
|
+
logger.out(new Error("Custom Error"), {foo: "bar"}, new Error().stack); //to console, only logs out when LOG_OUT=1
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Tests
|
|
58
|
+
#### Cli
|
|
59
|
+
```bash
|
|
60
|
+
npm install
|
|
61
|
+
npm test
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
#### Contributors
|
|
65
|
+
|
|
66
|
+
- [Micheal Akinwonmi](https://github.com/blackhades)
|