cloudcommerce 0.0.115 → 0.0.117
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -0
- package/ecomplus-stores/monocard/functions/core/package.json +1 -1
- package/ecomplus-stores/monocard/functions/events/package.json +2 -2
- package/ecomplus-stores/monocard/functions/modules/package.json +2 -2
- package/ecomplus-stores/monocard/functions/passport/package.json +2 -2
- package/ecomplus-stores/monocard/functions/ssr/.eslintrc.cjs +6 -0
- package/ecomplus-stores/monocard/functions/ssr/content/contacts.json +3 -3
- package/ecomplus-stores/monocard/functions/ssr/content/settings.json +0 -7
- package/ecomplus-stores/monocard/functions/ssr/package.json +11 -5
- package/ecomplus-stores/monocard/functions/ssr/public/assets/fonts/FavoritPro-Regular.woff2 +0 -0
- package/ecomplus-stores/monocard/functions/ssr/public/assets/fonts/MyriadPro-Regular.woff2 +0 -0
- package/ecomplus-stores/monocard/functions/ssr/public/assets/lotties/img_1.png +0 -0
- package/ecomplus-stores/monocard/functions/ssr/public/assets/lotties/phone-nfc.json +1 -0
- package/ecomplus-stores/monocard/functions/ssr/public/img/uploads/fluxo.png +0 -0
- package/ecomplus-stores/monocard/functions/ssr/public/img/uploads/padronagem-tilada.png +0 -0
- package/ecomplus-stores/monocard/functions/ssr/public/img/uploads/sua-logo-aqui.png +0 -0
- package/ecomplus-stores/monocard/functions/ssr/src/components/DemoVideo.vue +5 -0
- package/ecomplus-stores/monocard/functions/ssr/src/components/HowItWorksAccordion.vue +32 -0
- package/ecomplus-stores/monocard/functions/ssr/src/components/LottiePhoneNFC.vue +19 -0
- package/ecomplus-stores/monocard/functions/ssr/src/components/MonocardCustomizer.vue +358 -0
- package/ecomplus-stores/monocard/functions/ssr/src/components/TheHeader.vue +40 -3
- package/ecomplus-stores/monocard/functions/ssr/src/components/TopBar.vue +10 -0
- package/ecomplus-stores/monocard/functions/ssr/src/components/header/HeaderButtonLink.vue +5 -0
- package/ecomplus-stores/monocard/functions/ssr/src/components/header/HeaderButtons.vue +59 -0
- package/ecomplus-stores/monocard/functions/ssr/src/components/header/HeaderNav.vue +61 -0
- package/ecomplus-stores/monocard/functions/ssr/src/components/header/HeaderNavLink.vue +5 -0
- package/ecomplus-stores/monocard/functions/ssr/src/layouts/Base.astro +58 -0
- package/ecomplus-stores/monocard/functions/ssr/src/layouts/Pages.astro +18 -41
- package/ecomplus-stores/monocard/functions/ssr/src/layouts/PagesHeader.astro +51 -0
- package/{packages/storefront/src/lib → ecomplus-stores/monocard/functions/ssr/src}/main/Fallback.astro +0 -0
- package/ecomplus-stores/monocard/functions/ssr/src/main/Home.astro +63 -0
- package/{packages/storefront/src/lib → ecomplus-stores/monocard/functions/ssr/src}/main/Wildcard.astro +0 -0
- package/ecomplus-stores/monocard/functions/ssr/src/pages/[...slug].astro +2 -2
- package/ecomplus-stores/monocard/functions/ssr/src/pages/comprar/index.astro +45 -0
- package/ecomplus-stores/monocard/functions/ssr/src/pages/index.astro +3 -3
- package/{packages/storefront/src/components/.gitkeep → ecomplus-stores/monocard/functions/ssr/src/pages/monocard.astro} +0 -0
- package/ecomplus-stores/monocard/functions/ssr/tsconfig.json +14 -1
- package/ecomplus-stores/monocard/package.json +1 -1
- package/package.json +8 -8
- package/packages/api/lib/types.d.ts +14 -3
- package/packages/api/package.json +1 -1
- package/packages/api/src/types.ts +35 -12
- package/packages/apps/correios/package.json +1 -1
- package/packages/apps/custom-shipping/package.json +1 -1
- package/packages/apps/discounts/package.json +1 -1
- package/packages/apps/frenet/package.json +1 -1
- package/packages/apps/mercadopago/package.json +1 -1
- package/packages/apps/tiny-erp/lib/event-to-tiny.js +115 -0
- package/packages/apps/tiny-erp/lib/event-to-tiny.js.map +1 -0
- package/packages/apps/tiny-erp/lib/index.js +2 -0
- package/packages/apps/tiny-erp/lib/index.js.map +1 -0
- package/packages/apps/tiny-erp/lib/integration/after-tiny-queue.js +79 -0
- package/packages/apps/tiny-erp/lib/integration/after-tiny-queue.js.map +1 -0
- package/packages/apps/tiny-erp/lib/integration/export-order-to-tiny.js +84 -0
- package/packages/apps/tiny-erp/lib/integration/export-order-to-tiny.js.map +1 -0
- package/packages/apps/tiny-erp/lib/integration/export-product-to-tiny.js +58 -0
- package/packages/apps/tiny-erp/lib/integration/export-product-to-tiny.js.map +1 -0
- package/packages/apps/tiny-erp/lib/integration/helpers/format-tiny-date.js +7 -0
- package/packages/apps/tiny-erp/lib/integration/helpers/format-tiny-date.js.map +1 -0
- package/packages/apps/tiny-erp/lib/integration/import-order-from-tiny.js +92 -0
- package/packages/apps/tiny-erp/lib/integration/import-order-from-tiny.js.map +1 -0
- package/packages/apps/tiny-erp/lib/integration/import-product-from-tiny.js +158 -0
- package/packages/apps/tiny-erp/lib/integration/import-product-from-tiny.js.map +1 -0
- package/packages/apps/tiny-erp/lib/integration/parsers/order-from-tiny.js +46 -0
- package/packages/apps/tiny-erp/lib/integration/parsers/order-from-tiny.js.map +1 -0
- package/packages/apps/tiny-erp/lib/integration/parsers/order-to-tiny.js +193 -0
- package/packages/apps/tiny-erp/lib/integration/parsers/order-to-tiny.js.map +1 -0
- package/packages/apps/tiny-erp/lib/integration/parsers/product-from-tiny.js +199 -0
- package/packages/apps/tiny-erp/lib/integration/parsers/product-from-tiny.js.map +1 -0
- package/packages/apps/tiny-erp/lib/integration/parsers/product-to-tiny.js +129 -0
- package/packages/apps/tiny-erp/lib/integration/parsers/product-to-tiny.js.map +1 -0
- package/packages/apps/tiny-erp/lib/integration/parsers/status-from-tiny.js +34 -0
- package/packages/apps/tiny-erp/lib/integration/parsers/status-from-tiny.js.map +1 -0
- package/packages/apps/tiny-erp/lib/integration/parsers/status-to-tiny.js +39 -0
- package/packages/apps/tiny-erp/lib/integration/parsers/status-to-tiny.js.map +1 -0
- package/packages/apps/tiny-erp/lib/integration/post-tiny-erp.js +47 -0
- package/packages/apps/tiny-erp/lib/integration/post-tiny-erp.js.map +1 -0
- package/packages/apps/tiny-erp/lib/tiny-erp.js +18 -0
- package/packages/apps/tiny-erp/lib/tiny-erp.js.map +1 -0
- package/packages/apps/tiny-erp/lib/tiny-webhook.js +92 -0
- package/packages/apps/tiny-erp/lib/tiny-webhook.js.map +1 -0
- package/packages/apps/tiny-erp/package.json +1 -1
- package/packages/cli/package.json +1 -1
- package/packages/config/lib/config.js +12 -4
- package/packages/config/lib/config.js.map +1 -1
- package/packages/config/package.json +1 -1
- package/packages/config/src/config.ts +12 -4
- package/packages/events/package.json +2 -2
- package/packages/firebase/lib/config.js +34 -38
- package/packages/firebase/lib/const.js +2 -3
- package/packages/firebase/lib/env.js +1 -2
- package/packages/firebase/lib/handlers/check-store-events.js +145 -146
- package/packages/firebase/lib/helpers/pubsub.js +18 -20
- package/packages/firebase/lib/helpers/update-app-data.js +38 -38
- package/packages/firebase/lib/index.js +7 -9
- package/packages/firebase/lib/init.js +1 -2
- package/packages/firebase/package.json +1 -1
- package/packages/i18n/package.json +1 -1
- package/packages/modules/package.json +1 -1
- package/packages/modules/src/firebase/serve-modules-api.ts +1 -0
- package/packages/passport/package.json +1 -1
- package/packages/passport/src/firebase/authenticate-customer.ts +1 -1
- package/packages/passport/src/firebase/serve-passport-api.ts +2 -0
- package/packages/ssr/package.json +3 -3
- package/packages/storefront/astro.config.mjs +22 -17
- package/packages/storefront/package.json +6 -7
- package/packages/storefront/scripts/prepare-monorepo.sh +6 -0
- package/packages/storefront/src/env.d.ts +1 -1
- package/packages/storefront/src/lib/assets/pico.css +12 -11
- package/packages/storefront/src/lib/components/ADrawer.vue +33 -21
- package/packages/storefront/src/lib/components/LoginDrawer.vue +7 -13
- package/packages/storefront/src/lib/components/LoginForm.vue +3 -1
- package/packages/storefront/src/lib/layouts/Base.astro +3 -3
- package/packages/storefront/src/lib/layouts/BaseStateJson.astro +5 -0
- package/packages/storefront/src/lib/ssr-context.ts +6 -1
- package/packages/storefront/src/lib/state/customer-session.ts +1 -1
- package/packages/storefront/src/lib/types/cms-code.d.ts +1 -1
- package/packages/storefront/src/lib/types/cms-contacts.d.ts +1 -1
- package/packages/storefront/src/lib/types/cms-header.d.ts +1 -1
- package/packages/storefront/src/lib/types/cms-settings.d.ts +1 -1
- package/packages/storefront/src/lib/types/cms-social.d.ts +1 -1
- package/packages/storefront/tailwind.config.cjs +76 -1
- package/packages/storefront/tsconfig.json +4 -1
- package/packages/storefront/uno.config.ts +12 -31
- package/packages/types/package.json +1 -1
- package/turbo.json +0 -1
- package/ecomplus-stores/monocard/functions/ssr/public/assets/icons/bootstrap-icons/font/storefront-icons.woff2 +0 -0
- package/ecomplus-stores/monocard/functions/ssr/public/assets/icons/feather-icons/font/storefront-icons.woff2 +0 -0
- package/ecomplus-stores/monocard/functions/ssr/public/assets/icons/font-awesome/font/storefront-icons.woff2 +0 -0
- package/ecomplus-stores/monocard/functions/ssr/public/assets/icons/line-awesome/font/storefront-icons.woff2 +0 -0
- package/ecomplus-stores/monocard/functions/ssr/public/assets/icons/tabler-icons/font/storefront-icons.woff2 +0 -0
- package/ecomplus-stores/monocard/functions/ssr/public/assets/img-placeholder.png +0 -0
- package/ecomplus-stores/monocard/functions/ssr/public/assets/payments.png +0 -0
- package/ecomplus-stores/monocard/functions/ssr/public/img/uploads/banner1.png +0 -0
- package/ecomplus-stores/monocard/functions/ssr/public/img/uploads/banner2.png +0 -0
- package/ecomplus-stores/monocard/functions/ssr/public/img/uploads/banner2.webp +0 -0
- package/ecomplus-stores/monocard/functions/ssr/public/img/uploads/headless.png +0 -0
- package/ecomplus-stores/monocard/functions/ssr/public/img/uploads/headphone.png +0 -0
- package/ecomplus-stores/monocard/functions/ssr/public/img/uploads/headphone.webp +0 -0
- package/ecomplus-stores/monocard/functions/ssr/public/img/uploads/passion.png +0 -0
- package/ecomplus-stores/monocard/functions/ssr/public/img/uploads/passion.webp +0 -0
- package/ecomplus-stores/monocard/functions/ssr/public/img/uploads/pwa-reliable.png +0 -0
- package/ecomplus-stores/monocard/functions/ssr/public/img/uploads/rect8589.png +0 -0
- package/ecomplus-stores/monocard/functions/ssr/public/img/uploads/rect859.png +0 -0
- package/ecomplus-stores/monocard/functions/ssr/public/img/uploads/rect89.png +0 -0
- package/ecomplus-stores/monocard/functions/ssr/public/img/uploads/rect89.webp +0 -0
- package/ecomplus-stores/monocard/functions/ssr/public/img/uploads/ssl-safe.png +0 -0
- package/packages/storefront/content/blog.json +0 -18
- package/packages/storefront/content/brands.json +0 -24
- package/packages/storefront/content/categories.json +0 -24
- package/packages/storefront/content/code.json +0 -5
- package/packages/storefront/content/collections.json +0 -24
- package/packages/storefront/content/contacts.json +0 -13
- package/packages/storefront/content/footer.json +0 -46
- package/packages/storefront/content/header.json +0 -35
- package/packages/storefront/content/home.json +0 -45
- package/packages/storefront/content/info.json +0 -18
- package/packages/storefront/content/maintenance.json +0 -6
- package/packages/storefront/content/menu.json +0 -6
- package/packages/storefront/content/pages/contato.json +0 -6
- package/packages/storefront/content/pages/entrega.json +0 -6
- package/packages/storefront/content/pages/faq.json +0 -6
- package/packages/storefront/content/pages/pagamentos.json +0 -6
- package/packages/storefront/content/pages/privacidade.json +0 -6
- package/packages/storefront/content/pages/sobre-nos.json +0 -6
- package/packages/storefront/content/pages/termos.json +0 -6
- package/packages/storefront/content/pages/trocas.json +0 -6
- package/packages/storefront/content/posts/esta-loja-e-um-pwa.json +0 -9
- package/packages/storefront/content/products.json +0 -32
- package/packages/storefront/content/search.json +0 -8
- package/packages/storefront/content/settings.json +0 -21
- package/packages/storefront/content/social.json +0 -5
- package/packages/storefront/content/widgets/analytics.json +0 -11
- package/packages/storefront/content/widgets/compre-confie.json +0 -11
- package/packages/storefront/content/widgets/ebit.json +0 -11
- package/packages/storefront/content/widgets/fb-pixel.json +0 -12
- package/packages/storefront/content/widgets/gmc-ratings.json +0 -12
- package/packages/storefront/content/widgets/minicart.json +0 -6
- package/packages/storefront/content/widgets/offers-notification.json +0 -11
- package/packages/storefront/content/widgets/opinioes-verificadas.json +0 -18
- package/packages/storefront/content/widgets/product-card.json +0 -10
- package/packages/storefront/content/widgets/product.json +0 -13
- package/packages/storefront/content/widgets/search-engine.json +0 -8
- package/packages/storefront/content/widgets/search.json +0 -6
- package/packages/storefront/content/widgets/tag-manager.json +0 -12
- package/packages/storefront/content/widgets/tawkto.json +0 -12
- package/packages/storefront/content/widgets/trustvox.json +0 -15
- package/packages/storefront/content/widgets/user.json +0 -5
- package/packages/storefront/dist/server/assets/_...slug_.648f7d81.css +0 -4
- package/packages/storefront/dist/server/manifest.webmanifest +0 -1
- package/packages/storefront/dist/server/registerSW.js +0 -1
- package/packages/storefront/public/admin/config.json +0 -1
- package/packages/storefront/public/assets/cms-preview.css +0 -274
- package/packages/storefront/public/assets/cms.css +0 -114
- package/packages/storefront/public/assets/cvv.png +0 -0
- package/packages/storefront/public/assets/icons/bootstrap-icons/font/storefront-icons.woff2 +0 -0
- package/packages/storefront/public/assets/icons/feather-icons/font/storefront-icons.woff2 +0 -0
- package/packages/storefront/public/assets/icons/font-awesome/font/storefront-icons.woff2 +0 -0
- package/packages/storefront/public/assets/icons/line-awesome/font/storefront-icons.woff2 +0 -0
- package/packages/storefront/public/assets/icons/tabler-icons/font/storefront-icons.woff2 +0 -0
- package/packages/storefront/public/assets/img-placeholder.png +0 -0
- package/packages/storefront/public/assets/payments.png +0 -0
- package/packages/storefront/public/assets/ssl-safe.png +0 -0
- package/packages/storefront/public/img/icon.png +0 -0
- package/packages/storefront/public/img/large-icon.png +0 -0
- package/packages/storefront/public/img/uploads/banner1.png +0 -0
- package/packages/storefront/public/img/uploads/banner2.png +0 -0
- package/packages/storefront/public/img/uploads/banner2.webp +0 -0
- package/packages/storefront/public/img/uploads/favicon.png +0 -0
- package/packages/storefront/public/img/uploads/headless.png +0 -0
- package/packages/storefront/public/img/uploads/headphone.png +0 -0
- package/packages/storefront/public/img/uploads/headphone.webp +0 -0
- package/packages/storefront/public/img/uploads/icon.png +0 -0
- package/packages/storefront/public/img/uploads/large-icon.png +0 -0
- package/packages/storefront/public/img/uploads/logo.png +0 -0
- package/packages/storefront/public/img/uploads/logo.webp +0 -0
- package/packages/storefront/public/img/uploads/og-image.png +0 -0
- package/packages/storefront/public/img/uploads/passion.png +0 -0
- package/packages/storefront/public/img/uploads/passion.webp +0 -0
- package/packages/storefront/public/img/uploads/pwa-reliable.png +0 -0
- package/packages/storefront/public/img/uploads/rect8589.png +0 -0
- package/packages/storefront/public/img/uploads/rect859.png +0 -0
- package/packages/storefront/public/img/uploads/rect89.png +0 -0
- package/packages/storefront/public/img/uploads/rect89.webp +0 -0
- package/packages/storefront/public/img/uploads/ssl-safe.png +0 -0
- package/packages/storefront/public/robots.txt +0 -8
- package/packages/storefront/scripts/prerelease.sh +0 -4
- package/packages/storefront/src/layouts/Pages.astro +0 -38
- package/packages/storefront/src/lib/components/TheHeader.vue +0 -49
- package/packages/storefront/src/lib/components/TopBar.vue +0 -133
- package/packages/storefront/src/lib/layouts/Checkout.astro +0 -0
- package/packages/storefront/src/lib/layouts/Pages.astro +0 -26
- package/packages/storefront/src/lib/layouts/PagesHeader.astro +0 -116
- package/packages/storefront/src/lib/main/Home.astro +0 -19
- package/packages/storefront/src/pages/[...slug].astro +0 -36
- package/packages/storefront/src/pages/app/account.astro +0 -0
- package/packages/storefront/src/pages/app/index.astro +0 -0
- package/packages/storefront/src/pages/fallback.astro +0 -19
- package/packages/storefront/src/pages/index.astro +0 -26
- package/packages/storefront/src/scripts/InlineScripts.astro +0 -11
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import logger from 'firebase-functions/lib/logger';
|
|
2
|
+
import api from '@cloudcommerce/api';
|
|
3
|
+
import postTiny from './post-tiny-erp.js';
|
|
4
|
+
import parseStatus from './parsers/status-to-tiny.js';
|
|
5
|
+
import parseOrder from './parsers/order-to-tiny.js';
|
|
6
|
+
|
|
7
|
+
export default async (apiDoc, queueEntry, appData, canCreateNew) => {
|
|
8
|
+
const orderId = queueEntry.nextId;
|
|
9
|
+
let order;
|
|
10
|
+
if (orderId === apiDoc._id) {
|
|
11
|
+
order = apiDoc;
|
|
12
|
+
} else {
|
|
13
|
+
try {
|
|
14
|
+
order = (await api.get(`orders/${orderId}`)).data;
|
|
15
|
+
} catch (err) {
|
|
16
|
+
if (err.statusCode === 404) {
|
|
17
|
+
const msg = `O pedido ${orderId} não existe (:${err.statusCode})`;
|
|
18
|
+
const error = new Error(msg);
|
|
19
|
+
error.isConfigError = true;
|
|
20
|
+
return error;
|
|
21
|
+
}
|
|
22
|
+
throw err;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (!order.financial_status) {
|
|
26
|
+
logger.info(`${orderId} skipped with no financial status`);
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
logger.info(`${orderId} searching order ${order.number}`);
|
|
30
|
+
let tinyData;
|
|
31
|
+
try {
|
|
32
|
+
tinyData = await postTiny('/pedidos.pesquisa.php', {
|
|
33
|
+
numeroEcommerce: String(order.number),
|
|
34
|
+
});
|
|
35
|
+
} catch (err) {
|
|
36
|
+
const status = err.response && err.response.status;
|
|
37
|
+
if (status === 404) {
|
|
38
|
+
tinyData = {};
|
|
39
|
+
} else {
|
|
40
|
+
logger.info(`${orderId} search on tiny ends with status ${status}`);
|
|
41
|
+
throw err;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const { pedidos } = tinyData;
|
|
45
|
+
const tinyStatus = parseStatus(order);
|
|
46
|
+
let originalTinyOrder;
|
|
47
|
+
if (Array.isArray(pedidos)) {
|
|
48
|
+
originalTinyOrder = pedidos.find(({ pedido }) => {
|
|
49
|
+
return order.number === Number(pedido.numero_ecommerce);
|
|
50
|
+
});
|
|
51
|
+
if (originalTinyOrder) {
|
|
52
|
+
originalTinyOrder = originalTinyOrder.pedido;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (!originalTinyOrder) {
|
|
56
|
+
if (!canCreateNew) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
if (appData.approved_orders_only
|
|
60
|
+
&& (tinyStatus === 'aberto' || tinyStatus === 'cancelado')) {
|
|
61
|
+
logger.info(`${orderId} skipped with status "${tinyStatus}"`);
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
const tinyOrder = parseOrder(order, appData);
|
|
65
|
+
logger.info(`${orderId} ${JSON.stringify(tinyOrder)}`);
|
|
66
|
+
return postTiny('/pedido.incluir.php', {
|
|
67
|
+
pedido: {
|
|
68
|
+
pedido: tinyOrder,
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
if (originalTinyOrder) {
|
|
73
|
+
const { id, situacao } = originalTinyOrder;
|
|
74
|
+
logger.info(`${orderId} found with tiny status ${situacao} => ${tinyStatus}`);
|
|
75
|
+
if (tinyStatus && tinyStatus !== situacao) {
|
|
76
|
+
return postTiny('/pedido.alterar.situacao', {
|
|
77
|
+
id,
|
|
78
|
+
situacao: tinyStatus,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return null;
|
|
83
|
+
};
|
|
84
|
+
// # sourceMappingURL=export-order-to-tiny.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"export-order-to-tiny.js","sourceRoot":"","sources":["../../src/integration/export-order-to-tiny.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,+BAA+B,CAAC;AACnD,OAAO,GAAG,MAAM,oBAAoB,CAAC;AACrC,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AACvC,OAAO,WAAW,MAAM,0BAA0B,CAAC;AACnD,OAAO,UAAU,MAAM,yBAAyB,CAAC;AAEjD,eAAe,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE;IACjE,MAAM,OAAO,GAAG,UAAU,CAAC,MAAM,CAAC;IAClC,IAAI,KAAa,CAAC;IAClB,IAAI,OAAO,KAAK,MAAM,CAAC,GAAG,EAAE;QAC1B,KAAK,GAAG,MAAM,CAAC;KAChB;SAAM;QACL,IAAI;YACF,KAAK,GAAG,C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ACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import api from '@cloudcommerce/api';
|
|
2
|
+
import postTiny from './post-tiny-erp.js';
|
|
3
|
+
import parseProduct from './parsers/product-to-tiny.js';
|
|
4
|
+
|
|
5
|
+
export default async (apiDoc, queueEntry, appData, canCreateNew) => {
|
|
6
|
+
const productId = queueEntry.nextId;
|
|
7
|
+
let product;
|
|
8
|
+
if (productId === apiDoc._id) {
|
|
9
|
+
product = apiDoc;
|
|
10
|
+
} else {
|
|
11
|
+
try {
|
|
12
|
+
product = (await api.get(`products/${productId}`)).data;
|
|
13
|
+
} catch (err) {
|
|
14
|
+
if (err.statusCode === 404) {
|
|
15
|
+
const msg = `O produto ${productId} não existe (:${err.statusCode})`;
|
|
16
|
+
const error = new Error(msg);
|
|
17
|
+
error.isConfigError = true;
|
|
18
|
+
return error;
|
|
19
|
+
}
|
|
20
|
+
throw err;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
let tinyData;
|
|
24
|
+
try {
|
|
25
|
+
tinyData = await postTiny('/produtos.pesquisa.php', {
|
|
26
|
+
pesquisa: product.sku,
|
|
27
|
+
});
|
|
28
|
+
} catch (err) {
|
|
29
|
+
if (err.response && err.response.status === 404) {
|
|
30
|
+
tinyData = {};
|
|
31
|
+
} else {
|
|
32
|
+
throw err;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const { produtos } = tinyData;
|
|
36
|
+
let originalTinyProduct;
|
|
37
|
+
if (Array.isArray(produtos)) {
|
|
38
|
+
originalTinyProduct = produtos.find(({ produto }) => {
|
|
39
|
+
return product.sku === String(produto.codigo);
|
|
40
|
+
});
|
|
41
|
+
if (originalTinyProduct) {
|
|
42
|
+
originalTinyProduct = originalTinyProduct.produto;
|
|
43
|
+
} else if (!canCreateNew) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const tinyProduct = parseProduct(product, originalTinyProduct, appData);
|
|
48
|
+
return tinyProduct
|
|
49
|
+
? postTiny(originalTinyProduct ? '/produto.alterar.php' : '/produto.incluir.php', {
|
|
50
|
+
produto: {
|
|
51
|
+
produtos: [{
|
|
52
|
+
produto: tinyProduct,
|
|
53
|
+
}],
|
|
54
|
+
},
|
|
55
|
+
})
|
|
56
|
+
: null;
|
|
57
|
+
};
|
|
58
|
+
// # sourceMappingURL=export-product-to-tiny.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"export-product-to-tiny.js","sourceRoot":"","sources":["../../src/integration/export-product-to-tiny.ts"],"names":[],"mappings":"AACA,OAAO,GAAG,MAAM,oBAAoB,CAAC;AACrC,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AACvC,OAAO,YAAY,MAAM,2BAA2B,CAAC;AAErD,eAAe,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE;IACjE,MAAM,SAAS,GAAG,UAAU,CAAC,MAAM,CAAC;IACpC,IAAI,OAAiB,CAAC;IACtB,IAAI,SAAS,KAAK,MAAM,CAAC,GAAG,EAAE;QAC5B,OAAO,GAAG,MAAM,CAAC;KAClB;SAAM;QACL,IAAI;YACF,OAAO,GAAG,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC,YAAY,SAAS,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;SACzD;QAAC,OAAO,GAAQ,EAAE;YACjB,IAAI,GAAG,CAAC,UAAU,KAAK,GAAG,EAAE;gBAC1B,MAAM,GAAG,GAAG,aAAa,SAAS,iBAAiB,GAAG,CAAC,UAAU,GAAG,CAAC;gBACrE,MAAM,KAAK,GAAQ,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;gBAClC,KAAK,CAAC,aAAa,GAAG,IAAI,CAAC;gBAC3B,OAAO,KAAK,CAAC;aACd;YACD,MAAM,GAAG,CAAC;SACX;KACF;IAED,IAAI,QAA4B,CAAC;IACjC,IAAI;QACF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,CAAO,EAAE,EAAE;IACzB,oCAAoC;IACpC,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,GAAG;UAChD,CAAC,CAAC,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,GAAG;UACpD,CAAC,CAAC,WAAW,EAAE,CAAC;AACtB,CAAC,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// eslint-disable-next-line import/no-unresolved
|
|
2
|
+
import { getFirestore } from 'firebase-admin/firestore';
|
|
3
|
+
import logger from 'firebase-functions/lib/logger';
|
|
4
|
+
import api from '@cloudcommerce/api';
|
|
5
|
+
import postTiny from './post-tiny-erp.js';
|
|
6
|
+
import parseOrder from './parsers/order-from-tiny.js';
|
|
7
|
+
import parseStatus from './parsers/status-from-tiny.js';
|
|
8
|
+
|
|
9
|
+
const getLastStatus = (records) => {
|
|
10
|
+
let statusRecord;
|
|
11
|
+
records.forEach((record) => {
|
|
12
|
+
if (record
|
|
13
|
+
&& (!statusRecord || !record.date_time || record.date_time >= statusRecord.date_time)) {
|
|
14
|
+
statusRecord = record;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
return statusRecord && statusRecord.status;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default async (apiDoc, queueEntry) => {
|
|
21
|
+
const getTinyOrder = async (tinyOrderId) => {
|
|
22
|
+
const { pedido } = await postTiny('/pedido.obter.php', {
|
|
23
|
+
id: Number(tinyOrderId),
|
|
24
|
+
});
|
|
25
|
+
const situacao = typeof pedido.situacao === 'string'
|
|
26
|
+
? pedido.situacao.toLowerCase()
|
|
27
|
+
: null;
|
|
28
|
+
const orderNumber = pedido.numero_ecommerce;
|
|
29
|
+
logger.info(`Import order n${orderNumber} ${tinyOrderId} => ${situacao}`);
|
|
30
|
+
const documentRef = getFirestore().doc(`tinyErpOrders/${tinyOrderId}`);
|
|
31
|
+
const documentSnapshot = await documentRef.get();
|
|
32
|
+
if (documentSnapshot.exists
|
|
33
|
+
&& documentSnapshot.get('situacao') === situacao) {
|
|
34
|
+
logger.info(`>> Ignoring Tiny order n${orderNumber} ${tinyOrderId} with same status`);
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
let listEndpoint = 'orders?limit=1&fields=_id,payments_history,fulfillments,shipping_lines';
|
|
38
|
+
if (orderNumber) {
|
|
39
|
+
listEndpoint += `&number=${orderNumber}`;
|
|
40
|
+
} else {
|
|
41
|
+
listEndpoint += `&hidden_metafields.value=${tinyOrderId}_tiny`;
|
|
42
|
+
}
|
|
43
|
+
const { data: { result } } = await api.get(listEndpoint);
|
|
44
|
+
if (!result.length) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
const order = result[0];
|
|
48
|
+
const partialOrder = await parseOrder(pedido, order.shipping_lines);
|
|
49
|
+
const promises = [];
|
|
50
|
+
if (partialOrder && Object.keys(partialOrder).length) {
|
|
51
|
+
promises.push(api.patch(`orders/${order._id}`, partialOrder));
|
|
52
|
+
}
|
|
53
|
+
const { fulfillmentStatus, financialStatus } = parseStatus(situacao);
|
|
54
|
+
const data = {
|
|
55
|
+
date_time: new Date().toISOString(),
|
|
56
|
+
flags: ['from-tiny'],
|
|
57
|
+
};
|
|
58
|
+
[
|
|
59
|
+
[financialStatus, 'payments_history'],
|
|
60
|
+
[fulfillmentStatus, 'fulfillments'],
|
|
61
|
+
].forEach(([newStatus, subresource]) => {
|
|
62
|
+
if (newStatus
|
|
63
|
+
// @ts-ignore
|
|
64
|
+
&& (!order[subresource] || getLastStatus(order[subresource]) !== newStatus)) {
|
|
65
|
+
data.status = newStatus;
|
|
66
|
+
promises.push(api.post(`orders/${order._id}/${subresource}`, data));
|
|
67
|
+
logger.info(`${order._id} updated to ${newStatus} from Tiny ${tinyOrderId}`);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
return Promise.all(promises)
|
|
71
|
+
.then(([firstResult]) => {
|
|
72
|
+
documentRef.set({ situacao }).catch(logger.error);
|
|
73
|
+
return (firstResult && firstResult.response) || firstResult;
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
const tinyOrderNumber = queueEntry.nextId;
|
|
77
|
+
if (typeof tinyOrderNumber === 'string' && tinyOrderNumber.startsWith('id:')) {
|
|
78
|
+
return getTinyOrder(tinyOrderNumber.substring(3));
|
|
79
|
+
}
|
|
80
|
+
return postTiny('/pedidos.pesquisa.php', {
|
|
81
|
+
numero: tinyOrderNumber,
|
|
82
|
+
}).then(({ pedidos }) => {
|
|
83
|
+
const tinyOrder = pedidos.find(({ pedido }) => {
|
|
84
|
+
return Number(tinyOrderNumber) === Number(pedido.numero);
|
|
85
|
+
});
|
|
86
|
+
if (tinyOrder) {
|
|
87
|
+
return getTinyOrder(tinyOrder.pedido.id);
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
// # sourceMappingURL=import-order-from-tiny.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import-order-from-tiny.js","sourceRoot":"","sources":["../../src/integration/import-order-from-tiny.ts"],"names":[],"mappings":"AACA,gDAAgD;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,MAAM,MAAM,+BAA+B,CAAC;AACnD,OAAO,GAAG,MAAM,oBAAoB,CAAC;AACrC,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AACvC,OAAO,UAAU,MAAM,2BAA2B,CAAC;AACnD,OAAO,WAAW,MAAM,4BAA4B,CAAC;AAErD,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE,EAAE;IAChC,IAAI,YAAY,CAAC;IACjB,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;QACzB,IACE,MAAM;eACH,CAAC,CAAC,YA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/lib/logger';
|
|
2
|
+
import api from '@cloudcommerce/api';
|
|
3
|
+
import updateAppData from '@cloudcommerce/firebase/lib/helpers/update-app-data';
|
|
4
|
+
import postTiny from './post-tiny-erp.js';
|
|
5
|
+
import parseProduct from './parsers/product-from-tiny.js';
|
|
6
|
+
|
|
7
|
+
export default async (apiDoc, queueEntry, appData, canCreateNew, isHiddenQueue) => {
|
|
8
|
+
const [sku, productId] = String(queueEntry.nextId).split(';:');
|
|
9
|
+
let product = null;
|
|
10
|
+
try {
|
|
11
|
+
product = (await api.get(`products/${(productId || `sku:${sku}`)}`)).data;
|
|
12
|
+
} catch (err) {
|
|
13
|
+
if (err.statusCode !== 404) {
|
|
14
|
+
throw err;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
let hasVariations = false;
|
|
18
|
+
let variationId;
|
|
19
|
+
if (product) {
|
|
20
|
+
const { variations } = product;
|
|
21
|
+
hasVariations = Boolean(variations && variations.length);
|
|
22
|
+
const variation = variations?.find((variation) => sku === variation.sku);
|
|
23
|
+
if (variation) {
|
|
24
|
+
variationId = variation._id;
|
|
25
|
+
} else {
|
|
26
|
+
logger.info(`SKU not found ${sku}`);
|
|
27
|
+
if (!isHiddenQueue && !appData.update_product) {
|
|
28
|
+
const msg = `${sku
|
|
29
|
+
} corresponde a um produto com variações,`
|
|
30
|
+
+ ' especifique o SKU da variação para importar.';
|
|
31
|
+
const err = new Error(msg);
|
|
32
|
+
err.isConfigError = true;
|
|
33
|
+
return err;
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const handleTinyStock = ({ produto, tipo }, tinyProduct) => {
|
|
39
|
+
let quantity = Number(produto.saldo) || Number(produto.estoqueAtual);
|
|
40
|
+
if (produto.saldoReservado) {
|
|
41
|
+
quantity -= Number(produto.saldoReservado);
|
|
42
|
+
}
|
|
43
|
+
if (product && (!appData.update_product || variationId)) {
|
|
44
|
+
if (!Number.isNaN(quantity)) {
|
|
45
|
+
if (quantity < 0) {
|
|
46
|
+
quantity = 0;
|
|
47
|
+
}
|
|
48
|
+
let endpoint = `products/${product._id}`;
|
|
49
|
+
if (variationId) {
|
|
50
|
+
endpoint += `variations/${variationId}`;
|
|
51
|
+
}
|
|
52
|
+
endpoint += '/quantity';
|
|
53
|
+
logger.info(endpoint, { quantity });
|
|
54
|
+
// @ts-ignore
|
|
55
|
+
return api.put(endpoint, quantity);
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
if (!tinyProduct) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
return postTiny('/produto.obter.php', { id: tinyProduct.id })
|
|
63
|
+
.then(({ produto }) => {
|
|
64
|
+
let method;
|
|
65
|
+
let endpoint;
|
|
66
|
+
let productId = product && product._id;
|
|
67
|
+
if (productId) {
|
|
68
|
+
method = 'PATCH';
|
|
69
|
+
endpoint = `products/${productId}`;
|
|
70
|
+
} else if (tipo === 'produto' || !tipo) {
|
|
71
|
+
method = 'POST';
|
|
72
|
+
endpoint = 'products';
|
|
73
|
+
} else {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
// @ts-ignore
|
|
77
|
+
return parseProduct(produto, method === 'POST').then((product) => {
|
|
78
|
+
if (!Number.isNaN(quantity)) {
|
|
79
|
+
product.quantity = quantity >= 0 ? quantity : 0;
|
|
80
|
+
}
|
|
81
|
+
logger.info(`${method} ${endpoint}`);
|
|
82
|
+
const promise = api({
|
|
83
|
+
method,
|
|
84
|
+
endpoint,
|
|
85
|
+
data: product,
|
|
86
|
+
});
|
|
87
|
+
if (Array.isArray(produto.variacoes) && produto.variacoes.length) {
|
|
88
|
+
if (!queueEntry.app) {
|
|
89
|
+
logger.warn('Variations cannot be queued without `queueEntry.app`');
|
|
90
|
+
return promise;
|
|
91
|
+
}
|
|
92
|
+
promise.then((response) => {
|
|
93
|
+
let skus = appData.__importation && appData.__importation.skus;
|
|
94
|
+
if (!Array.isArray(skus)) {
|
|
95
|
+
skus = [];
|
|
96
|
+
}
|
|
97
|
+
let isQueuedVariations = false;
|
|
98
|
+
produto.variacoes.forEach(({ variacao }) => {
|
|
99
|
+
const { codigo } = variacao;
|
|
100
|
+
let skuAndId = codigo;
|
|
101
|
+
if (!productId) {
|
|
102
|
+
productId = response.data && response.data._id;
|
|
103
|
+
}
|
|
104
|
+
if (productId) {
|
|
105
|
+
skuAndId += `;:${productId}`;
|
|
106
|
+
}
|
|
107
|
+
if (!skus.includes(codigo) && !skus.includes(skuAndId)) {
|
|
108
|
+
isQueuedVariations = true;
|
|
109
|
+
skus.push(skuAndId);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
return isQueuedVariations
|
|
113
|
+
? updateAppData(queueEntry.app, {
|
|
114
|
+
__importation: {
|
|
115
|
+
...appData.__importation,
|
|
116
|
+
skus,
|
|
117
|
+
},
|
|
118
|
+
})
|
|
119
|
+
: response;
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
return promise;
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
logger.info(JSON.stringify({
|
|
127
|
+
sku,
|
|
128
|
+
productId,
|
|
129
|
+
hasVariations,
|
|
130
|
+
variationId,
|
|
131
|
+
}));
|
|
132
|
+
const { tinyStockUpdate } = queueEntry;
|
|
133
|
+
if (tinyStockUpdate && isHiddenQueue && productId) {
|
|
134
|
+
return handleTinyStock(tinyStockUpdate);
|
|
135
|
+
}
|
|
136
|
+
return postTiny('/produtos.pesquisa.php', { pesquisa: sku })
|
|
137
|
+
.then(({ produtos }) => {
|
|
138
|
+
if (Array.isArray(produtos)) {
|
|
139
|
+
let tinyProduct = produtos.find(({ produto }) => sku === String(produto.codigo));
|
|
140
|
+
if (tinyProduct) {
|
|
141
|
+
tinyProduct = tinyProduct.produto;
|
|
142
|
+
if (!hasVariations || variationId) {
|
|
143
|
+
if (tinyStockUpdate) {
|
|
144
|
+
return handleTinyStock(tinyStockUpdate, tinyProduct);
|
|
145
|
+
}
|
|
146
|
+
return postTiny('/produto.obter.estoque.php', { id: tinyProduct.id })
|
|
147
|
+
.then((tinyStock) => handleTinyStock(tinyStock, tinyProduct));
|
|
148
|
+
}
|
|
149
|
+
return handleTinyStock({ produto: {} }, tinyProduct);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
const msg = `SKU ${sku} não encontrado no Tiny`;
|
|
153
|
+
const err = new Error(msg);
|
|
154
|
+
err.isConfigError = true;
|
|
155
|
+
throw new Error(err);
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
// # sourceMappingURL=import-product-from-tiny.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import-product-from-tiny.js","sourceRoot":"","sources":["../../src/integration/import-product-from-tiny.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,+BAA+B,CAAC;AACnD,OAAO,GAAG,MAAM,oBAAoB,CAAC;AACrC,OAAO,aAAa,MAAM,qDAAqD,CAAC;AAChF,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AACvC,OAAO,YAAY,MAAM,6BAA6B,CAAC;AAEvD,eAAe,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,EAAE;IAChF,MAAM,CAAC,GAAG,EAAE,SAAS,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC/D,IAAI,OAAO,GAAoB,IAAI,CAAC;IACpC,IAAI;QACF,OAAO,GAAG,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC,YAAY,CAAC,SAAS,IAAI,OAAO,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;KAC3E;IAAC,OAAO,GAAQ,EAAE;QACjB,IAAI,GAAG,CAAC,UAAU,KAAK,GAAG,EAAE;YAC1B,MAAM,GAAG,CAAC;SACX;KACF;IACD,IAAI,aA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E,EAAE,EAAE,EAAE,WAAW,CAAC,EAAE,EAAE,CAAC;yBAClE,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,eAAe,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC,CAAC;iBACjE;gBACD,OAAO,eAAe,CAAC,EAAE,OAAO,EAAE,EAAE,EAAS,EAAE,WAAW,CAAC,CAAC;aAC7D;SACF;QACD,MAAM,GAAG,GAAG,OAAO,GAAG,yBAAyB,CAAC;QAChD,MAAM,GAAG,GAAQ,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;QAChC,GAAG,CAAC,aAAa,GAAG,IAAI,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;AACP,CAAC,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import postTiny from '../post-tiny-erp.js';
|
|
2
|
+
|
|
3
|
+
export default (tinyOrder, shippingLines) => new Promise((resolve, reject) => {
|
|
4
|
+
const partialOrder = {};
|
|
5
|
+
if (tinyOrder.obs_interna) {
|
|
6
|
+
partialOrder.staff_notes = tinyOrder.obs_interna;
|
|
7
|
+
}
|
|
8
|
+
if (shippingLines && shippingLines.length) {
|
|
9
|
+
const shippingLine = shippingLines[0];
|
|
10
|
+
if ((tinyOrder.codigo_rastreamento || tinyOrder.url_rastreamento)
|
|
11
|
+
&& (!shippingLine.tracking_codes || !shippingLine.tracking_codes.length)) {
|
|
12
|
+
let link;
|
|
13
|
+
if (tinyOrder.url_rastreamento) {
|
|
14
|
+
link = tinyOrder.url_rastreamento;
|
|
15
|
+
}
|
|
16
|
+
const tracking = {
|
|
17
|
+
code: String(tinyOrder.codigo_rastreamento)
|
|
18
|
+
|| link.replace(/^https?:\/\/[^/]+/, '').replace(/^[^?]+\?/, '').substring(0, 70),
|
|
19
|
+
link,
|
|
20
|
+
};
|
|
21
|
+
shippingLine.tracking_codes = [tracking];
|
|
22
|
+
partialOrder.shipping_lines = shippingLines;
|
|
23
|
+
}
|
|
24
|
+
if (tinyOrder.id_nota_fiscal > 0) {
|
|
25
|
+
if (!shippingLine.invoices) {
|
|
26
|
+
shippingLine.invoices = [];
|
|
27
|
+
}
|
|
28
|
+
postTiny('/nota.fiscal.obter.php', { id: tinyOrder.id_nota_fiscal })
|
|
29
|
+
.then((tinyInvoice) => {
|
|
30
|
+
const number = String(tinyInvoice.nota_fiscal.numero);
|
|
31
|
+
if (number && !shippingLine.invoices.find((invoice) => invoice.number === number)) {
|
|
32
|
+
shippingLine.invoices.push({
|
|
33
|
+
number,
|
|
34
|
+
serial_number: String(tinyInvoice.nota_fiscal.serie),
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
partialOrder.shipping_lines = shippingLines;
|
|
38
|
+
resolve(partialOrder);
|
|
39
|
+
})
|
|
40
|
+
.catch(reject);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
resolve(partialOrder);
|
|
45
|
+
});
|
|
46
|
+
// # sourceMappingURL=order-from-tiny.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"order-from-tiny.js","sourceRoot":"","sources":["../../../src/integration/parsers/order-from-tiny.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,kBAAkB,CAAC;AAExC,eAAe,CAAC,SAAS,EAAE,aAAa,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;IAC3E,MAAM,YAAY,GAAwB,EAAE,CAAC;IAC7C,IAAI,SAAS,CAAC,WAAW,EAAE;QACzB,YAAY,CAAC,WAAW,GAAG,SAAS,CAAC,WAAW,CAAC;KAClD;IAED,IAAI,aAAa,IAAI,aAAa,CAAC,MAAM,EAAE;QACzC,MAAM,YAAY,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;QACtC,IACE,CAAC,SAAS,CAAC,mBAAmB,IAAI,SAAS,CAAC,gBAAgB,CAAC;eAC1D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