@konplit-services/common 1.0.262 → 1.0.264
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/build/app.configs.d.ts +101 -0
- package/build/helper/transaction-type.d.ts +2 -1
- package/build/helper/transaction-type.js +1 -0
- package/build/middlewares/current-user.js +1 -1
- package/build/middlewares/transaction-session.d.ts +10 -0
- package/build/middlewares/transaction-session.js +36 -0
- package/build/services/Jwt.d.ts +13 -1
- package/build/services/Jwt.js +17 -0
- package/package.json +1 -1
package/build/app.configs.d.ts
CHANGED
|
@@ -21,6 +21,107 @@ interface EmailTemplate {
|
|
|
21
21
|
user_account_created: string;
|
|
22
22
|
user_invited: string;
|
|
23
23
|
}
|
|
24
|
+
export interface WelcomeEmail {
|
|
25
|
+
user_email: string;
|
|
26
|
+
first_name: string;
|
|
27
|
+
last_name: string;
|
|
28
|
+
}
|
|
29
|
+
export interface ForgotPasswordEmail {
|
|
30
|
+
user_email: string;
|
|
31
|
+
first_name: string;
|
|
32
|
+
token: string;
|
|
33
|
+
support_email: string;
|
|
34
|
+
account_name: string;
|
|
35
|
+
}
|
|
36
|
+
export interface UserInvitationEmail {
|
|
37
|
+
user_email: string;
|
|
38
|
+
merchant_name: string;
|
|
39
|
+
url: string;
|
|
40
|
+
}
|
|
41
|
+
export interface AdminUserAddedEmail {
|
|
42
|
+
user_email: string;
|
|
43
|
+
first_name: string;
|
|
44
|
+
password_reset_url: string;
|
|
45
|
+
}
|
|
46
|
+
export interface TwoFA_AuthenticationEmail {
|
|
47
|
+
status: string;
|
|
48
|
+
user_email: string;
|
|
49
|
+
}
|
|
50
|
+
export interface TokenVerification {
|
|
51
|
+
user_email: string;
|
|
52
|
+
token: string;
|
|
53
|
+
}
|
|
54
|
+
export interface PaymentLinkEmail {
|
|
55
|
+
user_email: string;
|
|
56
|
+
payment_url: string;
|
|
57
|
+
note: string;
|
|
58
|
+
}
|
|
59
|
+
export interface PasswordChangeConfirmation {
|
|
60
|
+
user_email: string;
|
|
61
|
+
merchant_name: string;
|
|
62
|
+
support_email: string;
|
|
63
|
+
support_phone: string;
|
|
64
|
+
ceo_name: string;
|
|
65
|
+
}
|
|
66
|
+
export interface Invoice {
|
|
67
|
+
user_email: string;
|
|
68
|
+
business_name: string;
|
|
69
|
+
business_logo: string;
|
|
70
|
+
business_support_email: string;
|
|
71
|
+
customer_name: string;
|
|
72
|
+
total_amount: string;
|
|
73
|
+
due_date: string;
|
|
74
|
+
created_date: string;
|
|
75
|
+
invoice_id: string;
|
|
76
|
+
invoice_payment_url: string;
|
|
77
|
+
description: string;
|
|
78
|
+
quantity: string;
|
|
79
|
+
unit_price: string;
|
|
80
|
+
amount: string;
|
|
81
|
+
discount: string;
|
|
82
|
+
tax: string;
|
|
83
|
+
shipping: string;
|
|
84
|
+
subtotal: string;
|
|
85
|
+
note: string;
|
|
86
|
+
items: Record<string, any>[];
|
|
87
|
+
}
|
|
88
|
+
export interface RegistrationConfirmation {
|
|
89
|
+
user_email: string;
|
|
90
|
+
support_phone: string;
|
|
91
|
+
ceo_name: string;
|
|
92
|
+
support_email: string;
|
|
93
|
+
merchant_name: string;
|
|
94
|
+
}
|
|
95
|
+
export interface TransactionDetailsMerchant {
|
|
96
|
+
user_email: string;
|
|
97
|
+
customer_email: string;
|
|
98
|
+
amount: string;
|
|
99
|
+
reference: string;
|
|
100
|
+
date: string;
|
|
101
|
+
channel: string;
|
|
102
|
+
merchant_dashboard_url: string;
|
|
103
|
+
}
|
|
104
|
+
export interface TransactionDetailsCustomer {
|
|
105
|
+
user_email: string;
|
|
106
|
+
business_name: string;
|
|
107
|
+
business_support_email: string;
|
|
108
|
+
amount: string;
|
|
109
|
+
reference: string;
|
|
110
|
+
date: string;
|
|
111
|
+
channel: string;
|
|
112
|
+
}
|
|
113
|
+
export interface PasswordReset {
|
|
114
|
+
user_email: string;
|
|
115
|
+
name: string;
|
|
116
|
+
token: string;
|
|
117
|
+
support_email: string;
|
|
118
|
+
business_name: string;
|
|
119
|
+
}
|
|
120
|
+
export interface ConfirmationToken {
|
|
121
|
+
user_email: string;
|
|
122
|
+
token: string;
|
|
123
|
+
support_email: string;
|
|
124
|
+
}
|
|
24
125
|
interface Interswitch {
|
|
25
126
|
merchant_id: string;
|
|
26
127
|
pay_item_id: string;
|
|
@@ -9,7 +9,8 @@ export declare enum TRANSACTION_STATUS {
|
|
|
9
9
|
}
|
|
10
10
|
export declare enum TRANSACTION_TYPE {
|
|
11
11
|
request = "request",
|
|
12
|
-
paymentLink = "paymentLink"
|
|
12
|
+
paymentLink = "paymentLink",
|
|
13
|
+
default = "default"
|
|
13
14
|
}
|
|
14
15
|
export declare enum TRANSACTION_TYPES {
|
|
15
16
|
UPDATE_TRANSACTION_STATUS = "UPDATE_TRANSACTION_STATUS",
|
|
@@ -15,6 +15,7 @@ var TRANSACTION_TYPE;
|
|
|
15
15
|
(function (TRANSACTION_TYPE) {
|
|
16
16
|
TRANSACTION_TYPE["request"] = "request";
|
|
17
17
|
TRANSACTION_TYPE["paymentLink"] = "paymentLink";
|
|
18
|
+
TRANSACTION_TYPE["default"] = "default";
|
|
18
19
|
})(TRANSACTION_TYPE = exports.TRANSACTION_TYPE || (exports.TRANSACTION_TYPE = {}));
|
|
19
20
|
var TRANSACTION_TYPES;
|
|
20
21
|
(function (TRANSACTION_TYPES) {
|
|
@@ -36,7 +36,7 @@ const currentUser = (req, res, next) => __awaiter(void 0, void 0, void 0, functi
|
|
|
36
36
|
}
|
|
37
37
|
catch (error) {
|
|
38
38
|
if (app_configs_1.appConfigs.getNODE_ENV() !== "production") {
|
|
39
|
-
console.log(
|
|
39
|
+
console.log("failed to process jwt token");
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
next();
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { NextFunction, Request, Response } from "express";
|
|
2
|
+
import { TRANSACTION_JWT_DATA } from "../services/Jwt";
|
|
3
|
+
declare global {
|
|
4
|
+
namespace Express {
|
|
5
|
+
interface Request {
|
|
6
|
+
transactionData: TRANSACTION_JWT_DATA;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export declare const validateTransactionSession: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
@@ -0,0 +1,36 @@
|
|
|
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.validateTransactionSession = void 0;
|
|
13
|
+
const Jwt_1 = require("../services/Jwt");
|
|
14
|
+
const notAuthorized_1 = require("../errors/notAuthorized");
|
|
15
|
+
const error_codes_1 = require("../helper/errorCodes/error-codes");
|
|
16
|
+
const app_configs_1 = require("../app.configs");
|
|
17
|
+
const validateTransactionSession = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
if (!req.headers["k-session"]) {
|
|
19
|
+
throw new notAuthorized_1.NotAuthorizedError("session token not provided", error_codes_1.error_codes.INVALID_AUTHORIZATION);
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
if (req.headers["k-session"]) {
|
|
23
|
+
const token = req.headers["k-session"];
|
|
24
|
+
const payload = yield Jwt_1.JWT.verifyTransactionToken(token);
|
|
25
|
+
req.transactionData = payload;
|
|
26
|
+
}
|
|
27
|
+
return next();
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
if (app_configs_1.appConfigs.getNODE_ENV() !== "production") {
|
|
31
|
+
console.log("failed to process transaction token");
|
|
32
|
+
}
|
|
33
|
+
throw new notAuthorized_1.NotAuthorizedError("Invalid transaction session pleas restart the process again", error_codes_1.error_codes.INVALID_AUTHORIZATION);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
exports.validateTransactionSession = validateTransactionSession;
|
package/build/services/Jwt.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SignOptions } from "jsonwebtoken";
|
|
2
|
-
import { USER_TYPES } from "../helper";
|
|
2
|
+
import { Usage, USER_TYPES } from "../helper";
|
|
3
3
|
export declare enum JWTType {
|
|
4
4
|
REFRESH = "REFRESH",
|
|
5
5
|
ACCESS = "ACCESS"
|
|
@@ -15,7 +15,19 @@ export interface JWT_Data {
|
|
|
15
15
|
iat?: string;
|
|
16
16
|
exp?: number;
|
|
17
17
|
}
|
|
18
|
+
export interface TRANSACTION_JWT_DATA {
|
|
19
|
+
id: string;
|
|
20
|
+
transactionRef: string;
|
|
21
|
+
accountId: string;
|
|
22
|
+
merchantId: string;
|
|
23
|
+
amount: number;
|
|
24
|
+
usage: Usage;
|
|
25
|
+
iat?: string;
|
|
26
|
+
exp?: number;
|
|
27
|
+
}
|
|
18
28
|
export declare class JWT {
|
|
19
29
|
static getToken(data: JWT_Data, options?: SignOptions): Promise<string>;
|
|
20
30
|
static verifyToken(token: string): Promise<JWT_Data>;
|
|
31
|
+
static getTransactionToken(data: TRANSACTION_JWT_DATA, options?: SignOptions): Promise<string>;
|
|
32
|
+
static verifyTransactionToken(token: string): Promise<TRANSACTION_JWT_DATA>;
|
|
21
33
|
}
|
package/build/services/Jwt.js
CHANGED
|
@@ -22,6 +22,7 @@ var JWTType;
|
|
|
22
22
|
JWTType["ACCESS"] = "ACCESS";
|
|
23
23
|
})(JWTType = exports.JWTType || (exports.JWTType = {}));
|
|
24
24
|
const secret = process.env.JWT_KEY;
|
|
25
|
+
const transactionSecret = process.env.TRANSACTION_JWT_KEY;
|
|
25
26
|
class JWT {
|
|
26
27
|
static getToken(data, options = {}) {
|
|
27
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -39,5 +40,21 @@ class JWT {
|
|
|
39
40
|
});
|
|
40
41
|
});
|
|
41
42
|
}
|
|
43
|
+
static getTransactionToken(data, options = {}) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
return signAsync(data, transactionSecret, options);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
static verifyTransactionToken(token) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
return new Promise((resolve, reject) => {
|
|
51
|
+
jsonwebtoken_1.default.verify(token, transactionSecret, function (err, decoded) {
|
|
52
|
+
if (err)
|
|
53
|
+
reject(err);
|
|
54
|
+
resolve(decoded);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
}
|
|
42
59
|
}
|
|
43
60
|
exports.JWT = JWT;
|