addio-ecomm-sdk 1.3.36 → 1.3.38

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 +202 -202
  4. package/dist/index.js +1812 -1808
  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 +973 -973
  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 +299 -299
  16. package/dist/lib/constants/contexts/DataContext/index.d.ts +40 -40
  17. package/dist/lib/constants/contexts/DataContext/index.js +66 -66
  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 +195 -195
  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 +14 -14
  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 +125 -125
package/dist/index.js CHANGED
@@ -1,1809 +1,1813 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
- return new (P || (P = Promise))(function (resolve, reject) {
16
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
- step((generator = generator.apply(thisArg, _arguments || [])).next());
20
- });
21
- };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
- 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;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
- var __rest = (this && this.__rest) || function (s, e) {
50
- var t = {};
51
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
52
- t[p] = s[p];
53
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
54
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
55
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
56
- t[p[i]] = s[p[i]];
57
- }
58
- return t;
59
- };
60
- var __importDefault = (this && this.__importDefault) || function (mod) {
61
- return (mod && mod.__esModule) ? mod : { "default": mod };
62
- };
63
- Object.defineProperty(exports, "__esModule", { value: true });
64
- var isomorphic_unfetch_1 = __importDefault(require("isomorphic-unfetch"));
65
- var image_1 = __importDefault(require("./lib/models/image"));
66
- var wishlist_1 = __importDefault(require("./lib/models/wishlist"));
67
- var stockNotification_1 = __importDefault(require("./lib/models/stockNotification"));
68
- var Product_1 = __importDefault(require("addio-admin-sdk/dist/lib/Product"));
69
- var js_cookie_1 = __importDefault(require("js-cookie"));
70
- var g2_1 = require("addio-admin-sdk/dist/rules/GR/utils/g2");
71
- var anonymisation_1 = require("addio-admin-sdk/dist/utils/anonymisation");
72
- var functions_1 = require("./utils/functions");
73
- var zones_1 = require("addio-admin-sdk/dist/utils/zones");
74
- var lodash_1 = require("lodash");
75
- var functions_2 = require("./utils/functions");
76
- var data_1 = require("addio-admin-sdk/dist/utils/data");
77
- var moment_1 = __importDefault(require("moment"));
78
- var object_1 = require("addio-admin-sdk/dist/utils/object");
79
- var services_1 = require("addio-admin-sdk/dist/utils/services");
80
- var SDK = (function () {
81
- function SDK() {
82
- var _this = this;
83
- this.init = function (sdk_config) { return __awaiter(_this, void 0, void 0, function () {
84
- return __generator(this, function (_a) {
85
- this._api = sdk_config.api;
86
- this._token = sdk_config.token;
87
- this._url = sdk_config.url;
88
- this._org = sdk_config.org;
89
- this._userToken = !!sdk_config.userToken ? sdk_config.userToken : '';
90
- this._storeData = null;
91
- return [2];
92
- });
93
- }); };
94
- this.getAPIInfos = function () { return ({
95
- api: _this._api,
96
- token: _this._token,
97
- userToken: _this._userToken,
98
- org: _this._org
99
- }); };
100
- this.getSDKOrgInitials = function () {
101
- var orgID = _this.getAPIInfos().org;
102
- if (!!!orgID)
103
- return '';
104
- if (orgID.length <= 3)
105
- return orgID.toUpperCase();
106
- return (0, services_1.getOrgInitialsByID)(orgID);
107
- };
108
- this.initWishlist = function (wishlist) { return __awaiter(_this, void 0, void 0, function () {
109
- return __generator(this, function (_a) {
110
- switch (_a.label) {
111
- case 0:
112
- this._wishlist = new wishlist_1.default(wishlist, this._api, this._token, this._userToken, this.setUserToken);
113
- return [4, this._wishlist.getFromDatabase(wishlist)];
114
- case 1: return [2, _a.sent()];
115
- }
116
- });
117
- }); };
118
- this.initStockNotif = function (stockNotif) { return __awaiter(_this, void 0, void 0, function () {
119
- return __generator(this, function (_a) {
120
- switch (_a.label) {
121
- case 0:
122
- this._stockNotif = new stockNotification_1.default(stockNotif, this._api, this._token, this._userToken, this.setUserToken);
123
- return [4, this._stockNotif.getFromDatabase(stockNotif)];
124
- case 1: return [2, _a.sent()];
125
- }
126
- });
127
- }); };
128
- this.initStoreData = function (defaultData) { return __awaiter(_this, void 0, void 0, function () {
129
- var fetchData, responseData;
130
- return __generator(this, function (_a) {
131
- switch (_a.label) {
132
- case 0:
133
- if (!!defaultData) {
134
- this._storeData = defaultData;
135
- return [2];
136
- }
137
- return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/store"), {
138
- method: 'GET',
139
- headers: {
140
- authorization: "Bearer ".concat(this._token),
141
- 'Content-Type': 'application/json'
142
- }
143
- })];
144
- case 1:
145
- fetchData = _a.sent();
146
- return [4, fetchData.json()];
147
- case 2:
148
- responseData = _a.sent();
149
- if (responseData.status !== 200) {
150
- throw new Error(JSON.stringify({ status: responseData.status, error: responseData.error }));
151
- }
152
- this._storeData = responseData.data;
153
- return [2, this._storeData];
154
- }
155
- });
156
- }); };
157
- this.shouldShowFixedPromoBanner = function (fixedPromoBannerData) {
158
- if (!!!fixedPromoBannerData.is_active) {
159
- return false;
160
- }
161
- if (!!fixedPromoBannerData.active_between_dates && !!fixedPromoBannerData.active_between_dates.length) {
162
- var date = fixedPromoBannerData.active_between_dates.some(function (date) {
163
- return (0, moment_1.default)().isBetween((0, moment_1.default)((0, data_1.formatDate)(date.start)), (0, moment_1.default)((0, data_1.formatDate)(date.end)), 'days', '[]');
164
- });
165
- return !!date;
166
- }
167
- return true;
168
- };
169
- this.getInventoryItem = function (sku, locale) { return __awaiter(_this, void 0, void 0, function () {
170
- var fetchData, responseData;
171
- return __generator(this, function (_a) {
172
- switch (_a.label) {
173
- case 0: return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/inventory/").concat(encodeURIComponent(sku)), {
174
- method: 'GET',
175
- headers: {
176
- Authorization: "Bearer ".concat(this._token),
177
- 'x-gng-ecomm-locale': locale
178
- }
179
- })];
180
- case 1:
181
- fetchData = _a.sent();
182
- return [4, fetchData.json()];
183
- case 2:
184
- responseData = _a.sent();
185
- if (responseData.status !== 200)
186
- throw new Error(JSON.stringify({ status: responseData.status, error: responseData.error }));
187
- return [2, responseData.data];
188
- }
189
- });
190
- }); };
191
- this.getFullInventory = function (locale) { return __awaiter(_this, void 0, void 0, function () {
192
- var fetchData, responseData;
193
- return __generator(this, function (_a) {
194
- switch (_a.label) {
195
- case 0: return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/inventory"), {
196
- method: 'GET',
197
- headers: {
198
- Authorization: "Bearer ".concat(this._token),
199
- 'x-gng-ecomm-locale': locale
200
- }
201
- })];
202
- case 1:
203
- fetchData = _a.sent();
204
- return [4, fetchData.json()];
205
- case 2:
206
- responseData = _a.sent();
207
- if (responseData.status !== 200)
208
- throw new Error(JSON.stringify({ status: responseData.status, error: responseData.error }));
209
- return [2, responseData.data];
210
- }
211
- });
212
- }); };
213
- this.inventory = {
214
- getFullInventory: this.getFullInventory,
215
- getInventoryItem: this.getInventoryItem
216
- };
217
- this.setUserToken = function (token) {
218
- _this._userToken = token;
219
- localStorage.setItem('userToken', token);
220
- js_cookie_1.default.set('userToken', token, { sameSite: 'strict', secure: true });
221
- };
222
- this.loginUserWithFacebook = function (fb) { return __awaiter(_this, void 0, void 0, function () {
223
- var email, id, name, fetchData, responseData;
224
- return __generator(this, function (_a) {
225
- switch (_a.label) {
226
- case 0:
227
- email = fb.email, id = fb.id, name = fb.name;
228
- return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/signinwithfacebook"), {
229
- method: 'POST',
230
- headers: {
231
- authorization: "Bearer ".concat(this._token),
232
- 'Content-Type': 'application/json'
233
- },
234
- body: JSON.stringify({ email: email, userID: id, name: name })
235
- })];
236
- case 1:
237
- fetchData = _a.sent();
238
- return [4, fetchData.json()];
239
- case 2:
240
- responseData = _a.sent();
241
- if (responseData.status !== 200) {
242
- throw { status: responseData.status, error: responseData.error };
243
- }
244
- try {
245
- if (!!!responseData.data.userData) {
246
- throw {
247
- status: responseData.status,
248
- error: 'user_not_found'
249
- };
250
- }
251
- if (!!responseData.data.cartData) {
252
- localStorage.setItem("".concat(this._org, "__cart"), responseData.data.cartData.id);
253
- }
254
- if (responseData.token)
255
- this.setUserToken(responseData.token);
256
- return [2, { userData: responseData.data.userData, cart: responseData.data.cartData }];
257
- }
258
- catch (err) {
259
- return [2, err.toString()];
260
- }
261
- return [2];
262
- }
263
- });
264
- }); };
265
- this.anonymousResetPassword = function (locale, id, oldPassword, newPassword, confirmPassword) { return __awaiter(_this, void 0, void 0, function () {
266
- var fetchData, responseData, error_1;
267
- return __generator(this, function (_a) {
268
- switch (_a.label) {
269
- case 0:
270
- _a.trys.push([0, 3, , 4]);
271
- return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/anonymousResetPassword"), {
272
- method: 'POST',
273
- headers: {
274
- authorization: "Bearer ".concat(this._token),
275
- 'Content-Type': 'application/json',
276
- 'x-gng-ecomm-locale': locale
277
- },
278
- body: JSON.stringify({
279
- id: id,
280
- oldPassword: oldPassword,
281
- newPassword: newPassword,
282
- confirmPassword: confirmPassword
283
- })
284
- })];
285
- case 1:
286
- fetchData = _a.sent();
287
- return [4, fetchData.json()];
288
- case 2:
289
- responseData = _a.sent();
290
- if (responseData.status !== 200) {
291
- return [2, { status: responseData.status, error: responseData.error }];
292
- }
293
- return [2, { status: responseData.status, data: { done: true } }];
294
- case 3:
295
- error_1 = _a.sent();
296
- console.log('error dans le catch du sdk: ', typeof error_1, error_1);
297
- return [2, {
298
- status: 400,
299
- error: typeof error_1 === 'string' ? error_1 : error_1.toString()
300
- }];
301
- case 4: return [2];
302
- }
303
- });
304
- }); };
305
- this.loginUser = function (locale, email, password, keepCart, isClerk) {
306
- if (keepCart === void 0) { keepCart = false; }
307
- if (isClerk === void 0) { isClerk = false; }
308
- return __awaiter(_this, void 0, void 0, function () {
309
- var fetchData, responseData, cartData, shouldResetCartData, currentCartInLocalStorage;
310
- return __generator(this, function (_a) {
311
- switch (_a.label) {
312
- case 0: return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/signin"), {
313
- method: 'POST',
314
- headers: {
315
- authorization: "Bearer ".concat(this._token),
316
- 'Content-Type': 'application/json',
317
- 'x-gng-ecomm-locale': locale
318
- },
319
- body: JSON.stringify({ email: email, password: password, isClerk: isClerk })
320
- })];
321
- case 1:
322
- fetchData = _a.sent();
323
- return [4, fetchData.json()];
324
- case 2:
325
- responseData = _a.sent();
326
- if (responseData.status !== 200) {
327
- throw { status: responseData.status, error: responseData.error };
328
- }
329
- try {
330
- if (!!!responseData.data.userData) {
331
- throw {
332
- status: responseData.status,
333
- error: 'user_not_found'
334
- };
335
- }
336
- cartData = responseData.data.cartData;
337
- shouldResetCartData = !!cartData && !!cartData.clerk_id && !!!isClerk;
338
- currentCartInLocalStorage = !!shouldResetCartData || !!!keepCart ? false : localStorage.getItem("".concat(this._org, "__cart"));
339
- if (!!cartData && !!!currentCartInLocalStorage) {
340
- localStorage.setItem("".concat(this._org, "__cart"), responseData.data.cartData.id);
341
- }
342
- if (responseData.token)
343
- this.setUserToken(responseData.token);
344
- return [2, {
345
- userData: responseData.data.userData,
346
- cart: shouldResetCartData ? null : cartData
347
- }];
348
- }
349
- catch (err) {
350
- return [2, err.toString()];
351
- }
352
- return [2];
353
- }
354
- });
355
- });
356
- };
357
- this.loginUserWithID = function (locale, id, password, keepCart, isClerk) {
358
- if (keepCart === void 0) { keepCart = false; }
359
- if (isClerk === void 0) { isClerk = false; }
360
- return __awaiter(_this, void 0, void 0, function () {
361
- var fetchData, responseData, currentCartInLocalStorage;
362
- return __generator(this, function (_a) {
363
- switch (_a.label) {
364
- case 0: return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/signinwithid"), {
365
- method: 'POST',
366
- headers: {
367
- authorization: "Bearer ".concat(this._token),
368
- 'Content-Type': 'application/json',
369
- 'x-gng-ecomm-locale': locale
370
- },
371
- body: JSON.stringify({ id: id, password: password, isClerk: isClerk })
372
- })];
373
- case 1:
374
- fetchData = _a.sent();
375
- return [4, fetchData.json()];
376
- case 2:
377
- responseData = _a.sent();
378
- if (responseData.status !== 200) {
379
- throw { status: responseData.status, error: responseData.error };
380
- }
381
- if (!!!responseData.data.userData) {
382
- throw {
383
- status: responseData.status,
384
- error: 'user_not_found'
385
- };
386
- }
387
- currentCartInLocalStorage = !!!keepCart ? false : localStorage.getItem("".concat(this._org, "__cart"));
388
- if (!!responseData.data.cartData && !!!currentCartInLocalStorage) {
389
- localStorage.setItem("".concat(this._org, "__cart"), responseData.data.cartData.id);
390
- }
391
- if (responseData.token)
392
- this.setUserToken(responseData.token);
393
- return [2, { userData: responseData.data.userData, cart: responseData.data.cartData }];
394
- }
395
- });
396
- });
397
- };
398
- this.checkG2ForCustomer = function (id, currentCustomer, customerGroups) { return __awaiter(_this, void 0, void 0, function () {
399
- var fetchData, G2RequestRes, allG2Customers, customerToCheck, customerToCreate, anonymizedCustomer, e_1;
400
- return __generator(this, function (_a) {
401
- switch (_a.label) {
402
- case 0:
403
- _a.trys.push([0, 3, , 4]);
404
- return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/services/g2/customers/").concat(id), {
405
- method: 'GET',
406
- headers: {
407
- authorization: "Bearer ".concat(this._token),
408
- 'Content-Type': 'application/json'
409
- }
410
- })];
411
- case 1:
412
- fetchData = _a.sent();
413
- return [4, fetchData.json()];
414
- case 2:
415
- G2RequestRes = _a.sent();
416
- if (!!fetchData.status && fetchData.status !== 200)
417
- throw "".concat(fetchData.status);
418
- if (!!!G2RequestRes || !!!G2RequestRes.length)
419
- throw 'no data';
420
- allG2Customers = G2RequestRes;
421
- customerToCheck = allG2Customers[0];
422
- if (!!(0, object_1.recursiveCheckObject)(customerToCheck, 'client.noClient') && customerToCheck.client.noClient !== id)
423
- throw 'no data';
424
- customerToCreate = (0, g2_1.transformG2CustomerToCustomer)(customerToCheck, currentCustomer, customerGroups);
425
- anonymizedCustomer = (0, anonymisation_1.hideG2CustomerInfoIfNeeded)(customerToCreate);
426
- return [2, (anonymizedCustomer !== null && anonymizedCustomer !== void 0 ? anonymizedCustomer : customerToCreate)];
427
- case 3:
428
- e_1 = _a.sent();
429
- console.log('error on fetching G2 customer: ', e_1.toString());
430
- return [2];
431
- case 4: return [2];
432
- }
433
- });
434
- }); };
435
- this.createProCustomer = function (customer) { return __awaiter(_this, void 0, void 0, function () {
436
- var fetchData, result, e_2;
437
- return __generator(this, function (_a) {
438
- switch (_a.label) {
439
- case 0:
440
- _a.trys.push([0, 3, , 4]);
441
- return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/user/createProWithId"), {
442
- method: 'POST',
443
- headers: {
444
- authorization: "Bearer ".concat(this._token),
445
- 'Content-Type': 'application/json'
446
- },
447
- body: JSON.stringify({ customer: customer })
448
- })];
449
- case 1:
450
- fetchData = _a.sent();
451
- return [4, fetchData.json()];
452
- case 2:
453
- result = _a.sent();
454
- if (!!fetchData.status && fetchData.status !== 200)
455
- throw "".concat(result.data);
456
- return [2, true];
457
- case 3:
458
- e_2 = _a.sent();
459
- console.log('error on creating G2 customer: ', e_2.toString());
460
- return [2, e_2.toString()];
461
- case 4: return [2];
462
- }
463
- });
464
- }); };
465
- this.fetchCustomPriceList = function (customerID, isPA) {
466
- if (isPA === void 0) { isPA = false; }
467
- return __awaiter(_this, void 0, void 0, function () {
468
- var id, g2PriceListQuery, prices, e_3;
469
- return __generator(this, function (_a) {
470
- switch (_a.label) {
471
- case 0:
472
- _a.trys.push([0, 3, , 4]);
473
- id = !!isPA ? "".concat(customerID, "PA") : customerID;
474
- return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/services/g2/customers/").concat(id, "/customPrices"), {
475
- method: 'POST',
476
- headers: {
477
- authorization: "Bearer ".concat(this._token),
478
- 'Content-Type': 'application/json'
479
- }
480
- })];
481
- case 1:
482
- g2PriceListQuery = _a.sent();
483
- return [4, g2PriceListQuery.json()];
484
- case 2:
485
- prices = _a.sent();
486
- if (!!g2PriceListQuery.status && g2PriceListQuery.status !== 200)
487
- throw "Error - ".concat(g2PriceListQuery.status);
488
- if (!!!prices || !!!prices.length)
489
- throw 'Error - no data';
490
- return [2, prices];
491
- case 3:
492
- e_3 = _a.sent();
493
- console.log('error on fetching customer from G2: ', e_3);
494
- return [2];
495
- case 4: return [2];
496
- }
497
- });
498
- });
499
- };
500
- this.validateAccount = function (code) { return __awaiter(_this, void 0, void 0, function () {
501
- var fetchData, responseData;
502
- return __generator(this, function (_a) {
503
- switch (_a.label) {
504
- case 0: return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/user/validateEmail"), {
505
- method: 'POST',
506
- headers: {
507
- authorization: "Bearer ".concat(this._token),
508
- 'Content-Type': 'application/json',
509
- 'x-gng-ecomm-token': this._userToken
510
- },
511
- body: JSON.stringify({ code: code })
512
- })];
513
- case 1:
514
- fetchData = _a.sent();
515
- return [4, fetchData.json()];
516
- case 2:
517
- responseData = _a.sent();
518
- if (responseData.status !== 200) {
519
- throw new Error(JSON.stringify({ status: responseData.status, error: responseData.error }));
520
- }
521
- if (!!!responseData.data.userData) {
522
- throw new Error(JSON.stringify({ status: responseData.status, error: 'User not sent in request.' }));
523
- }
524
- if (responseData.token)
525
- this.setUserToken(responseData.token);
526
- return [2, responseData.data.userData];
527
- }
528
- });
529
- }); };
530
- this.logout = function () {
531
- _this.setUserToken('');
532
- localStorage.removeItem("".concat(_this._org, "__cart"));
533
- localStorage.removeItem('userLogged');
534
- localStorage.removeItem('isPro');
535
- localStorage.removeItem('foundInG2');
536
- localStorage.removeItem('customPriceList');
537
- localStorage.removeItem('lastCustomPriceFetch');
538
- localStorage.removeItem('userToken');
539
- localStorage.removeItem('wishlist');
540
- localStorage.removeItem('stockNotification');
541
- js_cookie_1.default.remove('userToken', { expires: new Date(0) });
542
- };
543
- this.registerUser = function (locale, userData, password) { return __awaiter(_this, void 0, void 0, function () {
544
- var fetchData, responseData;
545
- return __generator(this, function (_a) {
546
- switch (_a.label) {
547
- case 0: return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/register"), {
548
- method: 'PUT',
549
- headers: {
550
- Authorization: "Bearer ".concat(this._token),
551
- 'Content-Type': 'application/json',
552
- 'x-gng-ecomm-locale': locale
553
- },
554
- body: JSON.stringify({ userData: userData, password: password })
555
- })];
556
- case 1:
557
- fetchData = _a.sent();
558
- if (fetchData.status == 200)
559
- return [2, { status: 200, error: '' }];
560
- return [4, fetchData.json()];
561
- case 2:
562
- responseData = _a.sent();
563
- return [2, { status: responseData.status, error: responseData.error }];
564
- }
565
- });
566
- }); };
567
- this.getUser = function (keepTempHash) { return __awaiter(_this, void 0, void 0, function () {
568
- var token, localToken, fetchData, responseData, _a, temp_hash, rest;
569
- return __generator(this, function (_b) {
570
- switch (_b.label) {
571
- case 0:
572
- token = this._userToken;
573
- if (!!!token) {
574
- localToken = localStorage.getItem('userToken');
575
- if (!!localToken) {
576
- token = localToken;
577
- }
578
- }
579
- return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/user/get"), {
580
- method: 'GET',
581
- headers: {
582
- authorization: "Bearer ".concat(this._token),
583
- 'Content-Type': 'application/json',
584
- 'x-gng-ecomm-token': token
585
- }
586
- })];
587
- case 1:
588
- fetchData = _b.sent();
589
- return [4, fetchData.json()];
590
- case 2:
591
- responseData = _b.sent();
592
- if (responseData.status !== 200) {
593
- throw new Error(JSON.stringify({ status: responseData.status, error: responseData.error }));
594
- }
595
- if (!!!responseData.data.userData) {
596
- throw new Error(JSON.stringify({ status: responseData.status, error: 'User not sent in request.' }));
597
- }
598
- if (responseData.token)
599
- this.setUserToken(responseData.token);
600
- _a = responseData.data.userData, temp_hash = _a.temp_hash, rest = __rest(_a, ["temp_hash"]);
601
- return [2, __assign(__assign({}, rest), (!!keepTempHash ? { temp_hash: temp_hash } : {}))];
602
- }
603
- });
604
- }); };
605
- this.saveUser = function (userData) { return __awaiter(_this, void 0, void 0, function () {
606
- var fetchData, responseData;
607
- return __generator(this, function (_a) {
608
- switch (_a.label) {
609
- case 0: return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/user/save"), {
610
- method: 'POST',
611
- headers: {
612
- authorization: "Bearer ".concat(this._token),
613
- 'Content-Type': 'application/json',
614
- 'x-gng-ecomm-token': this._userToken
615
- },
616
- body: JSON.stringify({ userData: userData })
617
- })];
618
- case 1:
619
- fetchData = _a.sent();
620
- return [4, fetchData.json()];
621
- case 2:
622
- responseData = _a.sent();
623
- if (responseData.status !== 200) {
624
- throw new Error(JSON.stringify({ status: responseData.status, error: responseData.error }));
625
- }
626
- if (responseData.data !== 'done') {
627
- throw new Error(JSON.stringify({ status: responseData.status, error: 'User not sent in response.' }));
628
- }
629
- if (responseData.token)
630
- this.setUserToken(responseData.token);
631
- return [2, true];
632
- }
633
- });
634
- }); };
635
- this.deleteUser = function () { return __awaiter(_this, void 0, void 0, function () {
636
- var fetchData, responseData;
637
- return __generator(this, function (_a) {
638
- switch (_a.label) {
639
- case 0: return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/user/delete"), {
640
- method: 'GET',
641
- headers: {
642
- authorization: "Bearer ".concat(this._token),
643
- 'x-gng-ecomm-token': this._userToken
644
- }
645
- })];
646
- case 1:
647
- fetchData = _a.sent();
648
- return [4, fetchData.json()];
649
- case 2:
650
- responseData = _a.sent();
651
- if (responseData.status !== 200) {
652
- return [2, false];
653
- }
654
- return [2, true];
655
- }
656
- });
657
- }); };
658
- this.getOrders = function (lastID, iteration) { return __awaiter(_this, void 0, void 0, function () {
659
- var queryString, fetchData, responseData;
660
- return __generator(this, function (_a) {
661
- switch (_a.label) {
662
- case 0:
663
- queryString = "?fromLastID=".concat(lastID !== null && lastID !== void 0 ? lastID : '', "&skip=").concat(iteration !== null && iteration !== void 0 ? iteration : '');
664
- return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/user/orders").concat(queryString), {
665
- method: 'GET',
666
- headers: {
667
- authorization: "Bearer ".concat(this._token),
668
- 'Content-Type': 'application/json',
669
- 'x-gng-ecomm-token': this._userToken
670
- }
671
- })];
672
- case 1:
673
- fetchData = _a.sent();
674
- return [4, fetchData.json()];
675
- case 2:
676
- responseData = (_a.sent());
677
- if (responseData.status !== 200) {
678
- return [2, responseData.data];
679
- }
680
- return [2, responseData.data];
681
- }
682
- });
683
- }); };
684
- this.killRepCart = function (hashed_cart_id) { return __awaiter(_this, void 0, void 0, function () {
685
- var fetchData, responseData, error_2;
686
- return __generator(this, function (_a) {
687
- switch (_a.label) {
688
- case 0:
689
- _a.trys.push([0, 3, , 4]);
690
- return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/user/killRepCart/").concat(encodeURIComponent(hashed_cart_id)), {
691
- method: 'GET',
692
- headers: {
693
- authorization: "Bearer ".concat(this._token),
694
- 'Content-Type': 'application/json',
695
- 'x-gng-ecomm-token': this._userToken
696
- }
697
- })];
698
- case 1:
699
- fetchData = _a.sent();
700
- return [4, fetchData.json()];
701
- case 2:
702
- responseData = (_a.sent());
703
- if (responseData.status !== 200) {
704
- return [2, responseData.data];
705
- }
706
- return [2, responseData.data];
707
- case 3:
708
- error_2 = _a.sent();
709
- console.log(error_2);
710
- return [2, ''];
711
- case 4: return [2];
712
- }
713
- });
714
- }); };
715
- this.getOrder = function (orderID, token) { return __awaiter(_this, void 0, void 0, function () {
716
- var fetchData, responseData, error_3;
717
- return __generator(this, function (_a) {
718
- switch (_a.label) {
719
- case 0:
720
- _a.trys.push([0, 3, , 4]);
721
- return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/user/order/").concat(orderID), {
722
- method: 'POST',
723
- headers: {
724
- authorization: "Bearer ".concat(this._token),
725
- 'Content-Type': 'application/json',
726
- 'x-gng-ecomm-token': this._userToken
727
- },
728
- body: JSON.stringify({ orderToken: token })
729
- })];
730
- case 1:
731
- fetchData = _a.sent();
732
- return [4, fetchData.json()];
733
- case 2:
734
- responseData = (_a.sent());
735
- if (responseData.status !== 200) {
736
- return [2, responseData.data];
737
- }
738
- return [2, responseData.data];
739
- case 3:
740
- error_3 = _a.sent();
741
- console.log(error_3);
742
- return [2, ''];
743
- case 4: return [2];
744
- }
745
- });
746
- }); };
747
- this.changeProfilePicture = function (file) { return __awaiter(_this, void 0, void 0, function () {
748
- var fetchData, responseData;
749
- return __generator(this, function (_a) {
750
- switch (_a.label) {
751
- case 0: return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/user/changeProfilePicture"), {
752
- method: 'POST',
753
- headers: {
754
- authorization: "Bearer ".concat(this._token),
755
- 'Content-Type': 'application/json',
756
- 'x-gng-ecomm-token': this._userToken
757
- },
758
- body: JSON.stringify({
759
- file: file
760
- })
761
- })];
762
- case 1:
763
- fetchData = _a.sent();
764
- return [4, fetchData.json()];
765
- case 2:
766
- responseData = (_a.sent());
767
- return [2, responseData.data];
768
- }
769
- });
770
- }); };
771
- this.changePassword = function (currentPassword, newPassword) { return __awaiter(_this, void 0, void 0, function () {
772
- var fetchData, responseData;
773
- return __generator(this, function (_a) {
774
- switch (_a.label) {
775
- case 0: return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/user/changePassword"), {
776
- method: 'POST',
777
- headers: {
778
- authorization: "Bearer ".concat(this._token),
779
- 'Content-Type': 'application/json',
780
- 'x-gng-ecomm-token': this._userToken
781
- },
782
- body: JSON.stringify({ currentPassword: currentPassword, newPassword: newPassword })
783
- })];
784
- case 1:
785
- fetchData = _a.sent();
786
- return [4, fetchData.json()];
787
- case 2:
788
- responseData = (_a.sent());
789
- if (responseData.status === 200)
790
- return [2, responseData.data];
791
- return [2, responseData.error];
792
- }
793
- });
794
- }); };
795
- this.sendResetPasswordEmail = function (locale, userEmail, forPro, withEmail, isTest) { return __awaiter(_this, void 0, void 0, function () {
796
- var fetchData, responseData;
797
- return __generator(this, function (_a) {
798
- switch (_a.label) {
799
- case 0: return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/user/sentForgotPasswordEmail"), {
800
- method: 'POST',
801
- headers: {
802
- authorization: "Bearer ".concat(this._token),
803
- 'Content-Type': 'application/json',
804
- 'x-gng-ecomm-token': this._userToken,
805
- 'x-gng-ecomm-locale': locale
806
- },
807
- body: JSON.stringify({ userEmail: userEmail, forPro: forPro, withEmail: withEmail, isTest: isTest })
808
- })];
809
- case 1:
810
- fetchData = _a.sent();
811
- return [4, fetchData.json()];
812
- case 2:
813
- responseData = (_a.sent());
814
- if (responseData.status === 200)
815
- return [2, responseData.data];
816
- if (responseData.status === 403)
817
- return [2, {
818
- fr: "Plus d'un compte a \u00E9t\u00E9 trouv\u00E9 avec ".concat(withEmail ? 'ce courriel' : 'ce ID client', ". Veuillez contacter un administrateur pour proc\u00E9der."),
819
- en: "More than one account was found with ".concat(withEmail ? 'this email' : 'this client ID', ". Please contact an administrator to proceed.")
820
- }];
821
- return [2, responseData.error];
822
- }
823
- });
824
- }); };
825
- this.sendApplicationEmail = function (locale, form) { return __awaiter(_this, void 0, void 0, function () {
826
- var cvBase64, fetchData, responseData, error_4;
827
- return __generator(this, function (_a) {
828
- switch (_a.label) {
829
- case 0:
830
- _a.trys.push([0, 4, , 5]);
831
- if (!!!form.cv)
832
- return [2, {
833
- error: "Couldn't find cv"
834
- }];
835
- return [4, (0, functions_2.toBase64)(form.cv)];
836
- case 1:
837
- cvBase64 = _a.sent();
838
- if (typeof cvBase64 !== 'string') {
839
- return [2, {
840
- error: "Couldn't convert file to base64"
841
- }];
842
- }
843
- return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/email/sendApplicationEmail"), {
844
- method: 'POST',
845
- headers: {
846
- authorization: "Bearer ".concat(this._token),
847
- 'Content-Type': 'application/json',
848
- 'x-gng-ecomm-token': this._userToken,
849
- 'x-gng-ecomm-locale': locale
850
- },
851
- body: JSON.stringify(__assign(__assign({}, form), { cv: cvBase64 }))
852
- })];
853
- case 2:
854
- fetchData = _a.sent();
855
- return [4, fetchData.json()];
856
- case 3:
857
- responseData = (_a.sent());
858
- if (responseData.status === 200)
859
- return [2, responseData.data];
860
- return [2, responseData.error];
861
- case 4:
862
- error_4 = _a.sent();
863
- return [2, 'error'];
864
- case 5: return [2];
865
- }
866
- });
867
- }); };
868
- this.sendContactEmail = function (locale, form) { return __awaiter(_this, void 0, void 0, function () {
869
- var fetchData, responseData;
870
- return __generator(this, function (_a) {
871
- switch (_a.label) {
872
- case 0: return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/email/sendContactEmail"), {
873
- method: 'POST',
874
- headers: {
875
- authorization: "Bearer ".concat(this._token),
876
- 'Content-Type': 'application/json',
877
- 'x-gng-ecomm-token': this._userToken,
878
- 'x-gng-ecomm-locale': locale
879
- },
880
- body: JSON.stringify(form)
881
- })];
882
- case 1:
883
- fetchData = _a.sent();
884
- return [4, fetchData.json()];
885
- case 2:
886
- responseData = (_a.sent());
887
- if (responseData.status === 200)
888
- return [2, responseData.data];
889
- return [2, responseData.error];
890
- }
891
- });
892
- }); };
893
- this.sendGenericOtherEmail = function (locale, form, templateId, to, replyTo) { return __awaiter(_this, void 0, void 0, function () {
894
- var getSubjectByType, fetchData, responseData, error_5;
895
- return __generator(this, function (_a) {
896
- switch (_a.label) {
897
- case 0:
898
- getSubjectByType = function (type) {
899
- switch (type) {
900
- case 'confirmation_lawn_submission':
901
- return { fr: 'Soumission gazon - Confirmation de réception', en: 'Lawn submission - Confirmation' };
902
- default:
903
- return undefined;
904
- }
905
- };
906
- _a.label = 1;
907
- case 1:
908
- _a.trys.push([1, 4, , 5]);
909
- return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/email/sendGenericOtherEmail"), {
910
- method: 'POST',
911
- headers: {
912
- authorization: "Bearer ".concat(this._token),
913
- 'Content-Type': 'application/json',
914
- 'x-gng-ecomm-token': this._userToken,
915
- 'x-gng-ecomm-locale': locale
916
- },
917
- body: JSON.stringify(__assign(__assign({}, (!!form ? { content: form } : {})), { subject: getSubjectByType(templateId), templateId: templateId, to: to, replyTo: replyTo }))
918
- })];
919
- case 2:
920
- fetchData = _a.sent();
921
- return [4, fetchData.json()];
922
- case 3:
923
- responseData = (_a.sent());
924
- if (responseData.status === 200)
925
- return [2, responseData.data];
926
- return [2, responseData.error];
927
- case 4:
928
- error_5 = _a.sent();
929
- console.log('error on sendGenericOtherEmail: ', error_5);
930
- return [3, 5];
931
- case 5: return [2];
932
- }
933
- });
934
- }); };
935
- this.sendServicePageEmail = function (locale, form, type, testEmail) { return __awaiter(_this, void 0, void 0, function () {
936
- var attachments, rest, updatedAttachments, _i, _a, att, cvBase64, e_4, getSubjectByType, fetchData, responseData, e_5;
937
- return __generator(this, function (_b) {
938
- switch (_b.label) {
939
- case 0:
940
- attachments = form.attachments, rest = __rest(form, ["attachments"]);
941
- updatedAttachments = [];
942
- if (!!!attachments) return [3, 6];
943
- _i = 0, _a = attachments;
944
- _b.label = 1;
945
- case 1:
946
- if (!(_i < _a.length)) return [3, 6];
947
- att = _a[_i];
948
- _b.label = 2;
949
- case 2:
950
- _b.trys.push([2, 4, , 5]);
951
- return [4, (0, functions_2.toBase64)(att)];
952
- case 3:
953
- cvBase64 = _b.sent();
954
- updatedAttachments.push({ name: att.name, content: cvBase64 });
955
- return [3, 5];
956
- case 4:
957
- e_4 = _b.sent();
958
- console.log('error on converting to base64: ', e_4);
959
- return [3, 5];
960
- case 5:
961
- _i++;
962
- return [3, 1];
963
- case 6:
964
- getSubjectByType = function () {
965
- switch (type) {
966
- case 'admin_3D_plans':
967
- return { fr: 'Plans 3D - Nouvelle demande', en: '3D plans - new request' };
968
- case 'admin_vegetals':
969
- return { fr: 'Commande de végétaux - nouvelle soumission', en: 'Vegetals - new quotation' };
970
- case 'admin_pickup_on_site':
971
- return { fr: 'Ramassage sur chantier - nouvelle demande', en: 'Pickup on site - new request' };
972
- case 'admin_borrow_tools':
973
- return { fr: "Location d'outils - nouvelle demande", en: 'Rent tools - new request' };
974
- case 'admin_sales_info':
975
- return {
976
- fr: 'Produits en solde - Information demandée',
977
- en: 'On sale products - Information request'
978
- };
979
- case 'admin_credit_info':
980
- return {
981
- fr: 'Département de crédit - Information demandée',
982
- en: 'Credit department - Information request'
983
- };
984
- case 'admin_transport_quote':
985
- return {
986
- fr: 'Location de camion - nouvelle soumission',
987
- en: 'Transport truck rental - new quotation'
988
- };
989
- case 'admin_special_order':
990
- return { fr: 'Commande spéciale - nouvelle demande', en: 'Special order - new request' };
991
- case 'admin_installation':
992
- return { fr: 'Installation - nouvelle soumission', en: 'Installation - new quotation' };
993
- case 'admin_find_landscaper':
994
- return { fr: 'Trouver un paysagiste - nouvelle demande', en: 'Find a landscaper - new request' };
995
- case 'admin_lawn_submission':
996
- return { fr: 'Soumission gazon - nouvelle demande', en: 'Lawn submission - new request' };
997
- case 'confirmation_find_landsacper':
998
- return { fr: 'Trouver un paysagiste - Confirmation', en: 'Find a landscaper - Confirmation' };
999
- default:
1000
- return { fr: 'Demande de service - nouvelle soumission', en: 'Service request - new quotation' };
1001
- }
1002
- };
1003
- _b.label = 7;
1004
- case 7:
1005
- _b.trys.push([7, 10, , 11]);
1006
- return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/email/sendServiceStaticPageEmail"), {
1007
- method: 'POST',
1008
- headers: {
1009
- authorization: "Bearer ".concat(this._token),
1010
- 'Content-Type': 'application/json',
1011
- 'x-gng-ecomm-token': this._userToken,
1012
- 'x-gng-ecomm-locale': locale
1013
- },
1014
- body: JSON.stringify(__assign(__assign(__assign(__assign({}, rest), (!!updatedAttachments && !!updatedAttachments.length ? { attachments: updatedAttachments } : {})), { subject: getSubjectByType(), title: getSubjectByType(), type: type }), (!!testEmail ? { test_email: testEmail } : {})))
1015
- })];
1016
- case 8:
1017
- fetchData = _b.sent();
1018
- return [4, fetchData.json()];
1019
- case 9:
1020
- responseData = (_b.sent());
1021
- if (responseData.status === 200)
1022
- return [2, true];
1023
- return [2, responseData.error];
1024
- case 10:
1025
- e_5 = _b.sent();
1026
- console.log('error on calling api: ', e_5);
1027
- if (!!updatedAttachments) {
1028
- return [2, {
1029
- status: 413,
1030
- error: {
1031
- fr: "Vos pièces jointes n'ont pas pu être envoyées. Veuillez réessayer.",
1032
- en: 'Your attachments could not be sent. Please try again.'
1033
- }
1034
- }];
1035
- }
1036
- return [2, ''];
1037
- case 11: return [2];
1038
- }
1039
- });
1040
- }); };
1041
- this.sendSponsorRequestEmail = function (locale, form, template_name) { return __awaiter(_this, void 0, void 0, function () {
1042
- var plan, rest, updatedPlan, planBase64, splitString, e_6, fetchData, responseData;
1043
- return __generator(this, function (_a) {
1044
- switch (_a.label) {
1045
- case 0:
1046
- plan = form.plan, rest = __rest(form, ["plan"]);
1047
- if (!!!plan) return [3, 4];
1048
- _a.label = 1;
1049
- case 1:
1050
- _a.trys.push([1, 3, , 4]);
1051
- return [4, (0, functions_2.toBase64)(plan)];
1052
- case 2:
1053
- planBase64 = _a.sent();
1054
- if (typeof planBase64 === 'string') {
1055
- splitString = planBase64.split(';base64,');
1056
- if (!!splitString.length && !!splitString[1]) {
1057
- updatedPlan = {
1058
- name: plan.name,
1059
- content: splitString[1]
1060
- };
1061
- }
1062
- }
1063
- return [3, 4];
1064
- case 3:
1065
- e_6 = _a.sent();
1066
- console.log('error on converting to base64: ', e_6);
1067
- return [3, 4];
1068
- case 4: return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/email/sendSponsorRequestEmail"), {
1069
- method: 'POST',
1070
- headers: {
1071
- authorization: "Bearer ".concat(this._token),
1072
- 'Content-Type': 'application/json',
1073
- 'x-gng-ecomm-token': this._userToken,
1074
- 'x-gng-ecomm-locale': locale
1075
- },
1076
- body: JSON.stringify({
1077
- contenu: __assign(__assign(__assign({}, rest), { admin: true, has_plan: !!updatedPlan }), (!!updatedPlan
1078
- ? {
1079
- plan: updatedPlan
1080
- }
1081
- : {})),
1082
- template_name: template_name
1083
- })
1084
- })];
1085
- case 5:
1086
- fetchData = _a.sent();
1087
- return [4, fetchData.json()];
1088
- case 6:
1089
- responseData = (_a.sent());
1090
- if (responseData.status === 200)
1091
- return [2, true];
1092
- return [2, responseData.error];
1093
- }
1094
- });
1095
- }); };
1096
- this.sendPreMeetingFormEmail = function (locale, form, proId) { return __awaiter(_this, void 0, void 0, function () {
1097
- var attachments, rest, _a, pro_logo, restProInfos, updatedAttachments, updatedLogo, _i, _b, att, cvBase64, e_7, logoBase64, e_8, fetchData, responseData;
1098
- return __generator(this, function (_c) {
1099
- switch (_c.label) {
1100
- case 0:
1101
- attachments = form.attachments, rest = __rest(form, ["attachments"]);
1102
- _a = rest.pro_infos, pro_logo = _a.pro_logo, restProInfos = __rest(_a, ["pro_logo"]);
1103
- updatedAttachments = [];
1104
- updatedLogo = '';
1105
- if (!!!attachments) return [3, 6];
1106
- _i = 0, _b = attachments;
1107
- _c.label = 1;
1108
- case 1:
1109
- if (!(_i < _b.length)) return [3, 6];
1110
- att = _b[_i];
1111
- _c.label = 2;
1112
- case 2:
1113
- _c.trys.push([2, 4, , 5]);
1114
- return [4, (0, functions_2.toBase64)(att)];
1115
- case 3:
1116
- cvBase64 = _c.sent();
1117
- updatedAttachments.push({ name: att.name, content: cvBase64 });
1118
- return [3, 5];
1119
- case 4:
1120
- e_7 = _c.sent();
1121
- console.log('error on converting to base64: ', e_7);
1122
- return [3, 5];
1123
- case 5:
1124
- _i++;
1125
- return [3, 1];
1126
- case 6:
1127
- if (!!!pro_logo) return [3, 10];
1128
- _c.label = 7;
1129
- case 7:
1130
- _c.trys.push([7, 9, , 10]);
1131
- return [4, (0, functions_2.toBase64)(pro_logo)];
1132
- case 8:
1133
- logoBase64 = _c.sent();
1134
- updatedLogo = { name: pro_logo.name, content: logoBase64 };
1135
- return [3, 10];
1136
- case 9:
1137
- e_8 = _c.sent();
1138
- console.log('error on converting logo to base64: ', e_8);
1139
- return [3, 10];
1140
- case 10: return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/email/sendPreMeetingFormEmail"), {
1141
- method: 'POST',
1142
- headers: {
1143
- authorization: "Bearer ".concat(this._token),
1144
- 'Content-Type': 'application/json',
1145
- 'x-gng-ecomm-token': this._userToken,
1146
- 'x-gng-ecomm-locale': locale
1147
- },
1148
- body: JSON.stringify(__assign(__assign(__assign(__assign({}, rest), { pro_infos: __assign(__assign({}, restProInfos), (!!updatedLogo ? { pro_logo: updatedLogo } : {})) }), (!!updatedAttachments && !!updatedAttachments.length ? { attachments: updatedAttachments } : {})), (!!proId ? { pro_id: proId } : {})))
1149
- })];
1150
- case 11:
1151
- fetchData = _c.sent();
1152
- return [4, fetchData.json()];
1153
- case 12:
1154
- responseData = (_c.sent());
1155
- if (responseData.status === 200)
1156
- return [2, true];
1157
- return [2, responseData.error];
1158
- }
1159
- });
1160
- }); };
1161
- this.sendWishlistByEmail = function (locale, contenu, template_name) { return __awaiter(_this, void 0, void 0, function () {
1162
- var fetchData, responseData;
1163
- return __generator(this, function (_a) {
1164
- switch (_a.label) {
1165
- case 0: return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/email/sendWishlistEmail"), {
1166
- method: 'POST',
1167
- headers: {
1168
- authorization: "Bearer ".concat(this._token),
1169
- 'Content-Type': 'application/json',
1170
- 'x-gng-ecomm-token': this._userToken,
1171
- 'x-gng-ecomm-locale': locale
1172
- },
1173
- body: JSON.stringify({ contenu: contenu, template_name: template_name })
1174
- })];
1175
- case 1:
1176
- fetchData = _a.sent();
1177
- return [4, fetchData.json()];
1178
- case 2:
1179
- responseData = (_a.sent());
1180
- if (responseData.status === 200)
1181
- return [2, true];
1182
- return [2, responseData.error];
1183
- }
1184
- });
1185
- }); };
1186
- this.resetPassword = function (token, newPassword, withEmail) { return __awaiter(_this, void 0, void 0, function () {
1187
- var fetchData, responseData;
1188
- return __generator(this, function (_a) {
1189
- switch (_a.label) {
1190
- case 0: return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/user/resetPassword"), {
1191
- method: 'POST',
1192
- headers: {
1193
- authorization: "Bearer ".concat(this._token),
1194
- 'Content-Type': 'application/json',
1195
- 'x-gng-ecomm-token': this._userToken
1196
- },
1197
- body: JSON.stringify({ validationCode: token, newPassword: newPassword, withEmail: withEmail })
1198
- })];
1199
- case 1:
1200
- fetchData = _a.sent();
1201
- return [4, fetchData.json()];
1202
- case 2:
1203
- responseData = (_a.sent());
1204
- if (responseData.status === 200)
1205
- return [2, responseData.data];
1206
- if (responseData.status === 403)
1207
- return [2, {
1208
- fr: "Plus d'un compte a \u00E9t\u00E9 trouv\u00E9 avec ".concat(withEmail ? 'ce courriel' : 'ce ID client', ". Veuillez contacter un administrateur pour proc\u00E9der."),
1209
- en: "More than one account was found with ".concat(withEmail ? 'this email' : 'this client ID', ". Please contact an administrator to proceed.")
1210
- }];
1211
- return [2, responseData.error];
1212
- }
1213
- });
1214
- }); };
1215
- this.user = {
1216
- getUser: this.getUser,
1217
- saveUser: this.saveUser,
1218
- deleteUser: this.deleteUser,
1219
- loginUser: this.loginUser,
1220
- loginUserWithID: this.loginUserWithID,
1221
- loginUserWithFacebook: this.loginUserWithFacebook,
1222
- logout: this.logout,
1223
- registerUser: this.registerUser,
1224
- killRepCart: this.killRepCart,
1225
- getOrder: this.getOrder,
1226
- getOrders: this.getOrders,
1227
- changePassword: this.changePassword,
1228
- changeProfilePicture: this.changeProfilePicture,
1229
- validateAccount: this.validateAccount,
1230
- sendResetPasswordEmail: this.sendResetPasswordEmail,
1231
- resetPassword: this.resetPassword,
1232
- sendApplicationEmail: this.sendApplicationEmail,
1233
- sendContactEmail: this.sendContactEmail,
1234
- sendServiceEmail: this.sendServicePageEmail,
1235
- anonymousResetPassword: this.anonymousResetPassword,
1236
- checkG2: this.checkG2ForCustomer,
1237
- createPro: this.createProCustomer,
1238
- fetchCustomPriceList: this.fetchCustomPriceList
1239
- };
1240
- this.getImage = function (imgName, formatQuery, addImgPath) {
1241
- if (addImgPath === void 0) { addImgPath = false; }
1242
- var img = new image_1.default("".concat(addImgPath ? _this._imgPath : '').concat(_this._imgPath, "/").concat(imgName));
1243
- return img.getFileDownloadUrl(formatQuery);
1244
- };
1245
- this.getProducts = function (page, hpp, query, filters, indice, f, useProspr) {
1246
- if (page === void 0) { page = 0; }
1247
- if (hpp === void 0) { hpp = 10; }
1248
- if (query === void 0) { query = ''; }
1249
- if (filters === void 0) { filters = ''; }
1250
- if (indice === void 0) { indice = 'products'; }
1251
- if (f === void 0) { f = ''; }
1252
- if (useProspr === void 0) { useProspr = false; }
1253
- return __awaiter(_this, void 0, void 0, function () {
1254
- var error_6;
1255
- return __generator(this, function (_a) {
1256
- switch (_a.label) {
1257
- case 0:
1258
- _a.trys.push([0, 2, , 3]);
1259
- return [4, Product_1.default.fetch({
1260
- app: process.env.NEXT_PUBLIC_ALGOLIA_APP,
1261
- api: process.env.NEXT_PUBLIC_ALGOLIA_TOKEN,
1262
- page: page,
1263
- hpp: hpp,
1264
- query: query,
1265
- filters: filters,
1266
- indice: indice || 'products',
1267
- f: f,
1268
- useProspr: useProspr,
1269
- space: undefined
1270
- })];
1271
- case 1: return [2, _a.sent()];
1272
- case 2:
1273
- error_6 = _a.sent();
1274
- throw error_6;
1275
- case 3: return [2];
1276
- }
1277
- });
1278
- });
1279
- };
1280
- this.getProduct = function (parent_slug, locale, useProdArray, noDrafts) { return __awaiter(_this, void 0, void 0, function () {
1281
- var prod, fetchData, responseData;
1282
- return __generator(this, function (_a) {
1283
- switch (_a.label) {
1284
- case 0:
1285
- prod = undefined;
1286
- if (!!useProdArray && !!useProdArray.length) {
1287
- prod = useProdArray.find(function (fee) { return fee.slug === parent_slug; });
1288
- }
1289
- if (!!!!prod) return [3, 3];
1290
- return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/products/").concat(encodeURIComponent(parent_slug)), {
1291
- method: 'GET',
1292
- headers: {
1293
- Authorization: "Bearer ".concat(this._token),
1294
- 'x-gng-ecomm-locale': locale,
1295
- 'x-gng-ecomm-token': this._userToken
1296
- }
1297
- })];
1298
- case 1:
1299
- fetchData = _a.sent();
1300
- return [4, fetchData.json()];
1301
- case 2:
1302
- responseData = _a.sent();
1303
- if (responseData.status !== 200)
1304
- throw new Error(JSON.stringify({ status: responseData.status, error: responseData.error }));
1305
- prod = responseData.data;
1306
- _a.label = 3;
1307
- case 3:
1308
- if (!!noDrafts && prod.draft)
1309
- return [2, undefined];
1310
- return [2, prod];
1311
- }
1312
- });
1313
- }); };
1314
- this.getUpsellOfProducts = function (slugs, customPriceList) { return __awaiter(_this, void 0, void 0, function () {
1315
- var fetchData, responseData;
1316
- return __generator(this, function (_a) {
1317
- switch (_a.label) {
1318
- case 0: return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/products/getUpsellOfProductsWithProducts"), {
1319
- method: 'POST',
1320
- headers: {
1321
- Authorization: "Bearer ".concat(this._token),
1322
- 'Content-Type': 'application/json'
1323
- },
1324
- body: JSON.stringify(__assign({ slugs: slugs }, (!!customPriceList ? { customPriceList: customPriceList } : {})))
1325
- })];
1326
- case 1:
1327
- fetchData = _a.sent();
1328
- return [4, fetchData.json()];
1329
- case 2:
1330
- responseData = _a.sent();
1331
- if (responseData.status !== 200)
1332
- throw new Error(JSON.stringify({ status: responseData.status, error: responseData.error }));
1333
- return [2, responseData.data];
1334
- }
1335
- });
1336
- }); };
1337
- this.getAttributes = function () { return __awaiter(_this, void 0, void 0, function () {
1338
- var fetchData, resJson, error_7;
1339
- return __generator(this, function (_a) {
1340
- switch (_a.label) {
1341
- case 0:
1342
- _a.trys.push([0, 3, , 4]);
1343
- return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/attributes"), {
1344
- method: 'GET',
1345
- headers: {
1346
- authorization: "Bearer ".concat(this._token),
1347
- 'Content-Type': 'application/json'
1348
- }
1349
- })];
1350
- case 1:
1351
- fetchData = _a.sent();
1352
- return [4, fetchData.json()];
1353
- case 2:
1354
- resJson = _a.sent();
1355
- return [2, resJson.data.map(function (a) { return (__assign(__assign({}, a), { slug: !!a.slug ? a.slug : (0, functions_1.string_to_slug)((0, functions_1.translate)('fr', a.name)) })); })];
1356
- case 3:
1357
- error_7 = _a.sent();
1358
- console.log('error fetch attributes: ', error_7);
1359
- return [3, 4];
1360
- case 4: return [2];
1361
- }
1362
- });
1363
- }); };
1364
- this.getCategories = function () { return __awaiter(_this, void 0, void 0, function () {
1365
- var fetchData, resJson, error_8;
1366
- return __generator(this, function (_a) {
1367
- switch (_a.label) {
1368
- case 0:
1369
- _a.trys.push([0, 3, , 4]);
1370
- return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/categories"), {
1371
- method: 'GET',
1372
- headers: {
1373
- authorization: "Bearer ".concat(this._token),
1374
- 'Content-Type': 'application/json'
1375
- }
1376
- })];
1377
- case 1:
1378
- fetchData = _a.sent();
1379
- return [4, fetchData.json()];
1380
- case 2:
1381
- resJson = (_a.sent());
1382
- return [2, resJson.data];
1383
- case 3:
1384
- error_8 = _a.sent();
1385
- console.log('error fetch categories: ', error_8);
1386
- return [3, 4];
1387
- case 4: return [2];
1388
- }
1389
- });
1390
- }); };
1391
- this.getBrands = function () { return __awaiter(_this, void 0, void 0, function () {
1392
- var fetchData, resJson, error_9;
1393
- return __generator(this, function (_a) {
1394
- switch (_a.label) {
1395
- case 0:
1396
- _a.trys.push([0, 3, , 4]);
1397
- return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/brands"), {
1398
- method: 'GET',
1399
- headers: {
1400
- authorization: "Bearer ".concat(this._token),
1401
- 'Content-Type': 'application/json'
1402
- }
1403
- })];
1404
- case 1:
1405
- fetchData = _a.sent();
1406
- return [4, fetchData.json()];
1407
- case 2:
1408
- resJson = (_a.sent());
1409
- return [2, resJson.data];
1410
- case 3:
1411
- error_9 = _a.sent();
1412
- console.log('error fetch brands: ', error_9);
1413
- return [3, 4];
1414
- case 4: return [2];
1415
- }
1416
- });
1417
- }); };
1418
- this.getInventoryItems = function (parentSlug) { return __awaiter(_this, void 0, void 0, function () {
1419
- var fetchData, resJson, error_10;
1420
- return __generator(this, function (_a) {
1421
- switch (_a.label) {
1422
- case 0:
1423
- _a.trys.push([0, 3, , 4]);
1424
- return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/inventories").concat(!!parentSlug ? "/".concat(encodeURIComponent(parentSlug)) : ''), {
1425
- method: 'GET',
1426
- headers: {
1427
- authorization: "Bearer ".concat(this._token),
1428
- 'Content-Type': 'application/json'
1429
- }
1430
- })];
1431
- case 1:
1432
- fetchData = _a.sent();
1433
- return [4, fetchData.json()];
1434
- case 2:
1435
- resJson = (_a.sent());
1436
- return [2, resJson.data];
1437
- case 3:
1438
- error_10 = _a.sent();
1439
- console.log("error fetch inventory items".concat(!!parentSlug ? 'for parentSlug ' + parentSlug : '', ": "), error_10);
1440
- return [3, 4];
1441
- case 4: return [2];
1442
- }
1443
- });
1444
- }); };
1445
- this.getOneInventoryItem = function (sku) { return __awaiter(_this, void 0, void 0, function () {
1446
- var fetchData, resJson, error_11;
1447
- return __generator(this, function (_a) {
1448
- switch (_a.label) {
1449
- case 0:
1450
- _a.trys.push([0, 3, , 4]);
1451
- return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/inventory/").concat(encodeURIComponent(sku)), {
1452
- method: 'GET',
1453
- headers: {
1454
- authorization: "Bearer ".concat(this._token),
1455
- 'Content-Type': 'application/json'
1456
- }
1457
- })];
1458
- case 1:
1459
- fetchData = _a.sent();
1460
- return [4, fetchData.json()];
1461
- case 2:
1462
- resJson = (_a.sent());
1463
- return [2, resJson.data];
1464
- case 3:
1465
- error_11 = _a.sent();
1466
- console.log("error fetch inventory item for sku: ".concat(sku), error_11);
1467
- return [2, undefined];
1468
- case 4: return [2];
1469
- }
1470
- });
1471
- }); };
1472
- this.getLatestProducts = function () { return __awaiter(_this, void 0, void 0, function () {
1473
- var fetchData, resJson, error_12;
1474
- return __generator(this, function (_a) {
1475
- switch (_a.label) {
1476
- case 0:
1477
- _a.trys.push([0, 3, , 4]);
1478
- return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/latest_products"), {
1479
- method: 'GET',
1480
- headers: {
1481
- authorization: "Bearer ".concat(this._token),
1482
- 'Content-Type': 'application/json'
1483
- }
1484
- })];
1485
- case 1:
1486
- fetchData = _a.sent();
1487
- return [4, fetchData.json()];
1488
- case 2:
1489
- resJson = (_a.sent());
1490
- return [2, resJson.data];
1491
- case 3:
1492
- error_12 = _a.sent();
1493
- console.log("error fetching latest products", error_12);
1494
- return [3, 4];
1495
- case 4: return [2];
1496
- }
1497
- });
1498
- }); };
1499
- this._getFees = function () { return __awaiter(_this, void 0, void 0, function () {
1500
- var fetchData, resJson, error_13;
1501
- return __generator(this, function (_a) {
1502
- switch (_a.label) {
1503
- case 0:
1504
- _a.trys.push([0, 3, , 4]);
1505
- return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/products/getFees"), {
1506
- method: 'GET',
1507
- headers: {
1508
- authorization: "Bearer ".concat(this._token),
1509
- 'x-gng-ecomm-token': this._userToken
1510
- }
1511
- })];
1512
- case 1:
1513
- fetchData = _a.sent();
1514
- return [4, fetchData.json()];
1515
- case 2:
1516
- resJson = (_a.sent());
1517
- if (resJson.status !== 200) {
1518
- console.log('error on fetching fees: ', !!resJson.error ? resJson.error.toString() : '');
1519
- return [2, []];
1520
- }
1521
- return [2, resJson.data];
1522
- case 3:
1523
- error_13 = _a.sent();
1524
- console.log("error fetching fees", error_13);
1525
- return [3, 4];
1526
- case 4: return [2];
1527
- }
1528
- });
1529
- }); };
1530
- this.products = {
1531
- getProducts: this.getProducts,
1532
- getProduct: this.getProduct,
1533
- getUpsellOfProducts: this.getUpsellOfProducts,
1534
- getAttributes: this.getAttributes,
1535
- getCategories: this.getCategories,
1536
- getBrands: this.getBrands,
1537
- getInventoryItems: this.getInventoryItems,
1538
- getOneInventoryItem: this.getOneInventoryItem,
1539
- getLatestProducts: this.getLatestProducts,
1540
- getFees: this._getFees
1541
- };
1542
- this.getIfAddressIsInsideZones = function (address) { return __awaiter(_this, void 0, void 0, function () {
1543
- var userPos, lat, lng, zone, zones, google_1, insideZones, _i, zones_2, zone_1, polygon, error_14;
1544
- return __generator(this, function (_a) {
1545
- switch (_a.label) {
1546
- case 0:
1547
- _a.trys.push([0, 4, , 5]);
1548
- return [4, (0, zones_1.getPositionFromAddress)(address)];
1549
- case 1:
1550
- userPos = _a.sent();
1551
- if (!!!userPos)
1552
- return [2, []];
1553
- lat = userPos.lat, lng = userPos.lng;
1554
- return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/shipping/zones"), {
1555
- method: 'POST',
1556
- headers: {
1557
- authorization: "Bearer ".concat(this._token),
1558
- 'Content-Type': 'application/json'
1559
- },
1560
- body: JSON.stringify({ address: address })
1561
- })];
1562
- case 2:
1563
- zone = _a.sent();
1564
- if (zone.status !== 200)
1565
- return [2, []];
1566
- return [4, zone.json()];
1567
- case 3:
1568
- zones = (_a.sent()).data.zones;
1569
- google_1 = window.google;
1570
- insideZones = [];
1571
- for (_i = 0, zones_2 = zones; _i < zones_2.length; _i++) {
1572
- zone_1 = zones_2[_i];
1573
- polygon = new google_1.maps.Polygon({
1574
- paths: zone_1.polygon.split(';').map(function (coords) { return ({
1575
- lat: (0, lodash_1.toNumber)(coords.split(',')[1]),
1576
- lng: (0, lodash_1.toNumber)(coords.split(',')[0])
1577
- }); })
1578
- });
1579
- if (google_1.maps.geometry.poly.containsLocation({ lat: Number(lat), lng: Number(lng) }, polygon)) {
1580
- insideZones.push(zone_1.slug);
1581
- }
1582
- }
1583
- return [2, insideZones];
1584
- case 4:
1585
- error_14 = _a.sent();
1586
- if (process.env.NODE_ENV !== 'production')
1587
- console.log('error while fetching zones', error_14);
1588
- return [2, []];
1589
- case 5: return [2];
1590
- }
1591
- });
1592
- }); };
1593
- this._pricingByQuery = function (query) { return __awaiter(_this, void 0, void 0, function () {
1594
- var fetchData, resJson, error_15;
1595
- return __generator(this, function (_a) {
1596
- switch (_a.label) {
1597
- case 0:
1598
- _a.trys.push([0, 3, , 4]);
1599
- return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/services/pricing/byQuery"), {
1600
- method: 'POST',
1601
- headers: {
1602
- authorization: "Bearer ".concat(this._token),
1603
- 'Content-Type': 'application/json'
1604
- },
1605
- body: JSON.stringify({ query: query })
1606
- })];
1607
- case 1:
1608
- fetchData = _a.sent();
1609
- return [4, fetchData.json()];
1610
- case 2:
1611
- resJson = _a.sent();
1612
- return [2, resJson.data];
1613
- case 3:
1614
- error_15 = _a.sent();
1615
- throw error_15;
1616
- case 4: return [2];
1617
- }
1618
- });
1619
- }); };
1620
- this._buyFromForm = function (form) { return __awaiter(_this, void 0, void 0, function () {
1621
- var fetchData, resJson, error_16;
1622
- return __generator(this, function (_a) {
1623
- switch (_a.label) {
1624
- case 0:
1625
- _a.trys.push([0, 3, , 4]);
1626
- return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/services/buy/fromForm"), {
1627
- method: 'POST',
1628
- headers: {
1629
- authorization: "Bearer ".concat(this._token),
1630
- 'Content-Type': 'application/json'
1631
- },
1632
- body: JSON.stringify(form)
1633
- })];
1634
- case 1:
1635
- fetchData = _a.sent();
1636
- return [4, fetchData.json()];
1637
- case 2:
1638
- resJson = _a.sent();
1639
- if (!!resJson.error) {
1640
- return [2, false];
1641
- }
1642
- return [2, true];
1643
- case 3:
1644
- error_16 = _a.sent();
1645
- throw error_16;
1646
- case 4: return [2];
1647
- }
1648
- });
1649
- }); };
1650
- this._getSearchServices = function () { return __awaiter(_this, void 0, void 0, function () {
1651
- var fetchData, resJson, space, error_17;
1652
- return __generator(this, function (_a) {
1653
- switch (_a.label) {
1654
- case 0:
1655
- _a.trys.push([0, 3, , 4]);
1656
- return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/space"), {
1657
- method: 'GET',
1658
- headers: {
1659
- authorization: "Bearer ".concat(this._token),
1660
- 'Content-Type': 'application/json'
1661
- }
1662
- })];
1663
- case 1:
1664
- fetchData = _a.sent();
1665
- return [4, fetchData.json()];
1666
- case 2:
1667
- resJson = _a.sent();
1668
- if (!!resJson.error) {
1669
- return [2, []];
1670
- }
1671
- space = resJson.data;
1672
- if (!!!space || !!!space._space)
1673
- return [2, []];
1674
- return [2, space._space.external_services.filter(function (s) { return s.type === 'index'; })];
1675
- case 3:
1676
- error_17 = _a.sent();
1677
- throw error_17;
1678
- case 4: return [2];
1679
- }
1680
- });
1681
- }); };
1682
- this.services = {
1683
- pricingByQuery: this._pricingByQuery,
1684
- buy: {
1685
- fromForm: this._buyFromForm
1686
- },
1687
- searchServices: this._getSearchServices
1688
- };
1689
- this._getAllCatalogues = function (locale) { return __awaiter(_this, void 0, void 0, function () {
1690
- var fetchData, responseData;
1691
- return __generator(this, function (_a) {
1692
- switch (_a.label) {
1693
- case 0: return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/catalogues"), {
1694
- method: 'GET',
1695
- headers: {
1696
- Authorization: "Bearer ".concat(this._token),
1697
- 'x-gng-ecomm-locale': locale
1698
- }
1699
- })];
1700
- case 1:
1701
- fetchData = _a.sent();
1702
- return [4, fetchData.json()];
1703
- case 2:
1704
- responseData = _a.sent();
1705
- if (responseData.status !== 200)
1706
- throw new Error(JSON.stringify({ status: responseData.status, error: responseData.error }));
1707
- return [2, responseData.data.filter(function (catalogue) { return !!!catalogue.draft; })];
1708
- }
1709
- });
1710
- }); };
1711
- this._getCatalogueBySlug = function (slug, locale) { return __awaiter(_this, void 0, void 0, function () {
1712
- var fetchData, responseData;
1713
- return __generator(this, function (_a) {
1714
- switch (_a.label) {
1715
- case 0: return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/catalogues/").concat(slug), {
1716
- method: 'GET',
1717
- headers: {
1718
- Authorization: "Bearer ".concat(this._token),
1719
- 'x-gng-ecomm-locale': locale
1720
- }
1721
- })];
1722
- case 1:
1723
- fetchData = _a.sent();
1724
- return [4, fetchData.json()];
1725
- case 2:
1726
- responseData = _a.sent();
1727
- if (responseData.status !== 200)
1728
- throw new Error(JSON.stringify({ status: responseData.status, error: responseData.error }));
1729
- return [2, responseData.data];
1730
- }
1731
- });
1732
- }); };
1733
- this.catalogues = {
1734
- getAll: this._getAllCatalogues,
1735
- getOne: this._getCatalogueBySlug
1736
- };
1737
- this.saveCustomerToMailchimpList = function (customerEmail, listID, mergeFields, tags) { return __awaiter(_this, void 0, void 0, function () {
1738
- var saved, responseData, e_9;
1739
- return __generator(this, function (_a) {
1740
- switch (_a.label) {
1741
- case 0:
1742
- _a.trys.push([0, 3, , 4]);
1743
- return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/marketing/mailchimp/updateOrCreateCustomer"), {
1744
- method: 'POST',
1745
- headers: {
1746
- Authorization: "Bearer ".concat(this._token),
1747
- 'Content-Type': 'application/json'
1748
- },
1749
- body: JSON.stringify(__assign(__assign({ email: customerEmail, listID: listID }, (!!mergeFields ? { mergeFields: mergeFields } : {})), (!!tags ? { tags: tags } : {})))
1750
- })];
1751
- case 1:
1752
- saved = _a.sent();
1753
- return [4, saved.json()];
1754
- case 2:
1755
- responseData = _a.sent();
1756
- if (responseData.status !== 200)
1757
- throw new Error(JSON.stringify({ status: responseData.status, error: responseData.error }));
1758
- return [2, true];
1759
- case 3:
1760
- e_9 = _a.sent();
1761
- console.log('error on saving customer to mailchimp list: ', e_9.toString());
1762
- return [2, false];
1763
- case 4: return [2];
1764
- }
1765
- });
1766
- }); };
1767
- this.getProductListForSitemap = function () { return __awaiter(_this, void 0, void 0, function () {
1768
- var fetchData, result, e_10;
1769
- return __generator(this, function (_a) {
1770
- switch (_a.label) {
1771
- case 0:
1772
- _a.trys.push([0, 3, , 4]);
1773
- return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/analytics/sitmap_data"), {
1774
- method: 'GET',
1775
- headers: {
1776
- authorization: "Bearer ".concat(this._token),
1777
- 'Content-Type': 'application/json'
1778
- }
1779
- })];
1780
- case 1:
1781
- fetchData = _a.sent();
1782
- return [4, fetchData.json()];
1783
- case 2:
1784
- result = _a.sent();
1785
- if (!!fetchData.status && fetchData.status !== 200)
1786
- throw "".concat(result.data);
1787
- return [2, result.data];
1788
- case 3:
1789
- e_10 = _a.sent();
1790
- console.log('error fetching sitemap data: ', e_10.toString());
1791
- return [2, e_10.toString()];
1792
- case 4: return [2];
1793
- }
1794
- });
1795
- }); };
1796
- this._api = '';
1797
- this._imgPath = '';
1798
- this._token = '';
1799
- this._userToken = '';
1800
- this._url = '';
1801
- this._org = '';
1802
- this._storeData = null;
1803
- this._wishlist = null;
1804
- this._stockNotif = null;
1805
- }
1806
- return SDK;
1807
- }());
1808
- exports.default = SDK;
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ 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;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __rest = (this && this.__rest) || function (s, e) {
50
+ var t = {};
51
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
52
+ t[p] = s[p];
53
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
54
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
55
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
56
+ t[p[i]] = s[p[i]];
57
+ }
58
+ return t;
59
+ };
60
+ var __importDefault = (this && this.__importDefault) || function (mod) {
61
+ return (mod && mod.__esModule) ? mod : { "default": mod };
62
+ };
63
+ Object.defineProperty(exports, "__esModule", { value: true });
64
+ var isomorphic_unfetch_1 = __importDefault(require("isomorphic-unfetch"));
65
+ var image_1 = __importDefault(require("./lib/models/image"));
66
+ var wishlist_1 = __importDefault(require("./lib/models/wishlist"));
67
+ var stockNotification_1 = __importDefault(require("./lib/models/stockNotification"));
68
+ var Product_1 = __importDefault(require("addio-admin-sdk/dist/lib/Product"));
69
+ var js_cookie_1 = __importDefault(require("js-cookie"));
70
+ var g2_1 = require("addio-admin-sdk/dist/rules/GR/utils/g2");
71
+ var anonymisation_1 = require("addio-admin-sdk/dist/utils/anonymisation");
72
+ var functions_1 = require("./utils/functions");
73
+ var zones_1 = require("addio-admin-sdk/dist/utils/zones");
74
+ var lodash_1 = require("lodash");
75
+ var functions_2 = require("./utils/functions");
76
+ var data_1 = require("addio-admin-sdk/dist/utils/data");
77
+ var moment_1 = __importDefault(require("moment"));
78
+ var object_1 = require("addio-admin-sdk/dist/utils/object");
79
+ var services_1 = require("addio-admin-sdk/dist/utils/services");
80
+ var logs_1 = require("addio-admin-sdk/dist/services/logs");
81
+ var SDK = (function () {
82
+ function SDK() {
83
+ var _this = this;
84
+ this.init = function (sdk_config) { return __awaiter(_this, void 0, void 0, function () {
85
+ return __generator(this, function (_a) {
86
+ this._api = sdk_config.api;
87
+ this._token = sdk_config.token;
88
+ this._url = sdk_config.url;
89
+ this._org = sdk_config.org;
90
+ this._userToken = !!sdk_config.userToken ? sdk_config.userToken : '';
91
+ this._storeData = null;
92
+ return [2];
93
+ });
94
+ }); };
95
+ this.getAPIInfos = function () { return ({
96
+ api: _this._api,
97
+ token: _this._token,
98
+ userToken: _this._userToken,
99
+ org: _this._org
100
+ }); };
101
+ this.getSDKOrgInitials = function () {
102
+ var orgID = _this.getAPIInfos().org;
103
+ if (!!!orgID)
104
+ return '';
105
+ if (orgID.length <= 3)
106
+ return orgID.toUpperCase();
107
+ return (0, services_1.getOrgInitialsByID)(orgID);
108
+ };
109
+ this.initWishlist = function (wishlist) { return __awaiter(_this, void 0, void 0, function () {
110
+ return __generator(this, function (_a) {
111
+ switch (_a.label) {
112
+ case 0:
113
+ this._wishlist = new wishlist_1.default(wishlist, this._api, this._token, this._userToken, this.setUserToken);
114
+ return [4, this._wishlist.getFromDatabase(wishlist)];
115
+ case 1: return [2, _a.sent()];
116
+ }
117
+ });
118
+ }); };
119
+ this.initStockNotif = function (stockNotif) { return __awaiter(_this, void 0, void 0, function () {
120
+ return __generator(this, function (_a) {
121
+ switch (_a.label) {
122
+ case 0:
123
+ this._stockNotif = new stockNotification_1.default(stockNotif, this._api, this._token, this._userToken, this.setUserToken);
124
+ return [4, this._stockNotif.getFromDatabase(stockNotif)];
125
+ case 1: return [2, _a.sent()];
126
+ }
127
+ });
128
+ }); };
129
+ this.initStoreData = function (defaultData) { return __awaiter(_this, void 0, void 0, function () {
130
+ var fetchData, responseData;
131
+ return __generator(this, function (_a) {
132
+ switch (_a.label) {
133
+ case 0:
134
+ if (!!defaultData) {
135
+ this._storeData = defaultData;
136
+ return [2];
137
+ }
138
+ return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/store"), {
139
+ method: 'GET',
140
+ headers: {
141
+ authorization: "Bearer ".concat(this._token),
142
+ 'Content-Type': 'application/json'
143
+ }
144
+ })];
145
+ case 1:
146
+ fetchData = _a.sent();
147
+ return [4, fetchData.json()];
148
+ case 2:
149
+ responseData = _a.sent();
150
+ if (responseData.status !== 200) {
151
+ throw new Error(JSON.stringify({ status: responseData.status, error: responseData.error }));
152
+ }
153
+ this._storeData = responseData.data;
154
+ return [2, this._storeData];
155
+ }
156
+ });
157
+ }); };
158
+ this.shouldShowFixedPromoBanner = function (fixedPromoBannerData) {
159
+ if (!!!fixedPromoBannerData.is_active) {
160
+ return false;
161
+ }
162
+ if (!!fixedPromoBannerData.active_between_dates && !!fixedPromoBannerData.active_between_dates.length) {
163
+ var date = fixedPromoBannerData.active_between_dates.some(function (date) {
164
+ return (0, moment_1.default)().isBetween((0, moment_1.default)((0, data_1.formatDate)(date.start)), (0, moment_1.default)((0, data_1.formatDate)(date.end)), 'days', '[]');
165
+ });
166
+ return !!date;
167
+ }
168
+ return true;
169
+ };
170
+ this.getInventoryItem = function (sku, locale) { return __awaiter(_this, void 0, void 0, function () {
171
+ var fetchData, responseData;
172
+ return __generator(this, function (_a) {
173
+ switch (_a.label) {
174
+ case 0: return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/inventory/").concat(encodeURIComponent(sku)), {
175
+ method: 'GET',
176
+ headers: {
177
+ Authorization: "Bearer ".concat(this._token),
178
+ 'x-gng-ecomm-locale': locale
179
+ }
180
+ })];
181
+ case 1:
182
+ fetchData = _a.sent();
183
+ return [4, fetchData.json()];
184
+ case 2:
185
+ responseData = _a.sent();
186
+ if (responseData.status !== 200)
187
+ throw new Error(JSON.stringify({ status: responseData.status, error: responseData.error }));
188
+ return [2, responseData.data];
189
+ }
190
+ });
191
+ }); };
192
+ this.getFullInventory = function (locale) { return __awaiter(_this, void 0, void 0, function () {
193
+ var fetchData, responseData;
194
+ return __generator(this, function (_a) {
195
+ switch (_a.label) {
196
+ case 0: return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/inventory"), {
197
+ method: 'GET',
198
+ headers: {
199
+ Authorization: "Bearer ".concat(this._token),
200
+ 'x-gng-ecomm-locale': locale
201
+ }
202
+ })];
203
+ case 1:
204
+ fetchData = _a.sent();
205
+ return [4, fetchData.json()];
206
+ case 2:
207
+ responseData = _a.sent();
208
+ if (responseData.status !== 200)
209
+ throw new Error(JSON.stringify({ status: responseData.status, error: responseData.error }));
210
+ return [2, responseData.data];
211
+ }
212
+ });
213
+ }); };
214
+ this.inventory = {
215
+ getFullInventory: this.getFullInventory,
216
+ getInventoryItem: this.getInventoryItem
217
+ };
218
+ this.setUserToken = function (token) {
219
+ _this._userToken = token;
220
+ localStorage.setItem('userToken', token);
221
+ js_cookie_1.default.set('userToken', token, { sameSite: 'strict', secure: true });
222
+ };
223
+ this.loginUserWithFacebook = function (fb) { return __awaiter(_this, void 0, void 0, function () {
224
+ var email, id, name, fetchData, responseData;
225
+ return __generator(this, function (_a) {
226
+ switch (_a.label) {
227
+ case 0:
228
+ email = fb.email, id = fb.id, name = fb.name;
229
+ return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/signinwithfacebook"), {
230
+ method: 'POST',
231
+ headers: {
232
+ authorization: "Bearer ".concat(this._token),
233
+ 'Content-Type': 'application/json'
234
+ },
235
+ body: JSON.stringify({ email: email, userID: id, name: name })
236
+ })];
237
+ case 1:
238
+ fetchData = _a.sent();
239
+ return [4, fetchData.json()];
240
+ case 2:
241
+ responseData = _a.sent();
242
+ if (responseData.status !== 200) {
243
+ throw { status: responseData.status, error: responseData.error };
244
+ }
245
+ try {
246
+ if (!!!responseData.data.userData) {
247
+ throw {
248
+ status: responseData.status,
249
+ error: 'user_not_found'
250
+ };
251
+ }
252
+ if (!!responseData.data.cartData) {
253
+ localStorage.setItem("".concat(this._org, "__cart"), responseData.data.cartData.id);
254
+ }
255
+ if (responseData.token)
256
+ this.setUserToken(responseData.token);
257
+ return [2, { userData: responseData.data.userData, cart: responseData.data.cartData }];
258
+ }
259
+ catch (err) {
260
+ return [2, err.toString()];
261
+ }
262
+ return [2];
263
+ }
264
+ });
265
+ }); };
266
+ this.anonymousResetPassword = function (locale, id, oldPassword, newPassword, confirmPassword) { return __awaiter(_this, void 0, void 0, function () {
267
+ var fetchData, responseData, error_1;
268
+ return __generator(this, function (_a) {
269
+ switch (_a.label) {
270
+ case 0:
271
+ _a.trys.push([0, 3, , 4]);
272
+ return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/anonymousResetPassword"), {
273
+ method: 'POST',
274
+ headers: {
275
+ authorization: "Bearer ".concat(this._token),
276
+ 'Content-Type': 'application/json',
277
+ 'x-gng-ecomm-locale': locale
278
+ },
279
+ body: JSON.stringify({
280
+ id: id,
281
+ oldPassword: oldPassword,
282
+ newPassword: newPassword,
283
+ confirmPassword: confirmPassword
284
+ })
285
+ })];
286
+ case 1:
287
+ fetchData = _a.sent();
288
+ return [4, fetchData.json()];
289
+ case 2:
290
+ responseData = _a.sent();
291
+ if (responseData.status !== 200) {
292
+ return [2, { status: responseData.status, error: responseData.error }];
293
+ }
294
+ return [2, { status: responseData.status, data: { done: true } }];
295
+ case 3:
296
+ error_1 = _a.sent();
297
+ console.log('error dans le catch du sdk: ', typeof error_1, error_1);
298
+ return [2, {
299
+ status: 400,
300
+ error: typeof error_1 === 'string' ? error_1 : error_1.toString()
301
+ }];
302
+ case 4: return [2];
303
+ }
304
+ });
305
+ }); };
306
+ this.loginUser = function (locale, email, password, keepCart, isClerk) {
307
+ if (keepCart === void 0) { keepCart = false; }
308
+ if (isClerk === void 0) { isClerk = false; }
309
+ return __awaiter(_this, void 0, void 0, function () {
310
+ var fetchData, responseData, cartData, shouldResetCartData, currentCartInLocalStorage;
311
+ return __generator(this, function (_a) {
312
+ switch (_a.label) {
313
+ case 0: return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/signin"), {
314
+ method: 'POST',
315
+ headers: {
316
+ authorization: "Bearer ".concat(this._token),
317
+ 'Content-Type': 'application/json',
318
+ 'x-gng-ecomm-locale': locale
319
+ },
320
+ body: JSON.stringify({ email: email, password: password, isClerk: isClerk })
321
+ })];
322
+ case 1:
323
+ fetchData = _a.sent();
324
+ return [4, fetchData.json()];
325
+ case 2:
326
+ responseData = _a.sent();
327
+ if (responseData.status !== 200) {
328
+ throw { status: responseData.status, error: responseData.error };
329
+ }
330
+ try {
331
+ if (!!!responseData.data.userData) {
332
+ throw {
333
+ status: responseData.status,
334
+ error: 'user_not_found'
335
+ };
336
+ }
337
+ cartData = responseData.data.cartData;
338
+ shouldResetCartData = !!cartData && !!cartData.clerk_id && !!!isClerk;
339
+ currentCartInLocalStorage = !!shouldResetCartData || !!!keepCart ? false : localStorage.getItem("".concat(this._org, "__cart"));
340
+ if (!!cartData && !!!currentCartInLocalStorage) {
341
+ localStorage.setItem("".concat(this._org, "__cart"), responseData.data.cartData.id);
342
+ }
343
+ if (responseData.token)
344
+ this.setUserToken(responseData.token);
345
+ return [2, {
346
+ userData: responseData.data.userData,
347
+ cart: shouldResetCartData ? null : cartData
348
+ }];
349
+ }
350
+ catch (err) {
351
+ return [2, err.toString()];
352
+ }
353
+ return [2];
354
+ }
355
+ });
356
+ });
357
+ };
358
+ this.loginUserWithID = function (locale, id, password, keepCart, isClerk) {
359
+ if (keepCart === void 0) { keepCart = false; }
360
+ if (isClerk === void 0) { isClerk = false; }
361
+ return __awaiter(_this, void 0, void 0, function () {
362
+ var fetchData, responseData, currentCartInLocalStorage;
363
+ return __generator(this, function (_a) {
364
+ switch (_a.label) {
365
+ case 0: return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/signinwithid"), {
366
+ method: 'POST',
367
+ headers: {
368
+ authorization: "Bearer ".concat(this._token),
369
+ 'Content-Type': 'application/json',
370
+ 'x-gng-ecomm-locale': locale
371
+ },
372
+ body: JSON.stringify({ id: id, password: password, isClerk: isClerk })
373
+ })];
374
+ case 1:
375
+ fetchData = _a.sent();
376
+ return [4, fetchData.json()];
377
+ case 2:
378
+ responseData = _a.sent();
379
+ if (responseData.status !== 200) {
380
+ throw { status: responseData.status, error: responseData.error };
381
+ }
382
+ if (!!!responseData.data.userData) {
383
+ throw {
384
+ status: responseData.status,
385
+ error: 'user_not_found'
386
+ };
387
+ }
388
+ currentCartInLocalStorage = !!!keepCart ? false : localStorage.getItem("".concat(this._org, "__cart"));
389
+ if (!!responseData.data.cartData && !!!currentCartInLocalStorage) {
390
+ localStorage.setItem("".concat(this._org, "__cart"), responseData.data.cartData.id);
391
+ }
392
+ if (responseData.token)
393
+ this.setUserToken(responseData.token);
394
+ return [2, { userData: responseData.data.userData, cart: responseData.data.cartData }];
395
+ }
396
+ });
397
+ });
398
+ };
399
+ this.checkG2ForCustomer = function (id, currentCustomer, customerGroups) { return __awaiter(_this, void 0, void 0, function () {
400
+ var fetchData, G2RequestRes, allG2Customers, customerToCheck, customerToCreate, anonymizedCustomer, e_1;
401
+ return __generator(this, function (_a) {
402
+ switch (_a.label) {
403
+ case 0:
404
+ _a.trys.push([0, 3, , 4]);
405
+ return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/services/g2/customers/").concat(id), {
406
+ method: 'GET',
407
+ headers: {
408
+ authorization: "Bearer ".concat(this._token),
409
+ 'Content-Type': 'application/json'
410
+ }
411
+ })];
412
+ case 1:
413
+ fetchData = _a.sent();
414
+ return [4, fetchData.json()];
415
+ case 2:
416
+ G2RequestRes = _a.sent();
417
+ if (!!fetchData.status && fetchData.status !== 200)
418
+ throw "".concat(fetchData.status);
419
+ if (!!!G2RequestRes || !!!G2RequestRes.length)
420
+ throw 'no data';
421
+ allG2Customers = G2RequestRes;
422
+ customerToCheck = allG2Customers[0];
423
+ if (!!(0, object_1.recursiveCheckObject)(customerToCheck, 'client.noClient') && customerToCheck.client.noClient !== id)
424
+ throw 'no data';
425
+ customerToCreate = (0, g2_1.transformG2CustomerToCustomer)(customerToCheck, currentCustomer, customerGroups);
426
+ anonymizedCustomer = (0, anonymisation_1.hideG2CustomerInfoIfNeeded)(customerToCreate);
427
+ return [2, (anonymizedCustomer !== null && anonymizedCustomer !== void 0 ? anonymizedCustomer : customerToCreate)];
428
+ case 3:
429
+ e_1 = _a.sent();
430
+ console.log('error on fetching G2 customer: ', e_1.toString());
431
+ return [2];
432
+ case 4: return [2];
433
+ }
434
+ });
435
+ }); };
436
+ this.createProCustomer = function (customer) { return __awaiter(_this, void 0, void 0, function () {
437
+ var fetchData, result, e_2;
438
+ return __generator(this, function (_a) {
439
+ switch (_a.label) {
440
+ case 0:
441
+ _a.trys.push([0, 3, , 4]);
442
+ return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/user/createProWithId"), {
443
+ method: 'POST',
444
+ headers: {
445
+ authorization: "Bearer ".concat(this._token),
446
+ 'Content-Type': 'application/json'
447
+ },
448
+ body: JSON.stringify({ customer: customer })
449
+ })];
450
+ case 1:
451
+ fetchData = _a.sent();
452
+ return [4, fetchData.json()];
453
+ case 2:
454
+ result = _a.sent();
455
+ if (!!fetchData.status && fetchData.status !== 200)
456
+ throw "".concat(result.data);
457
+ return [2, true];
458
+ case 3:
459
+ e_2 = _a.sent();
460
+ console.log('error on creating G2 customer: ', e_2.toString());
461
+ return [2, e_2.toString()];
462
+ case 4: return [2];
463
+ }
464
+ });
465
+ }); };
466
+ this.fetchCustomPriceList = function (customerID, isPA) {
467
+ if (isPA === void 0) { isPA = false; }
468
+ return __awaiter(_this, void 0, void 0, function () {
469
+ var id, g2PriceListQuery, prices, e_3;
470
+ return __generator(this, function (_a) {
471
+ switch (_a.label) {
472
+ case 0:
473
+ _a.trys.push([0, 3, , 4]);
474
+ id = !!isPA ? "".concat(customerID, "PA") : customerID;
475
+ return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/services/g2/customers/").concat(id, "/customPrices"), {
476
+ method: 'POST',
477
+ headers: {
478
+ authorization: "Bearer ".concat(this._token),
479
+ 'Content-Type': 'application/json'
480
+ }
481
+ })];
482
+ case 1:
483
+ g2PriceListQuery = _a.sent();
484
+ return [4, g2PriceListQuery.json()];
485
+ case 2:
486
+ prices = _a.sent();
487
+ if (!!g2PriceListQuery.status && g2PriceListQuery.status !== 200)
488
+ throw "Error - ".concat(g2PriceListQuery.status);
489
+ if (!!!prices || !!!prices.length)
490
+ throw 'Error - no data';
491
+ return [2, prices];
492
+ case 3:
493
+ e_3 = _a.sent();
494
+ console.log('error on fetching customer from G2: ', e_3);
495
+ return [2];
496
+ case 4: return [2];
497
+ }
498
+ });
499
+ });
500
+ };
501
+ this.validateAccount = function (code) { return __awaiter(_this, void 0, void 0, function () {
502
+ var fetchData, responseData;
503
+ return __generator(this, function (_a) {
504
+ switch (_a.label) {
505
+ case 0: return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/user/validateEmail"), {
506
+ method: 'POST',
507
+ headers: {
508
+ authorization: "Bearer ".concat(this._token),
509
+ 'Content-Type': 'application/json',
510
+ 'x-gng-ecomm-token': this._userToken
511
+ },
512
+ body: JSON.stringify({ code: code })
513
+ })];
514
+ case 1:
515
+ fetchData = _a.sent();
516
+ return [4, fetchData.json()];
517
+ case 2:
518
+ responseData = _a.sent();
519
+ if (responseData.status !== 200) {
520
+ throw new Error(JSON.stringify({ status: responseData.status, error: responseData.error }));
521
+ }
522
+ if (!!!responseData.data.userData) {
523
+ throw new Error(JSON.stringify({ status: responseData.status, error: 'User not sent in request.' }));
524
+ }
525
+ if (responseData.token)
526
+ this.setUserToken(responseData.token);
527
+ return [2, responseData.data.userData];
528
+ }
529
+ });
530
+ }); };
531
+ this.logout = function () {
532
+ _this.setUserToken('');
533
+ localStorage.removeItem("".concat(_this._org, "__cart"));
534
+ localStorage.removeItem('userLogged');
535
+ localStorage.removeItem('isPro');
536
+ localStorage.removeItem('foundInG2');
537
+ localStorage.removeItem('customPriceList');
538
+ localStorage.removeItem('lastCustomPriceFetch');
539
+ localStorage.removeItem('userToken');
540
+ localStorage.removeItem('wishlist');
541
+ localStorage.removeItem('stockNotification');
542
+ js_cookie_1.default.remove('userToken', { expires: new Date(0) });
543
+ };
544
+ this.registerUser = function (locale, userData, password) { return __awaiter(_this, void 0, void 0, function () {
545
+ var fetchData, responseData;
546
+ return __generator(this, function (_a) {
547
+ switch (_a.label) {
548
+ case 0: return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/register"), {
549
+ method: 'PUT',
550
+ headers: {
551
+ Authorization: "Bearer ".concat(this._token),
552
+ 'Content-Type': 'application/json',
553
+ 'x-gng-ecomm-locale': locale
554
+ },
555
+ body: JSON.stringify({ userData: userData, password: password })
556
+ })];
557
+ case 1:
558
+ fetchData = _a.sent();
559
+ if (fetchData.status == 200)
560
+ return [2, { status: 200, error: '' }];
561
+ return [4, fetchData.json()];
562
+ case 2:
563
+ responseData = _a.sent();
564
+ return [2, { status: responseData.status, error: responseData.error }];
565
+ }
566
+ });
567
+ }); };
568
+ this.getUser = function (keepTempHash) { return __awaiter(_this, void 0, void 0, function () {
569
+ var token, localToken, fetchData, responseData, _a, temp_hash, rest;
570
+ return __generator(this, function (_b) {
571
+ switch (_b.label) {
572
+ case 0:
573
+ token = this._userToken;
574
+ if (!!!token) {
575
+ localToken = localStorage.getItem('userToken');
576
+ if (!!localToken) {
577
+ token = localToken;
578
+ }
579
+ }
580
+ return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/user/get"), {
581
+ method: 'GET',
582
+ headers: {
583
+ authorization: "Bearer ".concat(this._token),
584
+ 'Content-Type': 'application/json',
585
+ 'x-gng-ecomm-token': token
586
+ }
587
+ })];
588
+ case 1:
589
+ fetchData = _b.sent();
590
+ return [4, fetchData.json()];
591
+ case 2:
592
+ responseData = _b.sent();
593
+ if (responseData.status !== 200) {
594
+ throw new Error(JSON.stringify({ status: responseData.status, error: responseData.error }));
595
+ }
596
+ if (!!!responseData.data.userData) {
597
+ throw new Error(JSON.stringify({ status: responseData.status, error: 'User not sent in request.' }));
598
+ }
599
+ if (responseData.token)
600
+ this.setUserToken(responseData.token);
601
+ _a = responseData.data.userData, temp_hash = _a.temp_hash, rest = __rest(_a, ["temp_hash"]);
602
+ return [2, __assign(__assign({}, rest), (!!keepTempHash ? { temp_hash: temp_hash } : {}))];
603
+ }
604
+ });
605
+ }); };
606
+ this.saveUser = function (userData) { return __awaiter(_this, void 0, void 0, function () {
607
+ var fetchData, responseData;
608
+ return __generator(this, function (_a) {
609
+ switch (_a.label) {
610
+ case 0: return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/user/save"), {
611
+ method: 'POST',
612
+ headers: {
613
+ authorization: "Bearer ".concat(this._token),
614
+ 'Content-Type': 'application/json',
615
+ 'x-gng-ecomm-token': this._userToken
616
+ },
617
+ body: JSON.stringify({ userData: userData })
618
+ })];
619
+ case 1:
620
+ fetchData = _a.sent();
621
+ return [4, fetchData.json()];
622
+ case 2:
623
+ responseData = _a.sent();
624
+ if (responseData.status !== 200) {
625
+ throw new Error(JSON.stringify({ status: responseData.status, error: responseData.error }));
626
+ }
627
+ if (responseData.data !== 'done') {
628
+ throw new Error(JSON.stringify({ status: responseData.status, error: 'User not sent in response.' }));
629
+ }
630
+ if (responseData.token)
631
+ this.setUserToken(responseData.token);
632
+ return [2, true];
633
+ }
634
+ });
635
+ }); };
636
+ this.deleteUser = function () { return __awaiter(_this, void 0, void 0, function () {
637
+ var fetchData, responseData;
638
+ return __generator(this, function (_a) {
639
+ switch (_a.label) {
640
+ case 0: return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/user/delete"), {
641
+ method: 'GET',
642
+ headers: {
643
+ authorization: "Bearer ".concat(this._token),
644
+ 'x-gng-ecomm-token': this._userToken
645
+ }
646
+ })];
647
+ case 1:
648
+ fetchData = _a.sent();
649
+ return [4, fetchData.json()];
650
+ case 2:
651
+ responseData = _a.sent();
652
+ if (responseData.status !== 200) {
653
+ return [2, false];
654
+ }
655
+ return [2, true];
656
+ }
657
+ });
658
+ }); };
659
+ this.getOrders = function (lastID, iteration) { return __awaiter(_this, void 0, void 0, function () {
660
+ var queryString, fetchData, responseData;
661
+ return __generator(this, function (_a) {
662
+ switch (_a.label) {
663
+ case 0:
664
+ queryString = "?fromLastID=".concat(lastID !== null && lastID !== void 0 ? lastID : '', "&skip=").concat(iteration !== null && iteration !== void 0 ? iteration : '');
665
+ return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/user/orders").concat(queryString), {
666
+ method: 'GET',
667
+ headers: {
668
+ authorization: "Bearer ".concat(this._token),
669
+ 'Content-Type': 'application/json',
670
+ 'x-gng-ecomm-token': this._userToken
671
+ }
672
+ })];
673
+ case 1:
674
+ fetchData = _a.sent();
675
+ return [4, fetchData.json()];
676
+ case 2:
677
+ responseData = (_a.sent());
678
+ if (responseData.status !== 200) {
679
+ return [2, responseData.data];
680
+ }
681
+ return [2, responseData.data];
682
+ }
683
+ });
684
+ }); };
685
+ this.killRepCart = function (hashed_cart_id) { return __awaiter(_this, void 0, void 0, function () {
686
+ var fetchData, responseData, error_2;
687
+ return __generator(this, function (_a) {
688
+ switch (_a.label) {
689
+ case 0:
690
+ _a.trys.push([0, 3, , 4]);
691
+ return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/user/killRepCart/").concat(encodeURIComponent(hashed_cart_id)), {
692
+ method: 'GET',
693
+ headers: {
694
+ authorization: "Bearer ".concat(this._token),
695
+ 'Content-Type': 'application/json',
696
+ 'x-gng-ecomm-token': this._userToken
697
+ }
698
+ })];
699
+ case 1:
700
+ fetchData = _a.sent();
701
+ return [4, fetchData.json()];
702
+ case 2:
703
+ responseData = (_a.sent());
704
+ if (responseData.status !== 200) {
705
+ return [2, responseData.data];
706
+ }
707
+ return [2, responseData.data];
708
+ case 3:
709
+ error_2 = _a.sent();
710
+ console.log(error_2);
711
+ return [2, ''];
712
+ case 4: return [2];
713
+ }
714
+ });
715
+ }); };
716
+ this.getOrder = function (orderID, token) { return __awaiter(_this, void 0, void 0, function () {
717
+ var fetchData, responseData, error_3;
718
+ return __generator(this, function (_a) {
719
+ switch (_a.label) {
720
+ case 0:
721
+ _a.trys.push([0, 3, , 4]);
722
+ return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/user/order/").concat(orderID), {
723
+ method: 'POST',
724
+ headers: {
725
+ authorization: "Bearer ".concat(this._token),
726
+ 'Content-Type': 'application/json',
727
+ 'x-gng-ecomm-token': this._userToken
728
+ },
729
+ body: JSON.stringify({ orderToken: token })
730
+ })];
731
+ case 1:
732
+ fetchData = _a.sent();
733
+ return [4, fetchData.json()];
734
+ case 2:
735
+ responseData = (_a.sent());
736
+ if (responseData.status !== 200) {
737
+ return [2, responseData.data];
738
+ }
739
+ return [2, responseData.data];
740
+ case 3:
741
+ error_3 = _a.sent();
742
+ console.log(error_3);
743
+ return [2, ''];
744
+ case 4: return [2];
745
+ }
746
+ });
747
+ }); };
748
+ this.changeProfilePicture = function (file) { return __awaiter(_this, void 0, void 0, function () {
749
+ var fetchData, responseData;
750
+ return __generator(this, function (_a) {
751
+ switch (_a.label) {
752
+ case 0: return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/user/changeProfilePicture"), {
753
+ method: 'POST',
754
+ headers: {
755
+ authorization: "Bearer ".concat(this._token),
756
+ 'Content-Type': 'application/json',
757
+ 'x-gng-ecomm-token': this._userToken
758
+ },
759
+ body: JSON.stringify({
760
+ file: file
761
+ })
762
+ })];
763
+ case 1:
764
+ fetchData = _a.sent();
765
+ return [4, fetchData.json()];
766
+ case 2:
767
+ responseData = (_a.sent());
768
+ return [2, responseData.data];
769
+ }
770
+ });
771
+ }); };
772
+ this.changePassword = function (currentPassword, newPassword) { return __awaiter(_this, void 0, void 0, function () {
773
+ var fetchData, responseData;
774
+ return __generator(this, function (_a) {
775
+ switch (_a.label) {
776
+ case 0: return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/user/changePassword"), {
777
+ method: 'POST',
778
+ headers: {
779
+ authorization: "Bearer ".concat(this._token),
780
+ 'Content-Type': 'application/json',
781
+ 'x-gng-ecomm-token': this._userToken
782
+ },
783
+ body: JSON.stringify({ currentPassword: currentPassword, newPassword: newPassword })
784
+ })];
785
+ case 1:
786
+ fetchData = _a.sent();
787
+ return [4, fetchData.json()];
788
+ case 2:
789
+ responseData = (_a.sent());
790
+ if (responseData.status === 200)
791
+ return [2, responseData.data];
792
+ return [2, responseData.error];
793
+ }
794
+ });
795
+ }); };
796
+ this.sendResetPasswordEmail = function (locale, userEmail, forPro, withEmail, isTest) { return __awaiter(_this, void 0, void 0, function () {
797
+ var fetchData, responseData;
798
+ return __generator(this, function (_a) {
799
+ switch (_a.label) {
800
+ case 0: return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/user/sentForgotPasswordEmail"), {
801
+ method: 'POST',
802
+ headers: {
803
+ authorization: "Bearer ".concat(this._token),
804
+ 'Content-Type': 'application/json',
805
+ 'x-gng-ecomm-token': this._userToken,
806
+ 'x-gng-ecomm-locale': locale
807
+ },
808
+ body: JSON.stringify({ userEmail: userEmail, forPro: forPro, withEmail: withEmail, isTest: isTest })
809
+ })];
810
+ case 1:
811
+ fetchData = _a.sent();
812
+ return [4, fetchData.json()];
813
+ case 2:
814
+ responseData = (_a.sent());
815
+ if (responseData.status === 200)
816
+ return [2, responseData.data];
817
+ if (responseData.status === 403)
818
+ return [2, {
819
+ fr: "Plus d'un compte a \u00E9t\u00E9 trouv\u00E9 avec ".concat(withEmail ? 'ce courriel' : 'ce ID client', ". Veuillez contacter un administrateur pour proc\u00E9der."),
820
+ en: "More than one account was found with ".concat(withEmail ? 'this email' : 'this client ID', ". Please contact an administrator to proceed.")
821
+ }];
822
+ return [2, responseData.error];
823
+ }
824
+ });
825
+ }); };
826
+ this.sendApplicationEmail = function (locale, form) { return __awaiter(_this, void 0, void 0, function () {
827
+ var cvBase64, fetchData, responseData, error_4;
828
+ return __generator(this, function (_a) {
829
+ switch (_a.label) {
830
+ case 0:
831
+ _a.trys.push([0, 4, , 5]);
832
+ if (!!!form.cv)
833
+ return [2, {
834
+ error: "Couldn't find cv"
835
+ }];
836
+ return [4, (0, functions_2.toBase64)(form.cv)];
837
+ case 1:
838
+ cvBase64 = _a.sent();
839
+ if (typeof cvBase64 !== 'string') {
840
+ return [2, {
841
+ error: "Couldn't convert file to base64"
842
+ }];
843
+ }
844
+ return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/email/sendApplicationEmail"), {
845
+ method: 'POST',
846
+ headers: {
847
+ authorization: "Bearer ".concat(this._token),
848
+ 'Content-Type': 'application/json',
849
+ 'x-gng-ecomm-token': this._userToken,
850
+ 'x-gng-ecomm-locale': locale
851
+ },
852
+ body: JSON.stringify(__assign(__assign({}, form), { cv: cvBase64 }))
853
+ })];
854
+ case 2:
855
+ fetchData = _a.sent();
856
+ return [4, fetchData.json()];
857
+ case 3:
858
+ responseData = (_a.sent());
859
+ if (responseData.status === 200)
860
+ return [2, responseData.data];
861
+ return [2, responseData.error];
862
+ case 4:
863
+ error_4 = _a.sent();
864
+ return [2, 'error'];
865
+ case 5: return [2];
866
+ }
867
+ });
868
+ }); };
869
+ this.sendContactEmail = function (locale, form) { return __awaiter(_this, void 0, void 0, function () {
870
+ var fetchData, responseData;
871
+ return __generator(this, function (_a) {
872
+ switch (_a.label) {
873
+ case 0: return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/email/sendContactEmail"), {
874
+ method: 'POST',
875
+ headers: {
876
+ authorization: "Bearer ".concat(this._token),
877
+ 'Content-Type': 'application/json',
878
+ 'x-gng-ecomm-token': this._userToken,
879
+ 'x-gng-ecomm-locale': locale
880
+ },
881
+ body: JSON.stringify(form)
882
+ })];
883
+ case 1:
884
+ fetchData = _a.sent();
885
+ return [4, fetchData.json()];
886
+ case 2:
887
+ responseData = (_a.sent());
888
+ if (responseData.status === 200)
889
+ return [2, responseData.data];
890
+ return [2, responseData.error];
891
+ }
892
+ });
893
+ }); };
894
+ this.sendGenericOtherEmail = function (locale, form, templateId, to, replyTo) { return __awaiter(_this, void 0, void 0, function () {
895
+ var getSubjectByType, fetchData, responseData, error_5;
896
+ return __generator(this, function (_a) {
897
+ switch (_a.label) {
898
+ case 0:
899
+ getSubjectByType = function (type) {
900
+ switch (type) {
901
+ case 'confirmation_lawn_submission':
902
+ return { fr: 'Soumission gazon - Confirmation de réception', en: 'Lawn submission - Confirmation' };
903
+ default:
904
+ return undefined;
905
+ }
906
+ };
907
+ _a.label = 1;
908
+ case 1:
909
+ _a.trys.push([1, 4, , 5]);
910
+ return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/email/sendGenericOtherEmail"), {
911
+ method: 'POST',
912
+ headers: {
913
+ authorization: "Bearer ".concat(this._token),
914
+ 'Content-Type': 'application/json',
915
+ 'x-gng-ecomm-token': this._userToken,
916
+ 'x-gng-ecomm-locale': locale
917
+ },
918
+ body: JSON.stringify(__assign(__assign({}, (!!form ? { content: form } : {})), { subject: getSubjectByType(templateId), templateId: templateId, to: to, replyTo: replyTo }))
919
+ })];
920
+ case 2:
921
+ fetchData = _a.sent();
922
+ return [4, fetchData.json()];
923
+ case 3:
924
+ responseData = (_a.sent());
925
+ if (responseData.status === 200)
926
+ return [2, responseData.data];
927
+ return [2, responseData.error];
928
+ case 4:
929
+ error_5 = _a.sent();
930
+ console.log('error on sendGenericOtherEmail: ', error_5);
931
+ return [3, 5];
932
+ case 5: return [2];
933
+ }
934
+ });
935
+ }); };
936
+ this.sendServicePageEmail = function (locale, form, type, testEmail) { return __awaiter(_this, void 0, void 0, function () {
937
+ var attachments, rest, updatedAttachments, _i, _a, att, cvBase64, e_4, getSubjectByType, fetchData, responseData, e_5;
938
+ return __generator(this, function (_b) {
939
+ switch (_b.label) {
940
+ case 0:
941
+ attachments = form.attachments, rest = __rest(form, ["attachments"]);
942
+ updatedAttachments = [];
943
+ if (!!!attachments) return [3, 6];
944
+ _i = 0, _a = attachments;
945
+ _b.label = 1;
946
+ case 1:
947
+ if (!(_i < _a.length)) return [3, 6];
948
+ att = _a[_i];
949
+ _b.label = 2;
950
+ case 2:
951
+ _b.trys.push([2, 4, , 5]);
952
+ return [4, (0, functions_2.toBase64)(att)];
953
+ case 3:
954
+ cvBase64 = _b.sent();
955
+ updatedAttachments.push({ name: att.name, content: cvBase64 });
956
+ return [3, 5];
957
+ case 4:
958
+ e_4 = _b.sent();
959
+ console.log('error on converting to base64: ', e_4);
960
+ return [3, 5];
961
+ case 5:
962
+ _i++;
963
+ return [3, 1];
964
+ case 6:
965
+ getSubjectByType = function () {
966
+ switch (type) {
967
+ case 'admin_3D_plans':
968
+ return { fr: 'Plans 3D - Nouvelle demande', en: '3D plans - new request' };
969
+ case 'admin_vegetals':
970
+ return { fr: 'Commande de végétaux - nouvelle soumission', en: 'Vegetals - new quotation' };
971
+ case 'admin_pickup_on_site':
972
+ return { fr: 'Ramassage sur chantier - nouvelle demande', en: 'Pickup on site - new request' };
973
+ case 'admin_borrow_tools':
974
+ return { fr: "Location d'outils - nouvelle demande", en: 'Rent tools - new request' };
975
+ case 'admin_sales_info':
976
+ return {
977
+ fr: 'Produits en solde - Information demandée',
978
+ en: 'On sale products - Information request'
979
+ };
980
+ case 'admin_credit_info':
981
+ return {
982
+ fr: 'Département de crédit - Information demandée',
983
+ en: 'Credit department - Information request'
984
+ };
985
+ case 'admin_transport_quote':
986
+ return {
987
+ fr: 'Location de camion - nouvelle soumission',
988
+ en: 'Transport truck rental - new quotation'
989
+ };
990
+ case 'admin_special_order':
991
+ return { fr: 'Commande spéciale - nouvelle demande', en: 'Special order - new request' };
992
+ case 'admin_installation':
993
+ return { fr: 'Installation - nouvelle soumission', en: 'Installation - new quotation' };
994
+ case 'admin_find_landscaper':
995
+ return { fr: 'Trouver un paysagiste - nouvelle demande', en: 'Find a landscaper - new request' };
996
+ case 'admin_lawn_submission':
997
+ return { fr: 'Soumission gazon - nouvelle demande', en: 'Lawn submission - new request' };
998
+ case 'confirmation_find_landsacper':
999
+ return { fr: 'Trouver un paysagiste - Confirmation', en: 'Find a landscaper - Confirmation' };
1000
+ default:
1001
+ return { fr: 'Demande de service - nouvelle soumission', en: 'Service request - new quotation' };
1002
+ }
1003
+ };
1004
+ _b.label = 7;
1005
+ case 7:
1006
+ _b.trys.push([7, 10, , 11]);
1007
+ return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/email/sendServiceStaticPageEmail"), {
1008
+ method: 'POST',
1009
+ headers: {
1010
+ authorization: "Bearer ".concat(this._token),
1011
+ 'Content-Type': 'application/json',
1012
+ 'x-gng-ecomm-token': this._userToken,
1013
+ 'x-gng-ecomm-locale': locale
1014
+ },
1015
+ body: JSON.stringify(__assign(__assign(__assign(__assign({}, rest), (!!updatedAttachments && !!updatedAttachments.length ? { attachments: updatedAttachments } : {})), { subject: getSubjectByType(), title: getSubjectByType(), type: type }), (!!testEmail ? { test_email: testEmail } : {})))
1016
+ })];
1017
+ case 8:
1018
+ fetchData = _b.sent();
1019
+ return [4, fetchData.json()];
1020
+ case 9:
1021
+ responseData = (_b.sent());
1022
+ if (responseData.status === 200)
1023
+ return [2, true];
1024
+ return [2, responseData.error];
1025
+ case 10:
1026
+ e_5 = _b.sent();
1027
+ console.log('error on calling api: ', e_5);
1028
+ if (!!updatedAttachments) {
1029
+ return [2, {
1030
+ status: 413,
1031
+ error: {
1032
+ fr: "Vos pièces jointes n'ont pas pu être envoyées. Veuillez réessayer.",
1033
+ en: 'Your attachments could not be sent. Please try again.'
1034
+ }
1035
+ }];
1036
+ }
1037
+ return [2, ''];
1038
+ case 11: return [2];
1039
+ }
1040
+ });
1041
+ }); };
1042
+ this.sendSponsorRequestEmail = function (locale, form, template_name) { return __awaiter(_this, void 0, void 0, function () {
1043
+ var plan, rest, updatedPlan, planBase64, splitString, e_6, fetchData, responseData;
1044
+ return __generator(this, function (_a) {
1045
+ switch (_a.label) {
1046
+ case 0:
1047
+ plan = form.plan, rest = __rest(form, ["plan"]);
1048
+ if (!!!plan) return [3, 4];
1049
+ _a.label = 1;
1050
+ case 1:
1051
+ _a.trys.push([1, 3, , 4]);
1052
+ return [4, (0, functions_2.toBase64)(plan)];
1053
+ case 2:
1054
+ planBase64 = _a.sent();
1055
+ if (typeof planBase64 === 'string') {
1056
+ splitString = planBase64.split(';base64,');
1057
+ if (!!splitString.length && !!splitString[1]) {
1058
+ updatedPlan = {
1059
+ name: plan.name,
1060
+ content: splitString[1]
1061
+ };
1062
+ }
1063
+ }
1064
+ return [3, 4];
1065
+ case 3:
1066
+ e_6 = _a.sent();
1067
+ console.log('error on converting to base64: ', e_6);
1068
+ return [3, 4];
1069
+ case 4: return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/email/sendSponsorRequestEmail"), {
1070
+ method: 'POST',
1071
+ headers: {
1072
+ authorization: "Bearer ".concat(this._token),
1073
+ 'Content-Type': 'application/json',
1074
+ 'x-gng-ecomm-token': this._userToken,
1075
+ 'x-gng-ecomm-locale': locale
1076
+ },
1077
+ body: JSON.stringify({
1078
+ contenu: __assign(__assign(__assign({}, rest), { admin: true, has_plan: !!updatedPlan }), (!!updatedPlan
1079
+ ? {
1080
+ plan: updatedPlan
1081
+ }
1082
+ : {})),
1083
+ template_name: template_name
1084
+ })
1085
+ })];
1086
+ case 5:
1087
+ fetchData = _a.sent();
1088
+ return [4, fetchData.json()];
1089
+ case 6:
1090
+ responseData = (_a.sent());
1091
+ if (responseData.status === 200)
1092
+ return [2, true];
1093
+ return [2, responseData.error];
1094
+ }
1095
+ });
1096
+ }); };
1097
+ this.sendPreMeetingFormEmail = function (locale, form, proId) { return __awaiter(_this, void 0, void 0, function () {
1098
+ var attachments, rest, _a, pro_logo, restProInfos, updatedAttachments, updatedLogo, _i, _b, att, cvBase64, e_7, logoBase64, e_8, fetchData, responseData;
1099
+ return __generator(this, function (_c) {
1100
+ switch (_c.label) {
1101
+ case 0:
1102
+ attachments = form.attachments, rest = __rest(form, ["attachments"]);
1103
+ _a = rest.pro_infos, pro_logo = _a.pro_logo, restProInfos = __rest(_a, ["pro_logo"]);
1104
+ updatedAttachments = [];
1105
+ updatedLogo = '';
1106
+ if (!!!attachments) return [3, 6];
1107
+ _i = 0, _b = attachments;
1108
+ _c.label = 1;
1109
+ case 1:
1110
+ if (!(_i < _b.length)) return [3, 6];
1111
+ att = _b[_i];
1112
+ _c.label = 2;
1113
+ case 2:
1114
+ _c.trys.push([2, 4, , 5]);
1115
+ return [4, (0, functions_2.toBase64)(att)];
1116
+ case 3:
1117
+ cvBase64 = _c.sent();
1118
+ updatedAttachments.push({ name: att.name, content: cvBase64 });
1119
+ return [3, 5];
1120
+ case 4:
1121
+ e_7 = _c.sent();
1122
+ console.log('error on converting to base64: ', e_7);
1123
+ return [3, 5];
1124
+ case 5:
1125
+ _i++;
1126
+ return [3, 1];
1127
+ case 6:
1128
+ if (!!!pro_logo) return [3, 10];
1129
+ _c.label = 7;
1130
+ case 7:
1131
+ _c.trys.push([7, 9, , 10]);
1132
+ return [4, (0, functions_2.toBase64)(pro_logo)];
1133
+ case 8:
1134
+ logoBase64 = _c.sent();
1135
+ updatedLogo = { name: pro_logo.name, content: logoBase64 };
1136
+ return [3, 10];
1137
+ case 9:
1138
+ e_8 = _c.sent();
1139
+ console.log('error on converting logo to base64: ', e_8);
1140
+ return [3, 10];
1141
+ case 10: return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/email/sendPreMeetingFormEmail"), {
1142
+ method: 'POST',
1143
+ headers: {
1144
+ authorization: "Bearer ".concat(this._token),
1145
+ 'Content-Type': 'application/json',
1146
+ 'x-gng-ecomm-token': this._userToken,
1147
+ 'x-gng-ecomm-locale': locale
1148
+ },
1149
+ body: JSON.stringify(__assign(__assign(__assign(__assign({}, rest), { pro_infos: __assign(__assign({}, restProInfos), (!!updatedLogo ? { pro_logo: updatedLogo } : {})) }), (!!updatedAttachments && !!updatedAttachments.length ? { attachments: updatedAttachments } : {})), (!!proId ? { pro_id: proId } : {})))
1150
+ })];
1151
+ case 11:
1152
+ fetchData = _c.sent();
1153
+ return [4, fetchData.json()];
1154
+ case 12:
1155
+ responseData = (_c.sent());
1156
+ if (responseData.status === 200)
1157
+ return [2, true];
1158
+ return [2, responseData.error];
1159
+ }
1160
+ });
1161
+ }); };
1162
+ this.sendWishlistByEmail = function (locale, contenu, template_name) { return __awaiter(_this, void 0, void 0, function () {
1163
+ var fetchData, responseData;
1164
+ return __generator(this, function (_a) {
1165
+ switch (_a.label) {
1166
+ case 0: return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/email/sendWishlistEmail"), {
1167
+ method: 'POST',
1168
+ headers: {
1169
+ authorization: "Bearer ".concat(this._token),
1170
+ 'Content-Type': 'application/json',
1171
+ 'x-gng-ecomm-token': this._userToken,
1172
+ 'x-gng-ecomm-locale': locale
1173
+ },
1174
+ body: JSON.stringify({ contenu: contenu, template_name: template_name })
1175
+ })];
1176
+ case 1:
1177
+ fetchData = _a.sent();
1178
+ return [4, fetchData.json()];
1179
+ case 2:
1180
+ responseData = (_a.sent());
1181
+ if (responseData.status === 200)
1182
+ return [2, true];
1183
+ return [2, responseData.error];
1184
+ }
1185
+ });
1186
+ }); };
1187
+ this.resetPassword = function (token, newPassword, withEmail) { return __awaiter(_this, void 0, void 0, function () {
1188
+ var fetchData, responseData;
1189
+ return __generator(this, function (_a) {
1190
+ switch (_a.label) {
1191
+ case 0: return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/user/resetPassword"), {
1192
+ method: 'POST',
1193
+ headers: {
1194
+ authorization: "Bearer ".concat(this._token),
1195
+ 'Content-Type': 'application/json',
1196
+ 'x-gng-ecomm-token': this._userToken
1197
+ },
1198
+ body: JSON.stringify({ validationCode: token, newPassword: newPassword, withEmail: withEmail })
1199
+ })];
1200
+ case 1:
1201
+ fetchData = _a.sent();
1202
+ return [4, fetchData.json()];
1203
+ case 2:
1204
+ responseData = (_a.sent());
1205
+ if (responseData.status === 200)
1206
+ return [2, responseData.data];
1207
+ if (responseData.status === 403)
1208
+ return [2, {
1209
+ fr: "Plus d'un compte a \u00E9t\u00E9 trouv\u00E9 avec ".concat(withEmail ? 'ce courriel' : 'ce ID client', ". Veuillez contacter un administrateur pour proc\u00E9der."),
1210
+ en: "More than one account was found with ".concat(withEmail ? 'this email' : 'this client ID', ". Please contact an administrator to proceed.")
1211
+ }];
1212
+ return [2, responseData.error];
1213
+ }
1214
+ });
1215
+ }); };
1216
+ this.user = {
1217
+ getUser: this.getUser,
1218
+ saveUser: this.saveUser,
1219
+ deleteUser: this.deleteUser,
1220
+ loginUser: this.loginUser,
1221
+ loginUserWithID: this.loginUserWithID,
1222
+ loginUserWithFacebook: this.loginUserWithFacebook,
1223
+ logout: this.logout,
1224
+ registerUser: this.registerUser,
1225
+ killRepCart: this.killRepCart,
1226
+ getOrder: this.getOrder,
1227
+ getOrders: this.getOrders,
1228
+ changePassword: this.changePassword,
1229
+ changeProfilePicture: this.changeProfilePicture,
1230
+ validateAccount: this.validateAccount,
1231
+ sendResetPasswordEmail: this.sendResetPasswordEmail,
1232
+ resetPassword: this.resetPassword,
1233
+ sendApplicationEmail: this.sendApplicationEmail,
1234
+ sendContactEmail: this.sendContactEmail,
1235
+ sendServiceEmail: this.sendServicePageEmail,
1236
+ anonymousResetPassword: this.anonymousResetPassword,
1237
+ checkG2: this.checkG2ForCustomer,
1238
+ createPro: this.createProCustomer,
1239
+ fetchCustomPriceList: this.fetchCustomPriceList
1240
+ };
1241
+ this.getImage = function (imgName, formatQuery, addImgPath) {
1242
+ if (addImgPath === void 0) { addImgPath = false; }
1243
+ var img = new image_1.default("".concat(addImgPath ? _this._imgPath : '').concat(_this._imgPath, "/").concat(imgName));
1244
+ return img.getFileDownloadUrl(formatQuery);
1245
+ };
1246
+ this.getProducts = function (page, hpp, query, filters, indice, f, useProspr) {
1247
+ if (page === void 0) { page = 0; }
1248
+ if (hpp === void 0) { hpp = 10; }
1249
+ if (query === void 0) { query = ''; }
1250
+ if (filters === void 0) { filters = ''; }
1251
+ if (indice === void 0) { indice = 'products'; }
1252
+ if (f === void 0) { f = ''; }
1253
+ if (useProspr === void 0) { useProspr = false; }
1254
+ return __awaiter(_this, void 0, void 0, function () {
1255
+ var error_6;
1256
+ return __generator(this, function (_a) {
1257
+ switch (_a.label) {
1258
+ case 0:
1259
+ _a.trys.push([0, 2, , 3]);
1260
+ return [4, Product_1.default.fetch({
1261
+ app: process.env.NEXT_PUBLIC_ALGOLIA_APP,
1262
+ api: process.env.NEXT_PUBLIC_ALGOLIA_TOKEN,
1263
+ page: page,
1264
+ hpp: hpp,
1265
+ query: query,
1266
+ filters: filters,
1267
+ indice: indice || 'products',
1268
+ f: f,
1269
+ useProspr: useProspr,
1270
+ space: undefined
1271
+ })];
1272
+ case 1: return [2, _a.sent()];
1273
+ case 2:
1274
+ error_6 = _a.sent();
1275
+ throw error_6;
1276
+ case 3: return [2];
1277
+ }
1278
+ });
1279
+ });
1280
+ };
1281
+ this.getProduct = function (parent_slug, locale, useProdArray, noDrafts) { return __awaiter(_this, void 0, void 0, function () {
1282
+ var prod, fetchData, responseData;
1283
+ return __generator(this, function (_a) {
1284
+ switch (_a.label) {
1285
+ case 0:
1286
+ prod = undefined;
1287
+ if (!!useProdArray && !!useProdArray.length) {
1288
+ prod = useProdArray.find(function (fee) { return fee.slug === parent_slug; });
1289
+ }
1290
+ if (!!!!prod) return [3, 3];
1291
+ return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/products/").concat(encodeURIComponent(parent_slug)), {
1292
+ method: 'GET',
1293
+ headers: {
1294
+ Authorization: "Bearer ".concat(this._token),
1295
+ 'x-gng-ecomm-locale': locale,
1296
+ 'x-gng-ecomm-token': this._userToken
1297
+ }
1298
+ })];
1299
+ case 1:
1300
+ fetchData = _a.sent();
1301
+ return [4, fetchData.json()];
1302
+ case 2:
1303
+ responseData = _a.sent();
1304
+ if (responseData.status !== 200)
1305
+ throw new Error(JSON.stringify({ status: responseData.status, error: responseData.error }));
1306
+ prod = responseData.data;
1307
+ _a.label = 3;
1308
+ case 3:
1309
+ if (!!noDrafts && prod.draft)
1310
+ return [2, undefined];
1311
+ return [2, prod];
1312
+ }
1313
+ });
1314
+ }); };
1315
+ this.getUpsellOfProducts = function (slugs, customPriceList) { return __awaiter(_this, void 0, void 0, function () {
1316
+ var fetchData, responseData;
1317
+ return __generator(this, function (_a) {
1318
+ switch (_a.label) {
1319
+ case 0: return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/products/getUpsellOfProductsWithProducts"), {
1320
+ method: 'POST',
1321
+ headers: {
1322
+ Authorization: "Bearer ".concat(this._token),
1323
+ 'Content-Type': 'application/json'
1324
+ },
1325
+ body: JSON.stringify(__assign({ slugs: slugs }, (!!customPriceList ? { customPriceList: customPriceList } : {})))
1326
+ })];
1327
+ case 1:
1328
+ fetchData = _a.sent();
1329
+ return [4, fetchData.json()];
1330
+ case 2:
1331
+ responseData = _a.sent();
1332
+ if (responseData.status !== 200)
1333
+ throw new Error(JSON.stringify({ status: responseData.status, error: responseData.error }));
1334
+ return [2, responseData.data];
1335
+ }
1336
+ });
1337
+ }); };
1338
+ this.getAttributes = function () { return __awaiter(_this, void 0, void 0, function () {
1339
+ var fetchData, resJson, error_7;
1340
+ return __generator(this, function (_a) {
1341
+ switch (_a.label) {
1342
+ case 0:
1343
+ _a.trys.push([0, 3, , 4]);
1344
+ return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/attributes"), {
1345
+ method: 'GET',
1346
+ headers: {
1347
+ authorization: "Bearer ".concat(this._token),
1348
+ 'Content-Type': 'application/json'
1349
+ }
1350
+ })];
1351
+ case 1:
1352
+ fetchData = _a.sent();
1353
+ return [4, fetchData.json()];
1354
+ case 2:
1355
+ resJson = _a.sent();
1356
+ return [2, resJson.data.map(function (a) { return (__assign(__assign({}, a), { slug: !!a.slug ? a.slug : (0, functions_1.string_to_slug)((0, functions_1.translate)('fr', a.name)) })); })];
1357
+ case 3:
1358
+ error_7 = _a.sent();
1359
+ console.log('error fetch attributes: ', error_7);
1360
+ return [3, 4];
1361
+ case 4: return [2];
1362
+ }
1363
+ });
1364
+ }); };
1365
+ this.getCategories = function () { return __awaiter(_this, void 0, void 0, function () {
1366
+ var fetchData, resJson, error_8;
1367
+ return __generator(this, function (_a) {
1368
+ switch (_a.label) {
1369
+ case 0:
1370
+ _a.trys.push([0, 3, , 4]);
1371
+ return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/categories"), {
1372
+ method: 'GET',
1373
+ headers: {
1374
+ authorization: "Bearer ".concat(this._token),
1375
+ 'Content-Type': 'application/json'
1376
+ }
1377
+ })];
1378
+ case 1:
1379
+ fetchData = _a.sent();
1380
+ return [4, fetchData.json()];
1381
+ case 2:
1382
+ resJson = (_a.sent());
1383
+ return [2, resJson.data];
1384
+ case 3:
1385
+ error_8 = _a.sent();
1386
+ console.log('error fetch categories: ', error_8);
1387
+ return [3, 4];
1388
+ case 4: return [2];
1389
+ }
1390
+ });
1391
+ }); };
1392
+ this.getBrands = function () { return __awaiter(_this, void 0, void 0, function () {
1393
+ var fetchData, resJson, error_9;
1394
+ return __generator(this, function (_a) {
1395
+ switch (_a.label) {
1396
+ case 0:
1397
+ _a.trys.push([0, 3, , 4]);
1398
+ return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/brands"), {
1399
+ method: 'GET',
1400
+ headers: {
1401
+ authorization: "Bearer ".concat(this._token),
1402
+ 'Content-Type': 'application/json'
1403
+ }
1404
+ })];
1405
+ case 1:
1406
+ fetchData = _a.sent();
1407
+ return [4, fetchData.json()];
1408
+ case 2:
1409
+ resJson = (_a.sent());
1410
+ return [2, resJson.data];
1411
+ case 3:
1412
+ error_9 = _a.sent();
1413
+ console.log('error fetch brands: ', error_9);
1414
+ return [3, 4];
1415
+ case 4: return [2];
1416
+ }
1417
+ });
1418
+ }); };
1419
+ this.getInventoryItems = function (parentSlug) { return __awaiter(_this, void 0, void 0, function () {
1420
+ var fetchData, resJson, error_10;
1421
+ return __generator(this, function (_a) {
1422
+ switch (_a.label) {
1423
+ case 0:
1424
+ _a.trys.push([0, 3, , 4]);
1425
+ return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/inventories").concat(!!parentSlug ? "/".concat(encodeURIComponent(parentSlug)) : ''), {
1426
+ method: 'GET',
1427
+ headers: {
1428
+ authorization: "Bearer ".concat(this._token),
1429
+ 'Content-Type': 'application/json'
1430
+ }
1431
+ })];
1432
+ case 1:
1433
+ fetchData = _a.sent();
1434
+ return [4, fetchData.json()];
1435
+ case 2:
1436
+ resJson = (_a.sent());
1437
+ return [2, resJson.data];
1438
+ case 3:
1439
+ error_10 = _a.sent();
1440
+ console.log("error fetch inventory items".concat(!!parentSlug ? 'for parentSlug ' + parentSlug : '', ": "), error_10);
1441
+ return [3, 4];
1442
+ case 4: return [2];
1443
+ }
1444
+ });
1445
+ }); };
1446
+ this.getOneInventoryItem = function (sku) { return __awaiter(_this, void 0, void 0, function () {
1447
+ var fetchData, resJson, error_11;
1448
+ return __generator(this, function (_a) {
1449
+ switch (_a.label) {
1450
+ case 0:
1451
+ _a.trys.push([0, 3, , 4]);
1452
+ return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/inventory/").concat(encodeURIComponent(sku)), {
1453
+ method: 'GET',
1454
+ headers: {
1455
+ authorization: "Bearer ".concat(this._token),
1456
+ 'Content-Type': 'application/json'
1457
+ }
1458
+ })];
1459
+ case 1:
1460
+ fetchData = _a.sent();
1461
+ return [4, fetchData.json()];
1462
+ case 2:
1463
+ resJson = (_a.sent());
1464
+ return [2, resJson.data];
1465
+ case 3:
1466
+ error_11 = _a.sent();
1467
+ console.log("error fetch inventory item for sku: ".concat(sku), error_11);
1468
+ return [2, undefined];
1469
+ case 4: return [2];
1470
+ }
1471
+ });
1472
+ }); };
1473
+ this.getLatestProducts = function () { return __awaiter(_this, void 0, void 0, function () {
1474
+ var fetchData, resJson, error_12;
1475
+ return __generator(this, function (_a) {
1476
+ switch (_a.label) {
1477
+ case 0:
1478
+ _a.trys.push([0, 3, , 4]);
1479
+ return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/latest_products"), {
1480
+ method: 'GET',
1481
+ headers: {
1482
+ authorization: "Bearer ".concat(this._token),
1483
+ 'Content-Type': 'application/json'
1484
+ }
1485
+ })];
1486
+ case 1:
1487
+ fetchData = _a.sent();
1488
+ return [4, fetchData.json()];
1489
+ case 2:
1490
+ resJson = (_a.sent());
1491
+ return [2, resJson.data];
1492
+ case 3:
1493
+ error_12 = _a.sent();
1494
+ console.log("error fetching latest products", error_12);
1495
+ return [3, 4];
1496
+ case 4: return [2];
1497
+ }
1498
+ });
1499
+ }); };
1500
+ this._getFees = function () { return __awaiter(_this, void 0, void 0, function () {
1501
+ var fetchData, resJson, error_13;
1502
+ return __generator(this, function (_a) {
1503
+ switch (_a.label) {
1504
+ case 0:
1505
+ _a.trys.push([0, 3, , 4]);
1506
+ return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/products/getFees"), {
1507
+ method: 'GET',
1508
+ headers: {
1509
+ authorization: "Bearer ".concat(this._token),
1510
+ 'x-gng-ecomm-token': this._userToken
1511
+ }
1512
+ })];
1513
+ case 1:
1514
+ fetchData = _a.sent();
1515
+ return [4, fetchData.json()];
1516
+ case 2:
1517
+ resJson = (_a.sent());
1518
+ if (resJson.status !== 200) {
1519
+ console.log('error on fetching fees: ', !!resJson.error ? resJson.error.toString() : '');
1520
+ return [2, []];
1521
+ }
1522
+ return [2, resJson.data];
1523
+ case 3:
1524
+ error_13 = _a.sent();
1525
+ console.log("error fetching fees", error_13);
1526
+ return [3, 4];
1527
+ case 4: return [2];
1528
+ }
1529
+ });
1530
+ }); };
1531
+ this.products = {
1532
+ getProducts: this.getProducts,
1533
+ getProduct: this.getProduct,
1534
+ getUpsellOfProducts: this.getUpsellOfProducts,
1535
+ getAttributes: this.getAttributes,
1536
+ getCategories: this.getCategories,
1537
+ getBrands: this.getBrands,
1538
+ getInventoryItems: this.getInventoryItems,
1539
+ getOneInventoryItem: this.getOneInventoryItem,
1540
+ getLatestProducts: this.getLatestProducts,
1541
+ getFees: this._getFees
1542
+ };
1543
+ this.getIfAddressIsInsideZones = function (address) { return __awaiter(_this, void 0, void 0, function () {
1544
+ var userPos, lat, lng, zone, zones, google_1, insideZones, _i, zones_2, zone_1, polygon, error_14;
1545
+ return __generator(this, function (_a) {
1546
+ switch (_a.label) {
1547
+ case 0:
1548
+ _a.trys.push([0, 4, , 5]);
1549
+ return [4, (0, zones_1.getPositionFromAddress)(address)];
1550
+ case 1:
1551
+ userPos = _a.sent();
1552
+ if (!!!userPos)
1553
+ return [2, []];
1554
+ lat = userPos.lat, lng = userPos.lng;
1555
+ return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/shipping/zones"), {
1556
+ method: 'POST',
1557
+ headers: {
1558
+ authorization: "Bearer ".concat(this._token),
1559
+ 'Content-Type': 'application/json'
1560
+ },
1561
+ body: JSON.stringify({ address: address })
1562
+ })];
1563
+ case 2:
1564
+ zone = _a.sent();
1565
+ if (zone.status !== 200)
1566
+ return [2, []];
1567
+ return [4, zone.json()];
1568
+ case 3:
1569
+ zones = (_a.sent()).data.zones;
1570
+ google_1 = window.google;
1571
+ insideZones = [];
1572
+ for (_i = 0, zones_2 = zones; _i < zones_2.length; _i++) {
1573
+ zone_1 = zones_2[_i];
1574
+ polygon = new google_1.maps.Polygon({
1575
+ paths: zone_1.polygon.split(';').map(function (coords) { return ({
1576
+ lat: (0, lodash_1.toNumber)(coords.split(',')[1]),
1577
+ lng: (0, lodash_1.toNumber)(coords.split(',')[0])
1578
+ }); })
1579
+ });
1580
+ if (google_1.maps.geometry.poly.containsLocation({ lat: Number(lat), lng: Number(lng) }, polygon)) {
1581
+ insideZones.push(zone_1.slug);
1582
+ }
1583
+ }
1584
+ return [2, insideZones];
1585
+ case 4:
1586
+ error_14 = _a.sent();
1587
+ if (!!window && !!window.RemoteLog) {
1588
+ ;
1589
+ window.RemoteLog("error while fetching zones - ".concat(error_14.toString()), logs_1.LogType.ERROR);
1590
+ }
1591
+ console.log('error while fetching zones', error_14.toString());
1592
+ return [2, []];
1593
+ case 5: return [2];
1594
+ }
1595
+ });
1596
+ }); };
1597
+ this._pricingByQuery = function (query) { return __awaiter(_this, void 0, void 0, function () {
1598
+ var fetchData, resJson, error_15;
1599
+ return __generator(this, function (_a) {
1600
+ switch (_a.label) {
1601
+ case 0:
1602
+ _a.trys.push([0, 3, , 4]);
1603
+ return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/services/pricing/byQuery"), {
1604
+ method: 'POST',
1605
+ headers: {
1606
+ authorization: "Bearer ".concat(this._token),
1607
+ 'Content-Type': 'application/json'
1608
+ },
1609
+ body: JSON.stringify({ query: query })
1610
+ })];
1611
+ case 1:
1612
+ fetchData = _a.sent();
1613
+ return [4, fetchData.json()];
1614
+ case 2:
1615
+ resJson = _a.sent();
1616
+ return [2, resJson.data];
1617
+ case 3:
1618
+ error_15 = _a.sent();
1619
+ throw error_15;
1620
+ case 4: return [2];
1621
+ }
1622
+ });
1623
+ }); };
1624
+ this._buyFromForm = function (form) { return __awaiter(_this, void 0, void 0, function () {
1625
+ var fetchData, resJson, error_16;
1626
+ return __generator(this, function (_a) {
1627
+ switch (_a.label) {
1628
+ case 0:
1629
+ _a.trys.push([0, 3, , 4]);
1630
+ return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/services/buy/fromForm"), {
1631
+ method: 'POST',
1632
+ headers: {
1633
+ authorization: "Bearer ".concat(this._token),
1634
+ 'Content-Type': 'application/json'
1635
+ },
1636
+ body: JSON.stringify(form)
1637
+ })];
1638
+ case 1:
1639
+ fetchData = _a.sent();
1640
+ return [4, fetchData.json()];
1641
+ case 2:
1642
+ resJson = _a.sent();
1643
+ if (!!resJson.error) {
1644
+ return [2, false];
1645
+ }
1646
+ return [2, true];
1647
+ case 3:
1648
+ error_16 = _a.sent();
1649
+ throw error_16;
1650
+ case 4: return [2];
1651
+ }
1652
+ });
1653
+ }); };
1654
+ this._getSearchServices = function () { return __awaiter(_this, void 0, void 0, function () {
1655
+ var fetchData, resJson, space, error_17;
1656
+ return __generator(this, function (_a) {
1657
+ switch (_a.label) {
1658
+ case 0:
1659
+ _a.trys.push([0, 3, , 4]);
1660
+ return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/space"), {
1661
+ method: 'GET',
1662
+ headers: {
1663
+ authorization: "Bearer ".concat(this._token),
1664
+ 'Content-Type': 'application/json'
1665
+ }
1666
+ })];
1667
+ case 1:
1668
+ fetchData = _a.sent();
1669
+ return [4, fetchData.json()];
1670
+ case 2:
1671
+ resJson = _a.sent();
1672
+ if (!!resJson.error) {
1673
+ return [2, []];
1674
+ }
1675
+ space = resJson.data;
1676
+ if (!!!space || !!!space._space)
1677
+ return [2, []];
1678
+ return [2, space._space.external_services.filter(function (s) { return s.type === 'index'; })];
1679
+ case 3:
1680
+ error_17 = _a.sent();
1681
+ throw error_17;
1682
+ case 4: return [2];
1683
+ }
1684
+ });
1685
+ }); };
1686
+ this.services = {
1687
+ pricingByQuery: this._pricingByQuery,
1688
+ buy: {
1689
+ fromForm: this._buyFromForm
1690
+ },
1691
+ searchServices: this._getSearchServices
1692
+ };
1693
+ this._getAllCatalogues = function (locale) { return __awaiter(_this, void 0, void 0, function () {
1694
+ var fetchData, responseData;
1695
+ return __generator(this, function (_a) {
1696
+ switch (_a.label) {
1697
+ case 0: return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/catalogues"), {
1698
+ method: 'GET',
1699
+ headers: {
1700
+ Authorization: "Bearer ".concat(this._token),
1701
+ 'x-gng-ecomm-locale': locale
1702
+ }
1703
+ })];
1704
+ case 1:
1705
+ fetchData = _a.sent();
1706
+ return [4, fetchData.json()];
1707
+ case 2:
1708
+ responseData = _a.sent();
1709
+ if (responseData.status !== 200)
1710
+ throw new Error(JSON.stringify({ status: responseData.status, error: responseData.error }));
1711
+ return [2, responseData.data.filter(function (catalogue) { return !!!catalogue.draft; })];
1712
+ }
1713
+ });
1714
+ }); };
1715
+ this._getCatalogueBySlug = function (slug, locale) { return __awaiter(_this, void 0, void 0, function () {
1716
+ var fetchData, responseData;
1717
+ return __generator(this, function (_a) {
1718
+ switch (_a.label) {
1719
+ case 0: return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/catalogues/").concat(slug), {
1720
+ method: 'GET',
1721
+ headers: {
1722
+ Authorization: "Bearer ".concat(this._token),
1723
+ 'x-gng-ecomm-locale': locale
1724
+ }
1725
+ })];
1726
+ case 1:
1727
+ fetchData = _a.sent();
1728
+ return [4, fetchData.json()];
1729
+ case 2:
1730
+ responseData = _a.sent();
1731
+ if (responseData.status !== 200)
1732
+ throw new Error(JSON.stringify({ status: responseData.status, error: responseData.error }));
1733
+ return [2, responseData.data];
1734
+ }
1735
+ });
1736
+ }); };
1737
+ this.catalogues = {
1738
+ getAll: this._getAllCatalogues,
1739
+ getOne: this._getCatalogueBySlug
1740
+ };
1741
+ this.saveCustomerToMailchimpList = function (customerEmail, listID, mergeFields, tags) { return __awaiter(_this, void 0, void 0, function () {
1742
+ var saved, responseData, e_9;
1743
+ return __generator(this, function (_a) {
1744
+ switch (_a.label) {
1745
+ case 0:
1746
+ _a.trys.push([0, 3, , 4]);
1747
+ return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/marketing/mailchimp/updateOrCreateCustomer"), {
1748
+ method: 'POST',
1749
+ headers: {
1750
+ Authorization: "Bearer ".concat(this._token),
1751
+ 'Content-Type': 'application/json'
1752
+ },
1753
+ body: JSON.stringify(__assign(__assign({ email: customerEmail, listID: listID }, (!!mergeFields ? { mergeFields: mergeFields } : {})), (!!tags ? { tags: tags } : {})))
1754
+ })];
1755
+ case 1:
1756
+ saved = _a.sent();
1757
+ return [4, saved.json()];
1758
+ case 2:
1759
+ responseData = _a.sent();
1760
+ if (responseData.status !== 200)
1761
+ throw new Error(JSON.stringify({ status: responseData.status, error: responseData.error }));
1762
+ return [2, true];
1763
+ case 3:
1764
+ e_9 = _a.sent();
1765
+ console.log('error on saving customer to mailchimp list: ', e_9.toString());
1766
+ return [2, false];
1767
+ case 4: return [2];
1768
+ }
1769
+ });
1770
+ }); };
1771
+ this.getProductListForSitemap = function () { return __awaiter(_this, void 0, void 0, function () {
1772
+ var fetchData, result, e_10;
1773
+ return __generator(this, function (_a) {
1774
+ switch (_a.label) {
1775
+ case 0:
1776
+ _a.trys.push([0, 3, , 4]);
1777
+ return [4, (0, isomorphic_unfetch_1.default)("".concat(this._api, "/analytics/sitmap_data"), {
1778
+ method: 'GET',
1779
+ headers: {
1780
+ authorization: "Bearer ".concat(this._token),
1781
+ 'Content-Type': 'application/json'
1782
+ }
1783
+ })];
1784
+ case 1:
1785
+ fetchData = _a.sent();
1786
+ return [4, fetchData.json()];
1787
+ case 2:
1788
+ result = _a.sent();
1789
+ if (!!fetchData.status && fetchData.status !== 200)
1790
+ throw "".concat(result.data);
1791
+ return [2, result.data];
1792
+ case 3:
1793
+ e_10 = _a.sent();
1794
+ console.log('error fetching sitemap data: ', e_10.toString());
1795
+ return [2, e_10.toString()];
1796
+ case 4: return [2];
1797
+ }
1798
+ });
1799
+ }); };
1800
+ this._api = '';
1801
+ this._imgPath = '';
1802
+ this._token = '';
1803
+ this._userToken = '';
1804
+ this._url = '';
1805
+ this._org = '';
1806
+ this._storeData = null;
1807
+ this._wishlist = null;
1808
+ this._stockNotif = null;
1809
+ }
1810
+ return SDK;
1811
+ }());
1812
+ exports.default = SDK;
1809
1813
  //# sourceMappingURL=index.js.map