diff --git a/README.md b/README.md index 90507cf..4f9f05b 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,10 @@ -# nodered-grist -getgrist.com connectivity for nodered +# nodered-contrib-grist +[Grist](https://getgrist.com) connectivity for [NodeRed](http://nodered.org). + + +**THIS IS A VERY EARLY DEVELOPMENT VERSION** USE AT YOUR OWN RISK + +### Included Nodes +- `records` - Read records of a table +- `server` - Config node for a grist server instance +- `document` - Config node for a grist document \ No newline at end of file diff --git a/node-red-grist/document.html b/node-red-grist/document.html new file mode 100644 index 0000000..bbad8d1 --- /dev/null +++ b/node-red-grist/document.html @@ -0,0 +1,25 @@ + + + \ No newline at end of file diff --git a/node-red-grist/document.js b/node-red-grist/document.js new file mode 100644 index 0000000..ec0d746 --- /dev/null +++ b/node-red-grist/document.js @@ -0,0 +1,8 @@ +module.exports = function(RED) { + function DocumentNode(n) { + RED.nodes.createNode(this,n); + this.docid = n.docid; + this.name = n.name; + } + RED.nodes.registerType("document",DocumentNode); +} \ No newline at end of file diff --git a/node-red-grist/package.json b/node-red-grist/package.json new file mode 100644 index 0000000..52a16b6 --- /dev/null +++ b/node-red-grist/package.json @@ -0,0 +1,21 @@ +{ + "name": "@gorootde/node-red-grist", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "GPL-3.0-or-later", + "node-red": { + "nodes": { + "records": "records.js", + "document": "document.js", + "server": "server.js" + } + }, + "dependencies": { + "grist-api": "^0.1.7" + } +} \ No newline at end of file diff --git a/node-red-grist/records.html b/node-red-grist/records.html new file mode 100644 index 0000000..951f4b8 --- /dev/null +++ b/node-red-grist/records.html @@ -0,0 +1,37 @@ + + + + + \ No newline at end of file diff --git a/node-red-grist/records.js b/node-red-grist/records.js new file mode 100644 index 0000000..9500df0 --- /dev/null +++ b/node-red-grist/records.js @@ -0,0 +1,22 @@ +const {GristDocAPI} = require('grist-api'); + +module.exports = function(RED) { + function RecordsNode(config) { + RED.nodes.createNode(this,config); + let node = this; + this.document = RED.nodes.getNode(config.document); + this.server = RED.nodes.getNode(config.server); + this.table = config.tableId + node.on('input', async function(msg, send, done) { + const protocol=this.server.tlsEnabled ? "https" : "http"; + const url=protocol+"://"+this.server.hostname+":"+this.server.port; + + const api = new GristDocAPI(this.document.docid,{apiKey:this.server.apiKey,server:url}); + api.fetchTable(this.table).then(data => { + node.send({payload:data,topic:this.table}) + }).catch(reason => done(reason,"Failed to perform grist request to "+url)); + + }); + } + RED.nodes.registerType("records",RecordsNode); +} \ No newline at end of file diff --git a/node-red-grist/server.html b/node-red-grist/server.html new file mode 100644 index 0000000..1e32afe --- /dev/null +++ b/node-red-grist/server.html @@ -0,0 +1,36 @@ + + + \ No newline at end of file diff --git a/node-red-grist/server.js b/node-red-grist/server.js new file mode 100644 index 0000000..cda06fb --- /dev/null +++ b/node-red-grist/server.js @@ -0,0 +1,11 @@ +module.exports = function(RED) { + function ServerNode(n) { + RED.nodes.createNode(this,n); + this.hostname = n.hostname; + this.port = n.port; + this.tlsEnabled = n.tlsEnabled; + this.apiKey = n.apiKey + + } + RED.nodes.registerType("server",ServerNode); +} \ No newline at end of file diff --git a/node-red-grist/yarn.lock b/node-red-grist/yarn.lock new file mode 100644 index 0000000..6acd064 --- /dev/null +++ b/node-red-grist/yarn.lock @@ -0,0 +1,68 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +axios@^0.21.1: + version "0.21.4" + resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.4.tgz#c67b90dc0568e5c1cf2b0b858c43ba28e2eda575" + integrity sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg== + dependencies: + follow-redirects "^1.14.0" + +debug@^4.1.1: + version "4.3.4" + resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865" + integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ== + dependencies: + ms "2.1.2" + +follow-redirects@^1.14.0: + version "1.15.2" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13" + integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA== + +fs-extra@^8.1.0: + version "8.1.0" + resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-8.1.0.tgz#49d43c45a88cd9677668cb7be1b46efdb8d2e1c0" + integrity sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g== + dependencies: + graceful-fs "^4.2.0" + jsonfile "^4.0.0" + universalify "^0.1.0" + +graceful-fs@^4.1.6, graceful-fs@^4.2.0: + version "4.2.10" + resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.10.tgz#147d3a006da4ca3ce14728c7aefc287c367d7a6c" + integrity sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA== + +grist-api@^0.1.7: + version "0.1.7" + resolved "https://registry.yarnpkg.com/grist-api/-/grist-api-0.1.7.tgz#7352b1c0e184f1a0069c479523dcb6b1fa877443" + integrity sha512-4NMve0od1uEtvfYTtFUhSm9ZKE8pTVauMLkJT2i78FxaEOlhu9va3uAjinPLORM5RGJ1zymlITBq5NpATCTddQ== + dependencies: + axios "^0.21.1" + debug "^4.1.1" + fs-extra "^8.1.0" + lodash "^4.17.19" + +jsonfile@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-4.0.0.tgz#8771aae0799b64076b76640fca058f9c10e33ecb" + integrity sha512-m6F1R3z8jjlf2imQHS2Qez5sjKWQzbuuhuJ/FKYFRZvPE3PuHcSMVZzfsLhGVOkfd20obL5SWEBew5ShlquNxg== + optionalDependencies: + graceful-fs "^4.1.6" + +lodash@^4.17.19: + version "4.17.21" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" + integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg== + +ms@2.1.2: + version "2.1.2" + resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009" + integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w== + +universalify@^0.1.0: + version "0.1.2" + resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.2.tgz#b646f69be3942dabcecc9d6639c80dc105efaa66" + integrity sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==