@6thbridge/utils 0.1.16 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/actions/charge.action.d.ts +3 -1
- package/lib/actions/charge.action.js +127 -10
- package/lib/actions/charge.action.js.map +1 -1
- package/lib/actions/currency.action.d.ts +1 -0
- package/lib/actions/currency.action.js +38 -23
- package/lib/actions/currency.action.js.map +1 -1
- package/lib/actions/index.d.ts +3 -3
- package/lib/actions/index.js +1 -1
- package/lib/actions/index.js.map +1 -1
- package/lib/actions/phone-number.action.d.ts +2 -2
- package/lib/actions/phone-number.action.js +1 -1
- package/lib/actions/phone-number.action.js.map +1 -1
- package/lib/brokers/index.d.ts +3 -3
- package/lib/brokers/index.js.map +1 -1
- package/lib/brokers/kafka.js +43 -33
- package/lib/brokers/kafka.js.map +1 -1
- package/lib/brokers/kafka.test.js +17 -18
- package/lib/brokers/kafka.test.js.map +1 -1
- package/lib/brokers/rabbitmq.d.ts +2 -2
- package/lib/brokers/rabbitmq.js +35 -37
- package/lib/brokers/rabbitmq.js.map +1 -1
- package/lib/cache/redis.d.ts +1 -1
- package/lib/cache/redis.js +14 -11
- package/lib/cache/redis.js.map +1 -1
- package/lib/database/MongoDBRepository.js +2 -2
- package/lib/database/MongoDBRepository.js.map +1 -1
- package/lib/database/MongoDBTypeRepository.js +2 -2
- package/lib/database/MongoDBTypeRepository.js.map +1 -1
- package/lib/database/index.d.ts +2 -2
- package/lib/database/index.js.map +1 -1
- package/lib/database/query.js +16 -18
- package/lib/database/query.js.map +1 -1
- package/lib/exceptions/custom.exception.js +1 -1
- package/lib/exceptions/custom.exception.js.map +1 -1
- package/lib/helpers/errors.d.ts +1 -1
- package/lib/helpers/errors.js +7 -7
- package/lib/helpers/errors.js.map +1 -1
- package/lib/helpers/index.d.ts +9 -9
- package/lib/helpers/index.js +30 -24
- package/lib/helpers/index.js.map +1 -1
- package/lib/helpers/utils.d.ts +1 -1
- package/lib/helpers/utils.js +3 -4
- package/lib/helpers/utils.js.map +1 -1
- package/lib/index.d.ts +16 -16
- package/lib/index.js +10 -10
- package/lib/index.js.map +1 -1
- package/lib/logger/index.js.map +1 -1
- package/lib/logger/logger-test.js +14 -14
- package/lib/logger/logger-test.js.map +1 -1
- package/lib/logger/logger.d.ts +2 -2
- package/lib/logger/logger.js +17 -18
- package/lib/logger/logger.js.map +1 -1
- package/lib/logger/null-logger.d.ts +1 -1
- package/lib/logger/null-logger.js +11 -22
- package/lib/logger/null-logger.js.map +1 -1
- package/lib/middlewares/common.js +47 -38
- package/lib/middlewares/common.js.map +1 -1
- package/lib/middlewares/express.d.ts +1 -1
- package/lib/middlewares/express.js +17 -17
- package/lib/middlewares/express.js.map +1 -1
- package/lib/middlewares/fastify.js +10 -10
- package/lib/middlewares/fastify.js.map +1 -1
- package/lib/middlewares/index.d.ts +3 -3
- package/lib/middlewares/index.js.map +1 -1
- package/lib/monitoring/index.d.ts +1 -1
- package/lib/monitoring/index.js +3 -3
- package/lib/monitoring/index.js.map +1 -1
- package/lib/responses/express.d.ts +2 -2
- package/lib/responses/express.js +7 -7
- package/lib/responses/express.js.map +1 -1
- package/lib/responses/fastify.js +4 -4
- package/lib/responses/fastify.js.map +1 -1
- package/lib/responses/index.d.ts +2 -2
- package/lib/responses/index.js.map +1 -1
- package/lib/secrets/aws-secret.d.ts +1 -1
- package/lib/secrets/aws-secret.js +4 -4
- package/lib/secrets/aws-secret.js.map +1 -1
- package/lib/secrets/index.js +3 -3
- package/lib/secrets/index.js.map +1 -1
- package/lib/test/actions/charge.action.test.js +116 -14
- package/lib/test/actions/charge.action.test.js.map +1 -1
- package/lib/test/database/test.spec.js +24 -24
- package/lib/test/database/test.spec.js.map +1 -1
- package/lib/test/helpers/PhoneNumber.spec.js +17 -17
- package/lib/test/helpers/PhoneNumber.spec.js.map +1 -1
- package/lib/test/logger/test.spec.js +15 -15
- package/lib/test/logger/test.spec.js.map +1 -1
- package/lib/test/types/context.entity.test.js +9 -9
- package/lib/test/types/context.entity.test.js.map +1 -1
- package/lib/translations/index.js +10 -10
- package/lib/translations/index.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/broker.entity.js.map +1 -1
- package/lib/types/client.entity.js.map +1 -1
- package/lib/types/context.entity.d.ts +3 -3
- package/lib/types/context.entity.js +19 -17
- package/lib/types/context.entity.js.map +1 -1
- package/lib/types/index.d.ts +46 -9
- package/lib/types/index.js +15 -1
- package/lib/types/index.js.map +1 -1
- package/lib/types/user.entity.js.map +1 -1
- package/package.json +1 -1
- package/readme.md +31 -18
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { TransactionCharge, TransactionFee } from
|
|
1
|
+
import { IntegrationCharge, TransactionCharge, TransactionFee } from '../types';
|
|
2
2
|
export declare const FRANCOPHONE_CURRENCY_CODES: string[];
|
|
3
3
|
interface CalculateTransactionFeePayload {
|
|
4
4
|
currency: string;
|
|
5
5
|
amount: number;
|
|
6
|
+
ownIntegration?: boolean;
|
|
6
7
|
}
|
|
7
8
|
export declare const calculateCharge: (chargeConfiguration: TransactionCharge, payload: CalculateTransactionFeePayload) => TransactionFee;
|
|
9
|
+
export declare const calculateIntegrationCharge: (integrationCharge: IntegrationCharge, payload: CalculateTransactionFeePayload) => TransactionFee;
|
|
8
10
|
export declare function processFrancophoneCountries(charge: TransactionFee): TransactionFee;
|
|
9
11
|
export {};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.processFrancophoneCountries = exports.calculateCharge = exports.FRANCOPHONE_CURRENCY_CODES = void 0;
|
|
6
|
+
exports.processFrancophoneCountries = exports.calculateIntegrationCharge = exports.calculateCharge = exports.FRANCOPHONE_CURRENCY_CODES = void 0;
|
|
7
7
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
8
|
-
|
|
8
|
+
const types_1 = require("../types");
|
|
9
|
+
exports.FRANCOPHONE_CURRENCY_CODES = ['xaf', 'xof'];
|
|
9
10
|
const calculateCharge = (chargeConfiguration, payload) => {
|
|
10
11
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
11
12
|
const response = {
|
|
@@ -15,7 +16,7 @@ const calculateCharge = (chargeConfiguration, payload) => {
|
|
|
15
16
|
platform: 0,
|
|
16
17
|
tax: 0,
|
|
17
18
|
VAT: 0,
|
|
18
|
-
total: 0
|
|
19
|
+
total: 0,
|
|
19
20
|
};
|
|
20
21
|
if (!chargeConfiguration)
|
|
21
22
|
return response;
|
|
@@ -23,25 +24,37 @@ const calculateCharge = (chargeConfiguration, payload) => {
|
|
|
23
24
|
//platform fee
|
|
24
25
|
response.platform = ((_a = chargeConfiguration.platform) === null || _a === void 0 ? void 0 : _a.fixed) || 0;
|
|
25
26
|
if ((_b = chargeConfiguration.platform) === null || _b === void 0 ? void 0 : _b.percentage) {
|
|
26
|
-
response.platform += new bignumber_js_1.default((_c = chargeConfiguration.platform) === null || _c === void 0 ? void 0 : _c.percentage)
|
|
27
|
+
response.platform += new bignumber_js_1.default((_c = chargeConfiguration.platform) === null || _c === void 0 ? void 0 : _c.percentage)
|
|
28
|
+
.div(100)
|
|
29
|
+
.multipliedBy(amount)
|
|
30
|
+
.toNumber();
|
|
27
31
|
}
|
|
28
32
|
response.charge += response.platform;
|
|
29
33
|
//provider
|
|
30
34
|
response.provider = ((_d = chargeConfiguration.provider) === null || _d === void 0 ? void 0 : _d.fixed) || 0;
|
|
31
35
|
if ((_e = chargeConfiguration.provider) === null || _e === void 0 ? void 0 : _e.percentage) {
|
|
32
|
-
response.provider += new bignumber_js_1.default((_f = chargeConfiguration.provider) === null || _f === void 0 ? void 0 : _f.percentage)
|
|
36
|
+
response.provider += new bignumber_js_1.default((_f = chargeConfiguration.provider) === null || _f === void 0 ? void 0 : _f.percentage)
|
|
37
|
+
.div(100)
|
|
38
|
+
.multipliedBy(amount)
|
|
39
|
+
.toNumber();
|
|
33
40
|
}
|
|
34
41
|
response.charge += response.provider;
|
|
35
42
|
//custom
|
|
36
43
|
response.custom = ((_g = chargeConfiguration.custom) === null || _g === void 0 ? void 0 : _g.fixed) || 0;
|
|
37
44
|
if ((_h = chargeConfiguration.custom) === null || _h === void 0 ? void 0 : _h.percentage) {
|
|
38
|
-
response.custom += new bignumber_js_1.default((_j = chargeConfiguration.custom) === null || _j === void 0 ? void 0 : _j.percentage)
|
|
45
|
+
response.custom += new bignumber_js_1.default((_j = chargeConfiguration.custom) === null || _j === void 0 ? void 0 : _j.percentage)
|
|
46
|
+
.div(100)
|
|
47
|
+
.multipliedBy(amount)
|
|
48
|
+
.toNumber();
|
|
39
49
|
}
|
|
40
50
|
response.charge += response.custom;
|
|
41
51
|
//tax
|
|
42
52
|
response.tax = ((_k = chargeConfiguration.tax) === null || _k === void 0 ? void 0 : _k.fixed) || 0;
|
|
43
53
|
if ((_l = chargeConfiguration.tax) === null || _l === void 0 ? void 0 : _l.percentage) {
|
|
44
|
-
response.tax += new bignumber_js_1.default((_m = chargeConfiguration.tax) === null || _m === void 0 ? void 0 : _m.percentage)
|
|
54
|
+
response.tax += new bignumber_js_1.default((_m = chargeConfiguration.tax) === null || _m === void 0 ? void 0 : _m.percentage)
|
|
55
|
+
.div(100)
|
|
56
|
+
.multipliedBy(amount)
|
|
57
|
+
.toNumber();
|
|
45
58
|
}
|
|
46
59
|
response.charge += response.tax;
|
|
47
60
|
response.total = response.charge;
|
|
@@ -53,7 +66,10 @@ const calculateCharge = (chargeConfiguration, payload) => {
|
|
|
53
66
|
}
|
|
54
67
|
//calculate VAT
|
|
55
68
|
if (chargeConfiguration.VATOnChargeAndFees) {
|
|
56
|
-
response.VAT = new bignumber_js_1.default(chargeConfiguration.VATOnChargeAndFees)
|
|
69
|
+
response.VAT = new bignumber_js_1.default(chargeConfiguration.VATOnChargeAndFees)
|
|
70
|
+
.div(100)
|
|
71
|
+
.multipliedBy(response.total)
|
|
72
|
+
.toNumber();
|
|
57
73
|
response.total += response.VAT;
|
|
58
74
|
}
|
|
59
75
|
response.total = Math.ceil(response.total);
|
|
@@ -62,8 +78,109 @@ const calculateCharge = (chargeConfiguration, payload) => {
|
|
|
62
78
|
return processFrancophoneCountries(response);
|
|
63
79
|
};
|
|
64
80
|
exports.calculateCharge = calculateCharge;
|
|
81
|
+
const getChargeValue = (charge, amount) => {
|
|
82
|
+
var _a, _b;
|
|
83
|
+
//divide by 100
|
|
84
|
+
if (charge.type == types_1.IntegrationChargeType.flat)
|
|
85
|
+
return { percentage: (_a = charge === null || charge === void 0 ? void 0 : charge.value) === null || _a === void 0 ? void 0 : _a.percentage, fixed: (_b = charge === null || charge === void 0 ? void 0 : charge.value) === null || _b === void 0 ? void 0 : _b.fixed };
|
|
86
|
+
const tieredCharges = charge.value;
|
|
87
|
+
let chargeValue = tieredCharges.find((t) => {
|
|
88
|
+
if (!t.upperBound)
|
|
89
|
+
return true;
|
|
90
|
+
const lowerBound = (t === null || t === void 0 ? void 0 : t.lowerBound) || 0;
|
|
91
|
+
return lowerBound <= amount && amount <= t.upperBound;
|
|
92
|
+
});
|
|
93
|
+
return { percentage: (chargeValue === null || chargeValue === void 0 ? void 0 : chargeValue.percentage) || 0, fixed: (chargeValue === null || chargeValue === void 0 ? void 0 : chargeValue.fixed) || 0 };
|
|
94
|
+
};
|
|
95
|
+
const calculateIntegrationCharge = (integrationCharge, payload) => {
|
|
96
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
97
|
+
let response = {
|
|
98
|
+
charge: 0,
|
|
99
|
+
provider: 0,
|
|
100
|
+
custom: 0,
|
|
101
|
+
platform: 0,
|
|
102
|
+
tax: 0,
|
|
103
|
+
VAT: 0,
|
|
104
|
+
total: 0,
|
|
105
|
+
merchant: 0,
|
|
106
|
+
customer: 0,
|
|
107
|
+
ownIntegration: (_a = payload.ownIntegration) !== null && _a !== void 0 ? _a : false,
|
|
108
|
+
};
|
|
109
|
+
if (!integrationCharge)
|
|
110
|
+
return response;
|
|
111
|
+
const amount = payload.amount;
|
|
112
|
+
//platform fee
|
|
113
|
+
const platformFee = getChargeValue(integrationCharge.platform, amount / 100);
|
|
114
|
+
response.platform = platformFee.fixed;
|
|
115
|
+
if (platformFee.percentage) {
|
|
116
|
+
response.platform += new bignumber_js_1.default(platformFee.percentage)
|
|
117
|
+
.div(100)
|
|
118
|
+
.multipliedBy(amount)
|
|
119
|
+
.toNumber();
|
|
120
|
+
}
|
|
121
|
+
response.charge += response.platform;
|
|
122
|
+
response.provider = 0;
|
|
123
|
+
//provider
|
|
124
|
+
const providerFee = getChargeValue(integrationCharge.provider, amount / 100);
|
|
125
|
+
response.provider = providerFee.fixed || 0;
|
|
126
|
+
if (providerFee.percentage) {
|
|
127
|
+
response.provider += new bignumber_js_1.default(providerFee.percentage)
|
|
128
|
+
.div(100)
|
|
129
|
+
.multipliedBy(amount)
|
|
130
|
+
.toNumber();
|
|
131
|
+
}
|
|
132
|
+
response.charge += response.provider;
|
|
133
|
+
//custom
|
|
134
|
+
const customConfig = getChargeValue(integrationCharge.custom, amount / 100);
|
|
135
|
+
response.custom = customConfig.fixed || 0;
|
|
136
|
+
if (customConfig === null || customConfig === void 0 ? void 0 : customConfig.percentage) {
|
|
137
|
+
response.custom += new bignumber_js_1.default(customConfig === null || customConfig === void 0 ? void 0 : customConfig.percentage)
|
|
138
|
+
.div(100)
|
|
139
|
+
.multipliedBy(amount)
|
|
140
|
+
.toNumber();
|
|
141
|
+
}
|
|
142
|
+
response.charge += response.custom;
|
|
143
|
+
//tax
|
|
144
|
+
const taxConfig = getChargeValue(integrationCharge.tax, amount / 100);
|
|
145
|
+
response.tax = taxConfig.fixed || 0;
|
|
146
|
+
if (taxConfig.percentage) {
|
|
147
|
+
response.tax += new bignumber_js_1.default(taxConfig.percentage).div(100).multipliedBy(amount).toNumber();
|
|
148
|
+
}
|
|
149
|
+
response.charge += response.tax;
|
|
150
|
+
response.total = response.charge;
|
|
151
|
+
if (((_b = integrationCharge.cap) === null || _b === void 0 ? void 0 : _b.minimum) && integrationCharge.cap.minimum > response.total) {
|
|
152
|
+
response.total = integrationCharge.cap.minimum;
|
|
153
|
+
}
|
|
154
|
+
if (((_c = integrationCharge.cap) === null || _c === void 0 ? void 0 : _c.maximum) && ((_d = integrationCharge.cap) === null || _d === void 0 ? void 0 : _d.maximum) < response.total) {
|
|
155
|
+
response.total = integrationCharge.cap.maximum;
|
|
156
|
+
}
|
|
157
|
+
//calculate VAT
|
|
158
|
+
const vatConfig = getChargeValue(integrationCharge.VATOnChargeAndFees, response.total / 100);
|
|
159
|
+
response.VAT = (_e = vatConfig.fixed) !== null && _e !== void 0 ? _e : 0;
|
|
160
|
+
if (vatConfig.percentage) {
|
|
161
|
+
response.VAT = new bignumber_js_1.default(vatConfig.percentage)
|
|
162
|
+
.div(100)
|
|
163
|
+
.multipliedBy(response.total)
|
|
164
|
+
.toNumber();
|
|
165
|
+
response.total += response.VAT;
|
|
166
|
+
}
|
|
167
|
+
response.total = Math.ceil(response.total);
|
|
168
|
+
if (exports.FRANCOPHONE_CURRENCY_CODES.includes((_f = payload.currency) === null || _f === void 0 ? void 0 : _f.toLowerCase())) {
|
|
169
|
+
response = processFrancophoneCountries(response);
|
|
170
|
+
}
|
|
171
|
+
response.merchant = new bignumber_js_1.default(((_g = integrationCharge.bearer) === null || _g === void 0 ? void 0 : _g.merchant) || 0)
|
|
172
|
+
.div(100)
|
|
173
|
+
.multipliedBy(response.total)
|
|
174
|
+
.toNumber();
|
|
175
|
+
response.customer = new bignumber_js_1.default(((_h = integrationCharge.bearer) === null || _h === void 0 ? void 0 : _h.customer) || 0)
|
|
176
|
+
.div(100)
|
|
177
|
+
.multipliedBy(response.total)
|
|
178
|
+
.toNumber();
|
|
179
|
+
return response;
|
|
180
|
+
};
|
|
181
|
+
exports.calculateIntegrationCharge = calculateIntegrationCharge;
|
|
65
182
|
function processFrancophoneCountries(charge) {
|
|
66
|
-
console.log(
|
|
183
|
+
console.log('calculateCharge: Processing Francophone currency', charge);
|
|
67
184
|
let chargeInLargestCurrency = charge.total / 100;
|
|
68
185
|
const roundedUpCharge = Math.ceil(chargeInLargestCurrency);
|
|
69
186
|
charge.extra = (roundedUpCharge - chargeInLargestCurrency) * 100;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"charge.action.js","sourceRoot":"","sources":["../../src/actions/charge.action.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;AAEb,gEAAqC;
|
|
1
|
+
{"version":3,"file":"charge.action.js","sourceRoot":"","sources":["../../src/actions/charge.action.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;AAEb,gEAAqC;AACrC,oCAQkB;AAEL,QAAA,0BAA0B,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAOlD,MAAM,eAAe,GAAG,CAC7B,mBAAsC,EACtC,OAAuC,EACvB,EAAE;;IAClB,MAAM,QAAQ,GAAmB;QAC/B,MAAM,EAAE,CAAC;QACT,QAAQ,EAAE,CAAC;QACX,MAAM,EAAE,CAAC;QACT,QAAQ,EAAE,CAAC;QACX,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,CAAC;QACN,KAAK,EAAE,CAAC;KACT,CAAC;IAEF,IAAI,CAAC,mBAAmB;QAAE,OAAO,QAAQ,CAAC;IAE1C,MAAM,MAAM,GAAW,OAAO,CAAC,MAAM,CAAC;IAEtC,cAAc;IACd,QAAQ,CAAC,QAAQ,GAAG,CAAA,MAAA,mBAAmB,CAAC,QAAQ,0CAAE,KAAK,KAAI,CAAC,CAAC;IAC7D,IAAI,MAAA,mBAAmB,CAAC,QAAQ,0CAAE,UAAU,EAAE,CAAC;QAC7C,QAAQ,CAAC,QAAQ,IAAI,IAAI,sBAAS,CAAC,MAAA,mBAAmB,CAAC,Q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Y,CAAC,QAAQ,CAAC,KAAK,CAAC;SAC5B,QAAQ,EAAE,CAAC;IAEd,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AA1GW,QAAA,0BAA0B,8BA0GrC;AAEF,SAAgB,2BAA2B,CAAC,MAAsB;IAChE,OAAO,CAAC,GAAG,CAAC,kDAAkD,EAAE,MAAM,CAAC,CAAC;IACxE,IAAI,uBAAuB,GAAG,MAAM,CAAC,KAAK,GAAG,GAAG,CAAC;IACjD,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;IAC3D,MAAM,CAAC,KAAK,GAAG,CAAC,eAAe,GAAG,uBAAuB,CAAC,GAAG,GAAG,CAAC;IACjE,MAAM,CAAC,KAAK,GAAG,eAAe,GAAG,GAAG,CAAC;IACrC,OAAO,MAAM,CAAC;AAChB,CAAC;AAPD,kEAOC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getCurrencySymbol = exports.symbols = exports.validateAmount = exports.formatAmountAndCurrency = exports.createAmountLabel = exports.FRANCOPHONE_CURRENCY_CODES = void 0;
|
|
6
|
+
exports.processAmount = exports.getCurrencySymbol = exports.symbols = exports.validateAmount = exports.formatAmountAndCurrency = exports.createAmountLabel = exports.FRANCOPHONE_CURRENCY_CODES = void 0;
|
|
7
7
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
8
|
-
exports.FRANCOPHONE_CURRENCY_CODES = [
|
|
8
|
+
exports.FRANCOPHONE_CURRENCY_CODES = ['xaf', 'xof'];
|
|
9
9
|
const createAmountLabel = (payload) => {
|
|
10
10
|
payload.currencyLabel = payload.currencyLabel || payload.currency;
|
|
11
11
|
if (payload.currencyLabel != payload.currency && payload.currencyExchangeValue != 1) {
|
|
@@ -19,39 +19,54 @@ const formatAmountAndCurrency = (currency, value) => {
|
|
|
19
19
|
//get currency symbol
|
|
20
20
|
const currencySymbol = (0, exports.getCurrencySymbol)(currency);
|
|
21
21
|
if (currency && exports.FRANCOPHONE_CURRENCY_CODES.includes(currency.toLowerCase()))
|
|
22
|
-
return `${parseFloat(value || 0)
|
|
23
|
-
|
|
22
|
+
return `${parseFloat(value || 0)
|
|
23
|
+
.toFixed(0)
|
|
24
|
+
.toLocaleString()} ${currencySymbol}`;
|
|
25
|
+
return `${currencySymbol}${parseFloat(value || 0)
|
|
26
|
+
.toFixed(2)
|
|
27
|
+
.toLocaleString()}`;
|
|
24
28
|
};
|
|
25
29
|
exports.formatAmountAndCurrency = formatAmountAndCurrency;
|
|
26
30
|
function validateAmount(currency, amount) {
|
|
27
|
-
if (![
|
|
31
|
+
if (!['XOF', 'XAF'].includes(currency.toUpperCase()))
|
|
28
32
|
return null;
|
|
29
33
|
if (!Number.isInteger(amount / 100)) {
|
|
30
|
-
return
|
|
34
|
+
return 'Oops. For XOF and XAF currencies, Please send in whole number amount as we do not allow decimal amounts';
|
|
31
35
|
}
|
|
32
36
|
return null;
|
|
33
37
|
}
|
|
34
38
|
exports.validateAmount = validateAmount;
|
|
35
39
|
exports.symbols = {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
40
|
+
USD: '$', // US Dollar
|
|
41
|
+
EUR: '€', // Euro
|
|
42
|
+
CAD: 'CA$',
|
|
43
|
+
CRC: '₡', // Costa Rican Colón
|
|
44
|
+
GBP: '£', // British Pound Sterling
|
|
45
|
+
ILS: '₪', // Israeli New Sheqel
|
|
46
|
+
INR: '₹', // Indian Rupee
|
|
47
|
+
JPY: '¥', // Japanese Yen
|
|
48
|
+
KRW: '₩', // South Korean Won
|
|
49
|
+
NGN: '₦', // Nigerian Naira
|
|
50
|
+
PHP: '₱', // Philippine Peso
|
|
51
|
+
PLN: 'zł', // Polish Zloty
|
|
52
|
+
PYG: '₲', // Paraguayan Guarani
|
|
53
|
+
THB: '฿', // Thai Baht
|
|
54
|
+
UAH: '₴', // Ukrainian Hryvnia
|
|
55
|
+
VND: '₫', // Vietnamese Dong,
|
|
56
|
+
XOF: 'F CFA', //ivory coast XOF
|
|
57
|
+
XAF: 'FCFA',
|
|
58
|
+
GHS: 'GH₵', //ghana cedis
|
|
52
59
|
};
|
|
53
60
|
const getCurrencySymbol = (currency) => {
|
|
54
61
|
return exports.symbols[currency] || currency;
|
|
55
62
|
};
|
|
56
63
|
exports.getCurrencySymbol = getCurrencySymbol;
|
|
64
|
+
function processAmount(currency, amount) {
|
|
65
|
+
if (!['XOF', 'XAF'].includes(currency))
|
|
66
|
+
return amount;
|
|
67
|
+
console.log('processAmount: Processing Francophone currency', amount);
|
|
68
|
+
let amountInLargestCurrency = amount / 100;
|
|
69
|
+
return Math.ceil(amountInLargestCurrency) * 100;
|
|
70
|
+
}
|
|
71
|
+
exports.processAmount = processAmount;
|
|
57
72
|
//# sourceMappingURL=currency.action.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"currency.action.js","sourceRoot":"","sources":["../../src/actions/currency.action.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;AAEb,gEAAqC;AAExB,QAAA,0BAA0B,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"currency.action.js","sourceRoot":"","sources":["../../src/actions/currency.action.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;AAEb,gEAAqC;AAExB,QAAA,0BAA0B,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAQlD,MAAM,iBAAiB,GAAG,CA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AAiB,qBAE5B;AAEF,SAAgB,aAAa,CAAC,QAAgB,EAAE,MAAc;IAC5D,IAAI,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAAE,OAAO,MAAM,CAAC;IACtD,OAAO,CAAC,GAAG,CAAC,gDAAgD,EAAE,MAAM,CAAC,CAAC;IACtE,IAAI,uBAAuB,GAAG,MAAM,GAAG,GAAG,CAAC;IAC3C,OAAO,IAAI,CAAC,IAAI,CAAC,uBAAuB,CAAC,GAAG,GAAG,CAAC;AAClD,CAAC;AALD,sCAKC"}
|
package/lib/actions/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as currency from
|
|
2
|
-
import * as charge from
|
|
3
|
-
import * as phoneNumber from
|
|
1
|
+
import * as currency from './currency.action';
|
|
2
|
+
import * as charge from './charge.action';
|
|
3
|
+
import * as phoneNumber from './phone-number.action';
|
|
4
4
|
declare const _default: {
|
|
5
5
|
currency: typeof currency;
|
|
6
6
|
charge: typeof charge;
|
package/lib/actions/index.js
CHANGED
package/lib/actions/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/actions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,4DAA8C;AAC9C,wDAA0C;AAC1C,mEAAqD;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/actions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,4DAA8C;AAC9C,wDAA0C;AAC1C,mEAAqD;AAErD,iBAAS;IACP,QAAQ;IACR,MAAM;IACN,WAAW;CACZ,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as libphonenumber from
|
|
2
|
-
import { CountryCode } from
|
|
1
|
+
import * as libphonenumber from 'libphonenumber-js';
|
|
2
|
+
import { CountryCode } from 'libphonenumber-js';
|
|
3
3
|
export declare class ProcessPhoneNumberDTO {
|
|
4
4
|
phoneNumber: string;
|
|
5
5
|
phoneNumberPrefix?: string;
|
|
@@ -53,7 +53,7 @@ const formatPhoneNumber = (payload, options) => __awaiter(void 0, void 0, void 0
|
|
|
53
53
|
phoneNumber: `${formatPhoneNumberResponse.countryCallingCode}${formatPhoneNumberResponse.nationalNumber}`,
|
|
54
54
|
phoneNumberWithPrefix: formatPhoneNumberResponse.number,
|
|
55
55
|
countryCode: formatPhoneNumberResponse.country,
|
|
56
|
-
meta: formatPhoneNumberResponse
|
|
56
|
+
meta: formatPhoneNumberResponse,
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
59
|
catch (e) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"phone-number.action.js","sourceRoot":"","sources":["../../src/actions/phone-number.action.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kEAAoD;AACpD,
|
|
1
|
+
{"version":3,"file":"phone-number.action.js","sourceRoot":"","sources":["../../src/actions/phone-number.action.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kEAAoD;AACpD,6CAA0C;AAC1C,yDAA+F;AAE/F,MAAa,qBAAqB;CAKjC;AALD,sDAKC;AAEM,MAAM,iBAAiB,GAAG,CAC/B,OAA8B,EAC9B,OAA4B,EAC5B,EAAE;IACF,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,eAAM,CAAC;IAC1C,IAAI,CAAC;QACH,MAAM,WAAW,GAAQ,OAAO,CAAC,WAAW,CAAC;QAE7C,IAAI,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;QAEtC,IAAI,OAAO,CAAC,iBAAiB,EAAE,CAAC;YAC9B,WAAW,GAAG,GAAG,OAAO,CAAC,iBAAiB,GAAG,WAAW,EAAE,CAAC;QAC7D,CAAC;QAED,MAAM,yBAAyB,GAAG,cAAc,CAAC,gBAAgB,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;QAE5F,OAAO;YACL,iBAAiB,EAAE,yBAAyB,CAAC,kBAAkB;YAC/D,WAAW,EAAE,GAAG,yBAAyB,CAAC,kBAAkB,GAAG,yBAAyB,CAAC,cAAc,EAAE;YACzG,qBAAqB,EAAE,yBAAyB,CAAC,MAAM;YACvD,WAAW,EAAE,yBAAyB,CAAC,OAAO;YAC9C,IAAI,EAAE,yBAAyB;SAChC,CAAC;IACJ,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;QAErC,OAAO;YACL,iBAAiB,EAAE,OAAO,CAAC,iBAAiB;YAC5C,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,WAAW,EAAE,OAAO,CAAC,WAAW;SACjC,CAAC;IACJ,CAAC;AACH,CAAC,CAAA,CAAC;AAhCW,QAAA,iBAAiB,qBAgC5B;AAEF,SAAgB,kBAAkB,CAChC,WAAmB,EACnB,WAAiC;IAEjC,OAAO,IAAA,0CAAsB,EAAC,WAAW,EAAE,WAA0B,CAAC,CAAC;AACzE,CAAC;AALD,gDAKC;AACD,SAAgB,qBAAqB,CACnC,WAAmB,EACnB,WAAiC;IAEjC,OAAO,IAAA,yCAAqB,EAAC,WAAW,EAAE,WAA0B,CAAC,CAAC;AACxE,CAAC;AALD,sDAKC"}
|
package/lib/brokers/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { KafkaInit, KafkaJS } from
|
|
2
|
-
import { RabbitMQ, RabbitMQInit } from
|
|
1
|
+
import { KafkaInit, KafkaJS } from './kafka';
|
|
2
|
+
import { RabbitMQ, RabbitMQInit } from './rabbitmq';
|
|
3
3
|
export interface MessageBrokerInterface {
|
|
4
4
|
init(config: any): Promise<MessageBrokerInterface>;
|
|
5
5
|
}
|
|
6
|
-
export { KafkaJS, KafkaInit, RabbitMQInit, RabbitMQ
|
|
6
|
+
export { KafkaJS, KafkaInit, RabbitMQInit, RabbitMQ };
|
package/lib/brokers/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/brokers/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/brokers/index.ts"],"names":[],"mappings":";;;AAAA,mCAA6C;AAOpC,wFAPW,eAAO,OAOX;AANhB,yCAAoD;AAMT,yFANlC,mBAAQ,OAMkC"}
|
package/lib/brokers/kafka.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -31,33 +31,38 @@ class KafkaJS {
|
|
|
31
31
|
init(options) {
|
|
32
32
|
options.url = options.url || process.env.KAFKA_CLUSTER_URL;
|
|
33
33
|
options.name = options.name || process.env.APP_NAME;
|
|
34
|
-
options.connectionTimeout =
|
|
35
|
-
|
|
36
|
-
options.
|
|
34
|
+
options.connectionTimeout =
|
|
35
|
+
options.connectionTimeout || parseInt(process.env.KAFKA_CONNECTION_TIMEOUT) || 3000;
|
|
36
|
+
options.requestTimeout =
|
|
37
|
+
options.requestTimeout || parseInt(process.env.KAFKA_REQUEST_TIMEOUT) || 25000;
|
|
38
|
+
options.logLevel =
|
|
39
|
+
options.logLevel === 0
|
|
40
|
+
? options.logLevel
|
|
41
|
+
: parseInt(process.env.KAFKA_LOG_LEVEL) || kafkajs_1.logLevel.ERROR;
|
|
37
42
|
options.saslUsername = options.saslUsername || process.env.KAFKA_SASL_USERNAME;
|
|
38
43
|
options.saslPassword = options.saslPassword || process.env.KAFKA_SASL_PASSWORD;
|
|
39
|
-
options.saslMechanism = options.saslMechanism ||
|
|
44
|
+
options.saslMechanism = options.saslMechanism || 'plain';
|
|
40
45
|
try {
|
|
41
46
|
if (!options.url)
|
|
42
|
-
throw Error(
|
|
47
|
+
throw Error('KAFKA URL is required');
|
|
43
48
|
//We are splitting the URL because of clusters
|
|
44
49
|
const kafkaConfig = {
|
|
45
50
|
clientId: options.name,
|
|
46
|
-
brokers: options.url.split(
|
|
51
|
+
brokers: options.url.split(','),
|
|
47
52
|
connectionTimeout: options.connectionTimeout,
|
|
48
53
|
requestTimeout: options.requestTimeout,
|
|
49
54
|
logLevel: options.logLevel,
|
|
50
55
|
retry: {
|
|
51
56
|
initialRetryTime: options.initialRetryTime || 100,
|
|
52
57
|
retries: options.retries || 10,
|
|
53
|
-
}
|
|
58
|
+
},
|
|
54
59
|
};
|
|
55
60
|
if (options.saslMechanism && options.saslPassword) {
|
|
56
61
|
kafkaConfig.ssl = true;
|
|
57
62
|
kafkaConfig.sasl = {
|
|
58
63
|
mechanism: options.saslMechanism, // scram-sha-256 or scram-sha-512
|
|
59
64
|
username: options.saslUsername,
|
|
60
|
-
password: options.saslPassword
|
|
65
|
+
password: options.saslPassword,
|
|
61
66
|
};
|
|
62
67
|
}
|
|
63
68
|
this.connection = new kafkajs_1.Kafka(kafkaConfig);
|
|
@@ -65,12 +70,12 @@ class KafkaJS {
|
|
|
65
70
|
}
|
|
66
71
|
catch (e) {
|
|
67
72
|
if (!this.retryCountBeforeExit) {
|
|
68
|
-
console.log(
|
|
73
|
+
console.log('Exiting....');
|
|
69
74
|
process.exit(1);
|
|
70
75
|
}
|
|
71
76
|
this.retryCountBeforeExit -= 1;
|
|
72
|
-
console.log(
|
|
73
|
-
console.log(
|
|
77
|
+
console.log('retryCountBeforeExit', this.retryCountBeforeExit);
|
|
78
|
+
console.log('Reconnecting Kafka', e);
|
|
74
79
|
return this.init(options);
|
|
75
80
|
}
|
|
76
81
|
}
|
|
@@ -91,7 +96,7 @@ class KafkaJS {
|
|
|
91
96
|
createTopics(topics) {
|
|
92
97
|
return __awaiter(this, void 0, void 0, function* () {
|
|
93
98
|
if (!this.connection)
|
|
94
|
-
throw Error(
|
|
99
|
+
throw Error('Connection has not been initialized. Call the init function first');
|
|
95
100
|
try {
|
|
96
101
|
const admin = this.connection.admin();
|
|
97
102
|
yield admin.connect();
|
|
@@ -100,25 +105,28 @@ class KafkaJS {
|
|
|
100
105
|
}
|
|
101
106
|
const kafkaTopics = [];
|
|
102
107
|
for (let topic of topics) {
|
|
103
|
-
if (!topic.name || topic.name.trim() ===
|
|
104
|
-
return { error:
|
|
108
|
+
if (!topic.name || topic.name.trim() === '')
|
|
109
|
+
return { error: 'KafkaJS: Topic Name Cannot Be Empty' };
|
|
105
110
|
kafkaTopics.push({
|
|
106
111
|
topic: topic.name,
|
|
107
112
|
numPartitions: topic.numberOfPartitions || 1,
|
|
108
113
|
replicationFactor: topic.replicationFactor || 1,
|
|
109
|
-
configEntries: [
|
|
114
|
+
configEntries: [
|
|
115
|
+
{
|
|
110
116
|
name: 'cleanup.policy',
|
|
111
|
-
value: topic.cleanUpPolicy || 'compact'
|
|
112
|
-
},
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
117
|
+
value: topic.cleanUpPolicy || 'compact',
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
name: 'retention.ms',
|
|
121
|
+
value: topic.retentionPolicy || '-1',
|
|
122
|
+
},
|
|
123
|
+
],
|
|
116
124
|
});
|
|
117
125
|
}
|
|
118
126
|
const response = yield admin.createTopics({
|
|
119
127
|
topics: kafkaTopics,
|
|
120
128
|
});
|
|
121
|
-
console.log(
|
|
129
|
+
console.log('Kafka: Topics Created', response);
|
|
122
130
|
return { data: true };
|
|
123
131
|
}
|
|
124
132
|
catch (e) {
|
|
@@ -130,7 +138,7 @@ class KafkaJS {
|
|
|
130
138
|
createProducer() {
|
|
131
139
|
return __awaiter(this, void 0, void 0, function* () {
|
|
132
140
|
if (!this.connection)
|
|
133
|
-
throw Error(
|
|
141
|
+
throw Error('Connection has not been made. Call the init function first');
|
|
134
142
|
try {
|
|
135
143
|
this.producer = this.connection.producer();
|
|
136
144
|
yield this.producer.connect();
|
|
@@ -156,8 +164,8 @@ class KafkaJS {
|
|
|
156
164
|
return {
|
|
157
165
|
data: yield this.producer.send({
|
|
158
166
|
topic,
|
|
159
|
-
messages: [{ value: JSON.stringify(payload), key }]
|
|
160
|
-
})
|
|
167
|
+
messages: [{ value: JSON.stringify(payload), key }],
|
|
168
|
+
}),
|
|
161
169
|
};
|
|
162
170
|
}
|
|
163
171
|
catch (e) {
|
|
@@ -178,8 +186,8 @@ class KafkaJS {
|
|
|
178
186
|
listen(topics_1, groupId_1, callback_1) {
|
|
179
187
|
return __awaiter(this, arguments, void 0, function* (topics, groupId, callback, fromBeginning = false, prefetch = 1) {
|
|
180
188
|
try {
|
|
181
|
-
if (typeof callback !=
|
|
182
|
-
throw new Error(
|
|
189
|
+
if (typeof callback != 'function')
|
|
190
|
+
throw new Error('Callback must be a function');
|
|
183
191
|
this.consumer = this.connection.consumer({ groupId });
|
|
184
192
|
yield this.consumer.connect();
|
|
185
193
|
for (let topic of topics) {
|
|
@@ -206,7 +214,7 @@ class KafkaJS {
|
|
|
206
214
|
});
|
|
207
215
|
}
|
|
208
216
|
catch (e) {
|
|
209
|
-
console.log(
|
|
217
|
+
console.log('Kafka consumer error', e);
|
|
210
218
|
this.consumer.pause([{ topic }]);
|
|
211
219
|
setTimeout(() => this.consumer.resume([{ topic }]), (e.retryAfter || 50) * 1000);
|
|
212
220
|
return callback(e.message);
|
|
@@ -222,11 +230,11 @@ class KafkaJS {
|
|
|
222
230
|
listenInBatch(topics_1, groupId_1, callback_1) {
|
|
223
231
|
return __awaiter(this, arguments, void 0, function* (topics, groupId, callback, options = {
|
|
224
232
|
fromBeginning: false,
|
|
225
|
-
prefetch: 1
|
|
233
|
+
prefetch: 1,
|
|
226
234
|
}) {
|
|
227
235
|
try {
|
|
228
|
-
if (typeof callback !=
|
|
229
|
-
throw new Error(
|
|
236
|
+
if (typeof callback != 'function')
|
|
237
|
+
throw new Error('Callback must be a function');
|
|
230
238
|
this.consumer = this.connection.consumer({ groupId });
|
|
231
239
|
yield this.consumer.connect();
|
|
232
240
|
for (let topic of topics) {
|
|
@@ -236,7 +244,9 @@ class KafkaJS {
|
|
|
236
244
|
eachBatchAutoResolve: options.eachBatchAutoResolve || true,
|
|
237
245
|
partitionsConsumedConcurrently: options.prefetch,
|
|
238
246
|
eachBatch: (batchPayload) => __awaiter(this, void 0, void 0, function* () {
|
|
239
|
-
yield callback(null, batchPayload.batch.messages
|
|
247
|
+
yield callback(null, batchPayload.batch.messages
|
|
248
|
+
.map((message) => { var _a; return (_a = message === null || message === void 0 ? void 0 : message.value) === null || _a === void 0 ? void 0 : _a.toString(); })
|
|
249
|
+
.filter(Boolean), batchPayload);
|
|
240
250
|
yield batchPayload.heartbeat();
|
|
241
251
|
}),
|
|
242
252
|
});
|
|
@@ -249,7 +259,7 @@ class KafkaJS {
|
|
|
249
259
|
close() {
|
|
250
260
|
setTimeout(() => {
|
|
251
261
|
if (this.connection) {
|
|
252
|
-
console.log(
|
|
262
|
+
console.log('Closing Kafka Connection');
|
|
253
263
|
try {
|
|
254
264
|
return this.connection.close();
|
|
255
265
|
}
|