@cloudcommerce/app-tiny-erp 0.0.113 → 0.0.115

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 (36) hide show
  1. package/.turbo/turbo-build.log +5 -25
  2. package/package.json +7 -7
  3. package/lib/event-to-tiny.js +0 -115
  4. package/lib/event-to-tiny.js.map +0 -1
  5. package/lib/index.js +0 -2
  6. package/lib/index.js.map +0 -1
  7. package/lib/integration/after-tiny-queue.js +0 -79
  8. package/lib/integration/after-tiny-queue.js.map +0 -1
  9. package/lib/integration/export-order-to-tiny.js +0 -84
  10. package/lib/integration/export-order-to-tiny.js.map +0 -1
  11. package/lib/integration/export-product-to-tiny.js +0 -58
  12. package/lib/integration/export-product-to-tiny.js.map +0 -1
  13. package/lib/integration/helpers/format-tiny-date.js +0 -7
  14. package/lib/integration/helpers/format-tiny-date.js.map +0 -1
  15. package/lib/integration/import-order-from-tiny.js +0 -92
  16. package/lib/integration/import-order-from-tiny.js.map +0 -1
  17. package/lib/integration/import-product-from-tiny.js +0 -158
  18. package/lib/integration/import-product-from-tiny.js.map +0 -1
  19. package/lib/integration/parsers/order-from-tiny.js +0 -46
  20. package/lib/integration/parsers/order-from-tiny.js.map +0 -1
  21. package/lib/integration/parsers/order-to-tiny.js +0 -193
  22. package/lib/integration/parsers/order-to-tiny.js.map +0 -1
  23. package/lib/integration/parsers/product-from-tiny.js +0 -199
  24. package/lib/integration/parsers/product-from-tiny.js.map +0 -1
  25. package/lib/integration/parsers/product-to-tiny.js +0 -129
  26. package/lib/integration/parsers/product-to-tiny.js.map +0 -1
  27. package/lib/integration/parsers/status-from-tiny.js +0 -34
  28. package/lib/integration/parsers/status-from-tiny.js.map +0 -1
  29. package/lib/integration/parsers/status-to-tiny.js +0 -39
  30. package/lib/integration/parsers/status-to-tiny.js.map +0 -1
  31. package/lib/integration/post-tiny-erp.js +0 -47
  32. package/lib/integration/post-tiny-erp.js.map +0 -1
  33. package/lib/tiny-erp.js +0 -18
  34. package/lib/tiny-erp.js.map +0 -1
  35. package/lib/tiny-webhook.js +0 -92
  36. package/lib/tiny-webhook.js.map +0 -1
