commit c254ca37f9931b573abb910e07dc1436246f9b65 Author: Chris Chase Date: Mon Sep 8 14:09:43 2025 +0930 inital diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9b1ee42 --- /dev/null +++ b/.gitignore @@ -0,0 +1,175 @@ +# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore + +# Logs + +logs +_.log +npm-debug.log_ +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Caches + +.cache + +# Diagnostic reports (https://nodejs.org/api/report.html) + +report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json + +# Runtime data + +pids +_.pid +_.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover + +lib-cov + +# Coverage directory used by tools like istanbul + +coverage +*.lcov + +# nyc test coverage + +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) + +.grunt + +# Bower dependency directory (https://bower.io/) + +bower_components + +# node-waf configuration + +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) + +build/Release + +# Dependency directories + +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) + +web_modules/ + +# TypeScript cache + +*.tsbuildinfo + +# Optional npm cache directory + +.npm + +# Optional eslint cache + +.eslintcache + +# Optional stylelint cache + +.stylelintcache + +# Microbundle cache + +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history + +.node_repl_history + +# Output of 'npm pack' + +*.tgz + +# Yarn Integrity file + +.yarn-integrity + +# dotenv environment variable files + +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# parcel-bundler cache (https://parceljs.org/) + +.parcel-cache + +# Next.js build output + +.next +out + +# Nuxt.js build / generate output + +.nuxt +dist + +# Gatsby files + +# Comment in the public line in if your project uses Gatsby and not Next.js + +# https://nextjs.org/blog/next-9-1#public-directory-support + +# public + +# vuepress build output + +.vuepress/dist + +# vuepress v2.x temp and cache directory + +.temp + +# Docusaurus cache and generated files + +.docusaurus + +# Serverless directories + +.serverless/ + +# FuseBox cache + +.fusebox/ + +# DynamoDB Local files + +.dynamodb/ + +# TernJS port file + +.tern-port + +# Stores VSCode versions used for testing VSCode extensions + +.vscode-test + +# yarn v2 + +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* + +# IntelliJ based IDEs +.idea + +# Finder (MacOS) folder config +.DS_Store diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..348fea6 --- /dev/null +++ b/LICENSE @@ -0,0 +1,7 @@ +ISC License + +Copyright 2025 Accede Holdings PTY LTD + +Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/icons/odbcwritenow.png b/icons/odbcwritenow.png new file mode 100644 index 0000000..4e39353 Binary files /dev/null and b/icons/odbcwritenow.png differ diff --git a/odbcwritenow.html b/odbcwritenow.html new file mode 100644 index 0000000..0a61d5f --- /dev/null +++ b/odbcwritenow.html @@ -0,0 +1,37 @@ + + + + + + diff --git a/odbcwritenow.js b/odbcwritenow.js new file mode 100644 index 0000000..b82f08d --- /dev/null +++ b/odbcwritenow.js @@ -0,0 +1,81 @@ +async function DoImport(msg, url, node) { + console.log('>', url) + msg.nodata = false + delete msg.complete + node.status({ fill: "blue", shape: "ring", text: `Fetching #${msg.page}: ${msg.what}` }) + var datastr = "" + try { + const response = await fetch(url); + + datastr = await response.text(); + if (datastr.toLowerCase().includes("no data found")) { + msg.nodata = true + msg.complete = true + msg.payload = [] + node.status({ fill: "green", shape: "ring", text: `#${msg.page}: No data found` }) + return node.send([null, msg]); + } + + //Errors and retrys etc + if (datastr.toLowerCase().includes("timeout")) { + node.status({ fill: "red", shape: "ring", text: `#${msg.page}: MYOB Gateway Timeout` }) + console.error("******* MYOB Gateway Timeout", msg.retry, msg.page, url) + msg.retry = msg.retry + 1 + return await DoImport(msg, url, node) + } + if (datastr.toLowerCase().includes("token error")) { + node.status({ fill: "red", shape: "ring", text: `#${msg.page}: MYOB Token Error` }) + console.error("******* MYOB Token Error", msg.retry, msg.page, url) + msg.retry = msg.retry + 1 + return await DoImport(msg, url, node) + } + //--------------------------------- + //Everything looks good + const data = JSON.parse(datastr); + msg.rows = data.length + node.status({ fill: "green", shape: "dot", text: `#${msg.page}: ${msg.rows} Rows` }) + msg.payload = data; + node.send([msg, null]); + } catch (error) { + node.status({ fill: "red", shape: "ring", text: error.message }) + console.error(error.message) + console.log(datastr) + } + +} + + +module.exports = function(RED) { + function ODBCWriteNowGet(config) { + RED.nodes.createNode(this, config); + var node = this; + node.status({ text: `` }) + node.on('input', async function(msg) { + const page = parseInt(encodeURIComponent(msg.page || 0)); + const apikey = encodeURIComponent(msg.apikey || config.apikey); + const what = encodeURIComponent(config.what) + + msg.page = page + msg.what = what + msg.retry = 0 + + var filtersstr = ""; + const filters = encodeURIComponent(msg.filters || "") + if (filters.length > 0) { + filtersstr += `&filters=${filters}` + } + + const datefrom = encodeURIComponent(msg.datefrom || "") + if (datefrom.length > 0) { + filtersstr += `&datefrom=${datefrom}` + } + + const url = `https://myobsync.accede.com.au/download/${what}/json/${page}?apikey=${apikey}${filtersstr}`; + DoImport(msg, url, node) + + }); + } + RED.nodes.registerType("odbcwritenow-get", ODBCWriteNowGet); + +} + diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..d5b9b7b --- /dev/null +++ b/package-lock.json @@ -0,0 +1,107 @@ +{ + "name": "node-red-contrib-odbcwritenow", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "node-red-contrib-odbcwritenow", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "node-fetch": "^3.3.2" + } + }, + "node_modules/data-uri-to-buffer": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", + "integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==", + "license": "MIT", + "engines": { + "node": ">= 12" + } + }, + "node_modules/fetch-blob": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", + "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "paypal", + "url": "https://paypal.me/jimmywarting" + } + ], + "license": "MIT", + "dependencies": { + "node-domexception": "^1.0.0", + "web-streams-polyfill": "^3.0.3" + }, + "engines": { + "node": "^12.20 || >= 14.13" + } + }, + "node_modules/formdata-polyfill": { + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", + "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", + "license": "MIT", + "dependencies": { + "fetch-blob": "^3.1.2" + }, + "engines": { + "node": ">=12.20.0" + } + }, + "node_modules/node-domexception": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", + "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", + "deprecated": "Use your platform's native DOMException instead", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "github", + "url": "https://paypal.me/jimmywarting" + } + ], + "license": "MIT", + "engines": { + "node": ">=10.5.0" + } + }, + "node_modules/node-fetch": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz", + "integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==", + "license": "MIT", + "dependencies": { + "data-uri-to-buffer": "^4.0.0", + "fetch-blob": "^3.1.4", + "formdata-polyfill": "^4.0.10" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/node-fetch" + } + }, + "node_modules/web-streams-polyfill": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz", + "integrity": "sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==", + "license": "MIT", + "engines": { + "node": ">= 8" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..ee12996 --- /dev/null +++ b/package.json @@ -0,0 +1,21 @@ +{ + "name": "@Accede/node-red-contrib-odbcwritenow", + "version": "1.0.0", + "description", "Node-RED library for access in MYOB data via ODBCWriteNow" + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "description": "", + "node-red": { + "version": ">=4.0.0", + "nodes": { + "odbcwritenow-get": "odbcwritenow.js" + } + }, + "dependencies": { + "node-fetch": "^3.3.2" + } +}