cloudcommerce 0.0.97 → 0.0.98

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 (114) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/package.json +1 -1
  3. package/packages/api/package.json +1 -1
  4. package/packages/apps/correios/package.json +1 -1
  5. package/packages/apps/custom-shipping/package.json +1 -1
  6. package/packages/apps/discounts/package.json +1 -1
  7. package/packages/apps/frenet/package.json +1 -1
  8. package/packages/apps/tiny-erp/lib/event-to-tiny.js +94 -94
  9. package/packages/apps/tiny-erp/lib/index.js +1 -1
  10. package/packages/apps/tiny-erp/lib/integration/after-tiny-queue.js +74 -71
  11. package/packages/apps/tiny-erp/lib/integration/export-order-to-tiny.js +73 -70
  12. package/packages/apps/tiny-erp/lib/integration/export-product-to-tiny.js +53 -49
  13. package/packages/apps/tiny-erp/lib/integration/helpers/format-tiny-date.js +3 -3
  14. package/packages/apps/tiny-erp/lib/integration/import-order-from-tiny.js +75 -76
  15. package/packages/apps/tiny-erp/lib/integration/import-product-from-tiny.js +140 -137
  16. package/packages/apps/tiny-erp/lib/integration/parsers/order-from-tiny.js +39 -40
  17. package/packages/apps/tiny-erp/lib/integration/parsers/order-to-tiny.js +178 -173
  18. package/packages/apps/tiny-erp/lib/integration/parsers/product-from-tiny.js +171 -173
  19. package/packages/apps/tiny-erp/lib/integration/parsers/product-to-tiny.js +127 -123
  20. package/packages/apps/tiny-erp/lib/integration/parsers/status-from-tiny.js +32 -32
  21. package/packages/apps/tiny-erp/lib/integration/parsers/status-to-tiny.js +37 -37
  22. package/packages/apps/tiny-erp/lib/integration/post-tiny-erp.js +43 -42
  23. package/packages/apps/tiny-erp/lib/tiny-erp.js +6 -8
  24. package/packages/apps/tiny-erp/lib/tiny-webhook.js +73 -76
  25. package/packages/apps/tiny-erp/package.json +1 -1
  26. package/packages/cli/package.json +1 -1
  27. package/packages/config/package.json +1 -1
  28. package/packages/events/package.json +1 -1
  29. package/packages/firebase/lib/config.js +27 -25
  30. package/packages/firebase/lib/const.js +3 -2
  31. package/packages/firebase/lib/env.js +2 -1
  32. package/packages/firebase/lib/handlers/check-store-events.js +146 -145
  33. package/packages/firebase/lib/helpers/pubsub.js +20 -18
  34. package/packages/firebase/lib/helpers/update-app-data.js +38 -38
  35. package/packages/firebase/lib/index.js +9 -7
  36. package/packages/firebase/lib/init.js +2 -1
  37. package/packages/firebase/package.json +1 -1
  38. package/packages/modules/lib/firebase/ajv.js +19 -24
  39. package/packages/modules/lib/firebase/call-app-module.js +116 -110
  40. package/packages/modules/lib/firebase/checkout.js +151 -152
  41. package/packages/modules/lib/firebase/functions-checkout/fix-items.js +194 -187
  42. package/packages/modules/lib/firebase/functions-checkout/get-custumerId.js +25 -26
  43. package/packages/modules/lib/firebase/functions-checkout/handle-order-transaction.js +110 -109
  44. package/packages/modules/lib/firebase/functions-checkout/new-order.js +177 -177
  45. package/packages/modules/lib/firebase/functions-checkout/request-to-module.js +59 -59
  46. package/packages/modules/lib/firebase/functions-checkout/utils.js +195 -197
  47. package/packages/modules/lib/firebase/handle-module.js +144 -146
  48. package/packages/modules/lib/firebase/proxy-apps.js +2 -1
  49. package/packages/modules/lib/firebase/serve-modules-api.js +52 -53
  50. package/packages/modules/lib/firebase.js +4 -6
  51. package/packages/modules/lib/index.js +12 -15
  52. package/packages/modules/package.json +1 -1
  53. package/packages/passport/package.json +1 -1
  54. package/packages/ssr/package.json +1 -1
  55. package/packages/storefront/dist/client/LoginOffcanvas.daf3f717.js +1 -0
  56. package/packages/storefront/dist/client/admin/config.json +1 -0
  57. package/packages/storefront/dist/client/assets/_...522e6bf2.css +4 -0
  58. package/packages/storefront/dist/client/assets/_...a48b75c7.css +1 -0
  59. package/packages/storefront/dist/client/assets/cms-preview.css +274 -0
  60. package/packages/storefront/dist/client/assets/cms.css +114 -0
  61. package/packages/storefront/dist/client/assets/cvv.png +0 -0
  62. package/packages/storefront/dist/client/assets/icons/bootstrap-icons/font/storefront-icons.woff2 +0 -0
  63. package/packages/storefront/dist/client/assets/icons/feather-icons/font/storefront-icons.woff2 +0 -0
  64. package/packages/storefront/dist/client/assets/icons/font-awesome/font/storefront-icons.woff2 +0 -0
  65. package/packages/storefront/dist/client/assets/icons/line-awesome/font/storefront-icons.woff2 +0 -0
  66. package/packages/storefront/dist/client/assets/icons/tabler-icons/font/storefront-icons.woff2 +0 -0
  67. package/packages/storefront/dist/client/assets/img-placeholder.png +0 -0
  68. package/packages/storefront/dist/client/assets/payments.png +0 -0
  69. package/packages/storefront/dist/client/assets/ssl-safe.png +0 -0
  70. package/packages/storefront/dist/client/chunks/LoginForm.d9251274.js +1066 -0
  71. package/packages/storefront/dist/client/chunks/LoginOffcanvas.07fe6492.js +1 -0
  72. package/packages/storefront/dist/client/chunks/index.esm.84a649c7.js +331 -0
  73. package/packages/storefront/dist/client/chunks/preload-helper.f15ab524.js +1 -0
  74. package/packages/storefront/dist/client/chunks/runtime-dom.esm-bundler.738639ee.js +1 -0
  75. package/packages/storefront/dist/client/chunks/workbox-window.prod.es5.4b654ae6.js +2 -0
  76. package/packages/storefront/dist/client/client.b552d86a.js +1 -0
  77. package/packages/storefront/dist/client/hoisted.054c36ac.js +1 -0
  78. package/packages/storefront/dist/client/img/icon.png +0 -0
  79. package/packages/storefront/dist/client/img/large-icon.png +0 -0
  80. package/packages/storefront/dist/client/img/uploads/banner1.png +0 -0
  81. package/packages/storefront/dist/client/img/uploads/banner2.png +0 -0
  82. package/packages/storefront/dist/client/img/uploads/banner2.webp +0 -0
  83. package/packages/storefront/dist/client/img/uploads/favicon.png +0 -0
  84. package/packages/storefront/dist/client/img/uploads/headless.png +0 -0
  85. package/packages/storefront/dist/client/img/uploads/headphone.png +0 -0
  86. package/packages/storefront/dist/client/img/uploads/headphone.webp +0 -0
  87. package/packages/storefront/dist/client/img/uploads/icon.png +0 -0
  88. package/packages/storefront/dist/client/img/uploads/large-icon.png +0 -0
  89. package/packages/storefront/dist/client/img/uploads/logo.png +0 -0
  90. package/packages/storefront/dist/client/img/uploads/logo.webp +0 -0
  91. package/packages/storefront/dist/client/img/uploads/og-image.png +0 -0
  92. package/packages/storefront/dist/client/img/uploads/passion.png +0 -0
  93. package/packages/storefront/dist/client/img/uploads/passion.webp +0 -0
  94. package/packages/storefront/dist/client/img/uploads/pwa-reliable.png +0 -0
  95. package/packages/storefront/dist/client/img/uploads/rect8589.png +0 -0
  96. package/packages/storefront/dist/client/img/uploads/rect859.png +0 -0
  97. package/packages/storefront/dist/client/img/uploads/rect89.png +0 -0
  98. package/packages/storefront/dist/client/img/uploads/rect89.webp +0 -0
  99. package/packages/storefront/dist/client/img/uploads/ssl-safe.png +0 -0
  100. package/packages/storefront/dist/client/manifest.webmanifest +1 -0
  101. package/packages/storefront/dist/client/page.3aa82516.js +1 -0
  102. package/packages/storefront/dist/client/robots.txt +8 -0
  103. package/packages/storefront/dist/client/sw.js +1 -0
  104. package/packages/storefront/dist/client/workbox-6f0d1f78.js +1 -0
  105. package/packages/storefront/dist/client/~partytown/partytown-atomics.js +2 -0
  106. package/packages/storefront/dist/client/~partytown/partytown-media.js +2 -0
  107. package/packages/storefront/dist/client/~partytown/partytown-sw.js +2 -0
  108. package/packages/storefront/dist/client/~partytown/partytown.js +2 -0
  109. package/packages/storefront/dist/server/entry.mjs +2852 -0
  110. package/packages/storefront/dist/server/manifest.webmanifest +1 -0
  111. package/packages/storefront/dist/server/registerSW.js +1 -0
  112. package/packages/storefront/package.json +1 -1
  113. package/packages/storefront/src/lib/layouts/PagesHeader.astro +2 -1
  114. package/packages/types/package.json +1 -1
