initial commit
This commit is contained in:
parent
4ecbaa612a
commit
3b102ee4f6
9 changed files with 238 additions and 2 deletions
12
README.md
12
README.md
|
|
@ -1,2 +1,10 @@
|
||||||
# nodered-grist
|
# nodered-contrib-grist
|
||||||
getgrist.com connectivity for nodered
|
[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
|
||||||
25
node-red-grist/document.html
Normal file
25
node-red-grist/document.html
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
<script type="text/javascript">
|
||||||
|
RED.nodes.registerType('document',{
|
||||||
|
category: 'config',
|
||||||
|
defaults: {
|
||||||
|
name: {value:"", required:false},
|
||||||
|
docid: {value:"",required:true},
|
||||||
|
},
|
||||||
|
label: function() {
|
||||||
|
return this.name || this.docid;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script type="text/html" data-template-name="document">
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-config-input-name"><i class="fa fa-bookmark"></i> Name</label>
|
||||||
|
<input type="text" id="node-config-input-name">
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-config-input-docid"><i class="fa fa-bookmark"></i> Document ID</label>
|
||||||
|
<input type="text" id="node-config-input-docid">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
</script>
|
||||||
8
node-red-grist/document.js
Normal file
8
node-red-grist/document.js
Normal file
|
|
@ -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);
|
||||||
|
}
|
||||||
21
node-red-grist/package.json
Normal file
21
node-red-grist/package.json
Normal file
|
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
37
node-red-grist/records.html
Normal file
37
node-red-grist/records.html
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
<script type="text/javascript">
|
||||||
|
RED.nodes.registerType('records',{
|
||||||
|
category: 'grist',
|
||||||
|
color: '#00bb00',
|
||||||
|
defaults: {
|
||||||
|
server:{value:"", type:"server",required:true},
|
||||||
|
document: {value:"",type:"document",required:true},
|
||||||
|
tableId: {value:"",required:true}
|
||||||
|
},
|
||||||
|
inputs:1,
|
||||||
|
outputs:1,
|
||||||
|
icon: "font-awesome/fa-table",
|
||||||
|
label: function() {
|
||||||
|
return this.tableId || "records";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script type="text/html" data-template-name="records">
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-document"><i class="fa fa-tag"></i> Document</label>
|
||||||
|
<input type="text" id="node-input-document" placeholder="Document">
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-server"><i class="fa fa-tag"></i> Server</label>
|
||||||
|
<input type="text" id="node-input-server" placeholder="Server">
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-tableId"><i class="fa fa-tag"></i> Table Name</label>
|
||||||
|
<input type="text" id="node-input-tableId" placeholder="Table Name">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script type="text/html" data-help-name="records">
|
||||||
|
<p>Retrieves records from a grist table</p>
|
||||||
|
</script>
|
||||||
22
node-red-grist/records.js
Normal file
22
node-red-grist/records.js
Normal file
|
|
@ -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);
|
||||||
|
}
|
||||||
36
node-red-grist/server.html
Normal file
36
node-red-grist/server.html
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
<script type="text/javascript">
|
||||||
|
RED.nodes.registerType('server',{
|
||||||
|
category: 'config',
|
||||||
|
defaults: {
|
||||||
|
|
||||||
|
hostname: {value:"",required:true},
|
||||||
|
port: {value:"",required:false,validate:RED.validators.number()},
|
||||||
|
tlsEnabled: {value: true, required:true},
|
||||||
|
apiKey: {value:"",required:false, type:"password"}
|
||||||
|
},
|
||||||
|
label: function() {
|
||||||
|
return this.hostname || "server";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script type="text/html" data-template-name="server">
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-config-input-hostname"><i class="fa fa-bookmark"></i> Hostname</label>
|
||||||
|
<input type="text" id="node-config-input-hostname">
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-config-input-port"><i class="fa fa-bookmark"></i> Port</label>
|
||||||
|
<input type="text" id="node-config-input-port">
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-config-input-tlsenabled"><i class="fa fa-bookmark"></i> Enable TLS</label>
|
||||||
|
<input type="text" id="node-config-input-tlsenabled">
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-config-input-apiKey"><i class="fa fa-bookmark"></i> API Key</label>
|
||||||
|
<input type="text" id="node-config-input-apiKey">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
</script>
|
||||||
11
node-red-grist/server.js
Normal file
11
node-red-grist/server.js
Normal file
|
|
@ -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);
|
||||||
|
}
|
||||||
68
node-red-grist/yarn.lock
Normal file
68
node-red-grist/yarn.lock
Normal file
|
|
@ -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==
|
||||||
Loading…
Add table
Add a link
Reference in a new issue