cloudcommerce 0.0.98 → 0.0.99

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 (55) 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 +71 -74
  11. package/packages/apps/tiny-erp/lib/integration/export-order-to-tiny.js +70 -73
  12. package/packages/apps/tiny-erp/lib/integration/export-product-to-tiny.js +49 -53
  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 +76 -75
  15. package/packages/apps/tiny-erp/lib/integration/import-product-from-tiny.js +137 -140
  16. package/packages/apps/tiny-erp/lib/integration/parsers/order-from-tiny.js +40 -39
  17. package/packages/apps/tiny-erp/lib/integration/parsers/order-to-tiny.js +173 -178
  18. package/packages/apps/tiny-erp/lib/integration/parsers/product-from-tiny.js +173 -171
  19. package/packages/apps/tiny-erp/lib/integration/parsers/product-to-tiny.js +123 -127
  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 +42 -43
  23. package/packages/apps/tiny-erp/lib/tiny-erp.js +8 -6
  24. package/packages/apps/tiny-erp/lib/tiny-webhook.js +76 -73
  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/package.json +1 -1
  30. package/packages/modules/lib/firebase/ajv.js +24 -19
  31. package/packages/modules/lib/firebase/call-app-module.js +110 -116
  32. package/packages/modules/lib/firebase/checkout.js +152 -151
  33. package/packages/modules/lib/firebase/functions-checkout/fix-items.js +187 -194
  34. package/packages/modules/lib/firebase/functions-checkout/get-custumerId.js +26 -25
  35. package/packages/modules/lib/firebase/functions-checkout/handle-order-transaction.js +109 -110
  36. package/packages/modules/lib/firebase/functions-checkout/new-order.js +177 -177
  37. package/packages/modules/lib/firebase/functions-checkout/request-to-module.js +59 -59
  38. package/packages/modules/lib/firebase/functions-checkout/utils.js +197 -195
  39. package/packages/modules/lib/firebase/handle-module.js +146 -144
  40. package/packages/modules/lib/firebase/proxy-apps.js +1 -2
  41. package/packages/modules/lib/firebase/serve-modules-api.js +53 -52
  42. package/packages/modules/lib/firebase.js +6 -4
  43. package/packages/modules/lib/index.js +15 -12
  44. package/packages/modules/package.json +1 -1
  45. package/packages/passport/package.json +1 -1
  46. package/packages/ssr/package.json +1 -1
  47. package/packages/storefront/astro.config.mjs +1 -1
  48. package/packages/storefront/dist/client/{LoginOffcanvas.daf3f717.js → LoginOffcanvas.c2faa1dc.js} +1 -1
  49. package/packages/storefront/dist/client/chunks/{LoginForm.d9251274.js → LoginForm.3bcb85fb.js} +10 -10
  50. package/packages/storefront/dist/client/chunks/{LoginOffcanvas.07fe6492.js → LoginOffcanvas.e48f274b.js} +1 -1
  51. package/packages/storefront/dist/client/sw.js +1 -1
  52. package/packages/storefront/dist/server/entry.mjs +2 -2
  53. package/packages/storefront/package.json +2 -2
  54. package/packages/storefront/tsconfig.json +1 -1
  55. package/packages/types/package.json +1 -1
@@ -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,163 @@
1
- import { ajv, sendRequestError, } from './ajv.js';
1
+ import { ajv, sendRequestError } from './ajv.js';
2
2
  import fixItems from './functions-checkout/fix-items.js';
3
3
  import getCustomerId from './functions-checkout/get-custumerId.js';
4
4
  import requestModule from './functions-checkout/request-to-module.js';
5
- import { sendError, fixAmount, getValidResults, handleShippingServices, handleApplyDiscount, handleListPayments, } from './functions-checkout/utils.js';
5
+ import {
6
+ sendError, fixAmount, getValidResults, handleShippingServices, handleApplyDiscount, handleListPayments,
7
+ } from './functions-checkout/utils.js';
6
8
  import createOrder from './functions-checkout/new-order.js';
9
+
7
10
  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
