ggez-banking-sdk 0.4.22 → 0.4.24
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/dist/api/service/limited.d.ts +2 -0
- package/dist/api/service/limited.js +11 -0
- package/dist/api/service/user.d.ts +1 -0
- package/dist/api/service/user.js +6 -2
- package/dist/helper/api/axiosHelper.d.ts +5 -2
- package/dist/helper/api/axiosHelper.js +23 -11
- package/dist/helper/api/responseHelper.js +3 -8
- package/dist/types/helper/api/axiosHelper.d.ts +8 -2
- package/package.json +1 -1
|
@@ -2,7 +2,9 @@ import { BaseService } from "./base";
|
|
|
2
2
|
import type { ConfirmUserSecurity, ForgetSecurityData, ValidateLimitedSecurity, VerifyUserSecurity, LimitedServiceParameters } from "../../types";
|
|
3
3
|
declare class LimitedService extends BaseService {
|
|
4
4
|
protected endpoint: string;
|
|
5
|
+
private authService;
|
|
5
6
|
constructor(data: LimitedServiceParameters);
|
|
7
|
+
private onLimitedRequest;
|
|
6
8
|
validateSecurityData(data: ValidateLimitedSecurity): Promise<import("../..").ApiResponse<ValidateLimitedSecurity>>;
|
|
7
9
|
verifySecurityData(data: VerifyUserSecurity): Promise<import("../..").ApiResponse<VerifyUserSecurity>>;
|
|
8
10
|
confirmSecurityData(data: ConfirmUserSecurity): Promise<import("../..").ApiResponse<ConfirmUserSecurity>>;
|
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
import { Endpoints, LimitedEndpoints } from "../../constant/constant";
|
|
2
|
+
import { AxiosHelper } from "../../helper/api/axiosHelper";
|
|
3
|
+
import { AuthService } from "./auth";
|
|
2
4
|
import { BaseService } from "./base";
|
|
3
5
|
class LimitedService extends BaseService {
|
|
4
6
|
endpoint = Endpoints.Limited;
|
|
7
|
+
authService;
|
|
5
8
|
constructor(data) {
|
|
6
9
|
super(data);
|
|
10
|
+
this.authService = new AuthService(data);
|
|
11
|
+
this.axiosInstance.interceptors.request.use((req) => this.onLimitedRequest(req));
|
|
7
12
|
}
|
|
13
|
+
// #region "Interceptors Handlers"
|
|
14
|
+
async onLimitedRequest(req) {
|
|
15
|
+
await AxiosHelper.injectLimitedToken(req, this.authService, this.cookiesHelper);
|
|
16
|
+
return req;
|
|
17
|
+
}
|
|
18
|
+
// #endregion
|
|
8
19
|
// #region "POST"
|
|
9
20
|
validateSecurityData(data) {
|
|
10
21
|
const url = this.resolveURL(LimitedEndpoints.SecurityValidate);
|
|
@@ -8,6 +8,7 @@ import type { ValidateUserSecurity } from "../../types/banking/user/validateUser
|
|
|
8
8
|
import type { VerifyUserSecurity } from "../../types/banking/user/verifyUserSecurity";
|
|
9
9
|
declare class UserService extends BaseService {
|
|
10
10
|
protected endpoint: string;
|
|
11
|
+
private authService;
|
|
11
12
|
constructor(data: UserServiceParameters);
|
|
12
13
|
private userId;
|
|
13
14
|
getUser(): Promise<import("../..").ApiResponse<UserData>>;
|
package/dist/api/service/user.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { Endpoints, UserEndpoints } from "../../constant/constant";
|
|
2
|
+
import { AuthService } from "./auth";
|
|
2
3
|
import { BaseService } from "./base";
|
|
3
4
|
import { IPAddressAndLocationService } from "./ipAddressAndLocation";
|
|
4
5
|
import { AxiosHelper } from "../../helper/api/axiosHelper";
|
|
5
6
|
import { GeoHelper } from "../../helper/geoHelper";
|
|
6
7
|
class UserService extends BaseService {
|
|
7
8
|
endpoint = Endpoints.User;
|
|
9
|
+
authService;
|
|
8
10
|
constructor(data) {
|
|
9
11
|
super(data);
|
|
12
|
+
this.authService = new AuthService(data);
|
|
10
13
|
this.axiosInstance.interceptors.request.use(async (req) => {
|
|
11
14
|
const locationService = new IPAddressAndLocationService(data);
|
|
12
15
|
const geoCoordinates = await GeoHelper.getGeoCoordinates(locationService);
|
|
@@ -100,9 +103,10 @@ class UserService extends BaseService {
|
|
|
100
103
|
}
|
|
101
104
|
// #endregion
|
|
102
105
|
// #region "POST"
|
|
103
|
-
createUser(payload) {
|
|
106
|
+
async createUser(payload) {
|
|
104
107
|
const url = this.resolveURL();
|
|
105
|
-
|
|
108
|
+
const headers = await AxiosHelper.getLimitedAuthHeaders(this.authService, this.cookiesHelper);
|
|
109
|
+
return this.POST(url, payload, { headers });
|
|
106
110
|
}
|
|
107
111
|
async createPhone(payload) {
|
|
108
112
|
const url = this.resolveURL(`${UserEndpoints.Phone}/${await this.userId()}`);
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import type { InjectBaseHeaders, TAddAxiosConfigHeader, TGetAuthAxiosConfig, TGetAxiosConfig, TInjectGeoCoordinates,
|
|
1
|
+
import type { Bearer, GetLimitedAuthHeaders, GetLimitedToken, InjectBaseHeaders, InjectLimitedToken, TAddAxiosConfigHeader, TGetAuthAxiosConfig, TGetAxiosConfig, TInjectGeoCoordinates, TInjectRequest } from "../../types/helper/api/axiosHelper";
|
|
2
2
|
import type { BaseResult } from "../../types/banking/common/baseresult";
|
|
3
3
|
declare class AxiosHelper {
|
|
4
|
+
static bearer: Bearer;
|
|
4
5
|
static getAxiosConfig: TGetAxiosConfig;
|
|
5
6
|
static getAuthAxiosConfig: TGetAuthAxiosConfig;
|
|
6
7
|
static addAxiosConfigHeader: TAddAxiosConfigHeader;
|
|
7
8
|
static injectBaseHeaders: InjectBaseHeaders<BaseResult>;
|
|
8
9
|
static injectBaseBodyProperties: TInjectRequest<BaseResult | string>;
|
|
10
|
+
static getLimitedToken: GetLimitedToken;
|
|
11
|
+
static getLimitedAuthHeaders: GetLimitedAuthHeaders;
|
|
12
|
+
static injectLimitedToken: InjectLimitedToken;
|
|
9
13
|
static injectGeoCoordinates: TInjectGeoCoordinates;
|
|
10
|
-
static injectLimitedToken: TInjectLimitedToken;
|
|
11
14
|
}
|
|
12
15
|
export { AxiosHelper };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
1
|
import { generateSourceID } from "../../utils/data/generation";
|
|
3
2
|
import { DateTimeHelper } from "../dateTimeHelper";
|
|
4
3
|
import qs from "qs";
|
|
5
4
|
import { HeaderKeys } from "../../constant/constant";
|
|
6
5
|
class AxiosHelper {
|
|
6
|
+
static bearer = (token) => `Bearer ${token}`;
|
|
7
7
|
static getAxiosConfig = (token, baseURL, lang, installationId) => {
|
|
8
8
|
const config = {
|
|
9
9
|
headers: {
|
|
@@ -18,7 +18,7 @@ class AxiosHelper {
|
|
|
18
18
|
withCredentials: true,
|
|
19
19
|
};
|
|
20
20
|
if (token && config.headers) {
|
|
21
|
-
config.headers.Authorization =
|
|
21
|
+
config.headers.Authorization = AxiosHelper.bearer(token);
|
|
22
22
|
}
|
|
23
23
|
return config;
|
|
24
24
|
};
|
|
@@ -46,8 +46,9 @@ class AxiosHelper {
|
|
|
46
46
|
const userId = await cookiesHelper.getUserId();
|
|
47
47
|
const lang = context.getLang();
|
|
48
48
|
const iid = await cookiesHelper.getIID();
|
|
49
|
-
if (token)
|
|
50
|
-
req.headers.set(HeaderKeys.Authorization,
|
|
49
|
+
if (token && !req.headers.has(HeaderKeys.Authorization)) {
|
|
50
|
+
req.headers.set(HeaderKeys.Authorization, AxiosHelper.bearer(token));
|
|
51
|
+
}
|
|
51
52
|
if (userId)
|
|
52
53
|
req.headers.set(HeaderKeys.SourceID, generateSourceID(userId));
|
|
53
54
|
if (lang)
|
|
@@ -82,6 +83,24 @@ class AxiosHelper {
|
|
|
82
83
|
return req;
|
|
83
84
|
}
|
|
84
85
|
};
|
|
86
|
+
static getLimitedToken = async (authService, cookiesHelper) => {
|
|
87
|
+
const installationId = (await cookiesHelper.getIID()) ?? "";
|
|
88
|
+
const res = await authService.generateLimitedToken({ installationId });
|
|
89
|
+
return res.data?.data?.access_token ?? null;
|
|
90
|
+
};
|
|
91
|
+
static getLimitedAuthHeaders = async (authService, cookiesHelper) => {
|
|
92
|
+
const token = await AxiosHelper.getLimitedToken(authService, cookiesHelper);
|
|
93
|
+
return token
|
|
94
|
+
? { [HeaderKeys.Authorization]: AxiosHelper.bearer(token) }
|
|
95
|
+
: undefined;
|
|
96
|
+
};
|
|
97
|
+
static injectLimitedToken = async (req, authService, cookiesHelper) => {
|
|
98
|
+
const headers = await AxiosHelper.getLimitedAuthHeaders(authService, cookiesHelper);
|
|
99
|
+
if (headers) {
|
|
100
|
+
req.headers.set(HeaderKeys.Authorization, headers.Authorization);
|
|
101
|
+
}
|
|
102
|
+
return req;
|
|
103
|
+
};
|
|
85
104
|
static injectGeoCoordinates = (req, geoCoordinates) => {
|
|
86
105
|
if (req.data && typeof req.data === "object") {
|
|
87
106
|
const data = req.data;
|
|
@@ -89,12 +108,5 @@ class AxiosHelper {
|
|
|
89
108
|
}
|
|
90
109
|
return req;
|
|
91
110
|
};
|
|
92
|
-
static injectLimitedToken = async (req, nodeUrl, installationId) => {
|
|
93
|
-
const tokenRes = await axios.post(`${nodeUrl}/token/limited-token`, {
|
|
94
|
-
installationId,
|
|
95
|
-
});
|
|
96
|
-
req.headers.set("Authorization", `Bearer ${tokenRes.data.data.access_token}`);
|
|
97
|
-
return req;
|
|
98
|
-
};
|
|
99
111
|
}
|
|
100
112
|
export { AxiosHelper };
|
|
@@ -1,25 +1,20 @@
|
|
|
1
1
|
import { createDefaultBaseResult, fillResultByError } from "../../api";
|
|
2
2
|
import { HttpStatusCode } from "axios";
|
|
3
3
|
import { ResultHelper } from "./resultHelper";
|
|
4
|
+
import { SystemResponses } from "../../constant";
|
|
4
5
|
class ResponseHelper {
|
|
5
6
|
static onResponse = (res) => {
|
|
6
7
|
const defaultResult = {
|
|
7
|
-
code:
|
|
8
|
+
code: SystemResponses.Approved,
|
|
8
9
|
message: "Operation completed successfully",
|
|
9
10
|
friendly_message: "Operation completed successfully",
|
|
10
11
|
description: "Operation completed successfully",
|
|
11
12
|
};
|
|
12
|
-
if (
|
|
13
|
+
if (!res.data.result) {
|
|
13
14
|
res.data = createDefaultBaseResult({
|
|
14
15
|
result: defaultResult,
|
|
15
|
-
value: res.data,
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
|
-
else if (!res.data.result) {
|
|
19
|
-
res.data.result = createDefaultBaseResult({
|
|
20
|
-
result: defaultResult,
|
|
21
|
-
}).result;
|
|
22
|
-
}
|
|
23
18
|
return res;
|
|
24
19
|
};
|
|
25
20
|
static onError = (error) => {
|
|
@@ -2,6 +2,7 @@ import { AxiosRequestConfig, InternalAxiosRequestConfig } from "axios";
|
|
|
2
2
|
import { GeoCoordinates } from "../../banking/common";
|
|
3
3
|
import { ClientContextProvider } from "../..";
|
|
4
4
|
import { CookiesHelper } from "../../..";
|
|
5
|
+
import type { AuthService } from "../../../api/service/auth";
|
|
5
6
|
type TGetAxiosConfig = (token: string, baseURL: string, lang?: string, installationId?: string) => AxiosRequestConfig;
|
|
6
7
|
type TGetAuthAxiosConfig = (baseURL: string, lang: string, installationId: string) => AxiosRequestConfig;
|
|
7
8
|
type TAddAxiosConfigHeader = (config: AxiosRequestConfig, key: string, value: string) => void;
|
|
@@ -11,5 +12,10 @@ type InjectBaseHeaders<D> = (req: InternalAxiosRequestConfig, context: ClientCon
|
|
|
11
12
|
type TInjectGeoCoordinates = <D extends {
|
|
12
13
|
geo_coordinates: GeoCoordinates;
|
|
13
14
|
}>(req: InternalAxiosRequestConfig<D>, geoCoordinates: GeoCoordinates) => InternalAxiosRequestConfig<D>;
|
|
14
|
-
type
|
|
15
|
-
|
|
15
|
+
type InjectLimitedToken = (req: InternalAxiosRequestConfig, authService: AuthService, cookiesHelper: CookiesHelper) => Promise<InternalAxiosRequestConfig>;
|
|
16
|
+
type GetLimitedToken = (authService: AuthService, cookiesHelper: CookiesHelper) => Promise<string | null>;
|
|
17
|
+
type GetLimitedAuthHeaders = (authService: AuthService, cookiesHelper: CookiesHelper) => Promise<{
|
|
18
|
+
Authorization: string;
|
|
19
|
+
} | undefined>;
|
|
20
|
+
type Bearer = (token: string) => string;
|
|
21
|
+
export { TGetAxiosConfig, TGetAuthAxiosConfig, TAddAxiosConfigHeader, TInjectRequest, InjectBaseHeaders, InjectRequiredHeaders, TInjectGeoCoordinates, InjectLimitedToken, GetLimitedToken, GetLimitedAuthHeaders, Bearer, };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ggez-banking-sdk",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.24",
|
|
4
4
|
"description": "A Node.js package to handle GGEZ Banking API endpoints, Simplify the process of managing CRUD operations with this efficient and easy-to-use package.",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"main": "dist/index.js",
|