@movalib/movalib-commons 1.1.49 → 1.1.50

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.
@@ -1,4 +1,4 @@
1
- import { APIMethod } from "./Enums";
1
+ import { APIMethod, MovaAppType } from "./Enums";
2
2
  export declare const API_BASE_URL: string;
3
3
  export type APIResponse<T> = {
4
4
  success: boolean;
@@ -8,6 +8,7 @@ export type APIResponse<T> = {
8
8
  export type APIRequest = {
9
9
  url: string;
10
10
  method: APIMethod;
11
+ appType: MovaAppType;
11
12
  body?: string | FormData;
12
13
  };
13
14
  /**
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.request = exports.API_BASE_URL = void 0;
7
+ var Enums_1 = require("./Enums");
7
8
  var CookieUtils_1 = require("./CookieUtils");
8
9
  var Logger_1 = __importDefault(require("./Logger"));
9
10
  exports.API_BASE_URL = process.env.REACT_APP_API_URL || 'https://localhost:8443/api';
@@ -55,8 +56,17 @@ var request = function (options) {
55
56
  headers.append('Content-Type', 'application/json');
56
57
  }
57
58
  // Récupération du TOKEN depuis les cookies et intégration au header
58
- if ((0, CookieUtils_1.readCookie)(CookieUtils_1.COOKIE_GARAGE_TOKEN)) {
59
- headers.append('Authorization', 'Bearer ' + (0, CookieUtils_1.readCookie)(CookieUtils_1.COOKIE_GARAGE_TOKEN));
59
+ switch (options.appType) {
60
+ case Enums_1.MovaAppType.INDIVIDUAL:
61
+ if ((0, CookieUtils_1.readCookie)(CookieUtils_1.COOKIE_INDIVIDUAL_TOKEN)) {
62
+ headers.append('Authorization', 'Bearer ' + (0, CookieUtils_1.readCookie)(CookieUtils_1.COOKIE_INDIVIDUAL_TOKEN));
63
+ }
64
+ break;
65
+ case Enums_1.MovaAppType.GARAGE:
66
+ if ((0, CookieUtils_1.readCookie)(CookieUtils_1.COOKIE_GARAGE_TOKEN)) {
67
+ headers.append('Authorization', 'Bearer ' + (0, CookieUtils_1.readCookie)(CookieUtils_1.COOKIE_GARAGE_TOKEN));
68
+ }
69
+ break;
60
70
  }
61
71
  // On intègre les headers aux options
62
72
  var defaults = { headers: headers };
@@ -70,6 +70,7 @@ var AuthenticationService = /** @class */ (function () {
70
70
  return [4 /*yield*/, (0, ApiHelper_1.request)({
71
71
  url: url,
72
72
  method: Enums_1.APIMethod.POST,
73
+ appType: appType,
73
74
  body: JSON.stringify({
74
75
  email: email,
75
76
  password: password
@@ -9,6 +9,7 @@ var GarageService = /** @class */ (function () {
9
9
  return (0, ApiHelper_1.request)({
10
10
  url: "".concat(ApiHelper_1.API_BASE_URL, "/garage/").concat(garageId, "/event/").concat(eventId, "/quote"),
11
11
  method: Enums_1.APIMethod.PATCH,
12
+ appType: Enums_1.MovaAppType.GARAGE,
12
13
  body: formData
13
14
  });
14
15
  };
@@ -16,6 +17,7 @@ var GarageService = /** @class */ (function () {
16
17
  return (0, ApiHelper_1.request)({
17
18
  url: "".concat(ApiHelper_1.API_BASE_URL, "/garage/").concat(garageId, "/event/").concat(eventId, "/customer-reminder"),
18
19
  method: Enums_1.APIMethod.POST,
20
+ appType: Enums_1.MovaAppType.GARAGE,
19
21
  body: message
20
22
  });
21
23
  };
@@ -23,6 +25,7 @@ var GarageService = /** @class */ (function () {
23
25
  return (0, ApiHelper_1.request)({
24
26
  url: "".concat(ApiHelper_1.API_BASE_URL, "/garage/").concat(garageId, "/event/").concat(eventId),
25
27
  method: Enums_1.APIMethod.PATCH,
28
+ appType: Enums_1.MovaAppType.GARAGE,
26
29
  body: JSON.stringify(req)
27
30
  });
28
31
  };
@@ -30,19 +33,22 @@ var GarageService = /** @class */ (function () {
30
33
  return (0, ApiHelper_1.request)({
31
34
  url: "".concat(ApiHelper_1.API_BASE_URL, "/garage/").concat(garageId, "/events/").concat(eventId, "/supplierRequest"),
32
35
  method: Enums_1.APIMethod.POST,
36
+ appType: Enums_1.MovaAppType.GARAGE,
33
37
  body: JSON.stringify(req)
34
38
  });
35
39
  };
36
40
  GarageService.deleteGarageSupplier = function (garageId, supplierId) {
37
41
  return (0, ApiHelper_1.request)({
38
42
  url: "".concat(ApiHelper_1.API_BASE_URL, "/garage/").concat(garageId, "/suppliers/").concat(supplierId),
39
- method: Enums_1.APIMethod.DELETE
43
+ method: Enums_1.APIMethod.DELETE,
44
+ appType: Enums_1.MovaAppType.GARAGE
40
45
  });
41
46
  };
42
47
  GarageService.createGarageSupplier = function (garageId, req) {
43
48
  return (0, ApiHelper_1.request)({
44
49
  url: "".concat(ApiHelper_1.API_BASE_URL, "/garage/").concat(garageId, "/suppliers"),
45
50
  method: Enums_1.APIMethod.POST,
51
+ appType: Enums_1.MovaAppType.GARAGE,
46
52
  body: JSON.stringify(req)
47
53
  });
48
54
  };
@@ -50,6 +56,7 @@ var GarageService = /** @class */ (function () {
50
56
  return (0, ApiHelper_1.request)({
51
57
  url: "".concat(ApiHelper_1.API_BASE_URL, "/garage/").concat(garageId),
52
58
  method: Enums_1.APIMethod.PATCH,
59
+ appType: Enums_1.MovaAppType.GARAGE,
53
60
  body: JSON.stringify(req)
54
61
  });
55
62
  };
@@ -57,6 +64,7 @@ var GarageService = /** @class */ (function () {
57
64
  return (0, ApiHelper_1.request)({
58
65
  url: "".concat(ApiHelper_1.API_BASE_URL, "/user/garages"),
59
66
  method: Enums_1.APIMethod.GET,
67
+ appType: Enums_1.MovaAppType.GARAGE
60
68
  });
61
69
  };
62
70
  return GarageService;
@@ -49,6 +49,7 @@ var UserService = /** @class */ (function () {
49
49
  return (0, ApiHelper_1.request)({
50
50
  url: "".concat(ApiHelper_1.API_BASE_URL, "/user/validate-account"),
51
51
  method: Enums_1.APIMethod.POST,
52
+ appType: Enums_1.MovaAppType.INDIVIDUAL,
52
53
  body: JSON.stringify(req)
53
54
  });
54
55
  };
@@ -66,7 +67,8 @@ var UserService = /** @class */ (function () {
66
67
  _a.trys.push([0, 2, , 3]);
67
68
  return [4 /*yield*/, (0, ApiHelper_1.request)({
68
69
  url: "".concat(ApiHelper_1.API_BASE_URL, "/user/me"),
69
- method: Enums_1.APIMethod.GET
70
+ method: Enums_1.APIMethod.GET,
71
+ appType: Enums_1.MovaAppType.INDIVIDUAL
70
72
  })];
71
73
  case 1: return [2 /*return*/, _a.sent()];
72
74
  case 2:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@movalib/movalib-commons",
3
- "version": "1.1.49",
3
+ "version": "1.1.50",
4
4
  "description": "Bibliothèque d'objets communs à l'ensemble des projets React de Movalib",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,5 +1,5 @@
1
- import { APIMethod } from "./Enums";
2
- import { COOKIE_GARAGE_TOKEN, readCookie } from "./CookieUtils";
1
+ import { APIMethod, MovaAppType } from "./Enums";
2
+ import { COOKIE_GARAGE_TOKEN, COOKIE_INDIVIDUAL_TOKEN, readCookie } from "./CookieUtils";
3
3
  import Logger from "./Logger";
4
4
  import { useHistory } from "react-router-dom";
5
5
 
@@ -14,6 +14,7 @@ export type APIResponse<T> = {
14
14
  export type APIRequest = {
15
15
  url: string,
16
16
  method: APIMethod,
17
+ appType: MovaAppType,
17
18
  body?: string | FormData
18
19
  }
19
20
 
@@ -75,8 +76,18 @@ export const request = (options:APIRequest): Promise<APIResponse<any>> => {
75
76
  }
76
77
 
77
78
  // Récupération du TOKEN depuis les cookies et intégration au header
78
- if(readCookie(COOKIE_GARAGE_TOKEN)) {
79
- headers.append('Authorization', 'Bearer ' + readCookie(COOKIE_GARAGE_TOKEN))
79
+ switch(options.appType){
80
+ case MovaAppType.INDIVIDUAL:
81
+ if(readCookie(COOKIE_INDIVIDUAL_TOKEN)) {
82
+ headers.append('Authorization', 'Bearer ' + readCookie(COOKIE_INDIVIDUAL_TOKEN))
83
+ }
84
+ break;
85
+
86
+ case MovaAppType.GARAGE:
87
+ if(readCookie(COOKIE_GARAGE_TOKEN)) {
88
+ headers.append('Authorization', 'Bearer ' + readCookie(COOKIE_GARAGE_TOKEN))
89
+ }
90
+ break;
80
91
  }
81
92
 
82
93
  // On intègre les headers aux options
@@ -30,6 +30,7 @@ export default class AuthenticationService {
30
30
  let tokenResponse = await request({
31
31
  url: url,
32
32
  method: APIMethod.POST,
33
+ appType: appType,
33
34
  body: JSON.stringify({
34
35
  email : email,
35
36
  password: password
@@ -1,5 +1,5 @@
1
1
  import { APIResponse, API_BASE_URL, request } from "../helpers/ApiHelper";
2
- import { APIMethod } from "../helpers/Enums";
2
+ import { APIMethod, MovaAppType } from "../helpers/Enums";
3
3
  import Garage from "../models/Garage";
4
4
 
5
5
  export default class GarageService {
@@ -8,6 +8,7 @@ export default class GarageService {
8
8
  return request({
9
9
  url: `${API_BASE_URL}/garage/${garageId}/event/${eventId}/quote`,
10
10
  method: APIMethod.PATCH,
11
+ appType: MovaAppType.GARAGE,
11
12
  body: formData
12
13
  });
13
14
  }
@@ -17,6 +18,7 @@ export default class GarageService {
17
18
  return request({
18
19
  url: `${API_BASE_URL}/garage/${garageId}/event/${eventId}/customer-reminder`,
19
20
  method: APIMethod.POST,
21
+ appType: MovaAppType.GARAGE,
20
22
  body: message
21
23
  });
22
24
  }
@@ -26,6 +28,7 @@ export default class GarageService {
26
28
  return request({
27
29
  url: `${API_BASE_URL}/garage/${garageId}/event/${eventId}`,
28
30
  method: APIMethod.PATCH,
31
+ appType: MovaAppType.GARAGE,
29
32
  body: JSON.stringify(req)
30
33
  });
31
34
  }
@@ -34,6 +37,7 @@ export default class GarageService {
34
37
  return request({
35
38
  url: `${API_BASE_URL}/garage/${garageId}/events/${eventId}/supplierRequest`,
36
39
  method: APIMethod.POST,
40
+ appType: MovaAppType.GARAGE,
37
41
  body: JSON.stringify(req)
38
42
  });
39
43
  }
@@ -41,7 +45,8 @@ export default class GarageService {
41
45
  static deleteGarageSupplier(garageId: string, supplierId: string): Promise<APIResponse<string>> {
42
46
  return request({
43
47
  url: `${API_BASE_URL}/garage/${garageId}/suppliers/${supplierId}`,
44
- method: APIMethod.DELETE
48
+ method: APIMethod.DELETE,
49
+ appType: MovaAppType.GARAGE
45
50
  });
46
51
  }
47
52
 
@@ -49,6 +54,7 @@ export default class GarageService {
49
54
  return request({
50
55
  url: `${API_BASE_URL}/garage/${garageId}/suppliers`,
51
56
  method: APIMethod.POST,
57
+ appType: MovaAppType.GARAGE,
52
58
  body: JSON.stringify(req)
53
59
  });
54
60
  }
@@ -57,6 +63,7 @@ export default class GarageService {
57
63
  return request({
58
64
  url: `${API_BASE_URL}/garage/${garageId}`,
59
65
  method: APIMethod.PATCH,
66
+ appType: MovaAppType.GARAGE,
60
67
  body: JSON.stringify(req)
61
68
  });
62
69
  }
@@ -65,6 +72,7 @@ export default class GarageService {
65
72
  return request({
66
73
  url: `${API_BASE_URL}/user/garages`,
67
74
  method: APIMethod.GET,
75
+ appType: MovaAppType.GARAGE
68
76
  });
69
77
  }
70
78
 
@@ -1,5 +1,5 @@
1
1
  import { APIResponse, API_BASE_URL, request } from "../helpers/ApiHelper";
2
- import { APIMethod } from "../helpers/Enums";
2
+ import { APIMethod, MovaAppType } from "../helpers/Enums";
3
3
  import Logger from "../helpers/Logger";
4
4
  import User from "../models/User";
5
5
 
@@ -9,6 +9,7 @@ export default class UserService {
9
9
  return request({
10
10
  url: `${API_BASE_URL}/user/validate-account`,
11
11
  method: APIMethod.POST,
12
+ appType: MovaAppType.INDIVIDUAL,
12
13
  body: JSON.stringify(req)
13
14
  });
14
15
  }
@@ -22,7 +23,8 @@ export default class UserService {
22
23
  try {
23
24
  return await request({
24
25
  url: `${API_BASE_URL}/user/me`,
25
- method: APIMethod.GET
26
+ method: APIMethod.GET,
27
+ appType: MovaAppType.INDIVIDUAL
26
28
  });
27
29
  } catch (error) {
28
30
  Logger.error('Error occurred during getting user:', error);