@@ -1,25 +1,5 @@
1
- @cloudcommerce/app-tiny-erp:build: cache hit, replaying output fa63d64672c13f8d
2
- @cloudcommerce/app-tiny-erp:build: 
3
- @cloudcommerce/app-tiny-erp:build: > @cloudcommerce/app-tiny-erp@0.0.112 build /home/leo/code/ecomplus/cloud-commerce/packages/apps/tiny-erp
4
- @cloudcommerce/app-tiny-erp:build: > sh ../../../scripts/build-lib.sh
5
- @cloudcommerce/app-tiny-erp:build: 
6
- @cloudcommerce/app-tiny-erp:build: 
7
- @cloudcommerce/app-tiny-erp:build: /home/leo/code/ecomplus/cloud-commerce/packages/apps/tiny-erp/lib/integration/after-tiny-queue.js
8
- @cloudcommerce/app-tiny-erp:build:  37:32 warning 'data' is already declared in the upper scope on line 29 column 17 no-shadow
9
- @cloudcommerce/app-tiny-erp:build: 
10
- @cloudcommerce/app-tiny-erp:build: /home/leo/code/ecomplus/cloud-commerce/packages/apps/tiny-erp/lib/integration/import-product-from-tiny.js
11
- @cloudcommerce/app-tiny-erp:build:  22:41 warning 'variation' is already declared in the upper scope on line 22 column 11 no-shadow
12
- @cloudcommerce/app-tiny-erp:build:  63:16 warning 'produto' is already declared in the upper scope on line 38 column 30 no-shadow
13
- @cloudcommerce/app-tiny-erp:build:  66:13 warning 'productId' is already declared in the upper scope on line 8 column 15 no-shadow
14
- @cloudcommerce/app-tiny-erp:build:  77:63 warning 'product' is already declared in the upper scope on line 9 column 7 no-shadow
15
- @cloudcommerce/app-tiny-erp:build: 
16
- @cloudcommerce/app-tiny-erp:build: /home/leo/code/ecomplus/cloud-commerce/packages/apps/tiny-erp/lib/integration/parsers/product-from-tiny.js
17
- @cloudcommerce/app-tiny-erp:build:  27:16 warning 'data' is already declared in the upper scope on line 17 column 14 no-shadow
18
- @cloudcommerce/app-tiny-erp:build: 
19
- @cloudcommerce/app-tiny-erp:build: /home/leo/code/ecomplus/cloud-commerce/packages/apps/tiny-erp/lib/integration/parsers/product-to-tiny.js
20
- @cloudcommerce/app-tiny-erp:build:  13:14 warning Do not nest ternary expressions no-nested-ternary
21
- @cloudcommerce/app-tiny-erp:build:  60:21 warning Do not nest ternary expressions no-nested-ternary
22
- @cloudcommerce/app-tiny-erp:build:  117:42 warning 'i' is already declared in the upper scope on line 106 column 45 no-shadow
23
- @cloudcommerce/app-tiny-erp:build: 
24
- @cloudcommerce/app-tiny-erp:build: ✖ 9 problems (0 errors, 9 warnings)
25
- @cloudcommerce/app-tiny-erp:build: 
1
+ @cloudcommerce/app-tiny-erp:build: cache hit, replaying output d6d2ca7c26b888b0
2
+ @cloudcommerce/app-tiny-erp:build: 
3
+ @cloudcommerce/app-tiny-erp:build: > @cloudcommerce/app-tiny-erp@0.0.114 build /home/leo/code/ecomplus/cloud-commerce/packages/apps/tiny-erp
4
+ @cloudcommerce/app-tiny-erp:build: > sh ../../../scripts/build-lib.sh
5
+ @cloudcommerce/app-tiny-erp:build: 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-tiny-erp",
3
3
  "type": "module",
4
- "version": "0.0.113",
4
+ "version": "0.0.115",
5
5
  "description": "E-Com Plus Cloud Commerce app for Tiny ERP",
6
6
  "main": "lib/tiny-erp.js",
7
7
  "repository": {
@@ -16,17 +16,17 @@
16
16
  },
17
17
  "homepage": "https://github.com/ecomplus/cloud-commerce/tree/main/packages/apps/tiny-erp#readme",
18
18
  "dependencies": {
19
- "@cloudcommerce/api": "0.0.113",
20
- "@cloudcommerce/firebase": "0.0.113",
19
+ "@cloudcommerce/api": "0.0.115",
20
+ "@cloudcommerce/firebase": "0.0.115",
21
21
  "@ecomplus/utils": "^1.4.1",
22
- "axios": "^0.27.2",
23
- "firebase-admin": "^11.0.1",
22
+ "axios": "^1.1.2",
23
+ "firebase-admin": "^11.1.0",
24
24
  "firebase-functions": "^3.24.1",
25
25
  "form-data": "^4.0.0"
26
26
  },
27
27
  "devDependencies": {
28
- "@cloudcommerce/types": "0.0.113",
29
- "@firebase/app-types": "^0.7.0"
28
+ "@cloudcommerce/types": "0.0.115",
29
+ "@firebase/app-types": "^0.8.0"
30
30
  },
