@movalib/movalib-commons 1.1.49 → 1.1.51

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
@@ -1,6 +1,7 @@
1
1
  import { APIResponse } from "../helpers/ApiHelper";
2
2
  import Garage from "../models/Garage";
3
3
  export default class GarageService {
4
+ static salesSignUp(req: any): Promise<APIResponse<string>>;
4
5
  static sendNewEventQuote(garageId: string, eventId: string, formData: FormData): Promise<APIResponse<string>>;
5
6
  static sendCustomerReminder(garageId: string, eventId: string, message: string): Promise<APIResponse<string>>;
6
7
  static updateGarageEvent(garageId: string, eventId: string, req: any): Promise<APIResponse<string>>;
@@ -5,10 +5,19 @@ var Enums_1 = require("../helpers/Enums");
5
5
  var GarageService = /** @class */ (function () {
6
6
  function GarageService() {
7
7
  }
8
+ GarageService.salesSignUp = function (req) {
9
+ return (0, ApiHelper_1.request)({
10
+ url: "".concat(ApiHelper_1.API_BASE_URL, "/garage/sales-signup"),
11
+ method: Enums_1.APIMethod.POST,
12
+ appType: Enums_1.MovaAppType.INDIVIDUAL,
13
+ body: JSON.stringify(req)
14
+ });
15
+ };
8
16
  GarageService.sendNewEventQuote = function (garageId, eventId, formData) {
9
17
  return (0, ApiHelper_1.request)({
10
18
  url: "".concat(ApiHelper_1.API_BASE_URL, "/garage/").concat(garageId, "/event/").concat(eventId, "/quote"),
11
19
  method: Enums_1.APIMethod.PATCH,
20
+ appType: Enums_1.MovaAppType.GARAGE,
12
21
  body: formData
13
22
  });
14
23
  };
@@ -16,6 +25,7 @@ var GarageService = /** @class */ (function () {
16
25
  return (0, ApiHelper_1.request)({
17
26
  url: "".concat(ApiHelper_1.API_BASE_URL, "/garage/").concat(garageId, "/event/").concat(eventId, "/customer-reminder"),
18
27
  method: Enums_1.APIMethod.POST,
28
+ appType: Enums_1.MovaAppType.GARAGE,
19
29
  body: message
20
30
  });
21
31
  };
@@ -23,6 +33,7 @@ var GarageService = /** @class */ (function () {
23
33
  return (0, ApiHelper_1.request)({
24
34
  url: "".concat(ApiHelper_1.API_BASE_URL, "/garage/").concat(garageId, "/event/").concat(eventId),
25
35
  method: Enums_1.APIMethod.PATCH,
36
+ appType: Enums_1.MovaAppType.GARAGE,
26
37
  body: JSON.stringify(req)
27
38
  });
28
39
  };
@@ -30,19 +41,22 @@ var GarageService = /** @class */ (function () {
30
41
  return (0, ApiHelper_1.request)({
31
42
  url: "".concat(ApiHelper_1.API_BASE_URL, "/garage/").concat(garageId, "/events/").concat(eventId, "/supplierRequest"),
32
43
  method: Enums_1.APIMethod.POST,
44
+ appType: Enums_1.MovaAppType.GARAGE,
33
45
  body: JSON.stringify(req)
34
46
  });
35
47
  };
36
48
  GarageService.deleteGarageSupplier = function (garageId, supplierId) {
37
49
  return (0, ApiHelper_1.request)({
38
50
  url: "".concat(ApiHelper_1.API_BASE_URL, "/garage/").concat(garageId, "/suppliers/").concat(supplierId),
39
- method: Enums_1.APIMethod.DELETE
51
+ method: Enums_1.APIMethod.DELETE,
52
+ appType: Enums_1.MovaAppType.GARAGE
40
53
  });
41
54
  };
42
55
  GarageService.createGarageSupplier = function (garageId, req) {
43
56
  return (0, ApiHelper_1.request)({
44
57
  url: "".concat(ApiHelper_1.API_BASE_URL, "/garage/").concat(garageId, "/suppliers"),
45
58
  method: Enums_1.APIMethod.POST,
59
+ appType: Enums_1.MovaAppType.GARAGE,
46
60
  body: JSON.stringify(req)
47
61
  });
48
62
  };
@@ -50,6 +64,7 @@ var GarageService = /** @class */ (function () {
50
64
  return (0, ApiHelper_1.request)({
51
65
  url: "".concat(ApiHelper_1.API_BASE_URL, "/garage/").concat(garageId),
52
66
  method: Enums_1.APIMethod.PATCH,
67
+ appType: Enums_1.MovaAppType.GARAGE,
53
68
  body: JSON.stringify(req)
54
69
  });
55
70
  };
@@ -57,6 +72,7 @@ var GarageService = /** @class */ (function () {
57
72
  return (0, ApiHelper_1.request)({
58
73
  url: "".concat(ApiHelper_1.API_BASE_URL, "/user/garages"),
59
74
  method: Enums_1.APIMethod.GET,
75
+ appType: Enums_1.MovaAppType.GARAGE
60
76
  });
61
77
  };
62
78
  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.51",
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,13 +1,23 @@
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 {
6
6
 
7
+ static salesSignUp(req: any): Promise<APIResponse<string>> {
8
+ return request({
9
+ url: `${API_BASE_URL}/garage/sales-signup`,
10
+ method: APIMethod.POST,
11
+ appType: MovaAppType.INDIVIDUAL,
12
+ body: JSON.stringify(req)
13
+ });
14
+ }
15
+
7
16
  static sendNewEventQuote(garageId: string, eventId: string, formData: FormData): Promise<APIResponse<string>> {
8
17
  return request({
9
18
  url: `${API_BASE_URL}/garage/${garageId}/event/${eventId}/quote`,
10
19
  method: APIMethod.PATCH,
20
+ appType: MovaAppType.GARAGE,
11
21
  body: formData
12
22
  });
13
23
  }
@@ -17,6 +27,7 @@ export default class GarageService {
17
27
  return request({
18
28
  url: `${API_BASE_URL}/garage/${garageId}/event/${eventId}/customer-reminder`,
19
29
  method: APIMethod.POST,
30
+ appType: MovaAppType.GARAGE,
20
31
  body: message
21
32
  });
22
33
  }
@@ -26,6 +37,7 @@ export default class GarageService {
26
37
  return request({
27
38
  url: `${API_BASE_URL}/garage/${garageId}/event/${eventId}`,
28
39
  method: APIMethod.PATCH,
40
+ appType: MovaAppType.GARAGE,
29
41
  body: JSON.stringify(req)
30
42
  });
31
43
  }
@@ -34,6 +46,7 @@ export default class GarageService {
34
46
  return request({
35
47
  url: `${API_BASE_URL}/garage/${garageId}/events/${eventId}/supplierRequest`,
36
48
  method: APIMethod.POST,
49
+ appType: MovaAppType.GARAGE,
37
50
  body: JSON.stringify(req)
38
51
  });
39
52
  }
@@ -41,7 +54,8 @@ export default class GarageService {
41
54
  static deleteGarageSupplier(garageId: string, supplierId: string): Promise<APIResponse<string>> {
42
55
  return request({
43
56
  url: `${API_BASE_URL}/garage/${garageId}/suppliers/${supplierId}`,
44
- method: APIMethod.DELETE
57
+ method: APIMethod.DELETE,
58
+ appType: MovaAppType.GARAGE
45
59
  });
46
60
  }
47
61
 
@@ -49,6 +63,7 @@ export default class GarageService {
49
63
  return request({
50
64
  url: `${API_BASE_URL}/garage/${garageId}/suppliers`,
51
65
  method: APIMethod.POST,
66
+ appType: MovaAppType.GARAGE,
52
67
  body: JSON.stringify(req)
53
68
  });
54
69
  }
@@ -57,6 +72,7 @@ export default class GarageService {
57
72
  return request({
58
73
  url: `${API_BASE_URL}/garage/${garageId}`,
59
74
  method: APIMethod.PATCH,
75
+ appType: MovaAppType.GARAGE,
60
76
  body: JSON.stringify(req)
61
77
  });
62
78
  }
@@ -65,6 +81,7 @@ export default class GarageService {
65
81
  return request({
66
82
  url: `${API_BASE_URL}/user/garages`,
67
83
  method: APIMethod.GET,
84
+ appType: MovaAppType.GARAGE
68
85
  });
69
86
  }
70
87
 
@@ -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);