ggez-banking-sdk 0.4.22 → 0.4.23

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.
@@ -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);
@@ -1,4 +1,4 @@
1
- import type { InjectBaseHeaders, TAddAxiosConfigHeader, TGetAuthAxiosConfig, TGetAxiosConfig, TInjectGeoCoordinates, TInjectLimitedToken, TInjectRequest } from "../../types/helper/api/axiosHelper";
1
+ import type { 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
4
  static getAxiosConfig: TGetAxiosConfig;
@@ -6,7 +6,7 @@ declare class AxiosHelper {
6
6
  static addAxiosConfigHeader: TAddAxiosConfigHeader;
7
7
  static injectBaseHeaders: InjectBaseHeaders<BaseResult>;
8
8
  static injectBaseBodyProperties: TInjectRequest<BaseResult | string>;
9
+ static injectLimitedToken: InjectLimitedToken;
9
10
  static injectGeoCoordinates: TInjectGeoCoordinates;
10
- static injectLimitedToken: TInjectLimitedToken;
11
11
  }
12
12
  export { AxiosHelper };
@@ -1,4 +1,3 @@
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";
@@ -46,8 +45,9 @@ class AxiosHelper {
46
45
  const userId = await cookiesHelper.getUserId();
47
46
  const lang = context.getLang();
48
47
  const iid = await cookiesHelper.getIID();
49
- if (token)
48
+ if (token && !req.headers.has(HeaderKeys.Authorization)) {
50
49
  req.headers.set(HeaderKeys.Authorization, `Bearer ${token}`);
50
+ }
51
51
  if (userId)
52
52
  req.headers.set(HeaderKeys.SourceID, generateSourceID(userId));
53
53
  if (lang)
@@ -82,6 +82,14 @@ class AxiosHelper {
82
82
  return req;
83
83
  }
84
84
  };
85
+ static injectLimitedToken = async (req, authService, cookiesHelper) => {
86
+ const installationId = (await cookiesHelper.getIID()) ?? "";
87
+ const res = await authService.generateLimitedToken({ installationId });
88
+ const token = res.data?.data?.access_token;
89
+ if (token)
90
+ req.headers.set(HeaderKeys.Authorization, `Bearer ${token}`);
91
+ return req;
92
+ };
85
93
  static injectGeoCoordinates = (req, geoCoordinates) => {
86
94
  if (req.data && typeof req.data === "object") {
87
95
  const data = req.data;
@@ -89,12 +97,5 @@ class AxiosHelper {
89
97
  }
90
98
  return req;
91
99
  };
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
100
  }
100
101
  export { AxiosHelper };
@@ -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,5 @@ 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 TInjectLimitedToken = (req: InternalAxiosRequestConfig, nodeUrl: string, installationId?: string) => Promise<InternalAxiosRequestConfig>;
15
- export { TGetAxiosConfig, TGetAuthAxiosConfig, TAddAxiosConfigHeader, TInjectRequest, InjectBaseHeaders, InjectRequiredHeaders, TInjectGeoCoordinates, TInjectLimitedToken, };
15
+ type InjectLimitedToken = (req: InternalAxiosRequestConfig, authService: AuthService, cookiesHelper: CookiesHelper) => Promise<InternalAxiosRequestConfig>;
16
+ export { TGetAxiosConfig, TGetAuthAxiosConfig, TAddAxiosConfigHeader, TInjectRequest, InjectBaseHeaders, InjectRequiredHeaders, TInjectGeoCoordinates, InjectLimitedToken, };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ggez-banking-sdk",
3
- "version": "0.4.22",
3
+ "version": "0.4.23",
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",