refs #4823 Libraries update

This commit is contained in:
Guillermo Bonet 2023-05-09 14:13:19 +02:00
parent 4aac074a8b
commit 8448dc52c6
5 changed files with 170 additions and 215 deletions

View File

@ -1,5 +1,5 @@
import * as utils from './utils.js'; import * as utils from './utils.js';
import { models, checkConn, closeConn } from './models/index.js'; import { models, checkConn, closeConn } from './models/sequelize.js';
import moment from 'moment'; import moment from 'moment';
import chalk from 'chalk'; import chalk from 'chalk';

View File

@ -2,7 +2,7 @@ import { Sequelize } from 'sequelize';
import dotenv from 'dotenv'; import dotenv from 'dotenv';
import chalk from 'chalk'; import chalk from 'chalk';
import ora from 'ora'; import ora from 'ora';
import { criticalError, updateClientConfig } from './../utils.js'; import { criticalError, updateClientConfig } from '../utils.js';
dotenv.config(); dotenv.config();
const env = process.env; const env = process.env;
@ -134,7 +134,6 @@ try {
targetKey: 'packingConfigurationId', targetKey: 'packingConfigurationId',
}); });
models.botanicalName.belongsTo(models.tradeItem, { models.botanicalName.belongsTo(models.tradeItem, {
foreignKey: 'tradeItemId', foreignKey: 'tradeItemId',
as: 'tradeItem_Fk', as: 'tradeItem_Fk',

242
package-lock.json generated
View File

@ -8,26 +8,50 @@
"dependencies": { "dependencies": {
"chalk": "^5.2.0", "chalk": "^5.2.0",
"dotenv": "^16.0.3", "dotenv": "^16.0.3",
"mariadb": "^3.0.2", "mariadb": "^3.1.2",
"moment": "^2.29.4", "moment": "^2.29.4",
"node-fetch": "^3.3.0", "node-fetch": "^3.3.1",
"ora": "^6.3.0", "ora": "^6.3.0",
"sequelize": "^6.26.0", "sequelize": "^6.31.1",
"uuid": "^9.0.0" "uuid": "^9.0.0"
}, },
"devDependencies": { "devDependencies": {
"eslint": "^8.31.0" "eslint": "^8.40.0"
}
},
"node_modules/@eslint-community/eslint-utils": {
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz",
"integrity": "sha512-1/sA4dwrzBAyeUoQ6oxahHKmrZvsnLCg4RfxW3ZFGGmQkSNQPFNLV9CUEFQP1x9EYXHTo5p6xdhZM1Ne9p/AfA==",
"dev": true,
"dependencies": {
"eslint-visitor-keys": "^3.3.0"
},
"engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
},
"peerDependencies": {
"eslint": "^6.0.0 || ^7.0.0 || >=8.0.0"
}
},
"node_modules/@eslint-community/regexpp": {
"version": "4.5.1",
"resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.5.1.tgz",
"integrity": "sha512-Z5ba73P98O1KUYCCJTUeVpja9RcGoMdncZ6T49FCUl2lN38JtCJ+3WgIDBv0AuY4WChU5PmtJmOCTlN6FZTFKQ==",
"dev": true,
"engines": {
"node": "^12.0.0 || ^14.0.0 || >=16.0.0"
} }
}, },
"node_modules/@eslint/eslintrc": { "node_modules/@eslint/eslintrc": {
"version": "1.4.1", "version": "2.0.3",
"resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.4.1.tgz", "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-2.0.3.tgz",
"integrity": "sha512-XXrH9Uarn0stsyldqDYq8r++mROmWRI1xKMXa640Bb//SY1+ECYX6VzT6Lcx5frD0V30XieqJ0oX9I2Xj5aoMA==", "integrity": "sha512-+5gy6OQfk+xx3q0d6jGZZC3f3KzAkXc/IanVxd1is/VIIziRqqt3ongQz0FiTUXqTk0c7aDB3OaFuKnuSoJicQ==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"ajv": "^6.12.4", "ajv": "^6.12.4",
"debug": "^4.3.2", "debug": "^4.3.2",
"espree": "^9.4.0", "espree": "^9.5.2",
"globals": "^13.19.0", "globals": "^13.19.0",
"ignore": "^5.2.0", "ignore": "^5.2.0",
"import-fresh": "^3.2.1", "import-fresh": "^3.2.1",
@ -42,6 +66,15 @@
"url": "https://opencollective.com/eslint" "url": "https://opencollective.com/eslint"
} }
}, },
"node_modules/@eslint/js": {
"version": "8.40.0",
"resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.40.0.tgz",
"integrity": "sha512-ElyB54bJIhXQYVKjDSvCkPO1iU1tSAeVQJbllWJq1XQSmmA4dgFk8CbiBGpiOPxleE48vDogxCtmMYku4HSVLA==",
"dev": true,
"engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
}
},
"node_modules/@humanwhocodes/config-array": { "node_modules/@humanwhocodes/config-array": {
"version": "0.11.8", "version": "0.11.8",
"resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.8.tgz", "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.8.tgz",
@ -134,14 +167,14 @@
"integrity": "sha512-w+tIMs3rq2afQdsPJlODhoUEKzFP1ayaoyl1CcnwtIlsVe7K7bA1NGm4s3PraqTLlXnbIN84zuBlxBWo1u9BLw==" "integrity": "sha512-w+tIMs3rq2afQdsPJlODhoUEKzFP1ayaoyl1CcnwtIlsVe7K7bA1NGm4s3PraqTLlXnbIN84zuBlxBWo1u9BLw=="
}, },
"node_modules/@types/validator": { "node_modules/@types/validator": {
"version": "13.7.10", "version": "13.7.16",
"resolved": "https://registry.npmjs.org/@types/validator/-/validator-13.7.10.tgz", "resolved": "https://registry.npmjs.org/@types/validator/-/validator-13.7.16.tgz",
"integrity": "sha512-t1yxFAR2n0+VO6hd/FJ9F2uezAZVWHLmpmlJzm1eX03+H7+HsuTAp7L8QJs+2pQCfWkP1+EXsGK9Z9v7o/qPVQ==" "integrity": "sha512-VyKmLktUHYLbrSbsRi241MSUlGYomQgK/tfCNpej3Gt5qDOM10AZ3nU2aR2s5JritClXuOBu4K7MkywVW/Y6Ow=="
}, },
"node_modules/acorn": { "node_modules/acorn": {
"version": "8.8.1", "version": "8.8.2",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.1.tgz", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.2.tgz",
"integrity": "sha512-7zFpHzhnqYKrkYdUjF1HI1bzd0VygEGX8lFk4k5zVMqHEoES+P+7TKI+EvLO9WVMJ8eekdO0aDEK044xTXwPPA==", "integrity": "sha512-xjIYgE8HBrkpd/sJqOGNspf8uHG+NOHGOw6a/Urj8taM2EXfdNAH2oFcPeIFfsv3+kz/mJrS5VuMqbNLjCa2vw==",
"dev": true, "dev": true,
"bin": { "bin": {
"acorn": "bin/acorn" "acorn": "bin/acorn"
@ -308,9 +341,9 @@
} }
}, },
"node_modules/cli-spinners": { "node_modules/cli-spinners": {
"version": "2.7.0", "version": "2.9.0",
"resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.7.0.tgz", "resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.9.0.tgz",
"integrity": "sha512-qu3pN8Y3qHNgE2AFweciB1IfMnmZ/fsNTEE+NOFjmGB2F/7rLhnhzppvpCnN4FovtP26k8lHyy9ptEbNwWFLzw==", "integrity": "sha512-4/aL9X3Wh0yiMQlE+eeRhWP6vclO3QRtw1JHKIT0FFUs5FjpFmESqtMvYZ0+lbzBw900b95mS0hohy+qn2VK/g==",
"engines": { "engines": {
"node": ">=6" "node": ">=6"
}, },
@ -365,9 +398,9 @@
} }
}, },
"node_modules/data-uri-to-buffer": { "node_modules/data-uri-to-buffer": {
"version": "4.0.0", "version": "4.0.1",
"resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.0.tgz", "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz",
"integrity": "sha512-Vr3mLBA8qWmcuschSLAOogKgQ/Jwxulv3RNE4FXnYWRGujzrRWQI4m12fQqRkwX06C0KanhLr4hK+GydchZsaA==", "integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==",
"engines": { "engines": {
"node": ">= 12" "node": ">= 12"
} }
@ -434,9 +467,9 @@
} }
}, },
"node_modules/dottie": { "node_modules/dottie": {
"version": "2.0.2", "version": "2.0.3",
"resolved": "https://registry.npmjs.org/dottie/-/dottie-2.0.2.tgz", "resolved": "https://registry.npmjs.org/dottie/-/dottie-2.0.3.tgz",
"integrity": "sha512-fmrwR04lsniq/uSr8yikThDTrM7epXHBAAjH9TbeH3rEA8tdCO7mRzB9hdmdGyJCxF8KERo9CITcm3kGuoyMhg==" "integrity": "sha512-4liA0PuRkZWQFQjwBypdxPfZaRWiv5tkhMXY2hzsa2pNf5s7U3m9cwUchfNKe8wZQxdGPQQzO6Rm2uGe0rvohQ=="
}, },
"node_modules/escape-string-regexp": { "node_modules/escape-string-regexp": {
"version": "4.0.0", "version": "4.0.0",
@ -451,12 +484,15 @@
} }
}, },
"node_modules/eslint": { "node_modules/eslint": {
"version": "8.31.0", "version": "8.40.0",
"resolved": "https://registry.npmjs.org/eslint/-/eslint-8.31.0.tgz", "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.40.0.tgz",
"integrity": "sha512-0tQQEVdmPZ1UtUKXjX7EMm9BlgJ08G90IhWh0PKDCb3ZLsgAOHI8fYSIzYVZej92zsgq+ft0FGsxhJ3xo2tbuA==", "integrity": "sha512-bvR+TsP9EHL3TqNtj9sCNJVAFK3fBN8Q7g5waghxyRsPLIMwL73XSKnZFK0hk/O2ANC+iAoq6PWMQ+IfBAJIiQ==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"@eslint/eslintrc": "^1.4.1", "@eslint-community/eslint-utils": "^4.2.0",
"@eslint-community/regexpp": "^4.4.0",
"@eslint/eslintrc": "^2.0.3",
"@eslint/js": "8.40.0",
"@humanwhocodes/config-array": "^0.11.8", "@humanwhocodes/config-array": "^0.11.8",
"@humanwhocodes/module-importer": "^1.0.1", "@humanwhocodes/module-importer": "^1.0.1",
"@nodelib/fs.walk": "^1.2.8", "@nodelib/fs.walk": "^1.2.8",
@ -466,11 +502,10 @@
"debug": "^4.3.2", "debug": "^4.3.2",
"doctrine": "^3.0.0", "doctrine": "^3.0.0",
"escape-string-regexp": "^4.0.0", "escape-string-regexp": "^4.0.0",
"eslint-scope": "^7.1.1", "eslint-scope": "^7.2.0",
"eslint-utils": "^3.0.0", "eslint-visitor-keys": "^3.4.1",
"eslint-visitor-keys": "^3.3.0", "espree": "^9.5.2",
"espree": "^9.4.0", "esquery": "^1.4.2",
"esquery": "^1.4.0",
"esutils": "^2.0.2", "esutils": "^2.0.2",
"fast-deep-equal": "^3.1.3", "fast-deep-equal": "^3.1.3",
"file-entry-cache": "^6.0.1", "file-entry-cache": "^6.0.1",
@ -491,7 +526,6 @@
"minimatch": "^3.1.2", "minimatch": "^3.1.2",
"natural-compare": "^1.4.0", "natural-compare": "^1.4.0",
"optionator": "^0.9.1", "optionator": "^0.9.1",
"regexpp": "^3.2.0",
"strip-ansi": "^6.0.1", "strip-ansi": "^6.0.1",
"strip-json-comments": "^3.1.0", "strip-json-comments": "^3.1.0",
"text-table": "^0.2.0" "text-table": "^0.2.0"
@ -507,9 +541,9 @@
} }
}, },
"node_modules/eslint-scope": { "node_modules/eslint-scope": {
"version": "7.1.1", "version": "7.2.0",
"resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.1.1.tgz", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.2.0.tgz",
"integrity": "sha512-QKQM/UXpIiHcLqJ5AOyIW7XZmzjkzQXYE54n1++wb0u9V/abW3l9uQnxX8Z5Xd18xyKIMTUAyQ0k1e8pz6LUrw==", "integrity": "sha512-DYj5deGlHBfMt15J7rdtyKNq/Nqlv5KfU4iodrQ019XESsRnwXH9KAE0y3cwtUHDo2ob7CypAnCqefh6vioWRw==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"esrecurse": "^4.3.0", "esrecurse": "^4.3.0",
@ -517,42 +551,21 @@
}, },
"engines": { "engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0" "node": "^12.22.0 || ^14.17.0 || >=16.0.0"
}
},
"node_modules/eslint-utils": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-3.0.0.tgz",
"integrity": "sha512-uuQC43IGctw68pJA1RgbQS8/NP7rch6Cwd4j3ZBtgo4/8Flj4eGE7ZYSZRN3iq5pVUv6GPdW5Z1RFleo84uLDA==",
"dev": true,
"dependencies": {
"eslint-visitor-keys": "^2.0.0"
},
"engines": {
"node": "^10.0.0 || ^12.0.0 || >= 14.0.0"
}, },
"funding": { "funding": {
"url": "https://github.com/sponsors/mysticatea" "url": "https://opencollective.com/eslint"
},
"peerDependencies": {
"eslint": ">=5"
}
},
"node_modules/eslint-utils/node_modules/eslint-visitor-keys": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz",
"integrity": "sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw==",
"dev": true,
"engines": {
"node": ">=10"
} }
}, },
"node_modules/eslint-visitor-keys": { "node_modules/eslint-visitor-keys": {
"version": "3.3.0", "version": "3.4.1",
"resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.3.0.tgz", "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.1.tgz",
"integrity": "sha512-mQ+suqKJVyeuwGYHAdjMFqjCyfl8+Ldnxuyp3ldiMBFKkvytrXUZWaiPCEav8qDHKty44bD+qV1IP4T+w+xXRA==", "integrity": "sha512-pZnmmLwYzf+kWaM/Qgrvpen51upAktaaiI01nsJD/Yr3lMOdNtq0cxkrrg16w64VtisN6okbs7Q8AfGqj4c9fA==",
"dev": true, "dev": true,
"engines": { "engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0" "node": "^12.22.0 || ^14.17.0 || >=16.0.0"
},
"funding": {
"url": "https://opencollective.com/eslint"
} }
}, },
"node_modules/eslint/node_modules/chalk": { "node_modules/eslint/node_modules/chalk": {
@ -572,14 +585,14 @@
} }
}, },
"node_modules/espree": { "node_modules/espree": {
"version": "9.4.1", "version": "9.5.2",
"resolved": "https://registry.npmjs.org/espree/-/espree-9.4.1.tgz", "resolved": "https://registry.npmjs.org/espree/-/espree-9.5.2.tgz",
"integrity": "sha512-XwctdmTO6SIvCzd9810yyNzIrOrqNYV9Koizx4C/mRhf9uq0o4yHoCEU/670pOxOL/MSraektvSAji79kX90Vg==", "integrity": "sha512-7OASN1Wma5fum5SrNhFMAMJxOUAbhyfQ8dQ//PJaJbNw0URTPWqIghHWt1MmAANKhHZIYOHruW4Kw4ruUWOdGw==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"acorn": "^8.8.0", "acorn": "^8.8.0",
"acorn-jsx": "^5.3.2", "acorn-jsx": "^5.3.2",
"eslint-visitor-keys": "^3.3.0" "eslint-visitor-keys": "^3.4.1"
}, },
"engines": { "engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0" "node": "^12.22.0 || ^14.17.0 || >=16.0.0"
@ -589,9 +602,9 @@
} }
}, },
"node_modules/esquery": { "node_modules/esquery": {
"version": "1.4.0", "version": "1.5.0",
"resolved": "https://registry.npmjs.org/esquery/-/esquery-1.4.0.tgz", "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.5.0.tgz",
"integrity": "sha512-cCDispWt5vHHtwMY2YrAQ4ibFkAL8RbH5YGBnZBc90MolvvfkkQcJro/aZiAQUlQ3qgrYS6D6v8Gc5G5CQsc9w==", "integrity": "sha512-YQLXUplAwJgCydQ78IMJywZCceoqk1oH01OERdSAJc/7U2AylwjhSCLDEtqwg811idIS/9fIU5GjG73IgjKMVg==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"estraverse": "^5.1.0" "estraverse": "^5.1.0"
@ -776,9 +789,9 @@
} }
}, },
"node_modules/globals": { "node_modules/globals": {
"version": "13.19.0", "version": "13.20.0",
"resolved": "https://registry.npmjs.org/globals/-/globals-13.19.0.tgz", "resolved": "https://registry.npmjs.org/globals/-/globals-13.20.0.tgz",
"integrity": "sha512-dkQ957uSRWHw7CFXLUtUHQI3g3aWApYhfNR2O6jn/907riyTYKVBmxYVROkBcY614FSSeSJh7Xm7SrUWCxvJMQ==", "integrity": "sha512-Qg5QtVkCy/kv3FUSlu4ukeZDVf9ee0iXLAUYX13gbR17bnejFTzr4iS9bY7kwCf1NztRNm1t91fjOiyx4CSwPQ==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"type-fest": "^0.20.2" "type-fest": "^0.20.2"
@ -951,9 +964,9 @@
"dev": true "dev": true
}, },
"node_modules/js-sdsl": { "node_modules/js-sdsl": {
"version": "4.2.0", "version": "4.4.0",
"resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.2.0.tgz", "resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.4.0.tgz",
"integrity": "sha512-dyBIzQBDkCqCu+0upx25Y2jGdbTGxE9fshMsCdK0ViOongpV+n5tXRcZY9v7CaVQ79AGS9KA1KHtojxiM7aXSQ==", "integrity": "sha512-FfVSdx6pJ41Oa+CF7RDaFmTnCaFhua+SNYQX74riGOpl96x+2jQCqEfQ2bnXu/5DPCqlRuiqyvTJM0Qjz26IVg==",
"dev": true, "dev": true,
"funding": { "funding": {
"type": "opencollective", "type": "opencollective",
@ -1039,24 +1052,23 @@
} }
}, },
"node_modules/lru-cache": { "node_modules/lru-cache": {
"version": "7.14.1", "version": "7.18.3",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.14.1.tgz", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.18.3.tgz",
"integrity": "sha512-ysxwsnTKdAx96aTRdhDOCQfDgbHnt8SK0KY8SEjO0wHinhWOFTESbjVCMPbU1uGXg/ch4lifqx0wfjOawU2+WA==", "integrity": "sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==",
"engines": { "engines": {
"node": ">=12" "node": ">=12"
} }
}, },
"node_modules/mariadb": { "node_modules/mariadb": {
"version": "3.0.2", "version": "3.1.2",
"resolved": "https://registry.npmjs.org/mariadb/-/mariadb-3.0.2.tgz", "resolved": "https://registry.npmjs.org/mariadb/-/mariadb-3.1.2.tgz",
"integrity": "sha512-dVjiQZ6RW0IXFnX+T/ZEmnqs724DgkQsXqfCyInXn0XxVfO2Px6KbS4M3Ny6UiBg0zJ93SHHvfVBgYO4ZnFvvw==", "integrity": "sha512-ILlC54fkXkvizTJZC1uP7f/REBxuu1k+OWzpiIITIEdS+dGIjFe/Ob3EW9KrdtBa38l3z+odz6elva0RG/y5og==",
"dependencies": { "dependencies": {
"@types/geojson": "^7946.0.10", "@types/geojson": "^7946.0.10",
"@types/node": "^17.0.45", "@types/node": "^17.0.45",
"denque": "^2.1.0", "denque": "^2.1.0",
"iconv-lite": "^0.6.3", "iconv-lite": "^0.6.3",
"lru-cache": "^7.14.0", "lru-cache": "^7.14.0"
"moment-timezone": "^0.5.38"
}, },
"engines": { "engines": {
"node": ">= 12" "node": ">= 12"
@ -1091,11 +1103,11 @@
} }
}, },
"node_modules/moment-timezone": { "node_modules/moment-timezone": {
"version": "0.5.39", "version": "0.5.43",
"resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.39.tgz", "resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.43.tgz",
"integrity": "sha512-hoB6suq4ISDj7BDgctiOy6zljBsdYT0++0ZzZm9rtxIvJhIbQ3nmbgSWe7dNFGurl6/7b1OUkHlmN9JWgXVz7w==", "integrity": "sha512-72j3aNyuIsDxdF1i7CEgV2FfxM1r6aaqJyLB2vwb33mXYyoyLly+F1zbWqhA3/bVIoJ4szlUoMbUnVdid32NUQ==",
"dependencies": { "dependencies": {
"moment": ">= 2.9.0" "moment": "^2.29.4"
}, },
"engines": { "engines": {
"node": "*" "node": "*"
@ -1131,9 +1143,9 @@
} }
}, },
"node_modules/node-fetch": { "node_modules/node-fetch": {
"version": "3.3.0", "version": "3.3.1",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.0.tgz", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.1.tgz",
"integrity": "sha512-BKwRP/O0UvoMKp7GNdwPlObhYGB5DQqwhEDQlNKuoqwVYSxkSZCSbHjnFFmUEtwSKRPU4kNK8PbDYYitwaE3QA==", "integrity": "sha512-cRVc/kyto/7E5shrWca1Wsea4y6tL9iYJE5FBCius3JQfb/4P4I295PfhgbJQBLTx6lATE4z+wK0rPM4VS2uow==",
"dependencies": { "dependencies": {
"data-uri-to-buffer": "^4.0.0", "data-uri-to-buffer": "^4.0.0",
"fetch-blob": "^3.1.4", "fetch-blob": "^3.1.4",
@ -1318,9 +1330,9 @@
} }
}, },
"node_modules/punycode": { "node_modules/punycode": {
"version": "2.1.1", "version": "2.3.0",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.0.tgz",
"integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==", "integrity": "sha512-rRV+zQD8tVFys26lAGR9WUuS4iUAngJScM+ZRSKtvl5tKeZ2t5bvdNFdNHBW9FWR4guGHlgmsZ1G7BSm2wTbuA==",
"dev": true, "dev": true,
"engines": { "engines": {
"node": ">=6" "node": ">=6"
@ -1359,18 +1371,6 @@
"node": ">= 6" "node": ">= 6"
} }
}, },
"node_modules/regexpp": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.2.0.tgz",
"integrity": "sha512-pq2bWo9mVD43nbts2wGv17XLiNLya+GklZ8kaDLV2Z08gDCsGpnKn9BFMepvWuHCbyVvY7J5o5+BVvoQbmlJLg==",
"dev": true,
"engines": {
"node": ">=8"
},
"funding": {
"url": "https://github.com/sponsors/mysticatea"
}
},
"node_modules/resolve-from": { "node_modules/resolve-from": {
"version": "4.0.0", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz",
@ -1396,9 +1396,9 @@
} }
}, },
"node_modules/retry-as-promised": { "node_modules/retry-as-promised": {
"version": "6.1.0", "version": "7.0.4",
"resolved": "https://registry.npmjs.org/retry-as-promised/-/retry-as-promised-6.1.0.tgz", "resolved": "https://registry.npmjs.org/retry-as-promised/-/retry-as-promised-7.0.4.tgz",
"integrity": "sha512-Hj/jY+wFC+SB9SDlIIFWiGOHnNG0swYbGYsOj2BJ8u2HKUaobNKab0OIC0zOLYzDy0mb7A4xA5BMo4LMz5YtEA==" "integrity": "sha512-XgmCoxKWkDofwH8WddD0w85ZfqYz+ZHlr5yo+3YUCfycWawU56T5ckWXsScsj5B8tqUcIG67DxXByo3VUgiAdA=="
}, },
"node_modules/reusify": { "node_modules/reusify": {
"version": "1.0.4", "version": "1.0.4",
@ -1473,9 +1473,9 @@
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
}, },
"node_modules/semver": { "node_modules/semver": {
"version": "7.3.8", "version": "7.5.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.0.tgz",
"integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", "integrity": "sha512-+XC0AD/R7Q2mPSRuy2Id0+CGTZ98+8f+KvwirxOKIEyid+XSx6HbC63p+O4IndTHuX5Z+JxQ0TghCkO5Cg/2HA==",
"dependencies": { "dependencies": {
"lru-cache": "^6.0.0" "lru-cache": "^6.0.0"
}, },
@ -1498,9 +1498,9 @@
} }
}, },
"node_modules/sequelize": { "node_modules/sequelize": {
"version": "6.26.0", "version": "6.31.1",
"resolved": "https://registry.npmjs.org/sequelize/-/sequelize-6.26.0.tgz", "resolved": "https://registry.npmjs.org/sequelize/-/sequelize-6.31.1.tgz",
"integrity": "sha512-Xv82z1FdSn/qwB1IObSxIHV519cFk/vSD28vWs8Y0VucQLn7pK2x2jYjf2Qg/rBUQbCVprDdU7RPf+55rrkc0A==", "integrity": "sha512-cahWtRrYLjqoZP/aurGBoaxn29qQCF4bxkAUPEQ/ozjJjt6mtL4Q113S3N39mQRmX5fgxRbli+bzZARP/N51eg==",
"funding": [ "funding": [
{ {
"type": "opencollective", "type": "opencollective",
@ -1515,9 +1515,9 @@
"inflection": "^1.13.2", "inflection": "^1.13.2",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"moment": "^2.29.1", "moment": "^2.29.1",
"moment-timezone": "^0.5.34", "moment-timezone": "^0.5.35",
"pg-connection-string": "^2.5.0", "pg-connection-string": "^2.5.0",
"retry-as-promised": "^6.1.0", "retry-as-promised": "^7.0.3",
"semver": "^7.3.5", "semver": "^7.3.5",
"sequelize-pool": "^7.1.0", "sequelize-pool": "^7.1.0",
"toposort-class": "^1.0.1", "toposort-class": "^1.0.1",
@ -1716,9 +1716,9 @@
} }
}, },
"node_modules/validator": { "node_modules/validator": {
"version": "13.7.0", "version": "13.9.0",
"resolved": "https://registry.npmjs.org/validator/-/validator-13.7.0.tgz", "resolved": "https://registry.npmjs.org/validator/-/validator-13.9.0.tgz",
"integrity": "sha512-nYXQLCBkpJ8X6ltALua9dRrZDHVYxjJ1wgskNt1lH9fzGjs3tgojGSCBjmEPwkWS1y29+DrizMTW19Pr9uB2nw==", "integrity": "sha512-B+dGG8U3fdtM0/aNK4/X8CXq/EcxU2WPrPEkJGslb47qyHsxmbggTWK0yEA4qnYVNF+nxNlN88o14hIcPmSIEA==",
"engines": { "engines": {
"node": ">= 0.10" "node": ">= 0.10"
} }

View File

@ -5,14 +5,14 @@
"dependencies": { "dependencies": {
"chalk": "^5.2.0", "chalk": "^5.2.0",
"dotenv": "^16.0.3", "dotenv": "^16.0.3",
"mariadb": "^3.0.2", "mariadb": "^3.1.2",
"moment": "^2.29.4", "moment": "^2.29.4",
"node-fetch": "^3.3.0", "node-fetch": "^3.3.1",
"ora": "^6.3.0", "ora": "^6.3.0",
"sequelize": "^6.26.0", "sequelize": "^6.31.1",
"uuid": "^9.0.0" "uuid": "^9.0.0"
}, },
"devDependencies": { "devDependencies": {
"eslint": "^8.31.0" "eslint": "^8.40.0"
} }
} }

130
utils.js
View File

@ -1,6 +1,6 @@
import moment from 'moment'; import moment from 'moment';
import fetch from 'node-fetch'; import fetch from 'node-fetch';
import { models } from './models/index.js'; import { models } from './models/sequelize.js';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
import chalk from 'chalk'; import chalk from 'chalk';
import ora, { spinners } from 'ora'; import ora, { spinners } from 'ora';
@ -404,19 +404,18 @@ export async function syncConn(){
export async function syncTradeItems(){ export async function syncTradeItems(){
const spinner = ora(`Syncing trade items...`).start(); const spinner = ora(`Syncing trade items...`).start();
const suppliers = await models.supplier.findAll(); const suppliers = await models.supplier.findAll({
where: { isConnected: true }
});
let i = 1; let i = 1;
for (let supplier of suppliers) { for (let supplier of suppliers) {
if (!supplier.isConnected) continue;
let query = `${env.API_URL}/trade-items?supplierOrganizationId=${supplier.supplierOrganizationId}`;
let headers = { let headers = {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'Authorization': `Bearer ${await getCurrentToken()}`, 'Authorization': `Bearer ${await getCurrentToken()}`,
'X-Api-Key': process.env.API_KEY 'X-Api-Key': process.env.API_KEY
}; };
try { try {
let request = await fetch(query, { let request = await fetch(`${env.API_URL}/trade-items?supplierOrganizationId=${supplier.supplierOrganizationId}`, {
method: 'GET', method: 'GET',
headers headers
}); });
@ -607,127 +606,84 @@ export async function syncSupplyLines(){
export async function insertItem(tradeItem, supplier) { export async function insertItem(tradeItem, supplier) {
try { try {
// Temporal connection to all suppliers that have trade items const tx = await models.sequelize.transaction();
let currentSupp = await models.supplier.findOne({
where: {
supplierOrganizationId: tradeItem.supplierOrganizationId
}
});
currentSupp.isConnected = true;
let tx = await models.sequelize.transaction();
await currentSupp.save({transaction: tx});
// Upsert supplier connection
await models.connection.upsert({ await models.connection.upsert({
supplierOrganizationId: tradeItem.supplierOrganizationId, supplierOrganizationId: tradeItem.supplierOrganizationId,
connect: true, connect: true,
}, {transaction: tx}); }, { transaction: tx });
// -----
// Upsert trade item
await models.tradeItem.upsert({ await models.tradeItem.upsert({
tradeItemId: tradeItem.tradeItemId, ...tradeItem,
supplierOrganizationId: tradeItem.supplierOrganizationId,
code: tradeItem.code,
gtin: tradeItem.gtin,
vbnProductCode: tradeItem.vbnProductCode,
name: tradeItem.name,
isDeleted: tradeItem.isDeleted, isDeleted: tradeItem.isDeleted,
sequenceNumber: tradeItem.sequenceNumber,
tradeItemVersion: tradeItem.tradeItemVersion,
isCustomerSpecific: tradeItem.isCustomerSpecific, isCustomerSpecific: tradeItem.isCustomerSpecific,
isHiddenInCatalog: tradeItem.isHiddenInCatalog, isHiddenInCatalog: tradeItem.isHiddenInCatalog,
}, }, { transaction: tx });
{transaction: tx});
let characteristics = tradeItem.characteristics; // Upsert characteristics
for (const characteristic of tradeItem.characteristics) {
for (let characteristic of characteristics) {
await models.characteristic.upsert({ await models.characteristic.upsert({
vbnCode: characteristic.vbnCode, ...characteristic,
vbnValueCode: characteristic.vbnValueCode,
tradeItemId: tradeItem.tradeItemId, tradeItemId: tradeItem.tradeItemId,
}, {transaction: tx}); }, { transaction: tx });
} }
let seasonalPeriods = tradeItem.seasonalPeriods; // Upsert seasonal periods
for (const seasonalPeriod of tradeItem.seasonalPeriods) {
for (let seasonalPeriod of seasonalPeriods) {
await models.seasonalPeriod.upsert({ await models.seasonalPeriod.upsert({
startWeek: seasonalPeriod.startWeek, ...seasonalPeriod,
endWeek: seasonalPeriod.endWeek,
tradeItemId: tradeItem.tradeItemId, tradeItemId: tradeItem.tradeItemId,
}, {transaction: tx}); }, { transaction: tx });
} }
let photos = tradeItem.photos; // Upsert photos
for (const photo of tradeItem.photos) {
for (let photo of photos)
await models.photo.upsert({ await models.photo.upsert({
id: photo.id, ...photo,
url: photo.url,
type: photo.type,
primary: photo.primary,
tradeItemId: tradeItem.tradeItemId, tradeItemId: tradeItem.tradeItemId,
}, {transaction: tx}); }, { transaction: tx });
}
let packingConfigurations = tradeItem.packingConfigurations; // Upsert packing configurations
for (const packingConfiguration of tradeItem.packingConfigurations) {
for (let packingConfiguration of packingConfigurations) { const uuid = uuidv4();
let uuid = uuidv4();
await models.packingConfiguration.upsert({ await models.packingConfiguration.upsert({
packingConfigurationId: uuid, packingConfigurationId: uuid,
piecesPerPackage: packingConfiguration.piecesPerPackage, ...packingConfiguration,
bunchesPerPackage: packingConfiguration.bunchesPerPackage, additionalPricePerPiece: JSON.stringify(packingConfiguration.additionalPricePerPiece),
photoUrl: packingConfiguration.photoUrl,
packagesPerLayer: packingConfiguration.packagesPerLayer,
layersPerLoadCarrier: packingConfiguration.layersPerLoadCarrier,
additionalPricePerPiece : JSON.stringify(packingConfiguration.additionalPricePerPiece),
transportHeightInCm: packingConfiguration.transportHeightInCm,
loadCarrierType: packingConfiguration.loadCarrierType,
isPrimary: packingConfiguration.isPrimary,
tradeItemId: tradeItem.tradeItemId, tradeItemId: tradeItem.tradeItemId,
}, {transaction: tx}); }, { transaction: tx });
await models.package.upsert({ await models.package.upsert({
vbnPackageCode: packingConfiguration.package.vbnPackageCode, ...packingConfiguration.package,
customPackageId: packingConfiguration.package.customPackageId,
packingConfigurationFk: uuid, packingConfigurationFk: uuid,
}, {transaction: tx}); }, { transaction: tx });
} }
let countryOfOriginIsoCodes = tradeItem.countryOfOriginIsoCodes; // Upsert country of origin ISO codes
for (const isoCode of tradeItem.countryOfOriginIsoCodes || []) {
countryOfOriginIsoCodes ??= 0;
for (let countryOfOriginIsoCode of countryOfOriginIsoCodes) {
await models.countryOfOriginIsoCode.upsert({ await models.countryOfOriginIsoCode.upsert({
isoCode: countryOfOriginIsoCode, isoCode,
tradeItemId: tradeItem.tradeItemId, tradeItemId: tradeItem.tradeItemId,
}, {transaction: tx}); }, { transaction: tx });
} }
let botanicalNames = tradeItem.botanicalNames; // Upsert botanical names
for (const botanicalName of tradeItem.botanicalNames) {
for (let botanicalName of botanicalNames) {
await models.botanicalName.upsert({ await models.botanicalName.upsert({
name: botanicalName.name, ...botanicalName,
tradeItemId: tradeItem.tradeItemId, tradeItemId: tradeItem.tradeItemId,
}, {transaction: tx}); }, { transaction: tx });
} }
await tx.commit(); await tx.commit();
} catch (err) {
} catch (error) { console.log(err);
await tx.rollback(); await tx.rollback();
console.log('Error while syncing trade items for: ', supplier.commercialName);
console.log(error);
} }
} }
/** /**