31
31
  "scripts": {
32
32
  "build": "sh ../../../scripts/build-lib.sh"
@@ -1,115 +0,0 @@
1
- import logger from 'firebase-functions/lib/logger';
2
- import exportProduct from './integration/export-product-to-tiny.js';
3
- import exportOrder from './integration/export-order-to-tiny.js';
4
- import importProduct from './integration/import-product-from-tiny.js';
5
- import importOrder from './integration/import-order-from-tiny.js';
6
- import afterQueue from './integration/after-tiny-queue.js';
7
-
8
- // Async integration handlers
9
- const integrationHandlers = {
10
- exportation: {
11
- product_ids: exportProduct,
12
- order_ids: exportOrder,
13
- },
14
- importation: {
15
- skus: importProduct,
16
- order_numbers: importOrder,
17
- },
18
- };
19
- const handleApiEvent = async ({
20
- evName, apiEvent, apiDoc, app,
21
- }) => {
22
- const resourceId = apiEvent.resource_id;
23
- logger.info('>> ', resourceId, ' - Action: ', apiEvent.action);
24
- const key = `${evName}_${resourceId}`;
25
- const appData = { ...app.data, ...app.hidden_data };
26
- if (Array.isArray(appData.ignore_events)
27
- && appData.ignore_events.includes(evName)) {
28
- logger.info('>> ', key, ' - Ignored event');
29
- return null;
30
- }
31
- logger.info(`> Webhook ${resourceId} [${evName}]`);
32
- if (!process.env.TINY_ERP_TOKEN) {
33
- const tinyToken = appData.tiny_api_token;
34
- if (typeof tinyToken === 'string' && tinyToken) {
35
- process.env.TINY_ERP_TOKEN = tinyToken;
36
- } else {
37
- logger.warn('Missing Tiny API token');
38
- }
39
- }
40
- if (process.env.TINY_ERP_TOKEN) {
41
- let integrationConfig;
42
- let canCreateNew = false;
43
- if (evName === 'applications-dataSet') {
44
- integrationConfig = appData;
45
- canCreateNew = true;
46
- } else if (evName === 'orders-anyStatusSet') {
47
- canCreateNew = Boolean(appData.new_orders);
48
- integrationConfig = {
49
- _exportation: {
50
- order_ids: [resourceId],
51
- },
52
- };
53
- } else {
54
- if (evName === 'products-new') {
55
- if (!appData.new_products) {
56
- return null;
57
- }
58
- } else if (!appData.update_price) {
59
- return null;
60
- }
61
- integrationConfig = {
62
- _exportation: {
63
- product_ids: [resourceId],
64
- },
65
- };
66
- }
67
- if (integrationConfig) {
68
- const actions = Object.keys(integrationHandlers);
69
- actions.forEach((action) => {
70
- for (let i = 1; i <= 3; i++) {
71
- actions.push(`${('_'.repeat(i))}${action}`);
72
- }
73
- });
74
- for (let i = 0; i < actions.length; i++) {
75
- const action = actions[i];
76
- const actionQueues = integrationConfig[action];
77
- if (typeof actionQueues === 'object' && actionQueues) {
78
- // eslint-disable-next-line guard-for-in, no-restricted-syntax
79
- for (const queue in actionQueues) {
80
- const ids = actionQueues[queue];
81
- if (Array.isArray(ids) && ids.length) {
82
- const isHiddenQueue = action.charAt(0) === '_';
83
- const handlerName = action.replace(/^_+/, '');
84
- const handler = integrationHandlers[handlerName][queue.toLowerCase()];
85
- const nextId = ids[0];
86
- if (typeof nextId === 'string'
87
- && nextId.length
88
- && handler) {
89
- const debugFlag = `#${action}/${queue}/${nextId}`;
90
- logger.info(`> Starting ${debugFlag}`);
91
- const queueEntry = {
92
- action,
93
- queue,
94
- nextId,
95
- key,
96
- app,
97
- };
98
- return handler(apiDoc, queueEntry, appData, canCreateNew, isHiddenQueue).then((payload) => {
99
- return afterQueue(queueEntry, appData, app, payload);
100
- }).catch((err) => {
101
- return afterQueue(queueEntry, appData, app, err);
102
- });
103
- }
104
- }
105
- }
106
- }
107
- }
108
- }
109
- }
110
- // Nothing to do
111
- return null;
112
- };
113
-
114
- export default handleApiEvent;
115
- // # sourceMappingURL=event-to-tiny.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"event-to-tiny.js","sourceRoot":"","sources":["../src/event-to-tiny.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,+BAA+B,CAAC;AACnD,OAAO,aAAa,MAAM,sCAAsC,C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AE,GAAG,EAAE,OAAO,CAAC,CAAC;gCACvD,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;oCACf,OAAO,UAAU,CAAC,UAAU,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;gCACnD,CAAC,CAAC,CAAC;6BACJ;yBACF;qBACF;iBACF;aACF;SACF;KACF;IACD,gBAAgB;IAChB,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,eAAe,cAAc,CAAC"}
package/lib/index.js DELETED
@@ -1,2 +0,0 @@
1
- export * from './tiny-erp.js';
2
- // # sourceMappingURL=index.js.map
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC"}
@@ -1,79 +0,0 @@
1
- import logger from 'firebase-functions/lib/logger';
2
- import updateAppData from '@cloudcommerce/firebase/lib/helpers/update-app-data';
3
-
4
- export default async (queueEntry, appData, application, payload) => {
5
- const isError = payload instanceof Error;
6
- const isImportation = queueEntry.action.endsWith('importation');
7
- const logs = appData.logs || [];
8
- const logEntry = {
9
- resource: /order/i.test(queueEntry.queue) ? 'orders' : 'products',
10
- [(isImportation ? 'tiny_id' : 'resource_id')]: queueEntry.nextId,
11
- success: !isError,
12
- imestamp: new Date().toISOString(),
13
- };
14
- let notes;
15
- if (payload) {
16
- if (!isError) {
17
- // payload = response
18
- const { data, status, config } = payload;
19
- if (data && data._id) {
20
- logEntry.resource_id = data._id;
21
- }
22
- notes = `Status ${status}`;
23
- if (config) {
24
- notes += ` [${config.url}]`;
25
- }
26
- } else {
27
- const { config, response } = payload;
28
- if (response) {
29
- const { data, status } = response;
30
- notes = `Error: Status ${status} \n${JSON.stringify(data)}`;
31
- if (!status || status === 429 || status >= 500) {
32
- return setTimeout(() => {
33
- throw payload;
34
- }, 2000);
35
- }
36
- if (config) {
37
- const { url, method, data } = config;
38
- notes += `\n\n-- Request -- \n${method} ${url} \n${JSON.stringify(data)}`;
39
- }
40
- // @ts-ignore
41
- } else if (payload.isConfigError === true) {
42
- notes = payload.message;
43
- } else {
44
- notes = payload.stack;
45
- }
46
- }
47
- }
48
- if (notes) {
49
- logEntry.notes = notes.substring(0, 5000);
50
- }
51
- if (isError || !isImportation) {
52
- logs.unshift(logEntry);
53
- await updateAppData(application, {
54
- logs: logs.slice(0, 200),
55
- }, {
56
- isHiddenData: true,
57
- canSendPubSub: false,
58
- });
59
- }
60
- const { action, queue, nextId } = queueEntry;
61
- let queueList = appData[action][queue];
62
- if (Array.isArray(queueList)) {
63
- const idIndex = queueList.indexOf(nextId);
64
- if (idIndex > -1) {
65
- queueList.splice(idIndex, 1);
66
- }
67
- } else {
68
- queueList = [];
69
- }
70
- const data = {
71
- [action]: {
72
- ...appData[action],
73
- [queue]: queueList,
74
- },
75
- };
76
- logger.info(JSON.stringify(data));
77
- return updateAppData(application, data);
78
- };
79
- // # sourceMappingURL=after-tiny-queue.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"after-tiny-queue.js","sourceRoot":"","sources":["../../src/integration/after-tiny-queue.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,+BAA+B,CAAC;AACnD,OAAO,aAAa,MAAM,qDAAqD,CAAC;AAEhF,eAAe,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE;IACjE,MAAM,OAAO,GAAG,OAAO,YAAY,KAAK,CAAC;IACzC,MAAM,aAAa,GAAG,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;IAChE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,EAAE,CAAC;IAChC,MAAM,QAAQ,GAAG;QACf,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU;QACjE,CAAC,CAAC,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WAAW,EAAE,IAAI,CAAC,CAAC;AAC1C,CAAC,CAAC"}
@@ -1,84 +0,0 @@
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
@@ -1 +0,0 @@
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,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC,UAAU,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;SACnD;QAAC,OAAO,GAAQ,EAAE;YACjB,IAAI,GAAG,CAAC,UAAU,KAAK,GAAG,EAAE;gBAC1B,MAAM,GAAG,GAAG,YAAY,OAAO,iBAAiB,GAAG,CAAC,UAAU,GAAG,CAAC;gBAClE,MAAM,KAAK,GAAQ,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;gB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CAAC;SAC9C;KACF;IACD,IAAI,CAAC,iBAAiB,EAAE;QACtB,IAAI,CAAC,YAAY,EAAE;YACjB,OAAO,IAAI,CAAC;SACb;QACD,IACE,OAAO,CAAC,oBAAoB;eACzB,CAAC,UAAU,KAAK,QAAQ,IAAI,UAAU,KAAK,WAAW,CAAC,EAC1D;YACA,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,yBAAyB,UAAU,GAAG,CAAC,CAAC;YAC9D,OAAO,IAAI,CAAC;SACb;QACD,MAAM,SAAS,GAAG,UAAU,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAC7C,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;QACvD,OAAO,QAAQ,CAAC,qBAAqB,EAAE;YACrC,MAAM,EAAE;gBACN,MAAM,EAAE,SAAS;aAClB;SACF,CAAC,CAAC;KACJ;IAED,IAAI,iBAAiB,EAAE;QACrB,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,iBAAiB,CAAC;QAC3C,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,2BAA2B,QAAQ,OAAO,UAAU,EAAE,CAAC,CAAC;QAC9E,IAAI,UAAU,IAAI,UAAU,KAAK,QAAQ,EAAE;YACzC,OAAO,QAAQ,CAAC,0BAA0B,EAAE;gBAC1C,EAAE;gBACF,QAAQ,EAAE,UAAU;aACrB,CAAC,CAAC;SACJ;KACF;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
@@ -1,58 +0,0 @@
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
@@ -1 +0,0 @@
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,C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AAE,OAAO,CAAC,CAAC;IACxE,OAAO,WAAW;QAChB,CAAC,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,sBAAsB,EAAE;YAChF,OAAO,EAAE;gBACP,QAAQ,EAAE,CAAC;wBACT,OAAO,EAAE,WAAW;qBACrB,CAAC;aACH;SACF,CAAC;QACF,CAAC,CAAC,IAAI,CAAC;AACX,CAAC,CAAC"}
@@ -1,7 +0,0 @@
1
- export default (d) => {
2
- /* eslint-disable prefer-template */
3
- return d.getDate().toString().padStart(2, '0') + '/'
4
- + (d.getMonth() + 1).toString().padStart(2, '0') + '/'
5
- + d.getFullYear();
6
- };
7
- // # sourceMappingURL=format-tiny-date.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"format-tiny-date.js","sourceRoot":"","sources":["../../../src/integration/helpers/format-tiny-date.ts"],"names":[],"mappings":"AAAA,eAAe,CAAC,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"}
@@ -1,92 +0,0 @@
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
@@ -1 +0,0 @@
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,YAAY,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,SAAS,IAAI,YAAY,CAAC,SAAS,CAAC,EACrF;YACA,YAAY,GAAG,MAAM,CAAC;SACvB;IACH,CAAC,CAAC,CAAC;IACH,OAAO,YAAY,IAAI,YAAY,CAAC,MAAM,CAAC;AAC7C,CAAC,CA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