+ if (!validate(checkoutBody)) {
12
+ return sendRequestError(res, '@checkout', validate.errors);
13
+ }
14
+ const { items, ...newBody } = checkoutBody;
15
+ const newItems = await fixItems(items);
16
+ const amount = {
17
+ subtotal: 0,
18
+ discount: 0,
19
+ freight: 0,
20
+ total: 0,
21
+ };
22
+ const body = {
23
+ ...newBody,
24
+ items: [...newItems],
25
+ subtotal: 0,
26
+ amount,
27
+ };
28
+ const countCheckoutItems = body.items.length;
29
+ const { customer } = body;
30
+ const customerId = await getCustomerId(accessToken, customer);
31
+ if (customerId && customer) {
32
+ if (newItems.length) {
33
+ const { _id, ...newCustomer } = customer;
34
+ // start mounting order body
35
+ // https://developers.e-com.plus/docs/api/#/store/orders/orders
36
+ const dateTime = new Date().toISOString();
37
+ const orderBody = {
38
+ opened_at: dateTime,
39
+ buyers: [
40
+ // received customer info
41
+ {
42
+ _id: customerId,
43
+ ...newCustomer,
44
+ },
45
+ ],
46
+ items: [],
47
+ amount: {
48
+ total: 0,
49
+ },
50
+ };
51
+ // bypass some order fields
52
+ const fields = [
53
+ 'utm',
54
+ 'affiliate_code',
55
+ 'browser_ip',
56
+ 'channel_id',
57
+ 'channel_type',
58
+ 'domain',
59
+ 'notes',
60
+ ];
61
+ fields.forEach((field) => {
62
+ if (body[field]) {
63
+ orderBody[field] = body[field];
64
+ }
65
+ });
66
+ if (orderBody.domain) {
67
+ // consider default Storefront app routes
68
+ if (!orderBody.checkout_link) {
69
+ orderBody.checkout_link = `https://${orderBody.domain}/app/#/checkout/(_id)`;
70
+ }
71
+ if (!orderBody.status_link) {
72
+ orderBody.status_link = `https://${orderBody.domain}/app/#/order/(_id)`;
73
+ }
74
+ }
75
+ // count subtotal value
76
+ let subtotal = 0;
77
+ newItems.forEach((item) => {
78
+ subtotal += (item.final_price || item.price * item.quantity);
79
+ // pass each item to prevent object overwrite
80
+ if (orderBody.items) {
81
+ orderBody.items.push({ ...item });
138
82
  }
83
+ });
84
+ if (subtotal <= 0 && items.length < countCheckoutItems) {
139
85
  return sendError(res, 400, 'CKT801', 'Cannot handle checkout, any valid cart item');
86
+ }
87
+ amount.subtotal = subtotal;
88
+ body.subtotal = subtotal;
89
+ fixAmount(amount, body, orderBody);
90
+ const transactions = Array.isArray(body.transaction) ? body.transaction : [body.transaction];
91
+ // add customer ID to order and transaction
92
+ customer._id = customerId;
93
+ transactions.forEach(({ buyer }) => {
94
+ if (buyer) {
95
+ buyer.customer_id = customerId;
96
+ }
97
+ });
98
+ let listShipping = await requestModule(body, hostname, 'shipping');
99
+ if (listShipping) {
100
+ listShipping = getValidResults(listShipping, 'shipping_services');
101
+ handleShippingServices(body, listShipping, amount, orderBody);
102
+ } else {
103
+ // problem with shipping response object
104
+ return sendError(res, 400, 'CKT901', 'Any valid shipping service from /calculate_shipping module', {
105
+ en_us: 'Shipping method not available, please choose another',
106
+ pt_br: 'Forma de envio indisponível, por favor escolha outra',
107
+ });
108
+ }
109
+ let discounts = await requestModule(body, hostname, 'discount');
110
+ if (discounts) {
111
+ discounts = getValidResults(discounts);
112
+ handleApplyDiscount(body, discounts, amount, orderBody);
113
+ }
114
+ const { transaction, ...bodyPayment } = body;
115
+ let paymentsBody;
116
+ if (Array.isArray(transaction)) {
117
+ paymentsBody = {
118
+ ...bodyPayment,
119
+ transaction: transaction[0],
120
+ };
121
+ } else {
122
+ paymentsBody = {
123
+ ...bodyPayment,
124
+ transaction,
125
+ };
126
+ }
127
+ let listPaymentGateways = await requestModule(paymentsBody, hostname, 'payment');
128
+ if (listPaymentGateways) {
129
+ listPaymentGateways = getValidResults(listPaymentGateways, 'payment_gateways');
130
+ handleListPayments(body, listPaymentGateways, paymentsBody, amount, orderBody);
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);
140
138
  }
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
- });
139
+ return sendError(res, 400, 'CKT801', 'Cannot handle checkout, any valid cart item');
140
+ }
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
145
  };
146
+
146
147
  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
- });
148
+ const validate = ajv.compile(schema);
149
+ const ip = req.headers['x-real-ip'];
150
+ if (!req.body.browser_ip && ip) {
151
+ req.body.browser_ip = ip;
152
+ }
153
+ let acessToken = req.headers.authorization;
154
+ if (acessToken) {
155
+ acessToken = acessToken.replace(/Bearer /i, '');
156
+ return runCheckout(req.body, acessToken, res, validate, hostname);
157
+ }
158
+ return sendError(res, 401, 109, "Token is required on 'Authorization'", {
159
+ en_us: 'No authorization for the requested method and resource',
160
+ pt_br: 'Sem autorização para o método e recurso solicitado',
161
+ });
161
162
  };
162
- //# sourceMappingURL=checkout.js.map
163
+ // # sourceMappingURL=checkout.js.map