@@ -1,67 +1,67 @@
1
1
  import { logger } from 'firebase-functions';
2
2
  import axios from 'axios';
3
-
4
3
  // handle other modules endpoints directly
5
4
  export default async (checkoutBody, hostname, label) => {
6
- const locationId = process.env.FIREBASE_CONFIG
7
- ? (JSON.parse(process.env.FIREBASE_CONFIG).locationId || 'southamerica-east1')
8
- : 'southamerica-east1';
9
- const baseUrl = hostname !== 'localhost' ? `https://${hostname}`
10
- : `http://localhost:5001/${process.env.GCLOUD_PROJECT}/${locationId}/modules`; // To LocalTest
11
- let moduleBody;
12
- let modName;
13
- switch (label) {
14
- case 'shipping':
15
- modName = 'calculate_shipping';
16
- moduleBody = checkoutBody.shipping;
17
- break;
18
- case 'payment':
19
- modName = 'list_payments';
20
- moduleBody = checkoutBody.transaction;
21
- break;
22
- case 'discount':
23
- modName = 'apply_discount';
24
- moduleBody = checkoutBody.discount;
25
- break;
26
- case 'transaction':
27
- modName = 'create_transaction';
28
- moduleBody = checkoutBody.transaction;
29
- break;
30
- default:
31
- break;
32
- }
33
- if (moduleBody && moduleBody.app_id && modName) {
34
- // mask request objects
35
- const url = `${baseUrl}/${modName}?app_id=${moduleBody.app_id}`;
36
- // mount request body with received checkout body object
37
- const body = {
38
- ...checkoutBody,
39
- ...moduleBody,
40
- is_checkout_confirmation: true,
41
- };
42
- try {
43
- console.log('> ', JSON.stringify({ url, body }));
44
- const resp = (await axios.post(url, body)).data;
45
- if (Array.isArray(resp.result)) {
46
- let countAppErro = 0;
47
- for (let i = 0; i < resp.result.length; i++) {
48
- const result = resp.result[i];
49
- if (!result.validated || result.error) {
50
- countAppErro += 1;
51
- console.error(result.response);
52
- logger.error(result.response);
53
- }
5
+ const locationId = process.env.FIREBASE_CONFIG
6
+ ? (JSON.parse(process.env.FIREBASE_CONFIG).locationId || 'southamerica-east1')
7
+ : 'southamerica-east1';
8
+ const baseUrl = hostname !== 'localhost' ? `https://${hostname}`
9
+ : `http://localhost:5001/${process.env.GCLOUD_PROJECT}/${locationId}/modules`; // To LocalTest
10
+ let moduleBody;
11
+ let modName;
12
+ switch (label) {
13
+ case 'shipping':
14
+ modName = 'calculate_shipping';
15
+ moduleBody = checkoutBody.shipping;
16
+ break;
17
+ case 'payment':
18
+ modName = 'list_payments';
19
+ moduleBody = checkoutBody.transaction;
20
+ break;
21
+ case 'discount':
22
+ modName = 'apply_discount';
23
+ moduleBody = checkoutBody.discount;
24
+ break;
25
+ case 'transaction':
26
+ modName = 'create_transaction';
27
+ moduleBody = checkoutBody.transaction;
28
+ break;
29
+ default:
30
+ break;
31
+ }
32
+ if (moduleBody && moduleBody.app_id && modName) {
33
+ // mask request objects
34
+ const url = `${baseUrl}/${modName}?app_id=${moduleBody.app_id}`;
35
+ // mount request body with received checkout body object
36
+ const body = {
37
+ ...checkoutBody,
38
+ ...moduleBody,
39
+ is_checkout_confirmation: true,
40
+ };
41
+ try {
42
+ console.log('> ', JSON.stringify({ url, body }));
43
+ const resp = (await axios.post(url, body)).data;
44
+ if (Array.isArray(resp.result)) {
45
+ let countAppErro = 0;
46
+ for (let i = 0; i < resp.result.length; i++) {
47
+ const result = resp.result[i];
48
+ if (!result.validated || result.error) {
49
+ countAppErro += 1;
50
+ console.error(result.response);
51
+ logger.error(result.response);
52
+ }
53
+ }
54
+ if (resp.result.length === countAppErro) {
55
+ return null;
56
+ }
57
+ }
58
+ return resp.result;
54
59
  }
55
- if (resp.result.length === countAppErro) {
56
- return null;
60
+ catch (e) {
61
+ logger.error('>>erro: ', e);
62
+ return null;
57
63
  }
58
- }
59
- return resp.result;
60
- } catch (e) {
61
- logger.error('>>erro: ', e);
62
- return null;
63
64
  }
64
- }
65
- return null;
65
+ return null;
66
66
  };
67
- // # sourceMappingURL=request-to-module.js.map
67
+ //# sourceMappingURL=request-to-module.js.map
@@ -1,227 +1,225 @@
1
1
  // eslint-disable-next-line padding-line-between-statements
2
2
  import logger from 'firebase-functions/lib/logger';
3
-
4
3
  const sendError = (res, status, errorCode, message, userMessage, moreInfo) => {
5
- return res.status(status)
6
- .send({
7
- status,
8
- error_code: errorCode,
9
- message,
10
- user_message: userMessage,
11
- more_info: moreInfo,
4
+ return res.status(status)
5
+ .send({
6
+ status,
7
+ error_code: errorCode,
8
+ message,
9
+ user_message: userMessage,
10
+ more_info: moreInfo,
12
11
  });
13
12
  };
14
13
  const fixAmount = (amount, body, orderBody) => {
15
- Object.keys(amount).forEach((field) => {
16
- if (amount[field] > 0 && field !== 'total') {
17
- amount[field] = Math.round(amount[field] * 100) / 100;
14
+ Object.keys(amount).forEach((field) => {
15
+ if (amount[field] > 0 && field !== 'total') {
16
+ amount[field] = Math.round(amount[field] * 100) / 100;
17
+ }
18
+ });
19
+ amount.total = Math.round(((amount.subtotal || 0) + (amount.freight || 0) - (amount.discount || 0)) * 100) / 100;
20
+ if (amount.total < 0) {
21
+ amount.total = 0;
18
22
  }
19
- });
20
- amount.total = Math.round(((amount.subtotal || 0) + (amount.freight || 0) - (amount.discount || 0)) * 100) / 100;
21
- if (amount.total < 0) {
22
- amount.total = 0;
23
- }
24
- // also save amount to checkout and order body objects
25
- body.amount = amount;
26
- orderBody.amount = amount;
23
+ // also save amount to checkout and order body objects
24
+ body.amount = amount;
25
+ orderBody.amount = amount;
27
26
  };
28
27
  const getValidResults = (results, checkProp) => {
29
- // results array returned from module
30
- // see ./#applications.js
31
- const validResults = [];
32
- if (Array.isArray(results)) {
33
- for (let i = 0; i < results.length; i++) {
34
- const result = results[i];
35
- if (result.validated) {
36
- if (checkProp) {
37
- // validate one property from response object
38
- const responseProp = result.response[checkProp];
39
- if (!responseProp || (Array.isArray(responseProp) && !responseProp.length)) {
40
- // try next module result
41
- continue;
42
- }
28
+ // results array returned from module
29
+ // see ./#applications.js
30
+ const validResults = [];
31
+ if (Array.isArray(results)) {
32
+ for (let i = 0; i < results.length; i++) {
33
+ const result = results[i];
34
+ if (result.validated) {
35
+ if (checkProp) {
36
+ // validate one property from response object
37
+ const responseProp = result.response[checkProp];
38
+ if (!responseProp || (Array.isArray(responseProp) && !responseProp.length)) {
39
+ // try next module result
40
+ continue;
41
+ }
42
+ }
43
+ // use it
44
+ validResults.push(result);
45
+ }
46
+ else {
47
+ // help identify likely app response errors
48
+ logger.error(result.response_errors);
49
+ }
43
50
  }
44
- // use it
45
- validResults.push(result);
46
- } else {
47
- // help identify likely app response errors
48
- logger.error(result.response_errors);
49
- }
50
51
  }
51
- }
52
- return validResults;
52
+ return validResults;
53
53
  };
54
54
  const handleListPayments = (body, listPayment, paymentsBody, amount, orderBody) => {
55
- for (let i = 0; i < listPayment.length; i++) {
56
- const result = listPayment[i];
57
- // treat list payments response
58
- const { response } = result;
59
- if (response && response.payment_gateways) {
60
- // check chosen payment method code and name
61
- const paymentMethod = paymentsBody.transaction.payment_method;
62
- let paymentMethodCode;
63
- let paymentMethodName;
64
- if (paymentMethod) {
65
- paymentMethodCode = paymentMethod.code;
66
- paymentMethodName = paymentMethod.name;
67
- }
68
- // filter gateways by method code
69
- const possibleGateways = response.payment_gateways.filter((paymentGatewayFound) => {
70
- const paymentMethodFound = paymentGatewayFound.payment_method;
71
- return !paymentMethodCode
55
+ for (let i = 0; i < listPayment.length; i++) {
56
+ const result = listPayment[i];
57
+ // treat list payments response
58
+ const { response } = result;
59
+ if (response && response.payment_gateways) {
60
+ // check chosen payment method code and name
61
+ const paymentMethod = paymentsBody.transaction.payment_method;
62
+ let paymentMethodCode;
63
+ let paymentMethodName;
64
+ if (paymentMethod) {
65
+ paymentMethodCode = paymentMethod.code;
66
+ paymentMethodName = paymentMethod.name;
67
+ }
68
+ // filter gateways by method code
69
+ const possibleGateways = response.payment_gateways.filter((paymentGatewayFound) => {
70
+ const paymentMethodFound = paymentGatewayFound.payment_method;
71
+ return !paymentMethodCode
72
72
  || (paymentMethodFound && paymentMethodFound.code === paymentMethodCode);
73
- });
74
- let paymentGateway;
75
- if (possibleGateways.length > 1 && paymentMethodName) {
76
- // prefer respective method name
77
- paymentGateway = possibleGateways.find((paymentGatewayFound) => {
78
- return paymentGatewayFound.payment_method.name === paymentMethodName;
79
- });
80
- }
81
- if (!paymentGateway) {
82
- [paymentGateway] = possibleGateways;
83
- }
84
- if (paymentGateway) {
85
- const { discount } = paymentGateway;
86
- // handle discount by payment method
87
- const applyDiscountIn = discount && discount.apply_at;
88
- if (applyDiscountIn && discount.value && amount[applyDiscountIn]) {
89
- const maxDiscount = amount[applyDiscountIn] || 0;
90
- // update amount discount and total
91
- let discountValue;
92
- if (discount.type === 'percentage') {
93
- discountValue = (maxDiscount * discount.value) / 100;
94
- } else {
95
- discountValue = discount.value;
96
- if (discountValue > maxDiscount) {
97
- discountValue = maxDiscount;
73
+ });
74
+ let paymentGateway;
75
+ if (possibleGateways.length > 1 && paymentMethodName) {
76
+ // prefer respective method name
77
+ paymentGateway = possibleGateways.find((paymentGatewayFound) => {
78
+ return paymentGatewayFound.payment_method.name === paymentMethodName;
79
+ });
80
+ }
81
+ if (!paymentGateway) {
82
+ [paymentGateway] = possibleGateways;
83
+ }
84
+ if (paymentGateway) {
85
+ const { discount } = paymentGateway;
86
+ // handle discount by payment method
87
+ const applyDiscountIn = discount && discount.apply_at;
88
+ if (applyDiscountIn && discount.value && amount[applyDiscountIn]) {
89
+ const maxDiscount = amount[applyDiscountIn] || 0;
90
+ // update amount discount and total
91
+ let discountValue;
92
+ if (discount.type === 'percentage') {
93
+ discountValue = (maxDiscount * discount.value) / 100;
94
+ }
95
+ else {
96
+ discountValue = discount.value;
97
+ if (discountValue > maxDiscount) {
98
+ discountValue = maxDiscount;
99
+ }
100
+ }
101
+ amount.discount = amount.discount ? amount.discount : 0;
102
+ amount.discount += discountValue;
103
+ fixAmount(amount, body, orderBody);
104
+ }
105
+ // add to order body
106
+ orderBody.payment_method_label = paymentGateway.label || '';
107
+ // finally start creating new order
98
108
  }
99
- }
100
- amount.discount = amount.discount ? amount.discount : 0;
101
- amount.discount += discountValue;
102
- fixAmount(amount, body, orderBody);
103
109
  }
104
- // add to order body
105
- orderBody.payment_method_label = paymentGateway.label || '';
106
- // finally start creating new order
107
- }
108
110
  }
109
- }
110
111
  };
111
112
  // simulate requets to calculate shipping endpoint
112
113
  const handleShippingServices = (body, listShipping, amount, orderBody) => {
113
- for (let i = 0; i < listShipping.length; i++) {
114
- const result = listShipping[i];
115
- // treat calculate shipping response
116
- const { response } = result;
117
- if (response && response.shipping_services) {
118
- // check chosen shipping code
119
- const shippingCode = body.shipping.service_code;
120
- for (let index = 0; index < response.shipping_services.length; index++) {
121
- const shippingService = response.shipping_services[index];
122
- const shippingLine = shippingService.shipping_line;
123
- if (shippingLine && (!shippingCode || shippingCode === shippingService.service_code)) {
124
- // update amount freight and total
125
- const priceFreight = (typeof shippingLine.price === 'number'
126
- ? shippingLine.price
127
- : 0);
128
- let freight = typeof shippingLine.total_price === 'number'
129
- ? shippingLine.total_price
130
- : priceFreight;
131
- if (freight < 0) {
132
- freight = 0;
133
- }
134
- amount.freight = freight;
135
- fixAmount(amount, body, orderBody);
136
- // app info
137
- const shippingApp = {
138
- app: { _id: result._id, ...shippingService },
139
- };
140
- // remove shipping line property
141
- delete shippingApp.app.shipping_line;
142
- // sum production time to posting deadline
143
- let maxProductionDays = 0;
144
- if (orderBody.items) {
145
- orderBody.items.forEach((item) => {
146
- const productionTime = item.production_time;
147
- if (productionTime) {
148
- let productionDays = productionTime.days;
149
- if (productionDays && productionTime.cumulative) {
150
- productionDays *= item.quantity;
151
- }
152
- if (productionTime.max_time) {
153
- if (productionDays > productionTime.max_time) {
154
- productionDays = productionTime.max_time;
155
- }
156
- }
157
- if (maxProductionDays < productionDays) {
158
- maxProductionDays = productionDays;
114
+ for (let i = 0; i < listShipping.length; i++) {
115
+ const result = listShipping[i];
116
+ // treat calculate shipping response
117
+ const { response } = result;
118
+ if (response && response.shipping_services) {
119
+ // check chosen shipping code
120
+ const shippingCode = body.shipping.service_code;
121
+ for (let index = 0; index < response.shipping_services.length; index++) {
122
+ const shippingService = response.shipping_services[index];
123
+ const shippingLine = shippingService.shipping_line;
124
+ if (shippingLine && (!shippingCode || shippingCode === shippingService.service_code)) {
125
+ // update amount freight and total
126
+ const priceFreight = (typeof shippingLine.price === 'number'
127
+ ? shippingLine.price
128
+ : 0);
129
+ let freight = typeof shippingLine.total_price === 'number'
130
+ ? shippingLine.total_price
131
+ : priceFreight;
132
+ if (freight < 0) {
133
+ freight = 0;
134
+ }
135
+ amount.freight = freight;
136
+ fixAmount(amount, body, orderBody);
137
+ // app info
138
+ const shippingApp = {
139
+ app: { _id: result._id, ...shippingService },
140
+ };
141
+ // remove shipping line property
142
+ delete shippingApp.app.shipping_line;
143
+ // sum production time to posting deadline
144
+ let maxProductionDays = 0;
145
+ if (orderBody.items) {
146
+ orderBody.items.forEach((item) => {
147
+ const productionTime = item.production_time;
148
+ if (productionTime) {
149
+ let productionDays = productionTime.days;
150
+ if (productionDays && productionTime.cumulative) {
151
+ productionDays *= item.quantity;
152
+ }
153
+ if (productionTime.max_time) {
154
+ if (productionDays > productionTime.max_time) {
155
+ productionDays = productionTime.max_time;
156
+ }
157
+ }
158
+ if (maxProductionDays < productionDays) {
159
+ maxProductionDays = productionDays;
160
+ }
161
+ }
162
+ });
163
+ }
164
+ if (maxProductionDays) {
165
+ if (!shippingLine.posting_deadline) {
166
+ shippingLine.posting_deadline = {
167
+ days: 0,
168
+ };
169
+ }
170
+ shippingLine.posting_deadline.days += maxProductionDays;
171
+ }
172
+ // add to order body
173
+ orderBody.shipping_lines = [
174
+ // generate new object id and compose shipping line object
175
+ { ...shippingApp, ...shippingLine },
176
+ ];
177
+ orderBody.shipping_method_label = shippingService.label || '';
178
+ // continue to discount step
159
179
  }
160
- }
161
- });
162
- }
163
- if (maxProductionDays) {
164
- if (!shippingLine.posting_deadline) {
165
- shippingLine.posting_deadline = {
166
- days: 0,
167
- };
168
180
  }
169
- shippingLine.posting_deadline.days += maxProductionDays;
170
- }
171
- // add to order body
172
- orderBody.shipping_lines = [
173
- // generate new object id and compose shipping line object
174
- { ...shippingApp, ...shippingLine },
175
- ];
176
- orderBody.shipping_method_label = shippingService.label || '';
177
- // continue to discount step
178
181
  }
179
- }
180
182
  }
181
- }
182
183
  };
183
184
  const handleApplyDiscount = (body, listDiscount, amount, orderBody) => {
184
- // simulate request to apply discount endpoint to get extra discount value
185
- for (let i = 0; i < listDiscount.length; i++) {
186
- const result = listDiscount[i];
187
- // treat apply discount response
188
- const { response } = result;
189
- if (response && response.discount_rule) {
190
- // check discount value
191
- const discountRule = response.discount_rule;
192
- const extraDiscount = discountRule.extra_discount;
193
- if (extraDiscount && extraDiscount.value) {
194
- // update amount and save extra discount to order body
195
- amount.discount += extraDiscount.value;
196
- fixAmount(amount, body, orderBody);
197
- orderBody.extra_discount = {
198
- ...body.discount,
199
- ...extraDiscount,
200
- // app info
201
- app: {
202
- ...discountRule,
203
- _id: result._id,
204
- },
205
- };
206
- if (response.freebie_product_ids) {
207
- // mark items provided for free
208
- orderBody.items.forEach((item) => {
209
- if (!item.flags) {
210
- item.flags = [];
211
- }
212
- if (response.freebie_product_ids.includes(item.product_id)) {
213
- item.flags.push('discount-set-free');
185
+ // simulate request to apply discount endpoint to get extra discount value
186
+ for (let i = 0; i < listDiscount.length; i++) {
187
+ const result = listDiscount[i];
188
+ // treat apply discount response
189
+ const { response } = result;
190
+ if (response && response.discount_rule) {
191
+ // check discount value
192
+ const discountRule = response.discount_rule;
193
+ const extraDiscount = discountRule.extra_discount;
194
+ if (extraDiscount && extraDiscount.value) {
195
+ // update amount and save extra discount to order body
196
+ amount.discount += extraDiscount.value;
197
+ fixAmount(amount, body, orderBody);
198
+ orderBody.extra_discount = {
199
+ ...body.discount,
200
+ ...extraDiscount,
201
+ // app info
202
+ app: {
203
+ ...discountRule,
204
+ _id: result._id,
205
+ },
206
+ };
207
+ if (response.freebie_product_ids) {
208
+ // mark items provided for free
209
+ orderBody.items.forEach((item) => {
210
+ if (!item.flags) {
211
+ item.flags = [];
212
+ }
213
+ if (response.freebie_product_ids.includes(item.product_id)) {
214
+ item.flags.push('discount-set-free');
215
+ }
216
+ });
217
+ }
218
+ break;
214
219
  }
215
- });
216
220
  }
217
- break;
218
- }
219
221
  }
220
- }
221
- // proceed to list payments
222
- };
223
-
224
- export {
225
- sendError, fixAmount, getValidResults, handleShippingServices, handleApplyDiscount, handleListPayments,
222
+ // proceed to list payments
226
223
  };
227
- // # sourceMappingURL=utils.js.map
224
+ export { sendError, fixAmount, getValidResults, handleShippingServices, handleApplyDiscount, handleListPayments, };
225
+ //# sourceMappingURL=utils.js.map