medusa-plugin-ses 1.0.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +13 -0
- package/README.md +61 -22
- package/api/index.js +26 -5
- package/jest.config.js +3 -0
- package/package.json +12 -8
- package/services/ses.js +458 -348
- package/src/api/index.js +33 -0
- package/src/services/ses.js +1292 -0
- package/src/subscribers/order.js +20 -0
- package/src/subscribers/restock.js +41 -0
- package/src/subscribers/user.js +17 -0
- package/api/middleware/await-middleware.js +0 -12
- package/api/middleware/index.js +0 -12
- package/api/routes/index.js +0 -19
- package/api/routes/send-email.js +0 -54
package/services/ses.js
CHANGED
|
@@ -5,9 +5,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports["default"] = void 0;
|
|
8
|
-
var
|
|
8
|
+
var aws = _interopRequireWildcard(require("@aws-sdk/client-ses"));
|
|
9
|
+
var _handlebars = _interopRequireDefault(require("handlebars"));
|
|
10
|
+
var _nodemailer = _interopRequireDefault(require("nodemailer"));
|
|
11
|
+
var _path = _interopRequireDefault(require("path"));
|
|
12
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
9
13
|
var _medusaCoreUtils = require("medusa-core-utils");
|
|
10
14
|
var _medusaInterfaces = require("medusa-interfaces");
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
16
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
17
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
11
18
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
12
19
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
13
20
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
@@ -37,12 +44,10 @@ var SESService = /*#__PURE__*/function (_NotificationService) {
|
|
|
37
44
|
* access_key_id: process.env.SES_ACCESS_KEY_ID,
|
|
38
45
|
* secret_access_key: process.env.SES_SECRET_ACCESS_KEY,
|
|
39
46
|
* region: process.env.SES_REGION,
|
|
40
|
-
* from:
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* user_password_reset_template: 0000,
|
|
45
|
-
* customer_password_reset_template: 1111,
|
|
47
|
+
* from: process.env.SES_FROM,
|
|
48
|
+
* enable_endpoint: process.env.SES_ENABLE_ENDPOINT,
|
|
49
|
+
* template_path: process.env.SES_TEMPLATE_PATH,
|
|
50
|
+
* order_placed_template: 'order_placed',
|
|
46
51
|
* }
|
|
47
52
|
*/
|
|
48
53
|
function SESService(_ref, options) {
|
|
@@ -72,13 +77,19 @@ var SESService = /*#__PURE__*/function (_NotificationService) {
|
|
|
72
77
|
_this.fulfillmentService_ = fulfillmentService;
|
|
73
78
|
_this.totalsService_ = totalsService;
|
|
74
79
|
_this.productVariantService_ = productVariantService;
|
|
75
|
-
|
|
80
|
+
var ses = new aws.SES({
|
|
76
81
|
region: options.region,
|
|
77
82
|
credentials: {
|
|
78
83
|
accessKeyId: options.access_key_id,
|
|
79
84
|
secretAccessKey: options.secret_access_key
|
|
80
85
|
}
|
|
81
86
|
});
|
|
87
|
+
_this.transporter_ = _nodemailer["default"].createTransport({
|
|
88
|
+
SES: {
|
|
89
|
+
ses: ses,
|
|
90
|
+
aws: aws
|
|
91
|
+
}
|
|
92
|
+
});
|
|
82
93
|
return _this;
|
|
83
94
|
}
|
|
84
95
|
_createClass(SESService, [{
|
|
@@ -277,73 +288,122 @@ var SESService = /*#__PURE__*/function (_NotificationService) {
|
|
|
277
288
|
}
|
|
278
289
|
}
|
|
279
290
|
}, {
|
|
280
|
-
key: "
|
|
291
|
+
key: "compileTemplate",
|
|
281
292
|
value: function () {
|
|
282
|
-
var
|
|
283
|
-
var
|
|
293
|
+
var _compileTemplate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(templateId, data) {
|
|
294
|
+
var base, subjectTemplate, htmlTemplate, textTemplate;
|
|
284
295
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
285
296
|
while (1) switch (_context3.prev = _context3.next) {
|
|
297
|
+
case 0:
|
|
298
|
+
base = _path["default"].resolve(__dirname, '../../', this.options_.template_path, templateId); // The absolute path below is useful when using yarn link or npm link
|
|
299
|
+
//const base = path.resolve(this.options_.template_path, templateId)
|
|
300
|
+
subjectTemplate = _handlebars["default"].compile(_fs["default"].readFileSync(_path["default"].join(base, 'subject.hbs'), "utf8"));
|
|
301
|
+
htmlTemplate = _handlebars["default"].compile(_fs["default"].readFileSync(_path["default"].join(base, 'html.hbs'), "utf8"));
|
|
302
|
+
textTemplate = _handlebars["default"].compile(_fs["default"].readFileSync(_path["default"].join(base, 'text.hbs'), "utf8"));
|
|
303
|
+
return _context3.abrupt("return", {
|
|
304
|
+
subject: subjectTemplate(data),
|
|
305
|
+
html: htmlTemplate(data),
|
|
306
|
+
text: textTemplate(data)
|
|
307
|
+
});
|
|
308
|
+
case 5:
|
|
309
|
+
case "end":
|
|
310
|
+
return _context3.stop();
|
|
311
|
+
}
|
|
312
|
+
}, _callee3, this);
|
|
313
|
+
}));
|
|
314
|
+
function compileTemplate(_x7, _x8) {
|
|
315
|
+
return _compileTemplate.apply(this, arguments);
|
|
316
|
+
}
|
|
317
|
+
return compileTemplate;
|
|
318
|
+
}()
|
|
319
|
+
}, {
|
|
320
|
+
key: "sendNotification",
|
|
321
|
+
value: function () {
|
|
322
|
+
var _sendNotification = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(event, eventData, attachmentGenerator) {
|
|
323
|
+
var templateId, data, _yield$this$compileTe, subject, html, text, sendOptions, attachments, status;
|
|
324
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
325
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
286
326
|
case 0:
|
|
287
327
|
templateId = this.getTemplateId(event);
|
|
288
328
|
if (templateId) {
|
|
289
|
-
|
|
329
|
+
_context4.next = 3;
|
|
290
330
|
break;
|
|
291
331
|
}
|
|
292
|
-
return
|
|
332
|
+
return _context4.abrupt("return", false);
|
|
293
333
|
case 3:
|
|
294
|
-
_context3.next = 5;
|
|
295
|
-
return this.fetchData(event, eventData, attachmentGenerator);
|
|
296
|
-
case 5:
|
|
297
|
-
data = _context3.sent;
|
|
298
|
-
_context3.next = 8;
|
|
299
|
-
return this.fetchAttachments(event, data, attachmentGenerator);
|
|
300
|
-
case 8:
|
|
301
|
-
attachments = _context3.sent;
|
|
302
334
|
if (data.locale) {
|
|
303
335
|
templateId = this.getLocalizedTemplateId(event, data.locale) || templateId;
|
|
304
336
|
}
|
|
337
|
+
_context4.next = 6;
|
|
338
|
+
return this.fetchData(event, eventData, attachmentGenerator);
|
|
339
|
+
case 6:
|
|
340
|
+
data = _context4.sent;
|
|
341
|
+
if (data) {
|
|
342
|
+
_context4.next = 9;
|
|
343
|
+
break;
|
|
344
|
+
}
|
|
345
|
+
return _context4.abrupt("return", false);
|
|
346
|
+
case 9:
|
|
347
|
+
_context4.next = 11;
|
|
348
|
+
return this.compileTemplate(templateId, data);
|
|
349
|
+
case 11:
|
|
350
|
+
_yield$this$compileTe = _context4.sent;
|
|
351
|
+
subject = _yield$this$compileTe.subject;
|
|
352
|
+
html = _yield$this$compileTe.html;
|
|
353
|
+
text = _yield$this$compileTe.text;
|
|
354
|
+
if (!(!subject || !html && !text)) {
|
|
355
|
+
_context4.next = 17;
|
|
356
|
+
break;
|
|
357
|
+
}
|
|
358
|
+
return _context4.abrupt("return", false);
|
|
359
|
+
case 17:
|
|
305
360
|
sendOptions = {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
}; // if (attachments?.length) {
|
|
313
|
-
// sendOptions.has_attachments = true
|
|
314
|
-
// sendOptions.attachments = attachments.map((a) => {
|
|
315
|
-
// return {
|
|
316
|
-
// content: a.base64,
|
|
317
|
-
// filename: a.name,
|
|
318
|
-
// type: a.type,
|
|
319
|
-
// disposition: "attachment",
|
|
320
|
-
// contentId: a.name,
|
|
321
|
-
// }
|
|
322
|
-
// })
|
|
323
|
-
// }
|
|
361
|
+
from: this.options_.from,
|
|
362
|
+
to: data.email,
|
|
363
|
+
subject: subject,
|
|
364
|
+
html: html,
|
|
365
|
+
text: text
|
|
366
|
+
};
|
|
324
367
|
console.log(sendOptions);
|
|
325
|
-
|
|
326
|
-
return this.
|
|
368
|
+
_context4.next = 21;
|
|
369
|
+
return this.fetchAttachments(event, data, attachmentGenerator);
|
|
370
|
+
case 21:
|
|
371
|
+
attachments = _context4.sent;
|
|
372
|
+
if (attachments !== null && attachments !== void 0 && attachments.length) {
|
|
373
|
+
sendOptions.has_attachments = true;
|
|
374
|
+
sendOptions.attachments = attachments.map(function (a) {
|
|
375
|
+
return {
|
|
376
|
+
content: a.base64,
|
|
377
|
+
filename: a.name,
|
|
378
|
+
encoding: 'base64',
|
|
379
|
+
contentType: a.type
|
|
380
|
+
};
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
//const status = await this.transporter_.sendMail(sendOptions).then(() => "sent").catch(() => "failed")
|
|
385
|
+
_context4.next = 25;
|
|
386
|
+
return this.transporter_.sendMail(sendOptions).then(function () {
|
|
327
387
|
status = "sent";
|
|
328
388
|
})["catch"](function (error) {
|
|
329
389
|
status = "failed";
|
|
330
390
|
console.log(error);
|
|
331
391
|
});
|
|
332
|
-
case
|
|
392
|
+
case 25:
|
|
333
393
|
// We don't want heavy docs stored in DB
|
|
334
394
|
delete sendOptions.attachments;
|
|
335
|
-
return
|
|
395
|
+
return _context4.abrupt("return", {
|
|
336
396
|
to: data.email,
|
|
337
397
|
status: status,
|
|
338
398
|
data: sendOptions
|
|
339
399
|
});
|
|
340
|
-
case
|
|
400
|
+
case 27:
|
|
341
401
|
case "end":
|
|
342
|
-
return
|
|
402
|
+
return _context4.stop();
|
|
343
403
|
}
|
|
344
|
-
},
|
|
404
|
+
}, _callee4, this);
|
|
345
405
|
}));
|
|
346
|
-
function sendNotification(
|
|
406
|
+
function sendNotification(_x9, _x10, _x11) {
|
|
347
407
|
return _sendNotification.apply(this, arguments);
|
|
348
408
|
}
|
|
349
409
|
return sendNotification;
|
|
@@ -351,87 +411,137 @@ var SESService = /*#__PURE__*/function (_NotificationService) {
|
|
|
351
411
|
}, {
|
|
352
412
|
key: "resendNotification",
|
|
353
413
|
value: function () {
|
|
354
|
-
var _resendNotification = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
355
|
-
var sendOptions, attachs;
|
|
356
|
-
return _regeneratorRuntime().wrap(function
|
|
357
|
-
while (1) switch (
|
|
414
|
+
var _resendNotification = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(notification, config, attachmentGenerator) {
|
|
415
|
+
var sendOptions, attachs, status;
|
|
416
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
417
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
358
418
|
case 0:
|
|
359
419
|
sendOptions = _objectSpread(_objectSpread({}, notification.data), {}, {
|
|
360
420
|
to: config.to || notification.to
|
|
361
421
|
});
|
|
362
|
-
|
|
422
|
+
_context5.next = 3;
|
|
363
423
|
return this.fetchAttachments(notification.event_name, notification.data.dynamic_template_data, attachmentGenerator);
|
|
364
424
|
case 3:
|
|
365
|
-
attachs =
|
|
425
|
+
attachs = _context5.sent;
|
|
366
426
|
sendOptions.attachments = attachs.map(function (a) {
|
|
367
427
|
return {
|
|
368
428
|
content: a.base64,
|
|
369
429
|
filename: a.name,
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
contentId: a.name
|
|
430
|
+
encoding: 'base64',
|
|
431
|
+
contentType: a.type
|
|
373
432
|
};
|
|
374
433
|
});
|
|
375
434
|
|
|
376
|
-
//
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
435
|
+
//const status = await this.transporter_.sendMail(sendOptions).then(() => "sent").catch(() => "failed")
|
|
436
|
+
_context5.next = 7;
|
|
437
|
+
return this.transporter_.sendMail(sendOptions).then(function () {
|
|
438
|
+
status = "sent";
|
|
439
|
+
})["catch"](function (error) {
|
|
440
|
+
status = "failed";
|
|
441
|
+
console.log(error);
|
|
442
|
+
});
|
|
443
|
+
case 7:
|
|
444
|
+
return _context5.abrupt("return", {
|
|
445
|
+
to: sendOptions.to,
|
|
446
|
+
status: status,
|
|
447
|
+
data: sendOptions
|
|
448
|
+
});
|
|
449
|
+
case 8:
|
|
383
450
|
case "end":
|
|
384
|
-
return
|
|
451
|
+
return _context5.stop();
|
|
385
452
|
}
|
|
386
|
-
},
|
|
453
|
+
}, _callee5, this);
|
|
387
454
|
}));
|
|
388
|
-
function resendNotification(
|
|
455
|
+
function resendNotification(_x12, _x13, _x14) {
|
|
389
456
|
return _resendNotification.apply(this, arguments);
|
|
390
457
|
}
|
|
391
458
|
return resendNotification;
|
|
392
459
|
}()
|
|
393
460
|
/**
|
|
394
|
-
* Sends an email using
|
|
395
|
-
* @param {string}
|
|
461
|
+
* Sends an email using SES.
|
|
462
|
+
* @param {string} template_id - id of template to use
|
|
396
463
|
* @param {string} from - sender of email
|
|
397
464
|
* @param {string} to - receiver of email
|
|
398
465
|
* @param {Object} data - data to send in mail (match with template)
|
|
399
466
|
* @return {Promise} result of the send operation
|
|
400
467
|
*/
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
468
|
+
}, {
|
|
469
|
+
key: "sendEmail",
|
|
470
|
+
value: function () {
|
|
471
|
+
var _sendEmail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(template_id, from, to, data) {
|
|
472
|
+
var _yield$this$compileTe2, subject, html, text;
|
|
473
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
474
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
475
|
+
case 0:
|
|
476
|
+
if (!(this.options_.enable_endpoint !== '42')) {
|
|
477
|
+
_context6.next = 2;
|
|
478
|
+
break;
|
|
479
|
+
}
|
|
480
|
+
return _context6.abrupt("return", false);
|
|
481
|
+
case 2:
|
|
482
|
+
_context6.next = 4;
|
|
483
|
+
return this.compileTemplate(template_id, data);
|
|
484
|
+
case 4:
|
|
485
|
+
_yield$this$compileTe2 = _context6.sent;
|
|
486
|
+
subject = _yield$this$compileTe2.subject;
|
|
487
|
+
html = _yield$this$compileTe2.html;
|
|
488
|
+
text = _yield$this$compileTe2.text;
|
|
489
|
+
if (!(!subject || !html && !text)) {
|
|
490
|
+
_context6.next = 10;
|
|
491
|
+
break;
|
|
492
|
+
}
|
|
493
|
+
return _context6.abrupt("return", false);
|
|
494
|
+
case 10:
|
|
495
|
+
_context6.prev = 10;
|
|
496
|
+
return _context6.abrupt("return", this.transporter_.sendMail({
|
|
497
|
+
from: from,
|
|
498
|
+
to: to,
|
|
499
|
+
subject: subject,
|
|
500
|
+
html: html,
|
|
501
|
+
text: text
|
|
502
|
+
}));
|
|
503
|
+
case 14:
|
|
504
|
+
_context6.prev = 14;
|
|
505
|
+
_context6.t0 = _context6["catch"](10);
|
|
506
|
+
throw _context6.t0;
|
|
507
|
+
case 17:
|
|
508
|
+
case "end":
|
|
509
|
+
return _context6.stop();
|
|
510
|
+
}
|
|
511
|
+
}, _callee6, this, [[10, 14]]);
|
|
512
|
+
}));
|
|
513
|
+
function sendEmail(_x15, _x16, _x17, _x18) {
|
|
514
|
+
return _sendEmail.apply(this, arguments);
|
|
515
|
+
}
|
|
516
|
+
return sendEmail;
|
|
517
|
+
}()
|
|
408
518
|
}, {
|
|
409
519
|
key: "orderShipmentCreatedData",
|
|
410
520
|
value: function () {
|
|
411
|
-
var _orderShipmentCreatedData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
521
|
+
var _orderShipmentCreatedData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(_ref2, attachmentGenerator) {
|
|
412
522
|
var id, fulfillment_id, order, shipment, locale;
|
|
413
|
-
return _regeneratorRuntime().wrap(function
|
|
414
|
-
while (1) switch (
|
|
523
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
524
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
415
525
|
case 0:
|
|
416
526
|
id = _ref2.id, fulfillment_id = _ref2.fulfillment_id;
|
|
417
|
-
|
|
527
|
+
_context7.next = 3;
|
|
418
528
|
return this.orderService_.retrieve(id, {
|
|
419
529
|
select: ["shipping_total", "discount_total", "tax_total", "refunded_total", "gift_card_total", "subtotal", "total", "refundable_amount"],
|
|
420
530
|
relations: ["customer", "billing_address", "shipping_address", "discounts", "discounts.rule", "shipping_methods", "shipping_methods.shipping_option", "payments", "fulfillments", "returns", "gift_cards", "gift_card_transactions"]
|
|
421
531
|
});
|
|
422
532
|
case 3:
|
|
423
|
-
order =
|
|
424
|
-
|
|
533
|
+
order = _context7.sent;
|
|
534
|
+
_context7.next = 6;
|
|
425
535
|
return this.fulfillmentService_.retrieve(fulfillment_id, {
|
|
426
536
|
relations: ["items", "tracking_links"]
|
|
427
537
|
});
|
|
428
538
|
case 6:
|
|
429
|
-
shipment =
|
|
430
|
-
|
|
539
|
+
shipment = _context7.sent;
|
|
540
|
+
_context7.next = 9;
|
|
431
541
|
return this.extractLocale(order);
|
|
432
542
|
case 9:
|
|
433
|
-
locale =
|
|
434
|
-
return
|
|
543
|
+
locale = _context7.sent;
|
|
544
|
+
return _context7.abrupt("return", {
|
|
435
545
|
locale: locale,
|
|
436
546
|
order: order,
|
|
437
547
|
date: shipment.shipped_at.toDateString(),
|
|
@@ -442,11 +552,11 @@ var SESService = /*#__PURE__*/function (_NotificationService) {
|
|
|
442
552
|
});
|
|
443
553
|
case 11:
|
|
444
554
|
case "end":
|
|
445
|
-
return
|
|
555
|
+
return _context7.stop();
|
|
446
556
|
}
|
|
447
|
-
},
|
|
557
|
+
}, _callee7, this);
|
|
448
558
|
}));
|
|
449
|
-
function orderShipmentCreatedData(
|
|
559
|
+
function orderShipmentCreatedData(_x19, _x20) {
|
|
450
560
|
return _orderShipmentCreatedData.apply(this, arguments);
|
|
451
561
|
}
|
|
452
562
|
return orderShipmentCreatedData;
|
|
@@ -454,19 +564,19 @@ var SESService = /*#__PURE__*/function (_NotificationService) {
|
|
|
454
564
|
}, {
|
|
455
565
|
key: "orderCanceledData",
|
|
456
566
|
value: function () {
|
|
457
|
-
var _orderCanceledData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
567
|
+
var _orderCanceledData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(_ref3) {
|
|
458
568
|
var id, order, subtotal, tax_total, discount_total, shipping_total, gift_card_total, total, taxRate, currencyCode, items, discounts, giftCards, locale;
|
|
459
|
-
return _regeneratorRuntime().wrap(function
|
|
460
|
-
while (1) switch (
|
|
569
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
570
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
461
571
|
case 0:
|
|
462
572
|
id = _ref3.id;
|
|
463
|
-
|
|
573
|
+
_context8.next = 3;
|
|
464
574
|
return this.orderService_.retrieve(id, {
|
|
465
575
|
select: ["shipping_total", "discount_total", "tax_total", "refunded_total", "gift_card_total", "subtotal", "total"],
|
|
466
576
|
relations: ["customer", "billing_address", "shipping_address", "discounts", "discounts.rule", "shipping_methods", "shipping_methods.shipping_option", "payments", "fulfillments", "returns", "gift_cards", "gift_card_transactions"]
|
|
467
577
|
});
|
|
468
578
|
case 3:
|
|
469
|
-
order =
|
|
579
|
+
order = _context8.sent;
|
|
470
580
|
subtotal = order.subtotal, tax_total = order.tax_total, discount_total = order.discount_total, shipping_total = order.shipping_total, gift_card_total = order.gift_card_total, total = order.total;
|
|
471
581
|
taxRate = order.tax_rate / 100;
|
|
472
582
|
currencyCode = order.currency_code.toUpperCase();
|
|
@@ -492,11 +602,11 @@ var SESService = /*#__PURE__*/function (_NotificationService) {
|
|
|
492
602
|
});
|
|
493
603
|
discounts.concat(giftCards);
|
|
494
604
|
}
|
|
495
|
-
|
|
605
|
+
_context8.next = 14;
|
|
496
606
|
return this.extractLocale(order);
|
|
497
607
|
case 14:
|
|
498
|
-
locale =
|
|
499
|
-
return
|
|
608
|
+
locale = _context8.sent;
|
|
609
|
+
return _context8.abrupt("return", _objectSpread(_objectSpread({}, order), {}, {
|
|
500
610
|
locale: locale,
|
|
501
611
|
has_discounts: order.discounts.length,
|
|
502
612
|
has_gift_cards: order.gift_cards.length,
|
|
@@ -512,11 +622,11 @@ var SESService = /*#__PURE__*/function (_NotificationService) {
|
|
|
512
622
|
}));
|
|
513
623
|
case 16:
|
|
514
624
|
case "end":
|
|
515
|
-
return
|
|
625
|
+
return _context8.stop();
|
|
516
626
|
}
|
|
517
|
-
},
|
|
627
|
+
}, _callee8, this);
|
|
518
628
|
}));
|
|
519
|
-
function orderCanceledData(
|
|
629
|
+
function orderCanceledData(_x21) {
|
|
520
630
|
return _orderCanceledData.apply(this, arguments);
|
|
521
631
|
}
|
|
522
632
|
return orderCanceledData;
|
|
@@ -524,51 +634,51 @@ var SESService = /*#__PURE__*/function (_NotificationService) {
|
|
|
524
634
|
}, {
|
|
525
635
|
key: "orderPlacedData",
|
|
526
636
|
value: function () {
|
|
527
|
-
var _orderPlacedData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
637
|
+
var _orderPlacedData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(_ref4) {
|
|
528
638
|
var _this2 = this;
|
|
529
639
|
var id, order, tax_total, shipping_total, gift_card_total, total, currencyCode, items, discounts, giftCards, locale, discountTotal, discounted_subtotal, subtotal, subtotal_ex_tax;
|
|
530
|
-
return _regeneratorRuntime().wrap(function
|
|
531
|
-
while (1) switch (
|
|
640
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
641
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
532
642
|
case 0:
|
|
533
643
|
id = _ref4.id;
|
|
534
|
-
|
|
644
|
+
_context10.next = 3;
|
|
535
645
|
return this.orderService_.retrieve(id, {
|
|
536
646
|
select: ["shipping_total", "discount_total", "tax_total", "refunded_total", "gift_card_total", "subtotal", "total"],
|
|
537
647
|
relations: ["customer", "billing_address", "shipping_address", "discounts", "discounts.rule", "shipping_methods", "shipping_methods.shipping_option", "payments", "fulfillments", "returns", "gift_cards", "gift_card_transactions"]
|
|
538
648
|
});
|
|
539
649
|
case 3:
|
|
540
|
-
order =
|
|
650
|
+
order = _context10.sent;
|
|
541
651
|
tax_total = order.tax_total, shipping_total = order.shipping_total, gift_card_total = order.gift_card_total, total = order.total;
|
|
542
652
|
currencyCode = order.currency_code.toUpperCase();
|
|
543
|
-
|
|
653
|
+
_context10.next = 8;
|
|
544
654
|
return Promise.all(order.items.map( /*#__PURE__*/function () {
|
|
545
|
-
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
546
|
-
return _regeneratorRuntime().wrap(function
|
|
547
|
-
while (1) switch (
|
|
655
|
+
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(i) {
|
|
656
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
657
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
548
658
|
case 0:
|
|
549
|
-
|
|
659
|
+
_context9.next = 2;
|
|
550
660
|
return _this2.totalsService_.getLineItemTotals(i, order, {
|
|
551
661
|
include_tax: true,
|
|
552
662
|
use_tax_lines: true
|
|
553
663
|
});
|
|
554
664
|
case 2:
|
|
555
|
-
i.totals =
|
|
665
|
+
i.totals = _context9.sent;
|
|
556
666
|
i.thumbnail = _this2.normalizeThumbUrl_(i.thumbnail);
|
|
557
667
|
i.discounted_price = "".concat(_this2.humanPrice_(i.totals.total / i.quantity, currencyCode), " ").concat(currencyCode);
|
|
558
668
|
i.price = "".concat(_this2.humanPrice_(i.totals.original_total / i.quantity, currencyCode), " ").concat(currencyCode);
|
|
559
|
-
return
|
|
669
|
+
return _context9.abrupt("return", i);
|
|
560
670
|
case 7:
|
|
561
671
|
case "end":
|
|
562
|
-
return
|
|
672
|
+
return _context9.stop();
|
|
563
673
|
}
|
|
564
|
-
},
|
|
674
|
+
}, _callee9);
|
|
565
675
|
}));
|
|
566
|
-
return function (
|
|
676
|
+
return function (_x23) {
|
|
567
677
|
return _ref5.apply(this, arguments);
|
|
568
678
|
};
|
|
569
679
|
}()));
|
|
570
680
|
case 8:
|
|
571
|
-
items =
|
|
681
|
+
items = _context10.sent;
|
|
572
682
|
discounts = [];
|
|
573
683
|
if (order.discounts) {
|
|
574
684
|
discounts = order.discounts.map(function (discount) {
|
|
@@ -590,10 +700,10 @@ var SESService = /*#__PURE__*/function (_NotificationService) {
|
|
|
590
700
|
});
|
|
591
701
|
discounts.concat(giftCards);
|
|
592
702
|
}
|
|
593
|
-
|
|
703
|
+
_context10.next = 15;
|
|
594
704
|
return this.extractLocale(order);
|
|
595
705
|
case 15:
|
|
596
|
-
locale =
|
|
706
|
+
locale = _context10.sent;
|
|
597
707
|
// Includes taxes in discount amount
|
|
598
708
|
discountTotal = items.reduce(function (acc, i) {
|
|
599
709
|
return acc + i.totals.original_total - i.totals.total;
|
|
@@ -607,7 +717,7 @@ var SESService = /*#__PURE__*/function (_NotificationService) {
|
|
|
607
717
|
subtotal_ex_tax = items.reduce(function (total, i) {
|
|
608
718
|
return total + i.totals.subtotal;
|
|
609
719
|
}, 0);
|
|
610
|
-
return
|
|
720
|
+
return _context10.abrupt("return", _objectSpread(_objectSpread({}, order), {}, {
|
|
611
721
|
locale: locale,
|
|
612
722
|
has_discounts: order.discounts.length,
|
|
613
723
|
has_gift_cards: order.gift_cards.length,
|
|
@@ -624,11 +734,11 @@ var SESService = /*#__PURE__*/function (_NotificationService) {
|
|
|
624
734
|
}));
|
|
625
735
|
case 21:
|
|
626
736
|
case "end":
|
|
627
|
-
return
|
|
737
|
+
return _context10.stop();
|
|
628
738
|
}
|
|
629
|
-
},
|
|
739
|
+
}, _callee10, this);
|
|
630
740
|
}));
|
|
631
|
-
function orderPlacedData(
|
|
741
|
+
function orderPlacedData(_x22) {
|
|
632
742
|
return _orderPlacedData.apply(this, arguments);
|
|
633
743
|
}
|
|
634
744
|
return orderPlacedData;
|
|
@@ -636,41 +746,41 @@ var SESService = /*#__PURE__*/function (_NotificationService) {
|
|
|
636
746
|
}, {
|
|
637
747
|
key: "gcCreatedData",
|
|
638
748
|
value: function () {
|
|
639
|
-
var _gcCreatedData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
749
|
+
var _gcCreatedData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(_ref6) {
|
|
640
750
|
var id, giftCard, taxRate, locale;
|
|
641
|
-
return _regeneratorRuntime().wrap(function
|
|
642
|
-
while (1) switch (
|
|
751
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
752
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
643
753
|
case 0:
|
|
644
754
|
id = _ref6.id;
|
|
645
|
-
|
|
755
|
+
_context11.next = 3;
|
|
646
756
|
return this.giftCardService_.retrieve(id, {
|
|
647
757
|
relations: ["region", "order"]
|
|
648
758
|
});
|
|
649
759
|
case 3:
|
|
650
|
-
giftCard =
|
|
760
|
+
giftCard = _context11.sent;
|
|
651
761
|
if (giftCard.order) {
|
|
652
|
-
|
|
762
|
+
_context11.next = 6;
|
|
653
763
|
break;
|
|
654
764
|
}
|
|
655
|
-
return
|
|
765
|
+
return _context11.abrupt("return");
|
|
656
766
|
case 6:
|
|
657
767
|
taxRate = giftCard.region.tax_rate / 100;
|
|
658
|
-
|
|
768
|
+
_context11.next = 9;
|
|
659
769
|
return this.extractLocale(order);
|
|
660
770
|
case 9:
|
|
661
|
-
locale =
|
|
662
|
-
return
|
|
771
|
+
locale = _context11.sent;
|
|
772
|
+
return _context11.abrupt("return", _objectSpread(_objectSpread({}, giftCard), {}, {
|
|
663
773
|
locale: locale,
|
|
664
774
|
email: giftCard.order.email,
|
|
665
775
|
display_value: giftCard.value * (1 + taxRate)
|
|
666
776
|
}));
|
|
667
777
|
case 11:
|
|
668
778
|
case "end":
|
|
669
|
-
return
|
|
779
|
+
return _context11.stop();
|
|
670
780
|
}
|
|
671
|
-
},
|
|
781
|
+
}, _callee11, this);
|
|
672
782
|
}));
|
|
673
|
-
function gcCreatedData(
|
|
783
|
+
function gcCreatedData(_x24) {
|
|
674
784
|
return _gcCreatedData.apply(this, arguments);
|
|
675
785
|
}
|
|
676
786
|
return gcCreatedData;
|
|
@@ -678,20 +788,20 @@ var SESService = /*#__PURE__*/function (_NotificationService) {
|
|
|
678
788
|
}, {
|
|
679
789
|
key: "returnRequestedData",
|
|
680
790
|
value: function () {
|
|
681
|
-
var _returnRequestedData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
791
|
+
var _returnRequestedData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(_ref7) {
|
|
682
792
|
var _this3 = this;
|
|
683
793
|
var id, return_id, returnRequest, items, order, currencyCode, returnItems, item_subtotal, shippingTotal, base, locale;
|
|
684
|
-
return _regeneratorRuntime().wrap(function
|
|
685
|
-
while (1) switch (
|
|
794
|
+
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
|
|
795
|
+
while (1) switch (_context13.prev = _context13.next) {
|
|
686
796
|
case 0:
|
|
687
797
|
id = _ref7.id, return_id = _ref7.return_id;
|
|
688
|
-
|
|
798
|
+
_context13.next = 3;
|
|
689
799
|
return this.returnService_.retrieve(return_id, {
|
|
690
800
|
relations: ["items", "items.item", "items.item.tax_lines", "items.item.variant", "items.item.variant.product", "shipping_method", "shipping_method.tax_lines", "shipping_method.shipping_option"]
|
|
691
801
|
});
|
|
692
802
|
case 3:
|
|
693
|
-
returnRequest =
|
|
694
|
-
|
|
803
|
+
returnRequest = _context13.sent;
|
|
804
|
+
_context13.next = 6;
|
|
695
805
|
return this.lineItemService_.list({
|
|
696
806
|
id: returnRequest.items.map(function (_ref8) {
|
|
697
807
|
var item_id = _ref8.item_id;
|
|
@@ -701,49 +811,49 @@ var SESService = /*#__PURE__*/function (_NotificationService) {
|
|
|
701
811
|
relations: ["tax_lines"]
|
|
702
812
|
});
|
|
703
813
|
case 6:
|
|
704
|
-
items =
|
|
705
|
-
|
|
814
|
+
items = _context13.sent;
|
|
815
|
+
_context13.next = 9;
|
|
706
816
|
return this.orderService_.retrieve(id, {
|
|
707
817
|
select: ["total"],
|
|
708
818
|
relations: ["items", "items.tax_lines", "discounts", "discounts.rule", "shipping_address", "returns"]
|
|
709
819
|
});
|
|
710
820
|
case 9:
|
|
711
|
-
order =
|
|
821
|
+
order = _context13.sent;
|
|
712
822
|
currencyCode = order.currency_code.toUpperCase(); // Calculate which items are in the return
|
|
713
|
-
|
|
823
|
+
_context13.next = 13;
|
|
714
824
|
return Promise.all(returnRequest.items.map( /*#__PURE__*/function () {
|
|
715
|
-
var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
825
|
+
var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(i) {
|
|
716
826
|
var found;
|
|
717
|
-
return _regeneratorRuntime().wrap(function
|
|
718
|
-
while (1) switch (
|
|
827
|
+
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
|
828
|
+
while (1) switch (_context12.prev = _context12.next) {
|
|
719
829
|
case 0:
|
|
720
830
|
found = items.find(function (oi) {
|
|
721
831
|
return oi.id === i.item_id;
|
|
722
832
|
});
|
|
723
833
|
found.quantity = i.quantity;
|
|
724
834
|
found.thumbnail = _this3.normalizeThumbUrl_(found.thumbnail);
|
|
725
|
-
|
|
835
|
+
_context12.next = 5;
|
|
726
836
|
return _this3.totalsService_.getLineItemTotals(found, order, {
|
|
727
837
|
include_tax: true,
|
|
728
838
|
use_tax_lines: true
|
|
729
839
|
});
|
|
730
840
|
case 5:
|
|
731
|
-
found.totals =
|
|
841
|
+
found.totals = _context12.sent;
|
|
732
842
|
found.price = "".concat(_this3.humanPrice_(found.totals.total, currencyCode), " ").concat(currencyCode);
|
|
733
843
|
found.tax_lines = found.totals.tax_lines;
|
|
734
|
-
return
|
|
844
|
+
return _context12.abrupt("return", found);
|
|
735
845
|
case 9:
|
|
736
846
|
case "end":
|
|
737
|
-
return
|
|
847
|
+
return _context12.stop();
|
|
738
848
|
}
|
|
739
|
-
},
|
|
849
|
+
}, _callee12);
|
|
740
850
|
}));
|
|
741
|
-
return function (
|
|
851
|
+
return function (_x26) {
|
|
742
852
|
return _ref9.apply(this, arguments);
|
|
743
853
|
};
|
|
744
854
|
}()));
|
|
745
855
|
case 13:
|
|
746
|
-
returnItems =
|
|
856
|
+
returnItems = _context13.sent;
|
|
747
857
|
// Get total of the returned products
|
|
748
858
|
item_subtotal = returnItems.reduce(function (acc, next) {
|
|
749
859
|
return acc + next.totals.total;
|
|
@@ -755,11 +865,11 @@ var SESService = /*#__PURE__*/function (_NotificationService) {
|
|
|
755
865
|
return Math.round(acc + base * (next.rate / 100));
|
|
756
866
|
}, 0);
|
|
757
867
|
}
|
|
758
|
-
|
|
868
|
+
_context13.next = 19;
|
|
759
869
|
return this.extractLocale(order);
|
|
760
870
|
case 19:
|
|
761
|
-
locale =
|
|
762
|
-
return
|
|
871
|
+
locale = _context13.sent;
|
|
872
|
+
return _context13.abrupt("return", {
|
|
763
873
|
locale: locale,
|
|
764
874
|
has_shipping: !!returnRequest.shipping_method,
|
|
765
875
|
email: order.email,
|
|
@@ -775,11 +885,11 @@ var SESService = /*#__PURE__*/function (_NotificationService) {
|
|
|
775
885
|
});
|
|
776
886
|
case 21:
|
|
777
887
|
case "end":
|
|
778
|
-
return
|
|
888
|
+
return _context13.stop();
|
|
779
889
|
}
|
|
780
|
-
},
|
|
890
|
+
}, _callee13, this);
|
|
781
891
|
}));
|
|
782
|
-
function returnRequestedData(
|
|
892
|
+
function returnRequestedData(_x25) {
|
|
783
893
|
return _returnRequestedData.apply(this, arguments);
|
|
784
894
|
}
|
|
785
895
|
return returnRequestedData;
|
|
@@ -787,25 +897,25 @@ var SESService = /*#__PURE__*/function (_NotificationService) {
|
|
|
787
897
|
}, {
|
|
788
898
|
key: "swapReceivedData",
|
|
789
899
|
value: function () {
|
|
790
|
-
var _swapReceivedData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
900
|
+
var _swapReceivedData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(_ref10) {
|
|
791
901
|
var _this4 = this;
|
|
792
902
|
var id, store, swap, returnRequest, items, swapLink, order, cart, currencyCode, decoratedItems, returnTotal, additionalTotal, refundAmount, locale;
|
|
793
|
-
return _regeneratorRuntime().wrap(function
|
|
794
|
-
while (1) switch (
|
|
903
|
+
return _regeneratorRuntime().wrap(function _callee15$(_context15) {
|
|
904
|
+
while (1) switch (_context15.prev = _context15.next) {
|
|
795
905
|
case 0:
|
|
796
906
|
id = _ref10.id;
|
|
797
|
-
|
|
907
|
+
_context15.next = 3;
|
|
798
908
|
return this.storeService_.retrieve();
|
|
799
909
|
case 3:
|
|
800
|
-
store =
|
|
801
|
-
|
|
910
|
+
store = _context15.sent;
|
|
911
|
+
_context15.next = 6;
|
|
802
912
|
return this.swapService_.retrieve(id, {
|
|
803
913
|
relations: ["additional_items", "additional_items.tax_lines", "return_order", "return_order.items", "return_order.items.item", "return_order.shipping_method", "return_order.shipping_method.shipping_option"]
|
|
804
914
|
});
|
|
805
915
|
case 6:
|
|
806
|
-
swap =
|
|
916
|
+
swap = _context15.sent;
|
|
807
917
|
returnRequest = swap.return_order;
|
|
808
|
-
|
|
918
|
+
_context15.next = 10;
|
|
809
919
|
return this.lineItemService_.list({
|
|
810
920
|
id: returnRequest.items.map(function (_ref11) {
|
|
811
921
|
var item_id = _ref11.item_id;
|
|
@@ -815,7 +925,7 @@ var SESService = /*#__PURE__*/function (_NotificationService) {
|
|
|
815
925
|
relations: ["tax_lines"]
|
|
816
926
|
});
|
|
817
927
|
case 10:
|
|
818
|
-
items =
|
|
928
|
+
items = _context15.sent;
|
|
819
929
|
returnRequest.items = returnRequest.items.map(function (item) {
|
|
820
930
|
var found = items.find(function (i) {
|
|
821
931
|
return i.id === item.item_id;
|
|
@@ -825,49 +935,49 @@ var SESService = /*#__PURE__*/function (_NotificationService) {
|
|
|
825
935
|
});
|
|
826
936
|
});
|
|
827
937
|
swapLink = store.swap_link_template.replace(/\{cart_id\}/, swap.cart_id);
|
|
828
|
-
|
|
938
|
+
_context15.next = 15;
|
|
829
939
|
return this.orderService_.retrieve(swap.order_id, {
|
|
830
940
|
select: ["total"],
|
|
831
941
|
relations: ["items", "discounts", "discounts.rule", "shipping_address", "swaps", "swaps.additional_items", "swaps.additional_items.tax_lines"]
|
|
832
942
|
});
|
|
833
943
|
case 15:
|
|
834
|
-
order =
|
|
835
|
-
|
|
944
|
+
order = _context15.sent;
|
|
945
|
+
_context15.next = 18;
|
|
836
946
|
return this.cartService_.retrieve(swap.cart_id, {
|
|
837
947
|
select: ["total", "tax_total", "discount_total", "shipping_total", "subtotal"]
|
|
838
948
|
});
|
|
839
949
|
case 18:
|
|
840
|
-
cart =
|
|
950
|
+
cart = _context15.sent;
|
|
841
951
|
currencyCode = order.currency_code.toUpperCase();
|
|
842
|
-
|
|
952
|
+
_context15.next = 22;
|
|
843
953
|
return Promise.all(cart.items.map( /*#__PURE__*/function () {
|
|
844
|
-
var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
954
|
+
var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(i) {
|
|
845
955
|
var totals;
|
|
846
|
-
return _regeneratorRuntime().wrap(function
|
|
847
|
-
while (1) switch (
|
|
956
|
+
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
|
|
957
|
+
while (1) switch (_context14.prev = _context14.next) {
|
|
848
958
|
case 0:
|
|
849
|
-
|
|
959
|
+
_context14.next = 2;
|
|
850
960
|
return _this4.totalsService_.getLineItemTotals(i, cart, {
|
|
851
961
|
include_tax: true
|
|
852
962
|
});
|
|
853
963
|
case 2:
|
|
854
|
-
totals =
|
|
855
|
-
return
|
|
964
|
+
totals = _context14.sent;
|
|
965
|
+
return _context14.abrupt("return", _objectSpread(_objectSpread({}, i), {}, {
|
|
856
966
|
totals: totals,
|
|
857
967
|
price: _this4.humanPrice_(totals.subtotal + totals.tax_total, currencyCode)
|
|
858
968
|
}));
|
|
859
969
|
case 4:
|
|
860
970
|
case "end":
|
|
861
|
-
return
|
|
971
|
+
return _context14.stop();
|
|
862
972
|
}
|
|
863
|
-
},
|
|
973
|
+
}, _callee14);
|
|
864
974
|
}));
|
|
865
|
-
return function (
|
|
975
|
+
return function (_x28) {
|
|
866
976
|
return _ref12.apply(this, arguments);
|
|
867
977
|
};
|
|
868
978
|
}()));
|
|
869
979
|
case 22:
|
|
870
|
-
decoratedItems =
|
|
980
|
+
decoratedItems = _context15.sent;
|
|
871
981
|
returnTotal = decoratedItems.reduce(function (acc, next) {
|
|
872
982
|
if (next.is_return) {
|
|
873
983
|
return acc + -1 * (next.totals.subtotal + next.totals.tax_total);
|
|
@@ -881,11 +991,11 @@ var SESService = /*#__PURE__*/function (_NotificationService) {
|
|
|
881
991
|
return acc;
|
|
882
992
|
}, 0);
|
|
883
993
|
refundAmount = swap.return_order.refund_amount;
|
|
884
|
-
|
|
994
|
+
_context15.next = 28;
|
|
885
995
|
return this.extractLocale(order);
|
|
886
996
|
case 28:
|
|
887
|
-
locale =
|
|
888
|
-
return
|
|
997
|
+
locale = _context15.sent;
|
|
998
|
+
return _context15.abrupt("return", {
|
|
889
999
|
locale: locale,
|
|
890
1000
|
swap: swap,
|
|
891
1001
|
order: order,
|
|
@@ -906,11 +1016,11 @@ var SESService = /*#__PURE__*/function (_NotificationService) {
|
|
|
906
1016
|
});
|
|
907
1017
|
case 30:
|
|
908
1018
|
case "end":
|
|
909
|
-
return
|
|
1019
|
+
return _context15.stop();
|
|
910
1020
|
}
|
|
911
|
-
},
|
|
1021
|
+
}, _callee15, this);
|
|
912
1022
|
}));
|
|
913
|
-
function swapReceivedData(
|
|
1023
|
+
function swapReceivedData(_x27) {
|
|
914
1024
|
return _swapReceivedData.apply(this, arguments);
|
|
915
1025
|
}
|
|
916
1026
|
return swapReceivedData;
|
|
@@ -918,25 +1028,25 @@ var SESService = /*#__PURE__*/function (_NotificationService) {
|
|
|
918
1028
|
}, {
|
|
919
1029
|
key: "swapCreatedData",
|
|
920
1030
|
value: function () {
|
|
921
|
-
var _swapCreatedData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1031
|
+
var _swapCreatedData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(_ref13) {
|
|
922
1032
|
var _this5 = this;
|
|
923
1033
|
var id, store, swap, returnRequest, items, swapLink, order, cart, currencyCode, decoratedItems, returnTotal, additionalTotal, refundAmount, locale;
|
|
924
|
-
return _regeneratorRuntime().wrap(function
|
|
925
|
-
while (1) switch (
|
|
1034
|
+
return _regeneratorRuntime().wrap(function _callee17$(_context17) {
|
|
1035
|
+
while (1) switch (_context17.prev = _context17.next) {
|
|
926
1036
|
case 0:
|
|
927
1037
|
id = _ref13.id;
|
|
928
|
-
|
|
1038
|
+
_context17.next = 3;
|
|
929
1039
|
return this.storeService_.retrieve();
|
|
930
1040
|
case 3:
|
|
931
|
-
store =
|
|
932
|
-
|
|
1041
|
+
store = _context17.sent;
|
|
1042
|
+
_context17.next = 6;
|
|
933
1043
|
return this.swapService_.retrieve(id, {
|
|
934
1044
|
relations: ["additional_items", "additional_items.tax_lines", "return_order", "return_order.items", "return_order.items.item", "return_order.shipping_method", "return_order.shipping_method.shipping_option"]
|
|
935
1045
|
});
|
|
936
1046
|
case 6:
|
|
937
|
-
swap =
|
|
1047
|
+
swap = _context17.sent;
|
|
938
1048
|
returnRequest = swap.return_order;
|
|
939
|
-
|
|
1049
|
+
_context17.next = 10;
|
|
940
1050
|
return this.lineItemService_.list({
|
|
941
1051
|
id: returnRequest.items.map(function (_ref14) {
|
|
942
1052
|
var item_id = _ref14.item_id;
|
|
@@ -946,7 +1056,7 @@ var SESService = /*#__PURE__*/function (_NotificationService) {
|
|
|
946
1056
|
relations: ["tax_lines"]
|
|
947
1057
|
});
|
|
948
1058
|
case 10:
|
|
949
|
-
items =
|
|
1059
|
+
items = _context17.sent;
|
|
950
1060
|
returnRequest.items = returnRequest.items.map(function (item) {
|
|
951
1061
|
var found = items.find(function (i) {
|
|
952
1062
|
return i.id === item.item_id;
|
|
@@ -956,34 +1066,34 @@ var SESService = /*#__PURE__*/function (_NotificationService) {
|
|
|
956
1066
|
});
|
|
957
1067
|
});
|
|
958
1068
|
swapLink = store.swap_link_template.replace(/\{cart_id\}/, swap.cart_id);
|
|
959
|
-
|
|
1069
|
+
_context17.next = 15;
|
|
960
1070
|
return this.orderService_.retrieve(swap.order_id, {
|
|
961
1071
|
select: ["total"],
|
|
962
1072
|
relations: ["items", "items.tax_lines", "discounts", "discounts.rule", "shipping_address", "swaps", "swaps.additional_items", "swaps.additional_items.tax_lines"]
|
|
963
1073
|
});
|
|
964
1074
|
case 15:
|
|
965
|
-
order =
|
|
966
|
-
|
|
1075
|
+
order = _context17.sent;
|
|
1076
|
+
_context17.next = 18;
|
|
967
1077
|
return this.cartService_.retrieve(swap.cart_id, {
|
|
968
1078
|
select: ["total", "tax_total", "discount_total", "shipping_total", "subtotal"]
|
|
969
1079
|
});
|
|
970
1080
|
case 18:
|
|
971
|
-
cart =
|
|
1081
|
+
cart = _context17.sent;
|
|
972
1082
|
currencyCode = order.currency_code.toUpperCase();
|
|
973
|
-
|
|
1083
|
+
_context17.next = 22;
|
|
974
1084
|
return Promise.all(cart.items.map( /*#__PURE__*/function () {
|
|
975
|
-
var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1085
|
+
var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(i) {
|
|
976
1086
|
var totals;
|
|
977
|
-
return _regeneratorRuntime().wrap(function
|
|
978
|
-
while (1) switch (
|
|
1087
|
+
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
|
|
1088
|
+
while (1) switch (_context16.prev = _context16.next) {
|
|
979
1089
|
case 0:
|
|
980
|
-
|
|
1090
|
+
_context16.next = 2;
|
|
981
1091
|
return _this5.totalsService_.getLineItemTotals(i, cart, {
|
|
982
1092
|
include_tax: true
|
|
983
1093
|
});
|
|
984
1094
|
case 2:
|
|
985
|
-
totals =
|
|
986
|
-
return
|
|
1095
|
+
totals = _context16.sent;
|
|
1096
|
+
return _context16.abrupt("return", _objectSpread(_objectSpread({}, i), {}, {
|
|
987
1097
|
totals: totals,
|
|
988
1098
|
tax_lines: totals.tax_lines,
|
|
989
1099
|
price: "".concat(_this5.humanPrice_(totals.original_total / i.quantity, currencyCode), " ").concat(currencyCode),
|
|
@@ -991,16 +1101,16 @@ var SESService = /*#__PURE__*/function (_NotificationService) {
|
|
|
991
1101
|
}));
|
|
992
1102
|
case 4:
|
|
993
1103
|
case "end":
|
|
994
|
-
return
|
|
1104
|
+
return _context16.stop();
|
|
995
1105
|
}
|
|
996
|
-
},
|
|
1106
|
+
}, _callee16);
|
|
997
1107
|
}));
|
|
998
|
-
return function (
|
|
1108
|
+
return function (_x30) {
|
|
999
1109
|
return _ref15.apply(this, arguments);
|
|
1000
1110
|
};
|
|
1001
1111
|
}()));
|
|
1002
1112
|
case 22:
|
|
1003
|
-
decoratedItems =
|
|
1113
|
+
decoratedItems = _context17.sent;
|
|
1004
1114
|
returnTotal = decoratedItems.reduce(function (acc, next) {
|
|
1005
1115
|
var total = next.totals.total;
|
|
1006
1116
|
if (next.is_return && next.variant_id) {
|
|
@@ -1016,11 +1126,11 @@ var SESService = /*#__PURE__*/function (_NotificationService) {
|
|
|
1016
1126
|
return acc;
|
|
1017
1127
|
}, 0);
|
|
1018
1128
|
refundAmount = swap.return_order.refund_amount;
|
|
1019
|
-
|
|
1129
|
+
_context17.next = 28;
|
|
1020
1130
|
return this.extractLocale(order);
|
|
1021
1131
|
case 28:
|
|
1022
|
-
locale =
|
|
1023
|
-
return
|
|
1132
|
+
locale = _context17.sent;
|
|
1133
|
+
return _context17.abrupt("return", {
|
|
1024
1134
|
locale: locale,
|
|
1025
1135
|
swap: swap,
|
|
1026
1136
|
order: order,
|
|
@@ -1040,11 +1150,11 @@ var SESService = /*#__PURE__*/function (_NotificationService) {
|
|
|
1040
1150
|
});
|
|
1041
1151
|
case 30:
|
|
1042
1152
|
case "end":
|
|
1043
|
-
return
|
|
1153
|
+
return _context17.stop();
|
|
1044
1154
|
}
|
|
1045
|
-
},
|
|
1155
|
+
}, _callee17, this);
|
|
1046
1156
|
}));
|
|
1047
|
-
function swapCreatedData(
|
|
1157
|
+
function swapCreatedData(_x29) {
|
|
1048
1158
|
return _swapCreatedData.apply(this, arguments);
|
|
1049
1159
|
}
|
|
1050
1160
|
return swapCreatedData;
|
|
@@ -1052,18 +1162,18 @@ var SESService = /*#__PURE__*/function (_NotificationService) {
|
|
|
1052
1162
|
}, {
|
|
1053
1163
|
key: "itemsReturnedData",
|
|
1054
1164
|
value: function () {
|
|
1055
|
-
var _itemsReturnedData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1056
|
-
return _regeneratorRuntime().wrap(function
|
|
1057
|
-
while (1) switch (
|
|
1165
|
+
var _itemsReturnedData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(data) {
|
|
1166
|
+
return _regeneratorRuntime().wrap(function _callee18$(_context18) {
|
|
1167
|
+
while (1) switch (_context18.prev = _context18.next) {
|
|
1058
1168
|
case 0:
|
|
1059
|
-
return
|
|
1169
|
+
return _context18.abrupt("return", this.returnRequestedData(data));
|
|
1060
1170
|
case 1:
|
|
1061
1171
|
case "end":
|
|
1062
|
-
return
|
|
1172
|
+
return _context18.stop();
|
|
1063
1173
|
}
|
|
1064
|
-
},
|
|
1174
|
+
}, _callee18, this);
|
|
1065
1175
|
}));
|
|
1066
|
-
function itemsReturnedData(
|
|
1176
|
+
function itemsReturnedData(_x31) {
|
|
1067
1177
|
return _itemsReturnedData.apply(this, arguments);
|
|
1068
1178
|
}
|
|
1069
1179
|
return itemsReturnedData;
|
|
@@ -1071,33 +1181,33 @@ var SESService = /*#__PURE__*/function (_NotificationService) {
|
|
|
1071
1181
|
}, {
|
|
1072
1182
|
key: "swapShipmentCreatedData",
|
|
1073
1183
|
value: function () {
|
|
1074
|
-
var _swapShipmentCreatedData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1184
|
+
var _swapShipmentCreatedData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(_ref16) {
|
|
1075
1185
|
var _this6 = this;
|
|
1076
1186
|
var id, fulfillment_id, swap, order, cart, returnRequest, items, taxRate, currencyCode, returnItems, returnTotal, constructedOrder, additionalTotal, refundAmount, shipment, locale;
|
|
1077
|
-
return _regeneratorRuntime().wrap(function
|
|
1078
|
-
while (1) switch (
|
|
1187
|
+
return _regeneratorRuntime().wrap(function _callee21$(_context21) {
|
|
1188
|
+
while (1) switch (_context21.prev = _context21.next) {
|
|
1079
1189
|
case 0:
|
|
1080
1190
|
id = _ref16.id, fulfillment_id = _ref16.fulfillment_id;
|
|
1081
|
-
|
|
1191
|
+
_context21.next = 3;
|
|
1082
1192
|
return this.swapService_.retrieve(id, {
|
|
1083
1193
|
relations: ["shipping_address", "shipping_methods", "shipping_methods.tax_lines", "additional_items", "additional_items.tax_lines", "return_order", "return_order.items"]
|
|
1084
1194
|
});
|
|
1085
1195
|
case 3:
|
|
1086
|
-
swap =
|
|
1087
|
-
|
|
1196
|
+
swap = _context21.sent;
|
|
1197
|
+
_context21.next = 6;
|
|
1088
1198
|
return this.orderService_.retrieve(swap.order_id, {
|
|
1089
1199
|
relations: ["region", "items", "items.tax_lines", "discounts", "discounts.rule", "swaps", "swaps.additional_items", "swaps.additional_items.tax_lines"]
|
|
1090
1200
|
});
|
|
1091
1201
|
case 6:
|
|
1092
|
-
order =
|
|
1093
|
-
|
|
1202
|
+
order = _context21.sent;
|
|
1203
|
+
_context21.next = 9;
|
|
1094
1204
|
return this.cartService_.retrieve(swap.cart_id, {
|
|
1095
1205
|
select: ["total", "tax_total", "discount_total", "shipping_total", "subtotal"]
|
|
1096
1206
|
});
|
|
1097
1207
|
case 9:
|
|
1098
|
-
cart =
|
|
1208
|
+
cart = _context21.sent;
|
|
1099
1209
|
returnRequest = swap.return_order;
|
|
1100
|
-
|
|
1210
|
+
_context21.next = 13;
|
|
1101
1211
|
return this.lineItemService_.list({
|
|
1102
1212
|
id: returnRequest.items.map(function (_ref17) {
|
|
1103
1213
|
var item_id = _ref17.item_id;
|
|
@@ -1107,26 +1217,26 @@ var SESService = /*#__PURE__*/function (_NotificationService) {
|
|
|
1107
1217
|
relations: ["tax_lines"]
|
|
1108
1218
|
});
|
|
1109
1219
|
case 13:
|
|
1110
|
-
items =
|
|
1220
|
+
items = _context21.sent;
|
|
1111
1221
|
taxRate = order.tax_rate / 100;
|
|
1112
1222
|
currencyCode = order.currency_code.toUpperCase();
|
|
1113
|
-
|
|
1223
|
+
_context21.next = 18;
|
|
1114
1224
|
return Promise.all(swap.return_order.items.map( /*#__PURE__*/function () {
|
|
1115
|
-
var _ref18 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1225
|
+
var _ref18 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(i) {
|
|
1116
1226
|
var found, totals;
|
|
1117
|
-
return _regeneratorRuntime().wrap(function
|
|
1118
|
-
while (1) switch (
|
|
1227
|
+
return _regeneratorRuntime().wrap(function _callee19$(_context19) {
|
|
1228
|
+
while (1) switch (_context19.prev = _context19.next) {
|
|
1119
1229
|
case 0:
|
|
1120
1230
|
found = items.find(function (oi) {
|
|
1121
1231
|
return oi.id === i.item_id;
|
|
1122
1232
|
});
|
|
1123
|
-
|
|
1233
|
+
_context19.next = 3;
|
|
1124
1234
|
return _this6.totalsService_.getLineItemTotals(i, cart, {
|
|
1125
1235
|
include_tax: true
|
|
1126
1236
|
});
|
|
1127
1237
|
case 3:
|
|
1128
|
-
totals =
|
|
1129
|
-
return
|
|
1238
|
+
totals = _context19.sent;
|
|
1239
|
+
return _context19.abrupt("return", _objectSpread(_objectSpread({}, found), {}, {
|
|
1130
1240
|
thumbnail: _this6.normalizeThumbUrl_(found.thumbnail),
|
|
1131
1241
|
price: "".concat(_this6.humanPrice_(totals.original_total / i.quantity, currencyCode), " ").concat(currencyCode),
|
|
1132
1242
|
discounted_price: "".concat(_this6.humanPrice_(totals.total / i.quantity, currencyCode), " ").concat(currencyCode),
|
|
@@ -1134,56 +1244,56 @@ var SESService = /*#__PURE__*/function (_NotificationService) {
|
|
|
1134
1244
|
}));
|
|
1135
1245
|
case 5:
|
|
1136
1246
|
case "end":
|
|
1137
|
-
return
|
|
1247
|
+
return _context19.stop();
|
|
1138
1248
|
}
|
|
1139
|
-
},
|
|
1249
|
+
}, _callee19);
|
|
1140
1250
|
}));
|
|
1141
|
-
return function (
|
|
1251
|
+
return function (_x33) {
|
|
1142
1252
|
return _ref18.apply(this, arguments);
|
|
1143
1253
|
};
|
|
1144
1254
|
}()));
|
|
1145
1255
|
case 18:
|
|
1146
|
-
returnItems =
|
|
1147
|
-
|
|
1256
|
+
returnItems = _context21.sent;
|
|
1257
|
+
_context21.next = 21;
|
|
1148
1258
|
return this.totalsService_.getRefundTotal(order, returnItems);
|
|
1149
1259
|
case 21:
|
|
1150
|
-
returnTotal =
|
|
1260
|
+
returnTotal = _context21.sent;
|
|
1151
1261
|
constructedOrder = _objectSpread(_objectSpread({}, order), {}, {
|
|
1152
1262
|
shipping_methods: swap.shipping_methods,
|
|
1153
1263
|
items: swap.additional_items
|
|
1154
1264
|
});
|
|
1155
|
-
|
|
1265
|
+
_context21.next = 25;
|
|
1156
1266
|
return this.totalsService_.getTotal(constructedOrder);
|
|
1157
1267
|
case 25:
|
|
1158
|
-
additionalTotal =
|
|
1268
|
+
additionalTotal = _context21.sent;
|
|
1159
1269
|
refundAmount = swap.return_order.refund_amount;
|
|
1160
|
-
|
|
1270
|
+
_context21.next = 29;
|
|
1161
1271
|
return this.fulfillmentService_.retrieve(fulfillment_id, {
|
|
1162
1272
|
relations: ["tracking_links"]
|
|
1163
1273
|
});
|
|
1164
1274
|
case 29:
|
|
1165
|
-
shipment =
|
|
1166
|
-
|
|
1275
|
+
shipment = _context21.sent;
|
|
1276
|
+
_context21.next = 32;
|
|
1167
1277
|
return this.extractLocale(order);
|
|
1168
1278
|
case 32:
|
|
1169
|
-
locale =
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1279
|
+
locale = _context21.sent;
|
|
1280
|
+
_context21.t0 = locale;
|
|
1281
|
+
_context21.t1 = swap;
|
|
1282
|
+
_context21.t2 = order;
|
|
1283
|
+
_context21.next = 38;
|
|
1174
1284
|
return Promise.all(swap.additional_items.map( /*#__PURE__*/function () {
|
|
1175
|
-
var _ref19 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1285
|
+
var _ref19 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(i) {
|
|
1176
1286
|
var totals;
|
|
1177
|
-
return _regeneratorRuntime().wrap(function
|
|
1178
|
-
while (1) switch (
|
|
1287
|
+
return _regeneratorRuntime().wrap(function _callee20$(_context20) {
|
|
1288
|
+
while (1) switch (_context20.prev = _context20.next) {
|
|
1179
1289
|
case 0:
|
|
1180
|
-
|
|
1290
|
+
_context20.next = 2;
|
|
1181
1291
|
return _this6.totalsService_.getLineItemTotals(i, cart, {
|
|
1182
1292
|
include_tax: true
|
|
1183
1293
|
});
|
|
1184
1294
|
case 2:
|
|
1185
|
-
totals =
|
|
1186
|
-
return
|
|
1295
|
+
totals = _context20.sent;
|
|
1296
|
+
return _context20.abrupt("return", _objectSpread(_objectSpread({}, i), {}, {
|
|
1187
1297
|
thumbnail: _this6.normalizeThumbUrl_(i.thumbnail),
|
|
1188
1298
|
price: "".concat(_this6.humanPrice_(totals.original_total / i.quantity, currencyCode), " ").concat(currencyCode),
|
|
1189
1299
|
discounted_price: "".concat(_this6.humanPrice_(totals.total / i.quantity, currencyCode), " ").concat(currencyCode),
|
|
@@ -1191,49 +1301,49 @@ var SESService = /*#__PURE__*/function (_NotificationService) {
|
|
|
1191
1301
|
}));
|
|
1192
1302
|
case 4:
|
|
1193
1303
|
case "end":
|
|
1194
|
-
return
|
|
1304
|
+
return _context20.stop();
|
|
1195
1305
|
}
|
|
1196
|
-
},
|
|
1306
|
+
}, _callee20);
|
|
1197
1307
|
}));
|
|
1198
|
-
return function (
|
|
1308
|
+
return function (_x34) {
|
|
1199
1309
|
return _ref19.apply(this, arguments);
|
|
1200
1310
|
};
|
|
1201
1311
|
}()));
|
|
1202
1312
|
case 38:
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
return
|
|
1215
|
-
locale:
|
|
1216
|
-
swap:
|
|
1217
|
-
order:
|
|
1218
|
-
items:
|
|
1219
|
-
date:
|
|
1220
|
-
email:
|
|
1221
|
-
tax_amount:
|
|
1222
|
-
paid_total:
|
|
1223
|
-
return_total:
|
|
1224
|
-
refund_amount:
|
|
1225
|
-
additional_total:
|
|
1226
|
-
fulfillment:
|
|
1227
|
-
tracking_links:
|
|
1228
|
-
tracking_number:
|
|
1313
|
+
_context21.t3 = _context21.sent;
|
|
1314
|
+
_context21.t4 = swap.updated_at.toDateString();
|
|
1315
|
+
_context21.t5 = order.email;
|
|
1316
|
+
_context21.t6 = "".concat(this.humanPrice_(cart.tax_total, currencyCode), " ").concat(currencyCode);
|
|
1317
|
+
_context21.t7 = "".concat(this.humanPrice_(swap.difference_due, currencyCode), " ").concat(currencyCode);
|
|
1318
|
+
_context21.t8 = "".concat(this.humanPrice_(returnTotal, currencyCode), " ").concat(currencyCode);
|
|
1319
|
+
_context21.t9 = "".concat(this.humanPrice_(refundAmount, currencyCode), " ").concat(currencyCode);
|
|
1320
|
+
_context21.t10 = "".concat(this.humanPrice_(additionalTotal, currencyCode), " ").concat(currencyCode);
|
|
1321
|
+
_context21.t11 = shipment;
|
|
1322
|
+
_context21.t12 = shipment.tracking_links;
|
|
1323
|
+
_context21.t13 = shipment.tracking_numbers.join(", ");
|
|
1324
|
+
return _context21.abrupt("return", {
|
|
1325
|
+
locale: _context21.t0,
|
|
1326
|
+
swap: _context21.t1,
|
|
1327
|
+
order: _context21.t2,
|
|
1328
|
+
items: _context21.t3,
|
|
1329
|
+
date: _context21.t4,
|
|
1330
|
+
email: _context21.t5,
|
|
1331
|
+
tax_amount: _context21.t6,
|
|
1332
|
+
paid_total: _context21.t7,
|
|
1333
|
+
return_total: _context21.t8,
|
|
1334
|
+
refund_amount: _context21.t9,
|
|
1335
|
+
additional_total: _context21.t10,
|
|
1336
|
+
fulfillment: _context21.t11,
|
|
1337
|
+
tracking_links: _context21.t12,
|
|
1338
|
+
tracking_number: _context21.t13
|
|
1229
1339
|
});
|
|
1230
1340
|
case 50:
|
|
1231
1341
|
case "end":
|
|
1232
|
-
return
|
|
1342
|
+
return _context21.stop();
|
|
1233
1343
|
}
|
|
1234
|
-
},
|
|
1344
|
+
}, _callee21, this);
|
|
1235
1345
|
}));
|
|
1236
|
-
function swapShipmentCreatedData(
|
|
1346
|
+
function swapShipmentCreatedData(_x32) {
|
|
1237
1347
|
return _swapShipmentCreatedData.apply(this, arguments);
|
|
1238
1348
|
}
|
|
1239
1349
|
return swapShipmentCreatedData;
|
|
@@ -1241,29 +1351,29 @@ var SESService = /*#__PURE__*/function (_NotificationService) {
|
|
|
1241
1351
|
}, {
|
|
1242
1352
|
key: "claimShipmentCreatedData",
|
|
1243
1353
|
value: function () {
|
|
1244
|
-
var _claimShipmentCreatedData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1354
|
+
var _claimShipmentCreatedData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(_ref20) {
|
|
1245
1355
|
var id, fulfillment_id, claim, shipment, locale;
|
|
1246
|
-
return _regeneratorRuntime().wrap(function
|
|
1247
|
-
while (1) switch (
|
|
1356
|
+
return _regeneratorRuntime().wrap(function _callee22$(_context22) {
|
|
1357
|
+
while (1) switch (_context22.prev = _context22.next) {
|
|
1248
1358
|
case 0:
|
|
1249
1359
|
id = _ref20.id, fulfillment_id = _ref20.fulfillment_id;
|
|
1250
|
-
|
|
1360
|
+
_context22.next = 3;
|
|
1251
1361
|
return this.claimService_.retrieve(id, {
|
|
1252
1362
|
relations: ["order", "order.items", "order.shipping_address"]
|
|
1253
1363
|
});
|
|
1254
1364
|
case 3:
|
|
1255
|
-
claim =
|
|
1256
|
-
|
|
1365
|
+
claim = _context22.sent;
|
|
1366
|
+
_context22.next = 6;
|
|
1257
1367
|
return this.fulfillmentService_.retrieve(fulfillment_id, {
|
|
1258
1368
|
relations: ["tracking_links"]
|
|
1259
1369
|
});
|
|
1260
1370
|
case 6:
|
|
1261
|
-
shipment =
|
|
1262
|
-
|
|
1371
|
+
shipment = _context22.sent;
|
|
1372
|
+
_context22.next = 9;
|
|
1263
1373
|
return this.extractLocale(claim.order);
|
|
1264
1374
|
case 9:
|
|
1265
|
-
locale =
|
|
1266
|
-
return
|
|
1375
|
+
locale = _context22.sent;
|
|
1376
|
+
return _context22.abrupt("return", {
|
|
1267
1377
|
locale: locale,
|
|
1268
1378
|
email: claim.order.email,
|
|
1269
1379
|
claim: claim,
|
|
@@ -1274,11 +1384,11 @@ var SESService = /*#__PURE__*/function (_NotificationService) {
|
|
|
1274
1384
|
});
|
|
1275
1385
|
case 11:
|
|
1276
1386
|
case "end":
|
|
1277
|
-
return
|
|
1387
|
+
return _context22.stop();
|
|
1278
1388
|
}
|
|
1279
|
-
},
|
|
1389
|
+
}, _callee22, this);
|
|
1280
1390
|
}));
|
|
1281
|
-
function claimShipmentCreatedData(
|
|
1391
|
+
function claimShipmentCreatedData(_x35) {
|
|
1282
1392
|
return _claimShipmentCreatedData.apply(this, arguments);
|
|
1283
1393
|
}
|
|
1284
1394
|
return claimShipmentCreatedData;
|
|
@@ -1286,22 +1396,22 @@ var SESService = /*#__PURE__*/function (_NotificationService) {
|
|
|
1286
1396
|
}, {
|
|
1287
1397
|
key: "restockNotificationData",
|
|
1288
1398
|
value: function () {
|
|
1289
|
-
var _restockNotificationData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1399
|
+
var _restockNotificationData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(_ref21) {
|
|
1290
1400
|
var variant_id, emails, variant, thumb;
|
|
1291
|
-
return _regeneratorRuntime().wrap(function
|
|
1292
|
-
while (1) switch (
|
|
1401
|
+
return _regeneratorRuntime().wrap(function _callee23$(_context23) {
|
|
1402
|
+
while (1) switch (_context23.prev = _context23.next) {
|
|
1293
1403
|
case 0:
|
|
1294
1404
|
variant_id = _ref21.variant_id, emails = _ref21.emails;
|
|
1295
|
-
|
|
1405
|
+
_context23.next = 3;
|
|
1296
1406
|
return this.productVariantService_.retrieve(variant_id, {
|
|
1297
1407
|
relations: ["product"]
|
|
1298
1408
|
});
|
|
1299
1409
|
case 3:
|
|
1300
|
-
variant =
|
|
1410
|
+
variant = _context23.sent;
|
|
1301
1411
|
if (variant.product.thumbnail) {
|
|
1302
1412
|
thumb = this.normalizeThumbUrl_(variant.product.thumbnail);
|
|
1303
1413
|
}
|
|
1304
|
-
return
|
|
1414
|
+
return _context23.abrupt("return", {
|
|
1305
1415
|
product: _objectSpread(_objectSpread({}, variant.product), {}, {
|
|
1306
1416
|
thumbnail: thumb
|
|
1307
1417
|
}),
|
|
@@ -1311,11 +1421,11 @@ var SESService = /*#__PURE__*/function (_NotificationService) {
|
|
|
1311
1421
|
});
|
|
1312
1422
|
case 6:
|
|
1313
1423
|
case "end":
|
|
1314
|
-
return
|
|
1424
|
+
return _context23.stop();
|
|
1315
1425
|
}
|
|
1316
|
-
},
|
|
1426
|
+
}, _callee23, this);
|
|
1317
1427
|
}));
|
|
1318
|
-
function restockNotificationData(
|
|
1428
|
+
function restockNotificationData(_x36) {
|
|
1319
1429
|
return _restockNotificationData.apply(this, arguments);
|
|
1320
1430
|
}
|
|
1321
1431
|
return restockNotificationData;
|
|
@@ -1333,23 +1443,23 @@ var SESService = /*#__PURE__*/function (_NotificationService) {
|
|
|
1333
1443
|
}, {
|
|
1334
1444
|
key: "orderRefundCreatedData",
|
|
1335
1445
|
value: function () {
|
|
1336
|
-
var _orderRefundCreatedData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1446
|
+
var _orderRefundCreatedData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(_ref22) {
|
|
1337
1447
|
var id, refund_id, order, refund;
|
|
1338
|
-
return _regeneratorRuntime().wrap(function
|
|
1339
|
-
while (1) switch (
|
|
1448
|
+
return _regeneratorRuntime().wrap(function _callee24$(_context24) {
|
|
1449
|
+
while (1) switch (_context24.prev = _context24.next) {
|
|
1340
1450
|
case 0:
|
|
1341
1451
|
id = _ref22.id, refund_id = _ref22.refund_id;
|
|
1342
|
-
|
|
1452
|
+
_context24.next = 3;
|
|
1343
1453
|
return this.orderService_.retrieveWithTotals(id, {
|
|
1344
1454
|
select: ["total"],
|
|
1345
1455
|
relations: ["refunds", "items"]
|
|
1346
1456
|
});
|
|
1347
1457
|
case 3:
|
|
1348
|
-
order =
|
|
1458
|
+
order = _context24.sent;
|
|
1349
1459
|
refund = order.refunds.find(function (refund) {
|
|
1350
1460
|
return refund.id === refund_id;
|
|
1351
1461
|
});
|
|
1352
|
-
return
|
|
1462
|
+
return _context24.abrupt("return", {
|
|
1353
1463
|
order: order,
|
|
1354
1464
|
refund: refund,
|
|
1355
1465
|
refund_amount: "".concat(this.humanPrice_(refund.amount, order.currency_code), " ").concat(order.currency_code),
|
|
@@ -1357,11 +1467,11 @@ var SESService = /*#__PURE__*/function (_NotificationService) {
|
|
|
1357
1467
|
});
|
|
1358
1468
|
case 6:
|
|
1359
1469
|
case "end":
|
|
1360
|
-
return
|
|
1470
|
+
return _context24.stop();
|
|
1361
1471
|
}
|
|
1362
|
-
},
|
|
1472
|
+
}, _callee24, this);
|
|
1363
1473
|
}));
|
|
1364
|
-
function orderRefundCreatedData(
|
|
1474
|
+
function orderRefundCreatedData(_x37) {
|
|
1365
1475
|
return _orderRefundCreatedData.apply(this, arguments);
|
|
1366
1476
|
}
|
|
1367
1477
|
return orderRefundCreatedData;
|
|
@@ -1402,45 +1512,45 @@ var SESService = /*#__PURE__*/function (_NotificationService) {
|
|
|
1402
1512
|
}, {
|
|
1403
1513
|
key: "extractLocale",
|
|
1404
1514
|
value: function () {
|
|
1405
|
-
var _extractLocale = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1515
|
+
var _extractLocale = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(fromOrder) {
|
|
1406
1516
|
var cart;
|
|
1407
|
-
return _regeneratorRuntime().wrap(function
|
|
1408
|
-
while (1) switch (
|
|
1517
|
+
return _regeneratorRuntime().wrap(function _callee25$(_context25) {
|
|
1518
|
+
while (1) switch (_context25.prev = _context25.next) {
|
|
1409
1519
|
case 0:
|
|
1410
1520
|
if (!fromOrder.cart_id) {
|
|
1411
|
-
|
|
1521
|
+
_context25.next = 14;
|
|
1412
1522
|
break;
|
|
1413
1523
|
}
|
|
1414
|
-
|
|
1415
|
-
|
|
1524
|
+
_context25.prev = 1;
|
|
1525
|
+
_context25.next = 4;
|
|
1416
1526
|
return this.cartService_.retrieve(fromOrder.cart_id, {
|
|
1417
1527
|
select: ["id", "context"]
|
|
1418
1528
|
});
|
|
1419
1529
|
case 4:
|
|
1420
|
-
cart =
|
|
1530
|
+
cart = _context25.sent;
|
|
1421
1531
|
if (!(cart.context && cart.context.locale)) {
|
|
1422
|
-
|
|
1532
|
+
_context25.next = 7;
|
|
1423
1533
|
break;
|
|
1424
1534
|
}
|
|
1425
|
-
return
|
|
1535
|
+
return _context25.abrupt("return", cart.context.locale);
|
|
1426
1536
|
case 7:
|
|
1427
|
-
|
|
1537
|
+
_context25.next = 14;
|
|
1428
1538
|
break;
|
|
1429
1539
|
case 9:
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
console.log(
|
|
1540
|
+
_context25.prev = 9;
|
|
1541
|
+
_context25.t0 = _context25["catch"](1);
|
|
1542
|
+
console.log(_context25.t0);
|
|
1433
1543
|
console.warn("Failed to gather context for order");
|
|
1434
|
-
return
|
|
1544
|
+
return _context25.abrupt("return", null);
|
|
1435
1545
|
case 14:
|
|
1436
|
-
return
|
|
1546
|
+
return _context25.abrupt("return", null);
|
|
1437
1547
|
case 15:
|
|
1438
1548
|
case "end":
|
|
1439
|
-
return
|
|
1549
|
+
return _context25.stop();
|
|
1440
1550
|
}
|
|
1441
|
-
},
|
|
1551
|
+
}, _callee25, this, [[1, 9]]);
|
|
1442
1552
|
}));
|
|
1443
|
-
function extractLocale(
|
|
1553
|
+
function extractLocale(_x38) {
|
|
1444
1554
|
return _extractLocale.apply(this, arguments);
|
|
1445
1555
|
}
|
|
1446
1556
|
return extractLocale;
|