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
@@ -3,197 +3,195 @@ import axios from 'axios';
3
3
  import FormData from 'form-data';
4
4
  import ecomUtils from '@ecomplus/utils';
5
5
  import getEnv from '@cloudcommerce/firebase/lib/env';
6
-
7
6
  const removeAccents = (str) => str.replace(/áàãâÁÀÃÂ/g, 'a')
8
- .replace(/éêÉÊ/g, 'e')
9
- .replace(/óõôÓÕÔ/g, 'o')
10
- .replace(/íÍ/g, 'e')
11
- .replace(/úÚ/g, 'u')
12
- .replace(/çÇ/g, 'c');
7
+ .replace(/éêÉÊ/g, 'e')
8
+ .replace(/óõôÓÕÔ/g, 'o')
9
+ .replace(/íÍ/g, 'e')
10
+ .replace(/úÚ/g, 'u')
11
+ .replace(/çÇ/g, 'c');
13
12
  const tryImageUpload = (originImgUrl, product) => new Promise((resolve) => {
14
- const { storeId, apiAuth: { authenticationId, apiKey } } = getEnv();
15
- axios.get(originImgUrl, {
16
- responseType: 'arraybuffer',
17
- }).then(({ data }) => {
18
- const form = new FormData();
19
- form.append('file', Buffer.from(data), originImgUrl.replace(/.*\/([^/]+)$/, '$1'));
20
- return axios.post(`https://apx-storage.e-com.plus/${storeId}/api/v1/upload.json`, form, {
21
- headers: {
22
- ...form.getHeaders(),
23
- 'X-Store-ID': storeId,
24
- 'X-My-ID': authenticationId,
25
- 'X-API-Key': apiKey,
26
- },
27
- }).then(({ data, status }) => {
28
- if (data.picture) {
29
- Object.keys(data.picture).forEach((imgSize) => {
30
- if (data.picture[imgSize]) {
31
- if (!data.picture[imgSize].url) {
32
- delete data.picture[imgSize];
33
- return;
13
+ const { storeId, apiAuth: { authenticationId, apiKey, }, } = getEnv();
14
+ axios.get(originImgUrl, {
15
+ responseType: 'arraybuffer',
16
+ }).then(({ data }) => {
17
+ const form = new FormData();
18
+ form.append('file', Buffer.from(data), originImgUrl.replace(/.*\/([^/]+)$/, '$1'));
19
+ return axios.post(`https://apx-storage.e-com.plus/${storeId}/api/v1/upload.json`, form, {
20
+ headers: {
21
+ ...form.getHeaders(),
22
+ 'X-Store-ID': storeId,
23
+ 'X-My-ID': authenticationId,
24
+ 'X-API-Key': apiKey,
25
+ },
26
+ }).then(({ data, status }) => {
27
+ if (data.picture) {
28
+ Object.keys(data.picture).forEach((imgSize) => {
29
+ if (data.picture[imgSize]) {
30
+ if (!data.picture[imgSize].url) {
31
+ delete data.picture[imgSize];
32
+ return;
33
+ }
34
+ if (data.picture[imgSize].size !== undefined) {
35
+ delete data.picture[imgSize].size;
36
+ }
37
+ data.picture[imgSize].alt = `${product.name} (${imgSize})`;
38
+ }
39
+ });
40
+ if (Object.keys(data.picture).length) {
41
+ return resolve({
42
+ _id: ecomUtils.randomObjectId(),
43
+ ...data.picture,
44
+ });
45
+ }
34
46
  }
35
- if (data.picture[imgSize].size !== undefined) {
36
- delete data.picture[imgSize].size;
37
- }
38
- data.picture[imgSize].alt = `${product.name} (${imgSize})`;
39
- }
47
+ const err = new Error('Unexpected Storage API response');
48
+ err.response = { data, status };
49
+ throw err;
40
50
  });
41
- if (Object.keys(data.picture).length) {
42
- return resolve({
51
+ })
52
+ .catch((err) => {
53
+ logger.error(err);
54
+ resolve({
43
55
  _id: ecomUtils.randomObjectId(),
44
- ...data.picture,
45
- });
46
- }
47
- }
48
- const err = new Error('Unexpected Storage API response');
49
- err.response = { data, status };
50
- throw err;
51
- });
52
- })
53
- .catch((err) => {
54
- logger.error(err);
55
- resolve({
56
- _id: ecomUtils.randomObjectId(),
57
- normal: {
58
- url: originImgUrl,
59
- alt: product.name,
60
- },
61
- });
56
+ normal: {
57
+ url: originImgUrl,
58
+ alt: product.name,
59
+ },
60
+ });
62
61
  });
63
62
  }).then((picture) => {
64
- if (product && product.pictures) {
65
- // @ts-ignore
66
- product.pictures.push(picture);
67
- }
68
- return picture;
63
+ if (product && product.pictures) {
64
+ // @ts-ignore
65
+ product.pictures.push(picture);
66
+ }
67
+ return picture;
69
68
  });
70
-
71
69
  export default (tinyProduct, isNew = true) => new Promise((resolve) => {
72
- const sku = tinyProduct.codigo || String(tinyProduct.id);
73
- const name = (tinyProduct.nome || sku).trim();
74
- const product = {
75
- available: tinyProduct.situacao === 'A',
76
- sku,
77
- name,
78
- cost_price: tinyProduct.preco_custo,
79
- price: tinyProduct.preco_promocional || tinyProduct.preco,
80
- base_price: tinyProduct.preco,
81
- body_html: tinyProduct.descricao_complementar,
82
- };
83
- if (isNew) {
84
- product.slug = removeAccents(name.toLowerCase())
85
- .replace(/\s+/g, '-')
86
- .replace(/[^a-z0-9-_./]/g, '');
87
- if (!/[a-z0-9]/.test(product.slug.charAt(0))) {
88
- product.slug = `p-${product.slug}`;
70
+ const sku = tinyProduct.codigo || String(tinyProduct.id);
71
+ const name = (tinyProduct.nome || sku).trim();
72
+ const product = {
73
+ available: tinyProduct.situacao === 'A',
74
+ sku,
75
+ name,
76
+ cost_price: tinyProduct.preco_custo,
77
+ price: tinyProduct.preco_promocional || tinyProduct.preco,
78
+ base_price: tinyProduct.preco,
79
+ body_html: tinyProduct.descricao_complementar,
80
+ };
81
+ if (isNew) {
82
+ product.slug = removeAccents(name.toLowerCase())
83
+ .replace(/\s+/g, '-')
84
+ .replace(/[^a-z0-9-_./]/g, '');
85
+ if (!/[a-z0-9]/.test(product.slug.charAt(0))) {
86
+ product.slug = `p-${product.slug}`;
87
+ }
88
+ }
89
+ if (tinyProduct.garantia) {
90
+ product.warranty = tinyProduct.garantia;
91
+ }
92
+ if (tinyProduct.unidade_por_caixa) {
93
+ product.min_quantity = Number(tinyProduct.unidade_por_caixa);
89
94
  }
90
- }
91
- if (tinyProduct.garantia) {
92
- product.warranty = tinyProduct.garantia;
93
- }
94
- if (tinyProduct.unidade_por_caixa) {
95
- product.min_quantity = Number(tinyProduct.unidade_por_caixa);
96
- }
97
- if (tinyProduct.ncm) {
98
- product.mpn = [tinyProduct.ncm];
99
- }
100
- const validateGtin = (gtin) => {
101
- return typeof gtin === 'string' && /^([0-9]{8}|[0-9]{12,14})$/.test(gtin);
102
- };
103
- if (validateGtin(tinyProduct.gtin)) {
104
- product.gtin = [tinyProduct.gtin];
105
- if (validateGtin(tinyProduct.gtin_embalagem)) {
106
- product.gtin.push(tinyProduct.gtin_embalagem);
95
+ if (tinyProduct.ncm) {
96
+ product.mpn = [tinyProduct.ncm];
107
97
  }
108
- }
109
- const weight = tinyProduct.peso_bruto || tinyProduct.peso_liquido;
110
- if (weight > 0) {
111
- product.weight = {
112
- unit: 'kg',
113
- value: parseFloat(weight),
98
+ const validateGtin = (gtin) => {
99
+ return typeof gtin === 'string' && /^([0-9]{8}|[0-9]{12,14})$/.test(gtin);
114
100
  };
115
- }
116
- [
117
- ['largura', 'width'],
118
- ['altura', 'height'],
119
- ['comprimento', 'length'],
120
- ].forEach(([lado, side]) => {
121
- const dimension = tinyProduct[`${lado}_embalagem`] || tinyProduct[`${lado}Embalagem`];
122
- if (dimension > 0) {
123
- if (!product.dimensions) {
124
- product.dimensions = {};
125
- }
126
- product.dimensions[side] = {
127
- unit: 'cm',
128
- value: parseFloat(dimension),
129
- };
101
+ if (validateGtin(tinyProduct.gtin)) {
102
+ product.gtin = [tinyProduct.gtin];
103
+ if (validateGtin(tinyProduct.gtin_embalagem)) {
104
+ product.gtin.push(tinyProduct.gtin_embalagem);
105
+ }
106
+ }
107
+ const weight = tinyProduct.peso_bruto || tinyProduct.peso_liquido;
108
+ if (weight > 0) {
109
+ product.weight = {
110
+ unit: 'kg',
111
+ value: parseFloat(weight),
112
+ };
130
113
  }
131
- });
132
- if (isNew) {
133
- if (Array.isArray(tinyProduct.variacoes) && tinyProduct.variacoes.length) {
134
- product.variations = [];
135
- tinyProduct.variacoes.forEach(({ variacao }) => {
136
- const { codigo, preco, grade } = variacao;
137
- if (grade && typeof grade === 'object') {
138
- const specifications = {};
139
- const specTexts = [];
140
- Object.keys(grade).forEach((tipo) => {
141
- if (grade[tipo]) {
142
- const gridId = removeAccents(tipo.toLowerCase())
143
- .replace(/\s+/g, '_')
144
- .replace(/[^a-z0-9_]/g, '')
145
- .substring(0, 30)
146
- .padStart(2, 'i');
147
- const spec = {
148
- text: grade[tipo],
149
- };
150
- specTexts.push(spec.text);
151
- if (gridId !== 'colors') {
152
- spec.value = removeAccents(spec.text.toLowerCase()).substring(0, 100);
153
- }
154
- specifications[gridId] = [spec];
114
+ [
115
+ ['largura', 'width'],
116
+ ['altura', 'height'],
117
+ ['comprimento', 'length'],
118
+ ].forEach(([lado, side]) => {
119
+ const dimension = tinyProduct[`${lado}_embalagem`] || tinyProduct[`${lado}Embalagem`];
120
+ if (dimension > 0) {
121
+ if (!product.dimensions) {
122
+ product.dimensions = {};
155
123
  }
156
- });
157
- if (specTexts.length) {
158
- product.variations?.push({
159
- _id: ecomUtils.randomObjectId(),
160
- name: `${name} / ${specTexts.join(' / ')}`.substring(0, 100),
161
- sku: codigo,
162
- specifications,
163
- price: parseFloat(preco || 0),
124
+ product.dimensions[side] = {
125
+ unit: 'cm',
126
+ value: parseFloat(dimension),
127
+ };
128
+ }
129
+ });
130
+ if (isNew) {
131
+ if (Array.isArray(tinyProduct.variacoes) && tinyProduct.variacoes.length) {
132
+ product.variations = [];
133
+ tinyProduct.variacoes.forEach(({ variacao }) => {
134
+ const { codigo, preco, grade } = variacao;
135
+ if (grade && typeof grade === 'object') {
136
+ const specifications = {};
137
+ const specTexts = [];
138
+ Object.keys(grade).forEach((tipo) => {
139
+ if (grade[tipo]) {
140
+ const gridId = removeAccents(tipo.toLowerCase())
141
+ .replace(/\s+/g, '_')
142
+ .replace(/[^a-z0-9_]/g, '')
143
+ .substring(0, 30)
144
+ .padStart(2, 'i');
145
+ const spec = {
146
+ text: grade[tipo],
147
+ };
148
+ specTexts.push(spec.text);
149
+ if (gridId !== 'colors') {
150
+ spec.value = removeAccents(spec.text.toLowerCase()).substring(0, 100);
151
+ }
152
+ specifications[gridId] = [spec];
153
+ }
154
+ });
155
+ if (specTexts.length) {
156
+ product.variations?.push({
157
+ _id: ecomUtils.randomObjectId(),
158
+ name: `${name} / ${specTexts.join(' / ')}`.substring(0, 100),
159
+ sku: codigo,
160
+ specifications,
161
+ price: parseFloat(preco || 0),
162
+ });
163
+ }
164
+ }
164
165
  });
165
- }
166
166
  }
167
- });
168
- }
169
- if (Array.isArray(tinyProduct.imagens_externas)) {
170
- product.pictures = [];
171
- tinyProduct.imagens_externas.forEach((imagemExterna) => {
172
- if (imagemExterna.imagem_externa) {
173
- const { url } = imagemExterna.imagem_externa;
174
- if (url) {
175
- product.pictures?.push({
176
- normal: { url },
177
- _id: ecomUtils.randomObjectId(),
167
+ if (Array.isArray(tinyProduct.imagens_externas)) {
168
+ product.pictures = [];
169
+ tinyProduct.imagens_externas.forEach((imagemExterna) => {
170
+ if (imagemExterna.imagem_externa) {
171
+ const { url } = imagemExterna.imagem_externa;
172
+ if (url) {
173
+ product.pictures?.push({
174
+ normal: { url },
175
+ _id: ecomUtils.randomObjectId(),
176
+ });
177
+ }
178
+ }
178
179
  });
179
- }
180
180
  }
181
- });
182
- }
183
- if (tinyProduct.anexos) {
184
- if (!product.pictures) {
185
- product.pictures = [];
186
- }
187
- const promises = [];
188
- tinyProduct.anexos.forEach(({ anexo }) => {
189
- if (typeof anexo === 'string' && anexo.startsWith('http')) {
190
- promises.push(tryImageUpload(anexo, product));
181
+ if (tinyProduct.anexos) {
182
+ if (!product.pictures) {
183
+ product.pictures = [];
184
+ }
185
+ const promises = [];
186
+ tinyProduct.anexos.forEach(({ anexo }) => {
187
+ if (typeof anexo === 'string' && anexo.startsWith('http')) {
188
+ promises.push(tryImageUpload(anexo, product));
189
+ }
190
+ });
191
+ Promise.all(promises).then(() => resolve(product));
192
+ return;
191
193
  }
192
- });
193
- Promise.all(promises).then(() => resolve(product));
194
- return;
195
194
  }
196
- }
197
- resolve(product);
195
+ resolve(product);
198
196
  });
199
- // # sourceMappingURL=product-from-tiny.js.map
197
+ //# sourceMappingURL=product-from-tiny.js.map
@@ -1,129 +1,133 @@
1
1
  import ecomUtils from '@ecomplus/utils';
2
-
3
2
  export default async (product, originalTinyProduct, appData) => {
4
- const hasVariations = product.variations && product.variations.length;
5
- const tinyProduct = {
6
- sequencia: 1,
7
- origem: 0,
8
- situacao: product.available && product.visible ? 'A' : 'I',
9
- tipo: 'P',
10
- classe_produto: hasVariations ? 'V' : 'S',
11
- codigo: product.sku,
12
- nome: ecomUtils.name(product, 'pt_br').substring(0, 120),
13
- unidade: originalTinyProduct && originalTinyProduct.unidade
14
- ? originalTinyProduct.unidade
15
- : product.measurement && product.measurement.unit !== 'oz' && product.measurement.unit !== 'ct'
16
- ? product.measurement.unit.substring(0, 3).toUpperCase()
17
- : 'UN',
18
- };
19
- if (ecomUtils.onPromotion(product)) {
20
- tinyProduct.preco = product.base_price;
21
- tinyProduct.preco_promocional = ecomUtils.price(product);
22
- } else {
23
- tinyProduct.preco = product.price;
24
- }
25
- if (product.cost_price) {
26
- tinyProduct.preco_custo = product.cost_price;
27
- }
28
- if (product.min_quantity) {
29
- tinyProduct.unidade_por_caixa = product.min_quantity < 1000
30
- ? String(product.min_quantity) : '999';
31
- }
32
- if (product.short_description) {
33
- tinyProduct.descricao_complementar = product.short_description;
34
- }
35
- if (product.warranty) {
36
- tinyProduct.garantia = product.warranty.substring(0, 20);
37
- }
38
- if (product.mpn && product.mpn.length) {
39
- [tinyProduct.ncm] = product.mpn;
40
- }
41
- if (product.gtin && product.gtin.length) {
42
- [tinyProduct.gtin] = product.gtin;
43
- if (product.gtin[1]) {
44
- // eslint-disable-next-line prefer-destructuring
45
- tinyProduct.gtin_embalagem = product.gtin[1];
46
- }
47
- }
48
- if (product.weight && product.weight.value) {
49
- tinyProduct.peso_bruto = product.weight.value;
50
- if (product.weight.unit === 'mg') {
51
- tinyProduct.peso_bruto /= 1000000;
52
- } else if (product.weight.unit === 'g') {
53
- tinyProduct.peso_bruto /= 1000;
54
- }
55
- }
56
- const { dimensions } = product;
57
- if (dimensions) {
58
- Object.keys(dimensions).forEach((side) => {
59
- if (dimensions[side] && dimensions[side].value) {
60
- let field = side === 'width' ? 'largura'
61
- : side === 'height' ? 'altura'
62
- : 'comprimento';
63
- field += '_embalagem';
64
- tinyProduct[field] = dimensions[side].value;
65
- if (dimensions[side].unit === 'mm') {
66
- tinyProduct[field] *= 0.1;
67
- } else if (dimensions[side].unit === 'm') {
68
- tinyProduct[field] *= 100;
3
+ const hasVariations = product.variations && product.variations.length;
4
+ const tinyProduct = {
5
+ sequencia: 1,
6
+ origem: 0,
7
+ situacao: product.available && product.visible ? 'A' : 'I',
8
+ tipo: 'P',
9
+ classe_produto: hasVariations ? 'V' : 'S',
10
+ codigo: product.sku,
11
+ nome: ecomUtils.name(product, 'pt_br').substring(0, 120),
12
+ unidade: originalTinyProduct && originalTinyProduct.unidade
13
+ ? originalTinyProduct.unidade
14
+ : product.measurement && product.measurement.unit !== 'oz' && product.measurement.unit !== 'ct'
15
+ ? product.measurement.unit.substring(0, 3).toUpperCase()
16
+ : 'UN',
17
+ };
18
+ if (ecomUtils.onPromotion(product)) {
19
+ tinyProduct.preco = product.base_price;
20
+ tinyProduct.preco_promocional = ecomUtils.price(product);
21
+ }
22
+ else {
23
+ tinyProduct.preco = product.price;
24
+ }
25
+ if (product.cost_price) {
26
+ tinyProduct.preco_custo = product.cost_price;
27
+ }
28
+ if (product.min_quantity) {
29
+ tinyProduct.unidade_por_caixa = product.min_quantity < 1000
30
+ ? String(product.min_quantity) : '999';
31
+ }
32
+ if (product.short_description) {
33
+ tinyProduct.descricao_complementar = product.short_description;
34
+ }
35
+ if (product.warranty) {
36
+ tinyProduct.garantia = product.warranty.substring(0, 20);
37
+ }
38
+ if (product.mpn && product.mpn.length) {
39
+ [tinyProduct.ncm] = product.mpn;
40
+ }
41
+ if (product.gtin && product.gtin.length) {
42
+ [tinyProduct.gtin] = product.gtin;
43
+ if (product.gtin[1]) {
44
+ // eslint-disable-next-line prefer-destructuring
45
+ tinyProduct.gtin_embalagem = product.gtin[1];
69
46
  }
70
- }
71
- });
72
- }
73
- if (product.brands && product.brands.length) {
74
- tinyProduct.marca = product.brands[0].name;
75
- }
76
- if (product.category_tree) {
77
- tinyProduct.categoria = product.category_tree.replace(/\s?>\s?/g, ' >> ');
78
- } else if (product.categories && product.categories.length) {
79
- tinyProduct.categoria = product.categories.map(({ name }) => name).join(' >> ');
80
- }
81
- if (product.pictures && product.pictures.length) {
82
- tinyProduct.anexos = [];
83
- product.pictures.forEach(({ zoom, big, normal }) => {
84
- const img = (zoom || big || normal);
85
- if (img) {
86
- tinyProduct.anexos.push({
87
- anexo: img.url,
88
- });
89
- }
90
- });
91
- }
92
- if (originalTinyProduct) {
93
- tinyProduct.id = originalTinyProduct.id;
94
- if (!appData.update_price) {
95
- ['preco', 'preco_promocional', 'preco_custo'].forEach((field) => {
96
- if (typeof originalTinyProduct[field] === 'number') {
97
- tinyProduct[field] = originalTinyProduct[field];
47
+ }
48
+ if (product.weight && product.weight.value) {
49
+ tinyProduct.peso_bruto = product.weight.value;
50
+ if (product.weight.unit === 'mg') {
51
+ tinyProduct.peso_bruto /= 1000000;
98
52
  }
99
- });
100
- }
101
- } else {
102
- tinyProduct.estoque_atual = product.quantity || 0;
103
- }
104
- if (hasVariations) {
105
- tinyProduct.variacoes = [];
106
- product.variations?.forEach((variation, i) => {
107
- const tinyVariation = {
108
- codigo: variation.sku || `${product.sku}-${(i + 1)}`,
109
- grade: {},
110
- };
111
- if (!originalTinyProduct) {
112
- tinyVariation.estoque_atual = variation.quantity || 0;
113
- }
114
- Object.keys(variation.specifications).forEach((gridId) => {
115
- const gridOptions = variation.specifications[gridId];
116
- if (gridOptions && gridOptions.length) {
117
- gridOptions.forEach(({ text }, i) => {
118
- tinyVariation.grade[i === 0 ? gridId : `${gridId}_${(i + 1)}`] = text;
119
- });
53
+ else if (product.weight.unit === 'g') {
54
+ tinyProduct.peso_bruto /= 1000;
55
+ }
56
+ }
57
+ const { dimensions } = product;
58
+ if (dimensions) {
59
+ Object.keys(dimensions).forEach((side) => {
60
+ if (dimensions[side] && dimensions[side].value) {
61
+ let field = side === 'width' ? 'largura'
62
+ : side === 'height' ? 'altura'
63
+ : 'comprimento';
64
+ field += '_embalagem';
65
+ tinyProduct[field] = dimensions[side].value;
66
+ if (dimensions[side].unit === 'mm') {
67
+ tinyProduct[field] *= 0.1;
68
+ }
69
+ else if (dimensions[side].unit === 'm') {
70
+ tinyProduct[field] *= 100;
71
+ }
72
+ }
73
+ });
74
+ }
75
+ if (product.brands && product.brands.length) {
76
+ tinyProduct.marca = product.brands[0].name;
77
+ }
78
+ if (product.category_tree) {
79
+ tinyProduct.categoria = product.category_tree.replace(/\s?>\s?/g, ' >> ');
80
+ }
81
+ else if (product.categories && product.categories.length) {
82
+ tinyProduct.categoria = product.categories.map(({ name }) => name).join(' >> ');
83
+ }
84
+ if (product.pictures && product.pictures.length) {
85
+ tinyProduct.anexos = [];
86
+ product.pictures.forEach(({ zoom, big, normal }) => {
87
+ const img = (zoom || big || normal);
88
+ if (img) {
89
+ tinyProduct.anexos.push({
90
+ anexo: img.url,
91
+ });
92
+ }
93
+ });
94
+ }
95
+ if (originalTinyProduct) {
96
+ tinyProduct.id = originalTinyProduct.id;
97
+ if (!appData.update_price) {
98
+ ['preco', 'preco_promocional', 'preco_custo'].forEach((field) => {
99
+ if (typeof originalTinyProduct[field] === 'number') {
100
+ tinyProduct[field] = originalTinyProduct[field];
101
+ }
102
+ });
120
103
  }
121
- });
122
- tinyProduct.variacoes.push({
123
- variacao: tinyVariation,
124
- });
125
- });
126
- }
127
- return tinyProduct;
104
+ }
105
+ else {
106
+ tinyProduct.estoque_atual = product.quantity || 0;
107
+ }
108
+ if (hasVariations) {
109
+ tinyProduct.variacoes = [];
110
+ product.variations?.forEach((variation, i) => {
111
+ const tinyVariation = {
112
+ codigo: variation.sku || `${product.sku}-${(i + 1)}`,
113
+ grade: {},
114
+ };
115
+ if (!originalTinyProduct) {
116
+ tinyVariation.estoque_atual = variation.quantity || 0;
117
+ }
118
+ Object.keys(variation.specifications).forEach((gridId) => {
119
+ const gridOptions = variation.specifications[gridId];
120
+ if (gridOptions && gridOptions.length) {
121
+ gridOptions.forEach(({ text }, i) => {
122
+ tinyVariation.grade[i === 0 ? gridId : `${gridId}_${(i + 1)}`] = text;
123
+ });
124
+ }
125
+ });
126
+ tinyProduct.variacoes.push({
127
+ variacao: tinyVariation,
128
+ });
129
+ });
130
+ }
131
+ return tinyProduct;
128
132
  };
129
- // # sourceMappingURL=product-to-tiny.js.map
133
+ //# sourceMappingURL=product-to-tiny.js.map