cloudcommerce 0.0.109 → 0.0.110

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 (117) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/package.json +1 -1
  3. package/packages/api/lib/api.d.ts +4 -4940
  4. package/packages/api/lib/types.d.ts +17 -3
  5. package/packages/api/package.json +1 -1
  6. package/packages/api/src/types.ts +45 -23
  7. package/packages/apps/correios/package.json +1 -1
  8. package/packages/apps/custom-shipping/package.json +1 -1
  9. package/packages/apps/discounts/package.json +1 -1
  10. package/packages/apps/frenet/lib-mjs/calculate-frenet.mjs +26 -23
  11. package/packages/apps/frenet/package.json +1 -1
  12. package/packages/apps/tiny-erp/lib/event-to-tiny.js +94 -94
  13. package/packages/apps/tiny-erp/lib/index.js +1 -1
  14. package/packages/apps/tiny-erp/lib/integration/after-tiny-queue.js +71 -74
  15. package/packages/apps/tiny-erp/lib/integration/export-order-to-tiny.js +70 -73
  16. package/packages/apps/tiny-erp/lib/integration/export-product-to-tiny.js +49 -53
  17. package/packages/apps/tiny-erp/lib/integration/helpers/format-tiny-date.js +3 -3
  18. package/packages/apps/tiny-erp/lib/integration/import-order-from-tiny.js +76 -75
  19. package/packages/apps/tiny-erp/lib/integration/import-product-from-tiny.js +137 -140
  20. package/packages/apps/tiny-erp/lib/integration/parsers/order-from-tiny.js +40 -39
  21. package/packages/apps/tiny-erp/lib/integration/parsers/order-to-tiny.js +173 -178
  22. package/packages/apps/tiny-erp/lib/integration/parsers/product-from-tiny.js +173 -171
  23. package/packages/apps/tiny-erp/lib/integration/parsers/product-to-tiny.js +123 -127
  24. package/packages/apps/tiny-erp/lib/integration/parsers/status-from-tiny.js +32 -32
  25. package/packages/apps/tiny-erp/lib/integration/parsers/status-to-tiny.js +37 -37
  26. package/packages/apps/tiny-erp/lib/integration/post-tiny-erp.js +42 -43
  27. package/packages/apps/tiny-erp/lib/tiny-erp.js +8 -6
  28. package/packages/apps/tiny-erp/lib/tiny-webhook.js +76 -73
  29. package/packages/apps/tiny-erp/package.json +1 -1
  30. package/packages/cli/package.json +1 -1
  31. package/packages/config/package.json +1 -1
  32. package/packages/events/package.json +1 -1
  33. package/packages/firebase/package.json +1 -1
  34. package/packages/i18n/lib/en_us.d.ts +1 -0
  35. package/packages/i18n/lib/en_us.js +1 -0
  36. package/packages/i18n/lib/en_us.js.map +1 -1
  37. package/packages/i18n/lib/pt_br.d.ts +1 -0
  38. package/packages/i18n/lib/pt_br.js +1 -0
  39. package/packages/i18n/lib/pt_br.js.map +1 -1
  40. package/packages/i18n/package.json +1 -1
  41. package/packages/i18n/src/en_us.ts +1 -0
  42. package/packages/i18n/src/pt_br.ts +1 -0
  43. package/packages/modules/lib/firebase/ajv.js +24 -19
  44. package/packages/modules/lib/firebase/call-app-module.js +110 -116
  45. package/packages/modules/lib/firebase/checkout.js +149 -154
  46. package/packages/modules/lib/firebase/checkout.js.map +1 -1
  47. package/packages/modules/lib/firebase/functions-checkout/fix-items.js +187 -194
  48. package/packages/modules/lib/firebase/functions-checkout/get-custumerId.js +33 -27
  49. package/packages/modules/lib/firebase/functions-checkout/get-custumerId.js.map +1 -1
  50. package/packages/modules/lib/firebase/functions-checkout/handle-order-transaction.js +111 -125
  51. package/packages/modules/lib/firebase/functions-checkout/handle-order-transaction.js.map +1 -1
  52. package/packages/modules/lib/firebase/functions-checkout/new-order.js +178 -178
  53. package/packages/modules/lib/firebase/functions-checkout/new-order.js.map +1 -1
  54. package/packages/modules/lib/firebase/functions-checkout/request-to-module.js +53 -60
  55. package/packages/modules/lib/firebase/functions-checkout/request-to-module.js.map +1 -1
  56. package/packages/modules/lib/firebase/functions-checkout/utils.js +197 -195
  57. package/packages/modules/lib/firebase/handle-module.js +146 -144
  58. package/packages/modules/lib/firebase/handle-module.js.map +1 -1
  59. package/packages/modules/lib/firebase/proxy-apps.js +1 -2
  60. package/packages/modules/lib/firebase/serve-modules-api.js +53 -52
  61. package/packages/modules/lib/firebase/serve-modules-api.js.map +1 -1
  62. package/packages/modules/lib/firebase.js +6 -4
  63. package/packages/modules/lib/index.js +17 -12
  64. package/packages/modules/lib/index.js.map +1 -1
  65. package/packages/modules/package.json +2 -1
  66. package/packages/modules/schemas/@checkout.cjs +13 -1
  67. package/packages/modules/schemas/list_payments.cjs +6 -0
  68. package/packages/modules/src/firebase/checkout.ts +22 -49
  69. package/packages/modules/src/firebase/functions-checkout/get-custumerId.ts +23 -17
  70. package/packages/modules/src/firebase/functions-checkout/handle-order-transaction.ts +8 -45
  71. package/packages/modules/src/firebase/functions-checkout/new-order.ts +4 -9
  72. package/packages/modules/src/firebase/functions-checkout/request-to-module.ts +2 -11
  73. package/packages/modules/src/firebase/handle-module.ts +1 -1
  74. package/packages/modules/src/firebase/serve-modules-api.ts +1 -1
  75. package/packages/modules/src/index.ts +2 -0
  76. package/packages/passport/lib/firebase/authenticate-customer.js +81 -0
  77. package/packages/passport/lib/firebase/authenticate-customer.js.map +1 -0
  78. package/packages/passport/lib/firebase/serve-passport-api.js +20 -30
  79. package/packages/passport/lib/firebase/serve-passport-api.js.map +1 -1
  80. package/packages/passport/lib/firebase.js +1 -13
  81. package/packages/passport/lib/firebase.js.map +1 -1
  82. package/packages/passport/lib/index.js +1 -1
  83. package/packages/passport/lib/index.js.map +1 -1
  84. package/packages/passport/package.json +1 -1
  85. package/packages/passport/src/firebase/authenticate-customer.ts +94 -0
  86. package/packages/passport/src/firebase/serve-passport-api.ts +21 -49
  87. package/packages/passport/src/firebase.ts +1 -21
  88. package/packages/passport/src/index.ts +4 -1
  89. package/packages/ssr/package.json +1 -1
  90. package/packages/storefront/content/header.json +6 -0
  91. package/packages/storefront/dist/client/LoginDrawer.e69d1c74.js +1 -0
  92. package/packages/storefront/dist/client/assets/_...d5980663.css +4 -0
  93. package/packages/storefront/dist/client/chunks/LoginDrawer.0c26574f.js +1 -0
  94. package/packages/storefront/dist/client/chunks/{LoginForm.c995d3d4.js → LoginForm.892d64a5.js} +109 -109
  95. package/packages/storefront/dist/client/chunks/runtime-dom.esm-bundler.7f8f570f.js +1 -0
  96. package/packages/storefront/dist/client/{client.6736232b.js → client.246ab4a4.js} +1 -1
  97. package/packages/storefront/dist/client/sw.js +1 -1
  98. package/packages/storefront/dist/server/entry.mjs +2204 -26
  99. package/packages/storefront/package.json +1 -1
  100. package/packages/storefront/src/assets/pico.css +3 -400
  101. package/packages/storefront/src/lib/components/{AOffcanvas.vue → ADrawer.vue} +3 -3
  102. package/packages/storefront/src/lib/components/LoginDrawer.vue +80 -0
  103. package/packages/storefront/src/lib/components/LoginForm.vue +31 -14
  104. package/packages/storefront/src/lib/layouts/PagesHeader.astro +18 -7
  105. package/packages/storefront/src/lib/state/customer-session.ts +137 -0
  106. package/packages/types/index.ts +22 -0
  107. package/packages/types/modules/@checkout:params.d.ts +9 -1
  108. package/packages/types/modules/list_payments:params.d.ts +4 -0
  109. package/packages/types/package.json +1 -1
  110. package/packages/passport/lib/firebase/handle-passport.js +0 -112
  111. package/packages/passport/lib/firebase/handle-passport.js.map +0 -1
  112. package/packages/passport/src/firebase/handle-passport.ts +0 -142
  113. package/packages/storefront/dist/client/LoginOffcanvas.28d2f50c.js +0 -1
  114. package/packages/storefront/dist/client/assets/_...41f686e3.css +0 -4
  115. package/packages/storefront/dist/client/chunks/LoginOffcanvas.a1f3fe3b.js +0 -1
  116. package/packages/storefront/dist/client/chunks/runtime-dom.esm-bundler.62d623e7.js +0 -1
  117. package/packages/storefront/src/lib/components/LoginOffcanvas.vue +0 -41
