orderiom-api-package 0.4.69 → 0.4.71

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orderiom-api-package",
3
- "version": "0.4.69",
3
+ "version": "0.4.71",
4
4
  "description": "This package will install all necessary API calls for every orderiom restaurant",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
package/src/common.js CHANGED
@@ -112,6 +112,22 @@ export function formatTime(date){
112
112
  ].join(':')
113
113
  }
114
114
 
115
+ export function isTokenExpired(token) {
116
+ const base64Url = token.split(".")[1];
117
+ const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
118
+ const jsonPayload = decodeURIComponent(
119
+ atob(base64)
120
+ .split("")
121
+ .map(function (c) {
122
+ return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
123
+ })
124
+ .join("")
125
+ );
126
+
127
+ const { exp } = JSON.parse(jsonPayload);
128
+ return Date.now() >= exp * 1000;
129
+ }
130
+
115
131
  axios.defaults.baseURL = process.env.VUE_APP_BASE_API_URL || window.dynamicData.VUE_APP_BASE_API_URL;
116
132
  axios.interceptors.request.use(config => {
117
133
  const token = localStorage.getItem("privateToken") || localStorage.getItem("publicToken");
@@ -137,6 +137,7 @@
137
137
  "order_limit_reached": "Leider sind wir zur von Ihnen gewählten Uhrzeit sehr ausgelastet und können Ihre Bestellung nicht vorbereiten. Möchten Sie Ihre Uhrzeit vielleicht auf {validTime} ändern?",
138
138
  "this_product_is_not_available_for_your_selected_date": "Leider ist {name} für Ihr ausgewähltes Datum nicht verfügbar.",
139
139
  "the_product_is_not_available": "Leider ist {name} nicht auf Lager",
140
+ "the_product_quantity_limit_reached": "Leider sind nur {inStock} Artikel von {name} verfügbar.",
140
141
 
141
142
  "request_submitted": "Ihre Anfrage wurde übermittelt!",
142
143
  "restaurant_past_time": "Das Restaurant ist nicht zur gewünschten Zeit geöffnet.",
@@ -137,6 +137,7 @@
137
137
  "order_limit_reached": "Unfortunately, we are very busy at the time you selected and cannot prepare your order. Do you want to change your time to {validTime} maybe?",
138
138
  "this_product_is_not_available_for_your_selected_date": "Unfortunately, {name} is not available for your selected date.",
139
139
  "the_product_is_not_available": "Unfortunately, {name} is out of stock",
140
+ "the_product_quantity_limit_reached": "Unfortunately, only {inStock} item(s) of {name} is available.",
140
141
 
141
142
  "request_submitted": "your request has been submitted!",
142
143
  "restaurant_past_time": "Restaurant is not open at your desired Time.",
@@ -137,6 +137,7 @@
137
137
  "order_limit_reached": "Malheureusement, nous sommes très occupés à l'heure que vous avez sélectionnée et ne pouvons pas préparer votre commande. Voulez-vous peut-être changer votre heure en {validTime}?",
138
138
  "this_product_is_not_available_for_your_selected_date": "Malheureusement, {name} n'est pas disponible pour la date sélectionnée.",
139
139
  "the_product_is_not_available": "Malheureusement, {name} est en rupture de stock",
140
+ "the_product_quantity_limit_reached": "Malheureusement, seulement {inStock} article(s) de {name} sont disponibles.",
140
141
 
141
142
  "request_submitted": "votre demande a été soumise!",
142
143
  "restaurant_past_time": "Le restaurant n'est pas ouvert à l'heure souhaitée.",
@@ -1,4 +1,4 @@
1
- import {commonErrorCallback, $http, calculateBasketIdParameter, restaurantIdEnv} from '../common';
1
+ import {commonErrorCallback, $http, isTokenExpired, restaurantIdEnv } from '../common';
2
2
 
3
3
  const state = {
4
4
  publicToken: null,
@@ -53,6 +53,9 @@ const mutations = {
53
53
  };
54
54
  const actions = {
55
55
  auth({ commit }) {
56
+ const publicToken = localStorage.getItem('publicToken');
57
+ if(publicToken && !isTokenExpired(publicToken)) return;
58
+
56
59
  return $http
57
60
  .post("api/oauth/token", {
58
61
  grant_type: process.env.VUE_APP_GRANT_TYPE || window.dynamicData.VUE_APP_GRANT_TYPE,
@@ -634,6 +634,7 @@ const actions = {
634
634
  const validation = error.response.data.error.validation;
635
635
 
636
636
  const name = validation.name && validation.name.length ? validation.name[0] : 'N/A';
637
+ const inStock = validation.inStock && validation.inStock.length ? validation.inStock[0] : 'N/A';
637
638
  const validTime = validation.validTime && validation.validTime.length ? validation.validTime[0] : 'N/A';
638
639
  delete validation.name;
639
640
  delete validation.validTime;
@@ -642,7 +643,8 @@ const actions = {
642
643
  type: 'error',
643
644
  msg: Object.values(validation)[0][0],
644
645
  name,
645
- validTime
646
+ validTime,
647
+ inStock
646
648
  }
647
649
  } else if ([401, 403, 404, 400].includes(status)) {
648
650
  return {
@@ -860,6 +862,7 @@ const actions = {
860
862
  const validation = error.response.data.error.validation;
861
863
 
862
864
  const name = validation.name && validation.name.length ? validation.name[0] : 'N/A';
865
+ const inStock = validation.inStock && validation.inStock.length ? validation.inStock[0] : 'N/A';
863
866
  const validTime = validation.validTime && validation.validTime.length ? validation.validTime[0] : 'N/A';
864
867
  delete validation.name;
865
868
  delete validation.validTime;
@@ -868,7 +871,8 @@ const actions = {
868
871
  type: 'error',
869
872
  msg: Object.values(validation)[0][0],
870
873
  name,
871
- validTime
874
+ validTime,
875
+ inStock
872
876
  }
873
877
  } else if ([401, 403, 404, 400].includes(status)) {
874
878
  return {