@gotillit/tillit-node-red 1.1.13 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ import { ApiCallNodeDef } from '../shared/types';
2
+ export declare const buildApiFunction: (RED: any) => (n: ApiCallNodeDef) => void;
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.buildApiFunction = void 0;
43
+ var utils_1 = require("../shared/utils");
44
+ var got_1 = __importDefault(require("got"));
45
+ var buildApiFunction = function (RED) { return (function apiCall(n) {
46
+ RED.nodes.createNode(this, n);
47
+ this.myDevice = n.device;
48
+ this.device = RED.nodes.getNode(this.myDevice);
49
+ this.connection = this.device.broker;
50
+ var _a = this.connection, environment = _a.environment, tenant = _a.tenant, username = _a.username, password = _a.password;
51
+ var self = this;
52
+ self.on("input", function (msg) {
53
+ var _a;
54
+ return __awaiter(this, void 0, void 0, function () {
55
+ var endpoint, url, method, ops, response, error_1;
56
+ return __generator(this, function (_b) {
57
+ switch (_b.label) {
58
+ case 0:
59
+ endpoint = (_a = msg.endpoint) !== null && _a !== void 0 ? _a : n.endpoint;
60
+ url = (0, utils_1.hostname)(environment, tenant) + '/api/' + endpoint;
61
+ method = n.method;
62
+ self.status({
63
+ fill: "blue",
64
+ shape: "ring",
65
+ text: "loading..."
66
+ });
67
+ _b.label = 1;
68
+ case 1:
69
+ _b.trys.push([1, 3, , 4]);
70
+ ops = {
71
+ method: method,
72
+ username: username,
73
+ password: password
74
+ };
75
+ if (msg.payload) {
76
+ if (['POST', 'PUT'].includes(method)) {
77
+ ops['json'] = msg.payload;
78
+ }
79
+ else if (typeof msg.payload === 'object') {
80
+ ops['searchParams'] = msg.payload;
81
+ }
82
+ }
83
+ return [4 /*yield*/, (0, got_1.default)(url, ops)];
84
+ case 2:
85
+ response = _b.sent();
86
+ // const data = await response.json();
87
+ self.status({
88
+ fill: "green",
89
+ shape: "ring",
90
+ text: response.statusCode
91
+ });
92
+ try {
93
+ self.send([{
94
+ topic: msg.topic,
95
+ payload: response.body ? JSON.parse(response.body) : null
96
+ }, null]);
97
+ }
98
+ catch (e) {
99
+ self.send([null, {
100
+ topic: msg.topic,
101
+ payload: response.body
102
+ }]);
103
+ }
104
+ return [3 /*break*/, 4];
105
+ case 3:
106
+ error_1 = _b.sent();
107
+ self.status({
108
+ fill: "red",
109
+ shape: "ring",
110
+ text: error_1.message
111
+ });
112
+ self.send([null, {
113
+ topic: msg.topic,
114
+ payload: error_1.response.body ? JSON.parse(error_1.response.body) : { message: error_1.message }
115
+ }]);
116
+ return [3 /*break*/, 4];
117
+ case 4: return [2 /*return*/];
118
+ }
119
+ });
120
+ });
121
+ });
122
+ }); };
123
+ exports.buildApiFunction = buildApiFunction;
124
+ //# sourceMappingURL=node-api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-api.js","sourceRoot":"","sources":["../../src/nodes/node-api.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,yCAAyC;AACzC,4CAAsB;AAEf,IAAM,gBAAgB,GAAG,UAAC,GAAQ,IAAK,OAAA,CAAC,SAAS,OAAO,CAAC,CAAiB;IAC7E,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAC9B,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,MAAM,CAAC;IACzB,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC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EAAE,MAAM;4BACb,IAAI,EAAE,QAAQ,CAAC,UAAU;yBAC5B,CAAC,CAAC;wBACH,IAAI;4BAEA,IAAI,CAAC,IAAI,CAAC,CAAC;oCACP,KAAK,EAAE,GAAG,CAAC,KAAK;oCAChB,OAAO,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI;iCAC5D,EAAE,IAAI,CAAC,CAAC,CAAC;yBACb;wBAAC,OAAO,CAAC,EAAE;4BACR,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE;oCACb,KAAK,EAAE,GAAG,CAAC,KAAK;oCAChB,OAAO,EAAE,QAAQ,CAAC,IAAI;iCACzB,CAAC,CAAC,CAAC;yBACP;;;;wBAGD,IAAI,CAAC,MAAM,CAAC;4BACR,IAAI,EAAE,KAAK;4BACX,KAAK,EAAE,MAAM;4BACb,IAAI,EAAE,OAAK,CAAC,OAAO;yBACtB,CAAC,CAAC;wBACH,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE;gCACb,KAAK,EAAE,GAAG,CAAC,KAAK;gCAChB,OAAO,EAAE,OAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAC,OAAO,EAAE,OAAK,CAAC,OAAO,EAAC;6BAC5F,CAAC,CAAC,CAAC;;;;;;KAGX,CAAC,CAAC;AACP,CAAC,CAAC,EAjE4C,CAiE5C,CAAA;AAjEW,QAAA,gBAAgB,oBAiE3B"}
@@ -0,0 +1,16 @@
1
+ import { TilliTConnection } from '../shared/types';
2
+ export interface NodeMqttClient {
3
+ client: any;
4
+ connected: boolean;
5
+ connect: () => Promise<boolean>;
6
+ reconnect: () => Promise<boolean>;
7
+ disconnect: () => Promise<boolean>;
8
+ unsubscribe: (topic: string) => Promise<any>;
9
+ subscribe: (topic: string, qos: '0' | '1' | '2', on_message?: any) => Promise<boolean>;
10
+ on: (event: string, listener: any) => void;
11
+ }
12
+ export interface NodeBrokerInterface {
13
+ connect: (clientId: string, reconnect: any, callback: any) => void;
14
+ mqttClient: NodeMqttClient;
15
+ }
16
+ export declare const buildNodeBrokerFunction: (RED: any) => (n: TilliTConnection) => void;
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildNodeBrokerFunction = void 0;
4
+ var utils_1 = require("../shared/utils");
5
+ var edge_from_s3_1 = require("../shared/edge-from-s3");
6
+ var aws_iot_device_sdk_v2_1 = require("aws-iot-device-sdk-v2");
7
+ var NodeBroker = /** @class */ (function () {
8
+ function NodeBroker(n, RED, log) {
9
+ var _a;
10
+ this.log = log;
11
+ this.workingDir = RED.settings.userDir + '/';
12
+ try {
13
+ this.clientId = process.env.CLIENT_ID || n.thingId;
14
+ this.environment = (_a = n.environment) !== null && _a !== void 0 ? _a : process.env.ENVIRONMENT;
15
+ this.endpoint = process.env.IOT_ENDPOINT || (0, utils_1.mqttEndpoint)(n.environment);
16
+ var username = n.username, tenant = n.tenant, password = n.password;
17
+ username = username !== null && username !== void 0 ? username : process.env.USERNAME;
18
+ this.password = password !== null && password !== void 0 ? password : process.env.PASSWORD;
19
+ this.tenant = tenant !== null && tenant !== void 0 ? tenant : process.env.TENANT;
20
+ this.username = "".concat(username, "@").concat(tenant, ".tillit.cloud");
21
+ this.thingCert = process.env.THING_CERT || (this.workingDir + this.clientId + '/tillitEdgeConfig/thingCert.crt');
22
+ this.privKey = process.env.PRIV_KEY || (this.workingDir + this.clientId + '/tillitEdgeConfig/privKey.key');
23
+ this.rootCa = process.env.ROOT_CA || (this.workingDir + this.clientId + '/tillitEdgeConfig/rootCA.pem');
24
+ if (process.env.EDGE_BUCKET && n.thingId) {
25
+ (0, edge_from_s3_1.downloadAndUnzipEdge)(this.workingDir, n.thingId);
26
+ }
27
+ }
28
+ catch (e) {
29
+ console.error(e);
30
+ }
31
+ }
32
+ NodeBroker.prototype.connect = function (clientId, reconnect, callback) {
33
+ var _a, _b;
34
+ this.log("connected: ".concat((_b = (_a = this.mqttClient) === null || _a === void 0 ? void 0 : _a.client) === null || _b === void 0 ? void 0 : _b.connected));
35
+ if (!this.mqttClient || reconnect) {
36
+ this.log("Attempt to connect to with " + clientId + " from: " + this.endpoint);
37
+ this.log("Using the certificates that are presented as follows:");
38
+ this.log(" - keyPath : " + this.privKey);
39
+ this.log(" - certPath : " + this.thingCert);
40
+ this.log(" - caPath : " + this.rootCa);
41
+ var configBuilder = aws_iot_device_sdk_v2_1.iot.AwsIotMqttConnectionConfigBuilder.new_mtls_builder_from_path(this.thingCert, this.privKey);
42
+ configBuilder.with_certificate_authority_from_path(undefined, this.rootCa);
43
+ configBuilder.with_clean_session(false);
44
+ configBuilder.with_client_id((clientId || "test-") + Math.floor(Math.random() * 100000000));
45
+ configBuilder.with_endpoint(this.endpoint);
46
+ configBuilder.with_keep_alive_seconds(20);
47
+ var config = configBuilder.build();
48
+ var client = new aws_iot_device_sdk_v2_1.mqtt.MqttClient();
49
+ this.mqttClient = client.new_connection(config);
50
+ this.mqttClient.connect().catch(function (error) {
51
+ console.log("Connect error: " + error);
52
+ }).then(function (connected) {
53
+ }).catch(function (err) {
54
+ console.log(err);
55
+ });
56
+ var self_1 = this;
57
+ if (this.mqttClient) {
58
+ this.mqttClient.on('connect', function () {
59
+ this.connnected = true;
60
+ callback('connected');
61
+ });
62
+ this.mqttClient.on('interrupt', function (error) {
63
+ this.connnected = false;
64
+ callback('interrupt', error);
65
+ });
66
+ this.mqttClient.on('resume', function (error) {
67
+ this.connnected = true;
68
+ callback('resume', error);
69
+ });
70
+ this.mqttClient.on('error', function (error) {
71
+ callback('error', error);
72
+ });
73
+ }
74
+ callback('created');
75
+ }
76
+ else if (this.mqttClient) {
77
+ callback('connected');
78
+ }
79
+ };
80
+ ;
81
+ return NodeBroker;
82
+ }());
83
+ var buildNodeBrokerFunction = function (RED) { return (function awsNodeBroker(n) {
84
+ RED.nodes.createNode(this, n);
85
+ var self = this;
86
+ this.broker = new NodeBroker(n, RED, function (msg) { return self.log(msg); });
87
+ this.on('close', function () {
88
+ self.log("closed " + self.clientId + " ok");
89
+ if (self.broker.mqttClient) {
90
+ self.broker.mqttClient.disconnect();
91
+ }
92
+ self.broker.mqttClient = null;
93
+ });
94
+ }); };
95
+ exports.buildNodeBrokerFunction = buildNodeBrokerFunction;
96
+ //# sourceMappingURL=node-broker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-broker.js","sourceRoot":"","sources":["../../src/nodes/node-broker.ts"],"names":[],"mappings":";;;AACA,yCAA6C;AAC7C,uDAA4D;AAC5D,+DAAgD;AAmBhD;IAgBI,oBAAY,CAAmB,EAAE,GAAQ,EAAE,GAAQ;;QAC/C,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC,QAAQ,CAAC,OAAO,GAAG,GAAG,CAAC;QAE7C,IAAI;YACA,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,CAAC,CAAC,OAAO,CAAC;YACnD,IAAI,CAAC,WAAW,GAAG,MAAA,CAAC,CAAC,WAAW,mCAAI,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;YAC5D,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,IAAA,oBAAY,EAAC,CAAC,CAAC,WAAW,CAAC,CAAC;YACnE,IAAA,QAAQ,GAAsB,CAAC,SAAvB,EAAE,MAAM,GAAc,CAAC,OAAf,EAAE,QAAQ,GAAI,CAAC,SAAL,CAAM;YACrC,QAAQ,GAAG,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC;YAC5C,IAAI,CAAC,QAAQ,GAAG,QAAQ,aA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,MAAM,GAAG,IAAI,UAAU,CAAC,CAAC,EAAE,GAAG,EAAE,UAAC,GAAW,IAAK,OAAA,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAb,CAAa,CAAC,CAAC;IACrE,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE;QACb,IAAI,CAAC,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,CAAC;QAC5C,IAAI,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE;YACxB,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,UAAU,EAAE,CAAC;SAEvC;QACD,IAAI,CAAC,MAAM,CAAC,UAAU,GAAG,IAAI,CAAC;IAClC,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,EAb+C,CAa/C,CAAA;AAbO,QAAA,uBAAuB,2BAa9B"}
@@ -0,0 +1,2 @@
1
+ import { TilliTEvent } from '../shared/types';
2
+ export declare const buildEventFunction: (RED: any) => (n: TilliTEvent) => void;
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.buildEventFunction = void 0;
43
+ var utils_1 = require("../shared/utils");
44
+ var got_1 = __importDefault(require("got"));
45
+ var buildEventFunction = function (RED) { return (function apiCall(n) {
46
+ RED.nodes.createNode(this, n);
47
+ this.myDevice = n.device;
48
+ this.device = RED.nodes.getNode(this.myDevice);
49
+ this.connection = this.device.broker;
50
+ var _a = this.connection, environment = _a.environment, tenant = _a.tenant, username = _a.username, password = _a.password;
51
+ var self = this;
52
+ var payload = {
53
+ assetId: n.assetId * 1,
54
+ eventTypeId: n.eventTypeId * 1,
55
+ subtitle: n.subtitle,
56
+ timestamp: new Date().toISOString()
57
+ };
58
+ self.on("input", function (msg) {
59
+ return __awaiter(this, void 0, void 0, function () {
60
+ var url, finalPayload, ops, response, error_1, error_2;
61
+ return __generator(this, function (_a) {
62
+ switch (_a.label) {
63
+ case 0:
64
+ _a.trys.push([0, 5, , 6]);
65
+ url = (0, utils_1.hostname)(environment, tenant) + '/api/core/event-instances/raise';
66
+ self.status({
67
+ fill: "blue",
68
+ shape: "ring",
69
+ text: "sending..."
70
+ });
71
+ _a.label = 1;
72
+ case 1:
73
+ _a.trys.push([1, 3, , 4]);
74
+ finalPayload = payload;
75
+ if (msg.payload && typeof msg.payload === 'object') {
76
+ finalPayload = Object.assign(payload, msg.payload);
77
+ }
78
+ if (!finalPayload.assetId) {
79
+ finalPayload.assetId = msg.topic;
80
+ }
81
+ ops = {
82
+ method: 'POST',
83
+ username: username,
84
+ password: password,
85
+ json: finalPayload
86
+ };
87
+ console.log('Raising event ' + url + ' ' + JSON.stringify(finalPayload));
88
+ return [4 /*yield*/, (0, got_1.default)(url, ops)];
89
+ case 2:
90
+ response = _a.sent();
91
+ // const data = await response.json();
92
+ self.status({
93
+ fill: "green",
94
+ shape: "ring",
95
+ text: response.statusCode
96
+ });
97
+ try {
98
+ self.send([{
99
+ topic: msg.topic,
100
+ payload: response.body ? JSON.parse(response.body) : null
101
+ }, null]);
102
+ }
103
+ catch (e) {
104
+ self.send([null, {
105
+ topic: msg.topic,
106
+ payload: response.body
107
+ }]);
108
+ }
109
+ return [3 /*break*/, 4];
110
+ case 3:
111
+ error_1 = _a.sent();
112
+ self.status({
113
+ fill: "red",
114
+ shape: "ring",
115
+ text: error_1.message
116
+ });
117
+ self.send([{
118
+ topic: msg.topic,
119
+ payload: error_1.response.body ? JSON.parse(error_1.response.body) : { message: error_1.message }
120
+ }]);
121
+ return [3 /*break*/, 4];
122
+ case 4: return [3 /*break*/, 6];
123
+ case 5:
124
+ error_2 = _a.sent();
125
+ self.status({
126
+ fill: "red",
127
+ shape: "ring",
128
+ text: error_2.message
129
+ });
130
+ return [3 /*break*/, 6];
131
+ case 6: return [2 /*return*/];
132
+ }
133
+ });
134
+ });
135
+ });
136
+ }); };
137
+ exports.buildEventFunction = buildEventFunction;
138
+ //# sourceMappingURL=node-event.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-event.js","sourceRoot":"","sources":["../../src/nodes/node-event.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,yCAAyC;AACzC,4CAAsB;AAEf,IAAM,kBAAkB,GAAG,UAAC,GAAQ,IAAK,OAAA,CAAC,SAAS,OAAO,CAAC,CAAc;IAC5E,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAC9B,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,MAAM,CAAC;IACzB,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC/C,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;IAC/B,IAAA,KAA4C,IAAI,CAAC,UAAU,EAA1D,WAAW,iBAAA,EAAE,MAAM,YAAA,EAAE,QAAQ,cAAA,EAAE,QAAQ,cAAmB,CAAC;IAClE,IAAM,IAAI,GAAG,IAAI,CAAC;IAClB,IAAI,OAAO,GAAG;QACV,OAAO,EAAE,CAAC,CAAC,OAAO,GAAG,CAAC;QACtB,WAAW,EAAE,CAAC,CAAC,WAAW,GAAG,CAAC;QAC9B,QAAQ,EAAE,CAAC,CAAC,QAAQ;QACpB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KAEtC,CAAA;IACD,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,UAAgB,GAAQ;;;;;;;wBAE3B,GAAG,GAAG,IAAA,gBAAQ,EAAC,WAAW,E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BACb;wBAAC,OAAO,CAAC,EAAE;4BACR,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE;oCACb,KAAK,EAAE,GAAG,CAAC,KAAK;oCAChB,OAAO,EAAE,QAAQ,CAAC,IAAI;iCACzB,CAAC,CAAC,CAAC;yBACP;;;;wBAGD,IAAI,CAAC,MAAM,CAAC;4BACR,IAAI,EAAE,KAAK;4BACX,KAAK,EAAE,MAAM;4BACb,IAAI,EAAE,OAAK,CAAC,OAAO;yBACtB,CAAC,CAAC;wBACH,IAAI,CAAC,IAAI,CAAC,CAAC;gCACP,KAAK,EAAE,GAAG,CAAC,KAAK;gCAChB,OAAO,EAAE,OAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAC,OAAO,EAAE,OAAK,CAAC,OAAO,EAAC;6BAC5F,CAAC,CAAC,CAAC;;;;;wBAIR,IAAI,CAAC,MAAM,CAAC;4BACR,IAAI,EAAE,KAAK;4BACX,KAAK,EAAE,MAAM;4BACb,IAAI,EAAE,OAAK,CAAC,OAAO;yBACtB,CAAC,CAAC;;;;;;KAEV,CAAC,CAAC;AACP,CAAC,CAAC,EA/E8C,CA+E9C,CAAA;AA/EW,QAAA,kBAAkB,sBA+E7B"}
@@ -0,0 +1,2 @@
1
+ import { TilliTIn } from '../shared/types';
2
+ export declare const buildNodeInFunction: (RED: any) => (n: TilliTIn) => void;
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildNodeInFunction = void 0;
4
+ var aws_iot_device_sdk_v2_1 = require("aws-iot-device-sdk-v2");
5
+ var decoder = new TextDecoder('utf8');
6
+ var buildNodeInFunction = function (RED) { return (function awsMqttNodeIn(n) {
7
+ RED.nodes.createNode(this, n);
8
+ this.configurationNode = RED.nodes.getNode(n.device);
9
+ var self = this;
10
+ self.broker = this.configurationNode.broker;
11
+ if (self.broker) {
12
+ self.status({
13
+ fill: "yellow",
14
+ shape: "ring",
15
+ text: "subscribing..."
16
+ });
17
+ self.broker.connect(null, null, function (event, error) {
18
+ if (event == "connected") {
19
+ var topic = self.broker.tenant + n.topic;
20
+ try {
21
+ self.broker.mqttClient.unsubscribe(topic);
22
+ }
23
+ catch (e) {
24
+ console.error('Error unsubscribing');
25
+ console.error(e);
26
+ }
27
+ var onMessage = function (topic, payload, dup, qos, retain) {
28
+ var json = JSON.parse(decoder.decode(payload));
29
+ self.log("RECV< " + topic + JSON.stringify(json));
30
+ self.send({
31
+ topic: topic,
32
+ payload: json
33
+ });
34
+ };
35
+ try {
36
+ self.broker.mqttClient.subscribe(topic, aws_iot_device_sdk_v2_1.mqtt.QoS.AtLeastOnce, onMessage);
37
+ self.status({
38
+ fill: "green",
39
+ shape: "ring",
40
+ text: "subscribed"
41
+ });
42
+ }
43
+ catch (error) {
44
+ self.status({
45
+ fill: "error",
46
+ shape: "ring",
47
+ text: error.message
48
+ });
49
+ self.broker.mqttClient.on('message');
50
+ }
51
+ }
52
+ else if (event == "error") {
53
+ self.status({
54
+ fill: "error",
55
+ shape: "ring",
56
+ text: error.message
57
+ });
58
+ }
59
+ else if (event == 'interrupt') {
60
+ self.status({
61
+ fill: "error",
62
+ shape: "ring",
63
+ text: 'Connection lost'
64
+ });
65
+ }
66
+ else if (event == 'resume') {
67
+ self.status({
68
+ fill: "green",
69
+ shape: "ring",
70
+ text: "subscribed"
71
+ });
72
+ }
73
+ });
74
+ }
75
+ else {
76
+ self.error("aws-mqtt in is not configured");
77
+ self.status({
78
+ fill: "red",
79
+ shape: "ring",
80
+ text: "not configured"
81
+ });
82
+ }
83
+ }); };
84
+ exports.buildNodeInFunction = buildNodeInFunction;
85
+ //# sourceMappingURL=node-in.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-in.js","sourceRoot":"","sources":["../../src/nodes/node-in.ts"],"names":[],"mappings":";;;AACA,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AAC,CAAC,CAAC;KACN;SAAM;QACH,IAAI,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC;QAC5C,IAAI,CAAC,MAAM,CAAC;YACR,IAAI,EAAE,KAAK;YACX,KAAK,EAAE,MAAM;YACb,IAAI,EAAE,gBAAgB;SACzB,CAAC,CAAC;KACN;AACL,CAAC,CAAC,EA5E2C,CA4E3C,CAAA;AA5EO,QAAA,mBAAmB,uBA4E1B"}
@@ -0,0 +1,2 @@
1
+ import { TilliTOut } from '../shared/types';
2
+ export declare const buildNodeOutFunction: (RED: any) => (n: TilliTOut) => void;
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildNodeOutFunction = void 0;
4
+ var buildNodeOutFunction = function (RED) { return (function awsMqttNodeOut(n) {
5
+ RED.nodes.createNode(this, n);
6
+ this.myDevice = n.device;
7
+ this.configuration = RED.nodes.getNode(this.myDevice);
8
+ this.broker = this.configuration.broker;
9
+ var self = this;
10
+ var options = {
11
+ qos: parseInt(n.qos) || 0
12
+ };
13
+ self.on("input", function (msg) {
14
+ if (self.broker) {
15
+ self.broker.connect(msg.clientId, msg.reconnect, function (event, error) {
16
+ if ((event == "connected")) {
17
+ self.log("SEND> " + (msg.topic || n.topic) + " " + JSON.stringify(msg.payload));
18
+ if (!Buffer.isBuffer(msg.payload)) {
19
+ if (typeof msg.payload === "object") {
20
+ msg.payload = JSON.stringify(msg.payload);
21
+ }
22
+ else if (typeof msg.payload !== "string") {
23
+ msg.payload = msg.payload.toString();
24
+ }
25
+ msg.payload = new Buffer(msg.payload, "utf-8");
26
+ }
27
+ self.status({
28
+ fill: "blue",
29
+ shape: "ring",
30
+ text: "sending..."
31
+ });
32
+ try {
33
+ self.broker.mqttClient.publish(msg.topic || n.topic, msg.payload, options.qos, false).then(function (result, error) {
34
+ if (error) {
35
+ self.status({
36
+ fill: "red",
37
+ shape: "ring",
38
+ text: error.message
39
+ });
40
+ }
41
+ else {
42
+ self.status({
43
+ fill: "green",
44
+ shape: "ring",
45
+ text: "done"
46
+ });
47
+ }
48
+ });
49
+ }
50
+ catch (e) {
51
+ self.status({
52
+ fill: "red",
53
+ shape: "ring",
54
+ text: e.message
55
+ });
56
+ }
57
+ }
58
+ if (event == 'error') {
59
+ self.error("connection error");
60
+ self.status({
61
+ fill: "red",
62
+ shape: "ring",
63
+ text: "not configured"
64
+ });
65
+ }
66
+ });
67
+ }
68
+ else {
69
+ self.error("aws-mqtt out is not configured");
70
+ self.status({
71
+ fill: "red",
72
+ shape: "ring",
73
+ text: "not configured"
74
+ });
75
+ }
76
+ });
77
+ }); };
78
+ exports.buildNodeOutFunction = buildNodeOutFunction;
79
+ //# sourceMappingURL=node-out.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-out.js","sourceRoot":"","sources":["../../src/nodes/node-out.ts"],"names":[],"mappings":";;;AAEO,IAAM,oBAAoB,GAAG,UAAC,GAAQ,IAAK,OAAA,CAC9C,SAAS,cAAc,CAAC,CAAY;IAChC,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAC9B,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,MAAM,CAAC;IACzB,IAAI,CAAC,aAAa,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACtD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC;IACxC,IAAM,IAAI,GAAG,IAAI,CAAC;IAClB,IAAM,OAAO,GAAG;QACZ,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC;KAC5B,CAAC;IACF,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,UAAU,GAAQ;QAC/B,IAAI,IAAI,CAAC,MAAM,EAAE;YACb,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,C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ACN;iCAAM;gCACH,IAAI,CAAC,MAAM,CAAC;oCACR,IAAI,EAAE,OAAO;oCACb,KAAK,EAAE,MAAM;oCACb,IAAI,EAAE,MAAM;iCACf,CAAC,CAAC;6BACN;wBACL,CAAC,CAAC,CAAC;qBACN;oBAAC,OAAO,CAAC,EAAE;wBACR,IAAI,CAAC,MAAM,CAAC;4BACR,IAAI,EAAE,KAAK;4BACX,KAAK,EAAE,MAAM;4BACb,IAAI,EAAE,CAAC,CAAC,OAAO;yBAClB,CAAC,CAAC;qBACN;iBACJ;gBACD,IAAI,KAAK,IAAI,OAAO,EAAC;oBACjB,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;oBAC/B,IAAI,CAAC,MAAM,CAAC;wBACR,IAAI,EAAE,KAAK;wBACX,KAAK,EAAE,MAAM;wBACb,IAAI,EAAE,gBAAgB;qBACzB,CAAC,CAAC;iBACN;YACL,CAAC,CAAC,CAAC;SACN;aAAM;YACH,IAAI,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAC;YAC7C,IAAI,CAAC,MAAM,CAAC;gBACR,IAAI,EAAE,KAAK;gBACX,KAAK,EAAE,MAAM;gBACb,IAAI,EAAE,gBAAgB;aACzB,CAAC,CAAC;SACN;IACL,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,EAtE4C,CAsE5C,CAAA;AAtEO,QAAA,oBAAoB,wBAsE3B"}
@@ -0,0 +1,2 @@
1
+ import { TilliTPv } from '../shared/types';
2
+ export declare const buildNodeProgressFunction: (RED: any) => (n: TilliTPv) => void;