addio-ecomm-sdk 1.3.74 → 1.3.76

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.
Files changed (107) hide show
  1. package/.vscode/settings.json +34 -34
  2. package/README.md +79 -79
  3. package/dist/index.d.ts +203 -202
  4. package/dist/index.js +1818 -1818
  5. package/dist/index.js.map +1 -1
  6. package/dist/lib/constants/components/CreditCardInput.d.ts +11 -11
  7. package/dist/lib/constants/components/CreditCardInput.js +79 -79
  8. package/dist/lib/constants/components/Snackbar.d.ts +11 -11
  9. package/dist/lib/constants/components/Snackbar.js +39 -39
  10. package/dist/lib/constants/contexts/CartContext/CartContextProvider.d.ts +7 -7
  11. package/dist/lib/constants/contexts/CartContext/CartContextProvider.js +980 -980
  12. package/dist/lib/constants/contexts/CartContext/index.d.ts +79 -79
  13. package/dist/lib/constants/contexts/CartContext/index.js +127 -127
  14. package/dist/lib/constants/contexts/DataContext/DataContextProvider.d.ts +15 -15
  15. package/dist/lib/constants/contexts/DataContext/DataContextProvider.js +304 -304
  16. package/dist/lib/constants/contexts/DataContext/index.d.ts +47 -47
  17. package/dist/lib/constants/contexts/DataContext/index.js +67 -67
  18. package/dist/lib/constants/contexts/LogContext/LogContextProvider.d.ts +6 -6
  19. package/dist/lib/constants/contexts/LogContext/LogContextProvider.js +103 -103
  20. package/dist/lib/constants/contexts/LogContext/index.d.ts +7 -7
  21. package/dist/lib/constants/contexts/LogContext/index.js +45 -45
  22. package/dist/lib/constants/contexts/ModalContext/ModalContextProvider.d.ts +7 -7
  23. package/dist/lib/constants/contexts/ModalContext/ModalContextProvider.js +76 -76
  24. package/dist/lib/constants/contexts/ModalContext/index.d.ts +14 -14
  25. package/dist/lib/constants/contexts/ModalContext/index.js +18 -18
  26. package/dist/lib/constants/contexts/SDKContext/SDKProvider.d.ts +8 -8
  27. package/dist/lib/constants/contexts/SDKContext/SDKProvider.js +79 -79
  28. package/dist/lib/constants/contexts/SDKContext/index.d.ts +4 -4
  29. package/dist/lib/constants/contexts/SDKContext/index.js +4 -4
  30. package/dist/lib/constants/contexts/SnackbarContext/SnackbarContext.d.ts +4 -4
  31. package/dist/lib/constants/contexts/SnackbarContext/SnackbarContext.js +6 -6
  32. package/dist/lib/constants/contexts/SnackbarContext/SnackbarContextProvider.d.ts +12 -12
  33. package/dist/lib/constants/contexts/SnackbarContext/SnackbarContextProvider.js +52 -52
  34. package/dist/lib/constants/contexts/SnackbarContext/interfaces/ISnackbarContext.d.ts +17 -17
  35. package/dist/lib/constants/contexts/SnackbarContext/interfaces/ISnackbarContext.js +21 -21
  36. package/dist/lib/constants/contexts/StockNotifContext/StockNotifContextProvider.d.ts +7 -7
  37. package/dist/lib/constants/contexts/StockNotifContext/StockNotifContextProvider.js +179 -179
  38. package/dist/lib/constants/contexts/StockNotifContext/index.d.ts +10 -10
  39. package/dist/lib/constants/contexts/StockNotifContext/index.js +10 -10
  40. package/dist/lib/constants/contexts/UserContext/UserContextProvider.d.ts +5 -5
  41. package/dist/lib/constants/contexts/UserContext/UserContextProvider.js +470 -470
  42. package/dist/lib/constants/contexts/UserContext/index.d.ts +54 -54
  43. package/dist/lib/constants/contexts/UserContext/index.js +82 -82
  44. package/dist/lib/constants/contexts/WishlistContext/WishlistContextProvider.d.ts +6 -6
  45. package/dist/lib/constants/contexts/WishlistContext/WishlistContextProvider.js +327 -327
  46. package/dist/lib/constants/contexts/WishlistContext/index.d.ts +12 -12
  47. package/dist/lib/constants/contexts/WishlistContext/index.js +12 -12
  48. package/dist/lib/constants/hooks/useCart.d.ts +2 -2
  49. package/dist/lib/constants/hooks/useCart.js +11 -11
  50. package/dist/lib/constants/hooks/useData.d.ts +2 -2
  51. package/dist/lib/constants/hooks/useData.js +11 -11
  52. package/dist/lib/constants/hooks/useLogs.d.ts +2 -2
  53. package/dist/lib/constants/hooks/useLogs.js +11 -11
  54. package/dist/lib/constants/hooks/useModal.d.ts +2 -2
  55. package/dist/lib/constants/hooks/useModal.js +11 -11
  56. package/dist/lib/constants/hooks/useSDK.d.ts +2 -2
  57. package/dist/lib/constants/hooks/useSDK.js +11 -11
  58. package/dist/lib/constants/hooks/useSnackbar.d.ts +2 -2
  59. package/dist/lib/constants/hooks/useSnackbar.js +11 -11
  60. package/dist/lib/constants/hooks/useStockNotif.d.ts +2 -2
  61. package/dist/lib/constants/hooks/useStockNotif.js +11 -11
  62. package/dist/lib/constants/hooks/useUser.d.ts +2 -2
  63. package/dist/lib/constants/hooks/useUser.js +11 -11
  64. package/dist/lib/constants/hooks/useWishlist.d.ts +2 -2
  65. package/dist/lib/constants/hooks/useWishlist.js +11 -11
  66. package/dist/lib/models/image/index.d.ts +6 -6
  67. package/dist/lib/models/image/index.js +15 -15
  68. package/dist/lib/models/stockNotification/index.d.ts +13 -13
  69. package/dist/lib/models/stockNotification/index.js +130 -130
  70. package/dist/lib/models/wishlist/index.d.ts +14 -14
  71. package/dist/lib/models/wishlist/index.js +155 -155
  72. package/dist/utils/StripeErrors.d.ts +24 -24
  73. package/dist/utils/StripeErrors.js +55 -55
  74. package/dist/utils/algolia.d.ts +3 -3
  75. package/dist/utils/algolia.js +81 -81
  76. package/dist/utils/analytics.d.ts +71 -71
  77. package/dist/utils/analytics.js +257 -257
  78. package/dist/utils/cart.d.ts +3 -3
  79. package/dist/utils/cart.js +66 -66
  80. package/dist/utils/contentful.d.ts +10 -10
  81. package/dist/utils/contentful.js +136 -136
  82. package/dist/utils/functions.d.ts +21 -21
  83. package/dist/utils/functions.js +200 -200
  84. package/dist/utils/getSDK.d.ts +4 -4
  85. package/dist/utils/getSDK.js +77 -77
  86. package/dist/utils/initStoreData.d.ts +3 -3
  87. package/dist/utils/initStoreData.js +62 -62
  88. package/dist/utils/interfaces/IClientCMSData.d.ts +132 -132
  89. package/dist/utils/interfaces/IClientCMSData.js +2 -2
  90. package/dist/utils/interfaces/IEndpointResult.d.ts +10 -10
  91. package/dist/utils/interfaces/IEndpointResult.js +2 -2
  92. package/dist/utils/interfaces/IFacebookUserProfile.d.ts +10 -10
  93. package/dist/utils/interfaces/IFacebookUserProfile.js +2 -2
  94. package/dist/utils/interfaces/IFilter.d.ts +23 -23
  95. package/dist/utils/interfaces/IFilter.js +2 -2
  96. package/dist/utils/interfaces/IGoogleUserProfile.d.ts +7 -7
  97. package/dist/utils/interfaces/IGoogleUserProfile.js +2 -2
  98. package/dist/utils/interfaces/ISDKConfig.d.ts +7 -7
  99. package/dist/utils/interfaces/ISDKConfig.js +2 -2
  100. package/dist/utils/interfaces/ISpaceData.d.ts +18 -18
  101. package/dist/utils/interfaces/ISpaceData.js +2 -2
  102. package/dist/utils/larivieremeunier.d.ts +3 -3
  103. package/dist/utils/larivieremeunier.js +156 -156
  104. package/dist/utils/technosupply.d.ts +3 -3
  105. package/dist/utils/technosupply.js +155 -155
  106. package/package.json +61 -61
  107. package/publish.sh +132 -132
