ggez-banking-sdk 0.4.23 → 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.
@@ -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>>;
@@ -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
- return this.POST(url, payload);
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,11 +1,14 @@
1
- import type { InjectBaseHeaders, InjectLimitedToken, TAddAxiosConfigHeader, TGetAuthAxiosConfig, TGetAxiosConfig, TInjectGeoCoordinates, TInjectRequest } from "../../types/helper/api/axiosHelper";
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;
9
12
  static injectLimitedToken: InjectLimitedToken;
10
13
  static injectGeoCoordinates: TInjectGeoCoordinates;
11
14
  }
@@ -3,6 +3,7 @@ import { DateTimeHelper } from "../dateTimeHelper";
3
3
  import qs from "qs";
4
4
  import { HeaderKeys } from "../../constant/constant";
5
5
  class AxiosHelper {
6
+ static bearer = (token) => `Bearer ${token}`;
6
7
  static getAxiosConfig = (token, baseURL, lang, installationId) => {
7
8
  const config = {
8
9
  headers: {
@@ -17,7 +18,7 @@ class AxiosHelper {
17
18
  withCredentials: true,
18
19
  };
19
20
  if (token && config.headers) {
20
- config.headers.Authorization = `Bearer ${token}`;
21
+ config.headers.Authorization = AxiosHelper.bearer(token);
21
22
  }
22
23
  return config;
23
24
  };
@@ -46,7 +47,7 @@ class AxiosHelper {
46
47
  const lang = context.getLang();
47
48
  const iid = await cookiesHelper.getIID();
48
49
  if (token && !req.headers.has(HeaderKeys.Authorization)) {
49
- req.headers.set(HeaderKeys.Authorization, `Bearer ${token}`);
50
+ req.headers.set(HeaderKeys.Authorization, AxiosHelper.bearer(token));
50
51
  }
51
52
  if (userId)
52
53
  req.headers.set(HeaderKeys.SourceID, generateSourceID(userId));
@@ -82,12 +83,22 @@ class AxiosHelper {
82
83
  return req;
83
84
  }
84
85
  };
85
- static injectLimitedToken = async (req, authService, cookiesHelper) => {
86
+ static getLimitedToken = async (authService, cookiesHelper) => {
86
87
  const installationId = (await cookiesHelper.getIID()) ?? "";
87
88
  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}`);
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
+ }
91
102
  return req;
92
103
  };
93
104
  static injectGeoCoordinates = (req, geoCoordinates) => {
@@ -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: "0000",
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 (typeof res.data !== "object" || res.data === null) {
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) => {
@@ -13,4 +13,9 @@ type TInjectGeoCoordinates = <D extends {
13
13
  geo_coordinates: GeoCoordinates;
14
14
  }>(req: InternalAxiosRequestConfig<D>, geoCoordinates: GeoCoordinates) => InternalAxiosRequestConfig<D>;
15
15
  type InjectLimitedToken = (req: InternalAxiosRequestConfig, authService: AuthService, cookiesHelper: CookiesHelper) => Promise<InternalAxiosRequestConfig>;
16
- export { TGetAxiosConfig, TGetAuthAxiosConfig, TAddAxiosConfigHeader, TInjectRequest, InjectBaseHeaders, InjectRequiredHeaders, TInjectGeoCoordinates, InjectLimitedToken, };
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.23",
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",