Skip to content

Commit

Permalink
Merge pull request #68 from thinger-io/develop
Browse files Browse the repository at this point in the history
Release version 1.7.6
  • Loading branch information
bautisflow authored May 23, 2024
2 parents 628dd63 + f3da47a commit 139476f
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 56 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

All notable changes to this project will be documented in this file.

## [1.7.6] - 2024-05-23

### Fixed

- Device create and Bucket create nodes failing on creation
- Bucket create node not hiding auxiliary sources fields when source changed


## [1.7.5] - 2024-05-22

### Fixed
Expand Down Expand Up @@ -313,6 +321,7 @@ All notable changes to this project will be documented in this file.

## [0.0.6] - 2019-06-20

[1.7.6]: https://github.com/thinger-io/Node-RED/compare/1.7.5...1.7.6
[1.7.5]: https://github.com/thinger-io/Node-RED/compare/1.7.4...1.7.5
[1.7.4]: https://github.com/thinger-io/Node-RED/compare/1.7.3...1.7.4
[1.7.3]: https://github.com/thinger-io/Node-RED/compare/1.7.2...1.7.3
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# node-red-contrib-thinger

[![NPM Version](https://img.shields.io/static/v1?label=npm&message=v1.7.5&color=blue&style=flat)](https://www.npmjs.com/package/node-red-contrib-thinger)
[![NPM Version](https://img.shields.io/static/v1?label=npm&message=v1.7.6&color=blue&style=flat)](https://www.npmjs.com/package/node-red-contrib-thinger)

![Node-RED and Thinger.io Integration](./images/laptop.png "Thinger.io web console with Node-RED plugin and ad-hoc nodes")

Expand Down
4 changes: 2 additions & 2 deletions nodes/bucket-create.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script type="text/javascript">

function hideSources() {
function hideBucketSources() {
$(".node-row-device").hide();
$(".node-row-resource").hide();
$(".node-row-update").hide();
Expand Down Expand Up @@ -52,7 +52,7 @@
// Event listeners
$("#node-input-source").change(function() {
if (!firstTime) {
hideSources();
hideBucketSources();
}
firstTime = false;

Expand Down
40 changes: 23 additions & 17 deletions nodes/bucket-create.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,28 +108,34 @@ module.exports = function(RED) {
const url = `${server.config.ssl ? "https://" : "http://"}${server.config.host}/v1/users/${server.config.username}/buckets`;

if (typeof server.request === "function") {

// Check if bucket exists
let exists = true;
let res;

try {
res = await server.request(node,`${url}/${json.bucket}`, 'GET');
if (res.status !== 200)
exists = false;

// Update if exist or create it
let bucket = json.bucket;
if ( exists ) {
delete json.bucket;
res = await server.request(node,`${url}/${bucket}`,'PUT',json);
} else {
res = await server.request(node, url, 'POST', json);
}

// Associate to projects
if (projects && projects.length !== 0) {
res = await server.request(node,`${url}/${bucket}/projects`,'PUT',projects);
}
res = await server.request(node,`${url}/${json.bucket}`, 'GET');
} catch (err) {
} finally {
if ( !res || res.status !== 200 )
exists = false;
}

try {

// Update if exist or create it
let bucket = json.bucket;
if ( exists ) {
delete json.bucket;
res = await server.request(node,`${url}/${bucket}`,'PUT',json);
} else {
res = await server.request(node, url, 'POST', json);
}

// Associate to projects
if (projects && projects.length !== 0) {
res = await server.request(node,`${url}/${bucket}/projects`,'PUT',projects);
}

} catch(err) {
delete err.stack;
Expand Down
18 changes: 11 additions & 7 deletions nodes/device-callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,21 @@ module.exports = function(RED) {

if (typeof server.request === "function") {

const url = `${server.config.ssl ? "https://" : "http://"}${server.config.host}/v3/users/${server.config.username}/devices/${prefix}${device}/callback`;

try {
const url = `${server.config.ssl ? "https://" : "http://"}${server.config.host}/v3/users/${server.config.username}/devices/${prefix}${device}/callback`;

// Check if device exists if not autoprovision resources
let res = await server.request(node,`${url}/data`,'POST',data);
if ( res.status !== 200 ) {

await provisionBucket(server,node,prefix,device,assetType,assetGroup,product);
await provisionDevice(server,node,prefix,device,assetType,assetGroup,product);
let res;
try {
res = await server.request(node,`${url}/data`,'POST',data);

} catch (err) {
} finally {
if ( !res || res.status !== 200 ) {
await provisionBucket(server,node,prefix,device,assetType,assetGroup,product);
await provisionDevice(server,node,prefix,device,assetType,assetGroup,product);
res = await server.request(node,`${url}/data`,'POST',data);
}
}

msg.payload = res.payload;
Expand Down
9 changes: 0 additions & 9 deletions nodes/device-create.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
<script type="text/javascript">

function hideSources() {
$(".node-row-device").hide();
$(".node-row-update").hide();
$(".node-row-topic").hide();
$("#node-input-device").val("");
$("#node-input-update").val("");
$("#node-input-topic").val("");
}

RED.nodes.registerType('device-create', {
category: 'thinger',
color: '#62b0fe', // #1F8EFE at 30% lightened
Expand Down
39 changes: 22 additions & 17 deletions nodes/device-create.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,28 @@ module.exports = function(RED) {
// Update if exist or create it
try {

res = await server.request(node,`${url}/${data.device}`, 'GET');
if (res.status !== 200)
exists = false;

let device = data.device;
if ( exists ) {
delete data.device;
delete data.type;
res = await server.request(node,`${url}/${device}`,'PUT',data);
} else {
res = await server.request(node, url, 'POST', data);
}

// Associate to projects
if (projects && projects.length !== 0) {
res = await server.request(node,`${url}/${device}/projects`,'PUT',projects);
}
try {
res = await server.request(node,`${url}/${data.device}`, 'GET');
} catch (err) {
} finally {
if ( !res || res.status !== 200 )
exists = false;

}

let device = data.device;
if ( exists ) {
delete data.device;
delete data.type;
res = await server.request(node,`${url}/${device}`,'PUT',data);
} else {
res = await server.request(node, url, 'POST', data);
}

// Associate to projects
if (projects && projects.length !== 0) {
res = await server.request(node,`${url}/${device}/projects`,'PUT',projects);
}

} catch(err) {
delete err.stack;
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-thinger",
"version": "1.7.5",
"version": "1.7.6-alpha.1",
"description": "Node-Red library for Thinger.io Platform",
"keywords": [
"node-red",
Expand Down

0 comments on commit 139476f

Please sign in to comment.