@@ -1,131 +1,131 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- var StockNotification = (function () {
40
- function StockNotification(stockNotif, apiUrl, token, userToken, setUserToken) {
41
- var _this = this;
42
- this.setUserToken = function (token) {
43
- _this._userToken = token;
44
- };
45
- this.data = function () { return _this._stockNotif; };
46
- this.getFromDatabase = function (stockNotif) { return __awaiter(_this, void 0, void 0, function () {
47
- var request, responseData, dbStockNotif;
48
- return __generator(this, function (_a) {
49
- switch (_a.label) {
50
- case 0: return [4, fetch("".concat(this._apiUrl, "/stockNotification"), {
51
- method: 'POST',
52
- headers: {
53
- Authorization: "Bearer ".concat(this._token),
54
- 'Content-Type': 'application/json',
55
- 'x-gng-ecomm-token': this._userToken
56
- },
57
- body: JSON.stringify(stockNotif)
58
- })];
59
- case 1:
60
- request = _a.sent();
61
- if (!!!request)
62
- return [2];
63
- return [4, request.json()];
64
- case 2:
65
- responseData = _a.sent();
66
- if (responseData.status != 200) {
67
- throw new Error('Impossible de fetch la stockNotification: ' + responseData.error);
68
- }
69
- if (responseData.token) {
70
- this._setUserToken(responseData.token);
71
- }
72
- dbStockNotif = responseData.data;
73
- this._stockNotif = dbStockNotif;
74
- return [2, this];
75
- }
76
- });
77
- }); };
78
- this.saveToDatabase = function (newStockNotif) { return __awaiter(_this, void 0, void 0, function () {
79
- var stockNotifData, request, responseData, err_1;
80
- return __generator(this, function (_a) {
81
- switch (_a.label) {
82
- case 0:
83
- stockNotifData = this.data();
84
- if (!!!stockNotifData)
85
- return [2];
86
- if (!!!stockNotifData.id)
87
- return [2];
88
- _a.label = 1;
89
- case 1:
90
- _a.trys.push([1, 4, , 5]);
91
- return [4, fetch("".concat(this._apiUrl, "/stockNotifications/").concat(stockNotifData.id, "/save"), {
92
- method: 'POST',
93
- headers: {
94
- Authorization: "Bearer ".concat(this._token),
95
- 'Content-Type': 'application/json',
96
- 'x-gng-ecomm-token': this._userToken
97
- },
98
- body: JSON.stringify(newStockNotif)
99
- })];
100
- case 2:
101
- request = _a.sent();
102
- if (!!!request)
103
- return [2];
104
- return [4, request.json()];
105
- case 3:
106
- responseData = _a.sent();
107
- if (responseData.status != 200) {
108
- throw new Error('Impossible de fetch la stockNotification: ' + responseData.error);
109
- }
110
- if (responseData.token) {
111
- this._setUserToken(responseData.token);
112
- }
113
- return [3, 5];
114
- case 4:
115
- err_1 = _a.sent();
116
- console.log(err_1);
117
- return [3, 5];
118
- case 5: return [2];
119
- }
120
- });
121
- }); };
122
- this._stockNotif = stockNotif;
123
- this._apiUrl = apiUrl;
124
- this._token = token;
125
- this._userToken = userToken;
126
- this._setUserToken = setUserToken;
127
- }
128
- return StockNotification;
129
- }());
130
- exports.default = StockNotification;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ var StockNotification = (function () {
40
+ function StockNotification(stockNotif, apiUrl, token, userToken, setUserToken) {
41
+ var _this = this;
42
+ this.setUserToken = function (token) {
43
+ _this._userToken = token;
44
+ };
45
+ this.data = function () { return _this._stockNotif; };
46
+ this.getFromDatabase = function (stockNotif) { return __awaiter(_this, void 0, void 0, function () {
47
+ var request, responseData, dbStockNotif;
48
+ return __generator(this, function (_a) {
49
+ switch (_a.label) {
50
+ case 0: return [4, fetch("".concat(this._apiUrl, "/stockNotification"), {
51
+ method: 'POST',
52
+ headers: {
53
+ Authorization: "Bearer ".concat(this._token),
54
+ 'Content-Type': 'application/json',
55
+ 'x-gng-ecomm-token': this._userToken
56
+ },
57
+ body: JSON.stringify(stockNotif)
58
+ })];
59
+ case 1:
60
+ request = _a.sent();
61
+ if (!!!request)
62
+ return [2];
63
+ return [4, request.json()];
64
+ case 2:
65
+ responseData = _a.sent();
66
+ if (responseData.status != 200) {
67
+ throw new Error('Impossible de fetch la stockNotification: ' + responseData.error);
68
+ }
69
+ if (responseData.token) {
70
+ this._setUserToken(responseData.token);
71
+ }
72
+ dbStockNotif = responseData.data;
73
+ this._stockNotif = dbStockNotif;
74
+ return [2, this];
75
+ }
76
+ });
77
+ }); };
78
+ this.saveToDatabase = function (newStockNotif) { return __awaiter(_this, void 0, void 0, function () {
79
+ var stockNotifData, request, responseData, err_1;
80
+ return __generator(this, function (_a) {
81
+ switch (_a.label) {
82
+ case 0:
83
+ stockNotifData = this.data();
84
+ if (!!!stockNotifData)
85
+ return [2];
86
+ if (!!!stockNotifData.id)
87
+ return [2];
88
+ _a.label = 1;
89
+ case 1:
90
+ _a.trys.push([1, 4, , 5]);
91
+ return [4, fetch("".concat(this._apiUrl, "/stockNotifications/").concat(stockNotifData.id, "/save"), {
92
+ method: 'POST',
93
+ headers: {
94
+ Authorization: "Bearer ".concat(this._token),
95
+ 'Content-Type': 'application/json',
96
+ 'x-gng-ecomm-token': this._userToken
97
+ },
98
+ body: JSON.stringify(newStockNotif)
99
+ })];
100
+ case 2:
101
+ request = _a.sent();
102
+ if (!!!request)
103
+ return [2];
104
+ return [4, request.json()];
105
+ case 3:
106
+ responseData = _a.sent();
107
+ if (responseData.status != 200) {
108
+ throw new Error('Impossible de fetch la stockNotification: ' + responseData.error);
109
+ }
110
+ if (responseData.token) {
111
+ this._setUserToken(responseData.token);
112
+ }
113
+ return [3, 5];
114
+ case 4:
115
+ err_1 = _a.sent();
116
+ console.log(err_1);
117
+ return [3, 5];
118
+ case 5: return [2];
119
+ }
120
+ });
121
+ }); };
122
+ this._stockNotif = stockNotif;
123
+ this._apiUrl = apiUrl;
124
+ this._token = token;
125
+ this._userToken = userToken;
126
+ this._setUserToken = setUserToken;
127
+ }
128
+ return StockNotification;
129
+ }());
130
+ exports.default = StockNotification;
131
131
  //# sourceMappingURL=index.js.map