@@ -1,79 +1,75 @@
1
1
  import { logger } from 'firebase-functions';
2
2
  import axios from 'axios';
3
3
  import config from '@cloudcommerce/firebase/lib/config';
4
+
4
5
  // Blacklist urls to prevent consecultive errors
5
6
  const blacklist = {};
7
+
6
8
  export default async (appId, modName, url, data, isBigTimeout) => {
7
- if (blacklist[url] > 2) {
8
- logger.log(`> Skipping blacklisted ${url}`);
9
- const err = new Error('Blacklited endpoint URL');
10
- return Promise.reject(err);
9
+ if (blacklist[url] > 2) {
10
+ logger.log(`> Skipping blacklisted ${url}`);
11
+ const err = new Error('Blacklited endpoint URL');
12
+ return Promise.reject(err);
13
+ }
14
+ const { storeId, apps } = config.get();
15
+ const checkErrorResponse = (logHead, resData) => {
16
+ if (typeof resData === 'object' && resData !== null) {
17
+ const { error, message } = resData;
18
+ if (typeof error === 'string' && error.length && typeof message === 'string') {
19
+ logger.warn(logHead, JSON.stringify({ error, message }));
20
+ }
11
21
  }
12
- const { storeId, apps } = config.get();
13
- const checkErrorResponse = (logHead, resData) => {
14
- if (typeof resData === 'object' && resData !== null) {
15
- const { error, message } = resData;
16
- if (typeof error === 'string' && error.length && typeof message === 'string') {
17
- logger.warn(logHead, JSON.stringify({ error, message }));
18
- }
19
- }
20
- };
21
- const debugAndBlacklist = (response) => {
22
- const status = response ? response.status : 0;
23
- if (!blacklist[url]) {
24
- blacklist[url] = 1;
25
- }
26
- else {
27
- blacklist[url] += 1;
28
- }
29
- setTimeout(() => {
30
- if (blacklist[url] > 1) {
31
- blacklist[url] -= 1;
32
- }
33
- else {
34
- delete blacklist[url];
35
- }
36
- }, !status ? 180000 : 6000);
37
- const logHead = `${url} : ${status}`;
38
- if (status >= 400 && status < 500) {
39
- checkErrorResponse(logHead, response.data);
40
- }
41
- else {
42
- logger.info(logHead);
43
- }
44
- };
22
+ };
23
+ const debugAndBlacklist = (response) => {
24
+ const status = response ? response.status : 0;
25
+ if (!blacklist[url]) {
26
+ blacklist[url] = 1;
27
+ } else {
28
+ blacklist[url] += 1;
29
+ }
30
+ setTimeout(() => {
31
+ if (blacklist[url] > 1) {
32
+ blacklist[url] -= 1;
33
+ } else {
34
+ delete blacklist[url];
35
+ }
36
+ }, !status ? 180000 : 6000);
37
+ const logHead = `${url} : ${status}`;
38
+ if (status >= 400 && status < 500) {
39
+ checkErrorResponse(logHead, response.data);
40
+ } else {
41
+ logger.info(logHead);
42
+ }
43
+ };
45
44
  // eslint-disable-next-line no-unused-vars
46
- let internalModuleFn;
47
- if (modName === 'apply_discount') {
48
- if (appId === apps.discounts.appId) {
49
- internalModuleFn = async (_data = data) => {
50
- return import('@cloudcommerce/app-discounts')
51
- .then(({ applyDiscount }) => applyDiscount(_data));
52
- };
53
- }
45
+ let internalModuleFn;
46
+ if (modName === 'apply_discount') {
47
+ if (appId === apps.discounts.appId) {
48
+ internalModuleFn = async (_data = data) => {
49
+ return import('@cloudcommerce/app-discounts')
50
+ .then(({ applyDiscount }) => applyDiscount(_data));
51
+ };
54
52
  }
55
- else if (modName === 'calculate_shipping') {
56
- if (appId === apps.correios.appId) {
57
- internalModuleFn = async (_data = data) => {
58
- return import('@cloudcommerce/app-correios')
59
- .then(({ calculateShipping }) => calculateShipping(_data));
60
- };
61
- }
62
- else if (appId === apps.customShipping.appId) {
63
- internalModuleFn = async (_data = data) => {
64
- return import('@cloudcommerce/app-custom-shipping')
65
- .then(({ calculateShipping }) => calculateShipping(_data));
66
- };
67
- }
68
- else if (appId === apps.frenet.appId) {
69
- internalModuleFn = async (_data = data) => {
70
- return import('@cloudcommerce/app-frenet')
71
- .then(({ calculateShipping }) => calculateShipping(_data));
72
- };
73
- }
53
+ } else if (modName === 'calculate_shipping') {
54
+ if (appId === apps.correios.appId) {
55
+ internalModuleFn = async (_data = data) => {
56
+ return import('@cloudcommerce/app-correios')
57
+ .then(({ calculateShipping }) => calculateShipping(_data));
58
+ };
59
+ } else if (appId === apps.customShipping.appId) {
60
+ internalModuleFn = async (_data = data) => {
61
+ return import('@cloudcommerce/app-custom-shipping')
62
+ .then(({ calculateShipping }) => calculateShipping(_data));
63
+ };
64
+ } else if (appId === apps.frenet.appId) {
65
+ internalModuleFn = async (_data = data) => {
66
+ return import('@cloudcommerce/app-frenet')
67
+ .then(({ calculateShipping }) => calculateShipping(_data));
68
+ };
74
69
  }
75
- if (internalModuleFn) {
76
- /*
70
+ }
71
+ if (internalModuleFn) {
72
+ /*
77
73
  global.app1_apply_discount_middleware = async (
78
74
  data: any,
79
75
  next: () => Promise<any>,
@@ -84,58 +80,56 @@ export default async (appId, modName, url, data, isBigTimeout) => {
84
80
  return next(data);
85
81
  };
86
82
  */
87
- const middleware = global[`app${appId}_${modName}_middleware`];
88
- try {
89
- let appResponse;
90
- if (typeof middleware === 'function') {
91
- appResponse = await middleware(data, internalModuleFn);
92
- }
93
- else {
94
- appResponse = await internalModuleFn(data);
95
- }
96
- checkErrorResponse(`${appId}_${modName}`, appResponse);
97
- return appResponse;
98
- }
99
- catch (err) {
100
- logger.error(err);
101
- let message = 'Failed to execute module function';
102
- if (typeof middleware === 'function') {
103
- message += ' (has middleware)';
104
- }
105
- return {
106
- error: 'INTERNAL_MODULE_ERROR',
107
- message,
108
- };
109
- }
83
+ const middleware = global[`app${appId}_${modName}_middleware`];
84
+ try {
85
+ let appResponse;
86
+ if (typeof middleware === 'function') {
87
+ appResponse = await middleware(data, internalModuleFn);
88
+ } else {
89
+ appResponse = await internalModuleFn(data);
90
+ }
91
+ checkErrorResponse(`${appId}_${modName}`, appResponse);
92
+ return appResponse;
93
+ } catch (err) {
94
+ logger.error(err);
95
+ let message = 'Failed to execute module function';
96
+ if (typeof middleware === 'function') {
97
+ message += ' (has middleware)';
98
+ }
99
+ return {
100
+ error: 'INTERNAL_MODULE_ERROR',
101
+ message,
102
+ };
110
103
  }
111
- return axios({
112
- method: 'POST',
113
- maxRedirects: 2,
114
- responseType: 'json',
115
- maxContentLength: 1000000,
116
- url,
117
- data,
118
- headers: {
119
- 'X-Store-ID': storeId.toString(),
120
- },
121
- // Wait 10s by default and 30s in specific cases
122
- timeout: isBigTimeout ? 30000 : 10000,
123
- })
124
- .then((response) => {
125
- debugAndBlacklist(response);
126
- return response.data;
104
+ }
105
+ return axios({
106
+ method: 'POST',
107
+ maxRedirects: 2,
108
+ responseType: 'json',
109
+ maxContentLength: 1000000,
110
+ url,
111
+ data,
112
+ headers: {
113
+ 'X-Store-ID': storeId.toString(),
114
+ },
115
+ // Wait 10s by default and 30s in specific cases
116
+ timeout: isBigTimeout ? 30000 : 10000,
117
+ })
118
+ .then((response) => {
119
+ debugAndBlacklist(response);
120
+ return response.data;
127
121
  })
128
- .catch((err) => {
129
- const { response } = err;
130
- debugAndBlacklist(response);
131
- if (err.message || err.code) {
132
- let msg = `Axios error ${err.code}: ${err.message}`;
133
- if (data) {
134
- msg += `\n\n${JSON.stringify(data)}`;
135
- }
136
- logger.warn(msg);
122
+ .catch((err) => {
123
+ const { response } = err;
124
+ debugAndBlacklist(response);
125
+ if (err.message || err.code) {
126
+ let msg = `Axios error ${err.code}: ${err.message}`;
127
+ if (data) {
128
+ msg += `\n\n${JSON.stringify(data)}`;
137
129
  }
138
- throw err;
130
+ logger.warn(msg);
131
+ }
132
+ throw err;
139
133
  });
140
134
  };
141
- //# sourceMappingURL=call-app-module.js.map
135
+ // # sourceMappingURL=call-app-module.js.map
@@ -1,162 +1,157 @@
1
- import { ajv, sendRequestError, } from './ajv.js';
1
+ import config from '@cloudcommerce/firebase/lib/config';
2
+ import { checkoutSchema } from '../index.js';
3
+ import { ajv, sendRequestError } from './ajv.js';
2
4
  import fixItems from './functions-checkout/fix-items.js';
3
5
  import getCustomerId from './functions-checkout/get-custumerId.js';
4
6
  import requestModule from './functions-checkout/request-to-module.js';
5
- import { sendError, fixAmount, getValidResults, handleShippingServices, handleApplyDiscount, handleListPayments, } from './functions-checkout/utils.js';
7
+ import {
8
+ sendError, fixAmount, getValidResults, handleShippingServices, handleApplyDiscount, handleListPayments,
9
+ } from './functions-checkout/utils.js';
6
10
  import createOrder from './functions-checkout/new-order.js';
7
- const runCheckout = async (checkoutBody, accessToken, res, validate, hostname) => {
8
- if (!validate(checkoutBody)) {
9
- return sendRequestError(res, '@checkout', validate.errors);
10
- }
11
- const { items, ...newBody } = checkoutBody;
12
- const newItems = await fixItems(items);
13
- const amount = {
14
- subtotal: 0,
15
- discount: 0,
16
- freight: 0,
17
- total: 0,
18
- };
19
- const body = {
20
- ...newBody,
21
- items: [...newItems],
22
- subtotal: 0,
23
- amount,
24
- };
25
- const countCheckoutItems = body.items.length;
26
- const { customer } = body;
27
- const customerId = await getCustomerId(accessToken, customer);
28
- if (customerId && customer) {
29
- if (newItems.length) {
30
- const { _id, ...newCustomer } = customer;
31
- // start mounting order body
32
- // https://developers.e-com.plus/docs/api/#/store/orders/orders
33
- const dateTime = new Date().toISOString();
34
- const orderBody = {
35
- opened_at: dateTime,
36
- buyers: [
37
- // received customer info
38
- {
39
- _id: customerId,
40
- ...newCustomer,
41
- },
42
- ],
43
- items: [],
44
- amount: {
45
- total: 0,
46
- },
47
- };
48
- // bypass some order fields
49
- const fields = [
50
- 'utm',
51
- 'affiliate_code',
52
- 'browser_ip',
53
- 'channel_id',
54
- 'channel_type',
55
- 'domain',
56
- 'notes',
57
- ];
58
- fields.forEach((field) => {
59
- if (body[field]) {
60
- orderBody[field] = body[field];
61
- }
62
- });
63
- if (orderBody.domain) {
64
- // consider default Storefront app routes
65
- if (!orderBody.checkout_link) {
66
- orderBody.checkout_link = `https://${orderBody.domain}/app/#/checkout/(_id)`;
67
- }
68
- if (!orderBody.status_link) {
69
- orderBody.status_link = `https://${orderBody.domain}/app/#/order/(_id)`;
70
- }
71
- }
72
- // count subtotal value
73
- let subtotal = 0;
74
- newItems.forEach((item) => {
75
- subtotal += (item.final_price || item.price * item.quantity);
76
- // pass each item to prevent object overwrite
77
- if (orderBody.items) {
78
- orderBody.items.push({ ...item });
79
- }
80
- });
81
- if (subtotal <= 0 && items.length < countCheckoutItems) {
82
- return sendError(res, 400, 'CKT801', 'Cannot handle checkout, any valid cart item');
83
- }
84
- amount.subtotal = subtotal;
85
- body.subtotal = subtotal;
86
- fixAmount(amount, body, orderBody);
87
- const transactions = Array.isArray(body.transaction) ? body.transaction : [body.transaction];
88
- // add customer ID to order and transaction
89
- customer._id = customerId;
90
- transactions.forEach(({ buyer }) => {
91
- if (buyer) {
92
- buyer.customer_id = customerId;
93
- }
94
- });
95
- let listShipping = await requestModule(body, hostname, 'shipping');
96
- if (listShipping) {
97
- listShipping = getValidResults(listShipping, 'shipping_services');
98
- handleShippingServices(body, listShipping, amount, orderBody);
99
- }
100
- else {
101
- // problem with shipping response object
102
- return sendError(res, 400, 'CKT901', 'Any valid shipping service from /calculate_shipping module', {
103
- en_us: 'Shipping method not available, please choose another',
104
- pt_br: 'Forma de envio indisponível, por favor escolha outra',
105
- });
106
- }
107
- let discounts = await requestModule(body, hostname, 'discount');
108
- if (discounts) {
109
- discounts = getValidResults(discounts);
110
- handleApplyDiscount(body, discounts, amount, orderBody);
111
- }
112
- const { transaction, ...bodyPayment } = body;
113
- let paymentsBody;
114
- if (Array.isArray(transaction)) {
115
- paymentsBody = {
116
- ...bodyPayment,
117
- transaction: transaction[0],
118
- };
119
- }
120
- else {
121
- paymentsBody = {
122
- ...bodyPayment,
123
- transaction,
124
- };
125
- }
126
- let listPaymentGateways = await requestModule(paymentsBody, hostname, 'payment');
127
- if (listPaymentGateways) {
128
- listPaymentGateways = getValidResults(listPaymentGateways, 'payment_gateways');
129
- handleListPayments(body, listPaymentGateways, paymentsBody, amount, orderBody);
130
- }
131
- else {
132
- return sendError(res, 409, 'CKT902', 'Any valid payment gateway from /list_payments module', {
133
- en_us: 'Payment method not available, please choose another',
134
- pt_br: 'Forma de pagamento indisponível, por favor escolha outra',
135
- });
136
- }
137
- return createOrder(res, accessToken, hostname, amount, checkoutBody, orderBody, transactions, dateTime);
11
+
12
+ export default async (req, res) => {
13
+ const { httpsFunctionOptions } = config.get();
14
+ const modulesBaseURL = req.hostname !== 'localhost'
15
+ ? `https://${req.hostname}${req.url.replace(/\/checkout[^/]*/i, '')}`
16
+ : `http://localhost:5001/${process.env.GCLOUD_PROJECT}`
17
+ + `/${(process.env.FUNCTION_REGION || httpsFunctionOptions.region)}/modules`;
18
+ const validate = ajv.compile(checkoutSchema);
19
+ const checkoutBody = req.body;
20
+ if (!req.body.browser_ip && req.ip) {
21
+ req.body.browser_ip = req.ip;
22
+ }
23
+ if (!validate(checkoutBody)) {
24
+ return sendRequestError(res, '@checkout', validate.errors);
25
+ }
26
+ const { items, ...newBody } = checkoutBody;
27
+ const newItems = await fixItems(items);
28
+ const amount = {
29
+ subtotal: 0,
30
+ discount: 0,
31
+ freight: 0,
32
+ total: 0,
33
+ };
34
+ const body = {
35
+ ...newBody,
36
+ items: [...newItems],
37
+ subtotal: 0,
38
+ amount,
39
+ };
40
+ const countCheckoutItems = body.items.length;
41
+ const { customer } = body;
42
+ const customerId = await getCustomerId(customer);
43
+ if (customerId) {
44
+ if (newItems.length) {
45
+ // start mounting order body
46
+ // https://developers.e-com.plus/docs/api/#/store/orders/orders
47
+ const dateTime = new Date().toISOString();
48
+ const orderBody = {
49
+ opened_at: dateTime,
50
+ buyers: [
51
+ // received customer info
52
+ {
53
+ ...customer,
54
+ _id: customerId,
55
+ },
56
+ ],
57
+ items: [],
58
+ amount: {
59
+ total: 0,
60
+ },
61
+ };
62
+ // bypass some order fields
63
+ const fields = [
64
+ 'utm',
65
+ 'affiliate_code',
66
+ 'browser_ip',
67
+ 'channel_id',
68
+ 'channel_type',
69
+ 'domain',
70
+ 'notes',
71
+ ];
72
+ fields.forEach((field) => {
73
+ if (body[field]) {
74
+ orderBody[field] = body[field];
75
+ }
76
+ });
77
+ if (orderBody.domain) {
78
+ // consider default Storefront app routes
79
+ if (!orderBody.checkout_link) {
80
+ orderBody.checkout_link = `https://${orderBody.domain}/app/#/checkout/(_id)`;
81
+ }
82
+ if (!orderBody.status_link) {
83
+ orderBody.status_link = `https://${orderBody.domain}/app/#/order/(_id)`;
84
+ }
85
+ }
86
+ // count subtotal value
87
+ let subtotal = 0;
88
+ newItems.forEach((item) => {
89
+ subtotal += (item.final_price || item.price * item.quantity);
90
+ // pass each item to prevent object overwrite
91
+ if (orderBody.items) {
92
+ orderBody.items.push({ ...item });
138
93
  }
94
+ });
95
+ if (subtotal <= 0 && items.length < countCheckoutItems) {
139
96
  return sendError(res, 400, 'CKT801', 'Cannot handle checkout, any valid cart item');
97
+ }
98
+ amount.subtotal = subtotal;
99
+ body.subtotal = subtotal;
100
+ fixAmount(amount, body, orderBody);
101
+ const transactions = Array.isArray(body.transaction) ? body.transaction : [body.transaction];
102
+ // add customer ID to order and transaction
103
+ customer._id = customerId;
104
+ transactions.forEach(({ buyer }) => {
105
+ if (buyer) {
106
+ buyer.customer_id = customerId;
107
+ }
108
+ });
109
+ let listShipping = await requestModule(body, modulesBaseURL, 'shipping');
110
+ if (listShipping) {
111
+ listShipping = getValidResults(listShipping, 'shipping_services');
112
+ handleShippingServices(body, listShipping, amount, orderBody);
113
+ } else {
114
+ // problem with shipping response object
115
+ return sendError(res, 400, 'CKT901', 'Any valid shipping service from /calculate_shipping module', {
116
+ en_us: 'Shipping method not available, please choose another',
117
+ pt_br: 'Forma de envio indisponível, por favor escolha outra',
118
+ });
119
+ }
120
+ let discounts = await requestModule(body, modulesBaseURL, 'discount');
121
+ if (discounts) {
122
+ discounts = getValidResults(discounts);
123
+ handleApplyDiscount(body, discounts, amount, orderBody);
124
+ }
125
+ const { transaction, ...bodyPayment } = body;
126
+ let paymentsBody;
127
+ if (Array.isArray(transaction)) {
128
+ paymentsBody = {
129
+ ...bodyPayment,
130
+ transaction: transaction[0],
131
+ };
132
+ } else {
133
+ paymentsBody = {
134
+ ...bodyPayment,
135
+ transaction,
136
+ };
137
+ }
138
+ let listPaymentGateways = await requestModule(paymentsBody, modulesBaseURL, 'payment');
139
+ if (listPaymentGateways) {
140
+ listPaymentGateways = getValidResults(listPaymentGateways, 'payment_gateways');
141
+ handleListPayments(body, listPaymentGateways, paymentsBody, amount, orderBody);
142
+ } else {
143
+ return sendError(res, 409, 'CKT902', 'Any valid payment gateway from /list_payments module', {
144
+ en_us: 'Payment method not available, please choose another',
145
+ pt_br: 'Forma de pagamento indisponível, por favor escolha outra',
146
+ });
147
+ }
148
+ return createOrder(res, modulesBaseURL, amount, checkoutBody, orderBody, transactions, dateTime);
140
149
  }
141
- return sendError(res, 404, -404, 'Not found', {
142
- en_us: 'No customers found with ID or email provided',
143
- pt_br: 'Nenhum cliente encontrado com ID ou e-mail fornecido',
144
- });
145
- };
146
- export default (schema, req, res, hostname) => {
147
- const validate = ajv.compile(schema);
148
- const ip = req.headers['x-real-ip'];
149
- if (!req.body.browser_ip && ip) {
150
- req.body.browser_ip = ip;
151
- }
152
- let acessToken = req.headers.authorization;
153
- if (acessToken) {
154
- acessToken = acessToken.replace(/Bearer /i, '');
155
- return runCheckout(req.body, acessToken, res, validate, hostname);
156
- }
157
- return sendError(res, 401, 109, "Token is required on 'Authorization'", {
158
- en_us: 'No authorization for the requested method and resource',
159
- pt_br: 'Sem autorização para o método e recurso solicitado',
160
- });
150
+ return sendError(res, 400, 'CKT801', 'Cannot handle checkout, any valid cart item');
151
+ }
152
+ return sendError(res, 404, -404, 'Not found', {
153
+ en_us: 'No customers found with ID or email provided',
154
+ pt_br: 'Nenhum cliente encontrado com ID ou e-mail fornecido',
155
+ });
161
156
  };
162
- //# sourceMappingURL=checkout.js.map
157
+ // # sourceMappingURL=checkout.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"checkout.js","sourceRoot":"","sources":["../../src/firebase/checkout.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,GAAG,EACH,gBAAgB,GACjB,MAAM,OAAO,CAAC;AACf,OAAO,QAAQ,MAAM,gCAAgC,CAAC;AACtD,OAAO,aAAa,MAAM,qCAAqC,CAAC;AAChE,OAAO,aAAa,MAAM,wCAAwC,CAAC;AACnE,OAAO,EACL,SAAS,EACT,SAAS,EACT,eAAe,EACf,sBAAsB,EACtB,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,4BAA4B,CAAC;AACpC,OAAO,WAAW,MAAM,gCAAgC,CAAC;AAEzD,MAAM,WAAW,GAAG,KAAK,EACvB,YAA0B,EAC1B,WAAkB,EAClB,GAAY,EACZ,QAA0B,EAC1B,QAAgB,EAChB,EAAE;IACF,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE;QAC3B,OAAO,gBAAgB,CAAC,GAAG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