@@ -1,14 +1,14 @@
1
- import IWishlist from 'addio-admin-sdk/dist/Interfaces/Wishlist';
2
- export default class Wishlist {
3
- private _wishlist;
4
- private _apiUrl;
5
- private _token;
6
- private _userToken;
7
- private _setUserToken;
8
- constructor(wishlist: IWishlist | null, apiUrl: string, token: string, userToken: string, setUserToken: (token: string) => void);
9
- setUserToken: (token: string) => void;
10
- data: () => IWishlist | null;
11
- getFromDatabase: (wishlist: IWishlist) => Promise<Wishlist | undefined>;
12
- saveToDatabase: (newWishlist: IWishlist) => Promise<void>;
13
- clear: () => Promise<any>;
14
- }
1
+ import IWishlist from 'addio-admin-sdk/dist/Interfaces/Wishlist';
2
+ export default class Wishlist {
3
+ private _wishlist;
4
+ private _apiUrl;
5
+ private _token;
6
+ private _userToken;
7
+ private _setUserToken;
8
+ constructor(wishlist: IWishlist | null, apiUrl: string, token: string, userToken: string, setUserToken: (token: string) => void);
9
+ setUserToken: (token: string) => void;
10
+ data: () => IWishlist | null;
11
+ getFromDatabase: (wishlist: IWishlist) => Promise<Wishlist | undefined>;
12
+ saveToDatabase: (newWishlist: IWishlist) => Promise<void>;
13
+ clear: () => Promise<any>;
14
+ }
@@ -1,156 +1,156 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- var Wishlist = (function () {
40
- function Wishlist(wishlist, apiUrl, token, userToken, setUserToken) {
41
- var _this = this;
42
- this.setUserToken = function (token) {
43
- _this._userToken = token;
44
- };
45
- this.data = function () { return _this._wishlist; };
46
- this.getFromDatabase = function (wishlist) { return __awaiter(_this, void 0, void 0, function () {
47
- var request, responseData, dbWishlist;
48
- return __generator(this, function (_a) {
49
- switch (_a.label) {
50
- case 0: return [4, fetch("".concat(this._apiUrl, "/wishlist"), {
51
- method: 'POST',
52
- headers: {
53
- Authorization: "Bearer ".concat(this._token),
54
- 'Content-Type': 'application/json',
55
- 'x-gng-ecomm-token': this._userToken
56
- },
57
- body: JSON.stringify(wishlist)
58
- })];
59
- case 1:
60
- request = _a.sent();
61
- if (!!!request)
62
- return [2];
63
- return [4, request.json()];
64
- case 2:
65
- responseData = _a.sent();
66
- if (responseData.status != 200) {
67
- throw new Error('Impossible de fetch la wishlist: ' + responseData.error);
68
- }
69
- if (responseData.token) {
70
- this._setUserToken(responseData.token);
71
- }
72
- dbWishlist = responseData.data;
73
- this._wishlist = dbWishlist;
74
- return [2, this];
75
- }
76
- });
77
- }); };
78
- this.saveToDatabase = function (newWishlist) { return __awaiter(_this, void 0, void 0, function () {
79
- var wishlistData, request, responseData, err_1;
80
- return __generator(this, function (_a) {
81
- switch (_a.label) {
82
- case 0:
83
- wishlistData = this.data();
84
- if (!!!wishlistData)
85
- return [2];
86
- if (!!!wishlistData.id)
87
- return [2];
88
- _a.label = 1;
89
- case 1:
90
- _a.trys.push([1, 4, , 5]);
91
- return [4, fetch("".concat(this._apiUrl, "/wishlists/").concat(wishlistData.id, "/save"), {
92
- method: 'POST',
93
- headers: {
94
- Authorization: "Bearer ".concat(this._token),
95
- 'Content-Type': 'application/json',
96
- 'x-gng-ecomm-token': this._userToken
97
- },
98
- body: JSON.stringify(newWishlist)
99
- })];
100
- case 2:
101
- request = _a.sent();
102
- if (!!!request)
103
- return [2];
104
- return [4, request.json()];
105
- case 3:
106
- responseData = _a.sent();
107
- if (responseData.status != 200) {
108
- throw new Error('Impossible de fetch la wishlist: ' + responseData.error);
109
- }
110
- if (responseData.token) {
111
- this._setUserToken(responseData.token);
112
- }
113
- return [3, 5];
114
- case 4:
115
- err_1 = _a.sent();
116
- console.log(err_1);
117
- return [3, 5];
118
- case 5: return [2];
119
- }
120
- });
121
- }); };
122
- this.clear = function () { return __awaiter(_this, void 0, void 0, function () {
123
- var res, error_1;
124
- return __generator(this, function (_a) {
125
- switch (_a.label) {
126
- case 0:
127
- _a.trys.push([0, 3, , 4]);
128
- return [4, fetch("".concat(this._apiUrl, "/wishlists"), {
129
- method: 'DELETE',
130
- headers: {
131
- authorization: "Bearer ".concat(this._token),
132
- 'Content-Type': 'application/json',
133
- 'x-gng-ecomm-token': this._userToken || localStorage.getItem('userToken') || ''
134
- }
135
- })];
136
- case 1:
137
- res = _a.sent();
138
- return [4, res.json()];
139
- case 2: return [2, _a.sent()];
140
- case 3:
141
- error_1 = _a.sent();
142
- throw error_1;
143
- case 4: return [2];
144
- }
145
- });
146
- }); };
147
- this._wishlist = wishlist;
148
- this._apiUrl = apiUrl;
149
- this._token = token;
150
- this._userToken = userToken;
151
- this._setUserToken = setUserToken;
152
- }
153
- return Wishlist;
154
- }());
155
- exports.default = Wishlist;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ var Wishlist = (function () {
40
+ function Wishlist(wishlist, apiUrl, token, userToken, setUserToken) {
41
+ var _this = this;
42
+ this.setUserToken = function (token) {
43
+ _this._userToken = token;
44
+ };
45
+ this.data = function () { return _this._wishlist; };
46
+ this.getFromDatabase = function (wishlist) { return __awaiter(_this, void 0, void 0, function () {
47
+ var request, responseData, dbWishlist;
48
+ return __generator(this, function (_a) {
49
+ switch (_a.label) {
50
+ case 0: return [4, fetch("".concat(this._apiUrl, "/wishlist"), {
51
+ method: 'POST',
52
+ headers: {
53
+ Authorization: "Bearer ".concat(this._token),
54
+ 'Content-Type': 'application/json',
55
+ 'x-gng-ecomm-token': this._userToken
56
+ },
57
+ body: JSON.stringify(wishlist)
58
+ })];
59
+ case 1:
60
+ request = _a.sent();
61
+ if (!!!request)
62
+ return [2];
63
+ return [4, request.json()];
64
+ case 2:
65
+ responseData = _a.sent();
66
+ if (responseData.status != 200) {
67
+ throw new Error('Impossible de fetch la wishlist: ' + responseData.error);
68
+ }
69
+ if (responseData.token) {
70
+ this._setUserToken(responseData.token);
71
+ }
72
+ dbWishlist = responseData.data;
73
+ this._wishlist = dbWishlist;
74
+ return [2, this];
75
+ }
76
+ });
77
+ }); };
78
+ this.saveToDatabase = function (newWishlist) { return __awaiter(_this, void 0, void 0, function () {
79
+ var wishlistData, request, responseData, err_1;
80
+ return __generator(this, function (_a) {
81
+ switch (_a.label) {
82
+ case 0:
83
+ wishlistData = this.data();
84
+ if (!!!wishlistData)
85
+ return [2];
86
+ if (!!!wishlistData.id)
87
+ return [2];
88
+ _a.label = 1;
89
+ case 1:
90
+ _a.trys.push([1, 4, , 5]);
91
+ return [4, fetch("".concat(this._apiUrl, "/wishlists/").concat(wishlistData.id, "/save"), {
92
+ method: 'POST',
93
+ headers: {
94
+ Authorization: "Bearer ".concat(this._token),
95
+ 'Content-Type': 'application/json',
96
+ 'x-gng-ecomm-token': this._userToken
97
+ },
98
+ body: JSON.stringify(newWishlist)
99
+ })];
100
+ case 2:
101
+ request = _a.sent();
102
+ if (!!!request)
103
+ return [2];
104
+ return [4, request.json()];
105
+ case 3:
106
+ responseData = _a.sent();
107
+ if (responseData.status != 200) {
108
+ throw new Error('Impossible de fetch la wishlist: ' + responseData.error);
109
+ }
110
+ if (responseData.token) {
111
+ this._setUserToken(responseData.token);
112
+ }
113
+ return [3, 5];
114
+ case 4:
115
+ err_1 = _a.sent();
116
+ console.log(err_1);
117
+ return [3, 5];
118
+ case 5: return [2];
119
+ }
120
+ });
121
+ }); };
122
+ this.clear = function () { return __awaiter(_this, void 0, void 0, function () {
123
+ var res, error_1;
124
+ return __generator(this, function (_a) {
125
+ switch (_a.label) {
126
+ case 0:
127
+ _a.trys.push([0, 3, , 4]);
128
+ return [4, fetch("".concat(this._apiUrl, "/wishlists"), {
129
+ method: 'DELETE',
130
+ headers: {
131
+ authorization: "Bearer ".concat(this._token),
132
+ 'Content-Type': 'application/json',
133
+ 'x-gng-ecomm-token': this._userToken || localStorage.getItem('userToken') || ''
134
+ }
135
+ })];
136
+ case 1:
137
+ res = _a.sent();
138
+ return [4, res.json()];
139
+ case 2: return [2, _a.sent()];
140
+ case 3:
141
+ error_1 = _a.sent();
142
+ throw error_1;
143
+ case 4: return [2];
144
+ }
145
+ });
146
+ }); };
147
+ this._wishlist = wishlist;
148
+ this._apiUrl = apiUrl;
149
+ this._token = token;
150
+ this._userToken = userToken;
151
+ this._setUserToken = setUserToken;
152
+ }
153
+ return Wishlist;
154
+ }());
155
+ exports.default = Wishlist;
156
156
  //# sourceMappingURL=index.js.map