From 0ff2abf19e285c3bb78d7cbfcecab06f82fdbc49 Mon Sep 17 00:00:00 2001 From: rafaelTelesS Date: Fri, 14 Jul 2023 15:24:30 -0300 Subject: [PATCH 1/4] updating sdk and documentation --- README.md | 24 ++-- analysis.js | 42 ++---- package-lock.json | 334 +++++++++++++++++++++------------------------- package.json | 2 +- 4 files changed, 174 insertions(+), 228 deletions(-) diff --git a/README.md b/README.md index 6570904..118500a 100755 --- a/README.md +++ b/README.md @@ -5,17 +5,19 @@ You can get the dashboard template to use here: https://admin.tago.io/template/6 Use a dummy HTTPs device with the dashboard. -Environment Variables -In order to use this analysis, you must setup the Environment Variable table. - account_token: Your account token. Check bellow how to get this. - -Steps to generate an account_token: - -1. Enter the following link: https://admin.tago.io/account/ -2. Select your Profile. -3. Enter Tokens tab. -4. Generate a new Token with Expires Never. -5. Press the Copy Button and place at the Environment Variables tab of this analysis. +## How to use this analysis internally at TagoIO servers + +In order to use this analysis, you must to add a new policy in your account.
+ +Steps to add a new policy: + + 1 - Click the button "Add Policy" at this url: https://admin.tago.io/am; + + 2 - In the Target selector, with the field set as "ID", choose your Analysis in the list; + + 3 - Click the "Click to add a new permission" element and select "Device" with the rule "Access" with the field as "Any"; + + 4 - To save your new Policy, click the save button in the bottom right corner;
# How to run this analysis You can just upload the `analysis.js` file. diff --git a/analysis.js b/analysis.js index 1881695..34898a5 100644 --- a/analysis.js +++ b/analysis.js @@ -6,18 +6,14 @@ ** You can get the dashboard template to use here: https://admin.tago.io/template/6143555a314cef001871ec78 ** Use a dummy HTTPs device with the dashboard. ** - ** Environment Variables - ** In order to use this analysis, you must setup the Environment Variable table. - ** account_token: Your account token. Check bellow how to get this. - ** - ** Steps to generate an account_token: - ** 1 - Enter the following link: https://admin.tago.io/account/ - ** 2 - Select your Profile. - ** 3 - Enter Tokens tab. - ** 4 - Generate a new Token with Expires Never. - ** 5 - Press the Copy Button and place at the Environment Variables tab of this analysis. + ** How to use: + ** To analysis works, you need to add a new policy in your account. Steps to add a new policy: + ** 1 - Click the button "Add Policy" at this url: https://admin.tago.io/am; + ** 2 - In the Target selector, with the field set as "ID", choose your Analysis in the list; + ** 3 - Click the "Click to add a new permission" element and select "Device" with the rule "Access" with the field as "Any"; + ** 4 - To save your new Policy, click the save button in the bottom right corner; */ -const { Analysis, Account, Utils, Device } = require("@tago-io/sdk"); +const { Analysis, Resources } = require("@tago-io/sdk"); async function startAnalysis(context, scope) { if (!scope[0]) { @@ -25,18 +21,6 @@ async function startAnalysis(context, scope) { } context.log("Creating your device"); - // Get the environment variables. - const env = Utils.envToJson(context.environment); - if (!env.account_token) return context.log('Missing "account_token" environment variable'); - else if (env.account_token.length !== 36) return context.log('Invalid "account_token" in the environment variable'); - - // Instance the Account class - const account = new Account({ token: env.account_token }); - - // Get the token of the settings device used in the dashboard, then instance the device class. - // We will use this to send the Validation (feedback) to the dashboard. - const dashboard_dev_token = await Utils.getTokenByName(account, scope[0].device); - const dashboard_device = new Device({ token: dashboard_dev_token }); // Get the variables sent by the widget/dashboard. const network_id = scope.find((x) => x.variable === "device_network"); @@ -52,7 +36,7 @@ async function startAnalysis(context, scope) { return context.log('Missing "device_eui" in the data scope.'); } - const result = await account.devices + const result = await Resources.devices .create({ name: device_name.value, // Serie number is the parameter for device eui, sigfox id, etc.. @@ -72,19 +56,15 @@ async function startAnalysis(context, scope) { .catch((error) => { // Send the validation to the device. // That way we create an error in the dashboard for feedback. - dashboard_device.sendData({ variable: "validation", value: `Error when creating the device ${error}`, metadata: { color: "red" } }); + Resources.devices.sendDeviceData(scope[0].device, { variable: "validation", value: `Error when creating the device ${error}`, metadata: { color: "red" } }); throw error; }); // To add Configuration Parameters to the device: - account.devices.paramSet(result.device_id, { key: "param_key", value: "10", sent: false }); - - // To add any data to the device that was just created: - // const device = new Device({ token: result.token }); - // device.sendData({ variable: 'temperature', value: 17 }); + Resources.devices.paramSet(result.device_id, { key: "param_key", value: "10", sent: false }); // Send feedback to the dashboard: - dashboard_device.sendData({ variable: "validation", value: "Device succesfully created!", metadata: { type: "success" } }); + Resources.devices.sendDeviceData(scope[0].device, { variable: "validation", value: "Device succesfully created!", metadata: { type: "success" } }); context.log(`Device succesfully created. ID: ${result.device_id}`); } diff --git a/package-lock.json b/package-lock.json index 0eeaadc..7fd26b8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,26 +9,25 @@ "version": "1.0.0", "license": "MIT", "dependencies": { - "@tago-io/sdk": "10.7.6" + "@tago-io/sdk": "^11.0.6" } }, "node_modules/@socket.io/component-emitter": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/@socket.io/component-emitter/-/component-emitter-3.0.0.tgz", - "integrity": "sha512-2pTGuibAXJswAPJjaKisthqS/NOK5ypG4LYT6tEAV0S/mxW0zOIvYvGK0V8w8+SHxAm6vRMSjqSalFXeBAqs+Q==" + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@socket.io/component-emitter/-/component-emitter-3.1.0.tgz", + "integrity": "sha512-+9jVqKhRSpsc591z5vX+X5Yyw+he/HCB4iQ/RYxw35CEPaY1gnsNE43nf9n9AaYjAQrTiI/mOwKUKdUs9vf7Xg==" }, "node_modules/@tago-io/sdk": { - "version": "10.7.6", - "resolved": "https://registry.npmjs.org/@tago-io/sdk/-/sdk-10.7.6.tgz", - "integrity": "sha512-3EM0JO/SA5NdLgCjf3lcxfR9VBhrOjo8Aph93R/t1juLO5lOJoqARpD26vVzHiK/4VkeKrfUm3QImlIzGQ76LQ==", + "version": "11.0.6", + "resolved": "https://registry.npmjs.org/@tago-io/sdk/-/sdk-11.0.6.tgz", + "integrity": "sha512-z3pKn9nZNZ8rIvaXp2mh1UExfqrWG9hc94iJZx7rnTIqNe0XpIMywU1OMbxoaimDDYDjXI7V24XSMDd+AaK9uQ==", "dependencies": { - "axios": "0.26.1", + "axios": "1.4.0", "form-data": "4.0.0", - "lodash": "4.17.21", - "nanoid": "3.3.2", - "papaparse": "5.3.2", - "qs": "6.10.3", - "socket.io-client": "4.4.1" + "nanoid": "3.3.6", + "papaparse": "5.4.1", + "qs": "6.11.2", + "socket.io-client": "4.6.2" }, "engines": { "node": ">=14.0.0", @@ -41,18 +40,15 @@ "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" }, "node_modules/axios": { - "version": "0.26.1", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.26.1.tgz", - "integrity": "sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==", + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.4.0.tgz", + "integrity": "sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA==", "dependencies": { - "follow-redirects": "^1.14.8" + "follow-redirects": "^1.15.0", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" } }, - "node_modules/backo2": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/backo2/-/backo2-1.0.2.tgz", - "integrity": "sha1-MasayLEpNjRj41s+u2n038+6eUc=" - }, "node_modules/call-bind": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz", @@ -101,33 +97,29 @@ } }, "node_modules/engine.io-client": { - "version": "6.1.1", - "resolved": "https://registry.npmjs.org/engine.io-client/-/engine.io-client-6.1.1.tgz", - "integrity": "sha512-V05mmDo4gjimYW+FGujoGmmmxRaDsrVr7AXA3ZIfa04MWM1jOfZfUwou0oNqhNwy/votUDvGDt4JA4QF4e0b4g==", + "version": "6.4.0", + "resolved": "https://registry.npmjs.org/engine.io-client/-/engine.io-client-6.4.0.tgz", + "integrity": "sha512-GyKPDyoEha+XZ7iEqam49vz6auPnNJ9ZBfy89f+rMMas8AuiMWOZ9PVzu8xb9ZC6rafUqiGHSCfu22ih66E+1g==", "dependencies": { - "@socket.io/component-emitter": "~3.0.0", + "@socket.io/component-emitter": "~3.1.0", "debug": "~4.3.1", - "engine.io-parser": "~5.0.0", - "has-cors": "1.1.0", - "parseqs": "0.0.6", - "parseuri": "0.0.6", - "ws": "~8.2.3", - "xmlhttprequest-ssl": "~2.0.0", - "yeast": "0.1.2" + "engine.io-parser": "~5.0.3", + "ws": "~8.11.0", + "xmlhttprequest-ssl": "~2.0.0" } }, "node_modules/engine.io-parser": { - "version": "5.0.4", - "resolved": "https://registry.npmjs.org/engine.io-parser/-/engine.io-parser-5.0.4.tgz", - "integrity": "sha512-+nVFp+5z1E3HcToEnO7ZIj3g+3k9389DvWtvJZz0T6/eOCPIyyxehFcedoYrZQrp0LgQbD9pPXhpMBKMd5QURg==", + "version": "5.0.7", + "resolved": "https://registry.npmjs.org/engine.io-parser/-/engine.io-parser-5.0.7.tgz", + "integrity": "sha512-P+jDFbvK6lE3n1OL+q9KuzdOFWkkZ/cMV9gol/SbVfpyqfvrfrFTOFJ6fQm2VC3PZHlU3QPhVwmbsCnauHF2MQ==", "engines": { "node": ">=10.0.0" } }, "node_modules/follow-redirects": { - "version": "1.14.9", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.9.tgz", - "integrity": "sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==", + "version": "1.15.2", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", + "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==", "funding": [ { "type": "individual", @@ -162,13 +154,14 @@ "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" }, "node_modules/get-intrinsic": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.1.tgz", - "integrity": "sha512-kWZrnVM42QCiEA2Ig1bG8zjoIMOgxWwYCEeNdwY6Tv/cOSeGpcoX4pXHfKUxNKVoArnrEr2e9srnAxxGIraS9Q==", + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.1.tgz", + "integrity": "sha512-2DcsyfABl+gVHEfCOaTrWgyt+tb6MSEGmKq+kI5HwLbIYgjgmMcV8KQ41uaKz1xxUcn9tJtgFbQUEVcEbd0FYw==", "dependencies": { "function-bind": "^1.1.1", "has": "^1.0.3", - "has-symbols": "^1.0.1" + "has-proto": "^1.0.1", + "has-symbols": "^1.0.3" }, "funding": { "url": "https://github.com/sponsors/ljharb" @@ -185,10 +178,16 @@ "node": ">= 0.4.0" } }, - "node_modules/has-cors": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/has-cors/-/has-cors-1.1.0.tgz", - "integrity": "sha1-XkdHk/fqmEPRu5nCPu9J/xJv/zk=" + "node_modules/has-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.1.tgz", + "integrity": "sha512-7qE+iP+O+bgF9clE5+UoBFzE65mlBiVj3tKCrlNQ0Ogwm0BjpT/gK4SlLYDMybDh5I3TCTKnPPa0oMG7JDYrhg==", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } }, "node_modules/has-symbols": { "version": "1.0.3", @@ -201,11 +200,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/lodash": { - "version": "4.17.21", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", - "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" - }, "node_modules/mime-db": { "version": "1.52.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", @@ -231,9 +225,15 @@ "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, "node_modules/nanoid": { - "version": "3.3.2", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.2.tgz", - "integrity": "sha512-CuHBogktKwpm5g2sRgv83jEy2ijFzBwMoYA60orPDR7ynsLijJDqgsi4RDGj3OJpy3Ieb+LYwiRmIOGyytgITA==", + "version": "3.3.6", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.6.tgz", + "integrity": "sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], "bin": { "nanoid": "bin/nanoid.cjs" }, @@ -242,32 +242,27 @@ } }, "node_modules/object-inspect": { - "version": "1.12.0", - "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.0.tgz", - "integrity": "sha512-Ho2z80bVIvJloH+YzRmpZVQe87+qASmBUKZDWgx9cu+KDrX2ZDH/3tMy+gXbZETVGs2M8YdxObOh7XAtim9Y0g==", + "version": "1.12.3", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.3.tgz", + "integrity": "sha512-geUvdk7c+eizMNUDkRpW1wJwgfOiOeHbxBR/hLXK1aT6zmVSO0jsQcs7fj6MGw89jC/cjGfLcNOrtMYtGqm81g==", "funding": { "url": "https://github.com/sponsors/ljharb" } }, "node_modules/papaparse": { - "version": "5.3.2", - "resolved": "https://registry.npmjs.org/papaparse/-/papaparse-5.3.2.tgz", - "integrity": "sha512-6dNZu0Ki+gyV0eBsFKJhYr+MdQYAzFUGlBMNj3GNrmHxmz1lfRa24CjFObPXtjcetlOv5Ad299MhIK0znp3afw==" + "version": "5.4.1", + "resolved": "https://registry.npmjs.org/papaparse/-/papaparse-5.4.1.tgz", + "integrity": "sha512-HipMsgJkZu8br23pW15uvo6sib6wne/4woLZPlFf3rpDyMe9ywEXUsuD7+6K9PRkJlVT51j/sCOYDKGGS3ZJrw==" }, - "node_modules/parseqs": { - "version": "0.0.6", - "resolved": "https://registry.npmjs.org/parseqs/-/parseqs-0.0.6.tgz", - "integrity": "sha512-jeAGzMDbfSHHA091hr0r31eYfTig+29g3GKKE/PPbEQ65X0lmMwlEoqmhzu0iztID5uJpZsFlUPDP8ThPL7M8w==" - }, - "node_modules/parseuri": { - "version": "0.0.6", - "resolved": "https://registry.npmjs.org/parseuri/-/parseuri-0.0.6.tgz", - "integrity": "sha512-AUjen8sAkGgao7UyCX6Ahv0gIK2fABKmYjvP4xmy5JaKvcbTRueIqIPHLAfq30xJddqSE033IOMUSOMCcK3Sow==" + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" }, "node_modules/qs": { - "version": "6.10.3", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.10.3.tgz", - "integrity": "sha512-wr7M2E0OFRfIfJZjKGieI8lBKb7fRCH4Fv5KNPEs7gJ8jadvotdsS08PzOKR7opXhZ/Xkjtt3WF9g38drmyRqQ==", + "version": "6.11.2", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.2.tgz", + "integrity": "sha512-tDNIz22aBzCDxLtVH++VnTfzxlfeK5CbqohpSqpJgj1Wg/cQbStNAz3NuqCs5vV+pjBsK4x4pN9HlVh7rcYRiA==", "dependencies": { "side-channel": "^1.0.4" }, @@ -292,27 +287,25 @@ } }, "node_modules/socket.io-client": { - "version": "4.4.1", - "resolved": "https://registry.npmjs.org/socket.io-client/-/socket.io-client-4.4.1.tgz", - "integrity": "sha512-N5C/L5fLNha5Ojd7Yeb/puKcPWWcoB/A09fEjjNsg91EDVr5twk/OEyO6VT9dlLSUNY85NpW6KBhVMvaLKQ3vQ==", + "version": "4.6.2", + "resolved": "https://registry.npmjs.org/socket.io-client/-/socket.io-client-4.6.2.tgz", + "integrity": "sha512-OwWrMbbA8wSqhBAR0yoPK6EdQLERQAYjXb3A0zLpgxfM1ZGLKoxHx8gVmCHA6pcclRX5oA/zvQf7bghAS11jRA==", "dependencies": { - "@socket.io/component-emitter": "~3.0.0", - "backo2": "~1.0.2", + "@socket.io/component-emitter": "~3.1.0", "debug": "~4.3.2", - "engine.io-client": "~6.1.1", - "parseuri": "0.0.6", - "socket.io-parser": "~4.1.1" + "engine.io-client": "~6.4.0", + "socket.io-parser": "~4.2.4" }, "engines": { "node": ">=10.0.0" } }, "node_modules/socket.io-parser": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-4.1.2.tgz", - "integrity": "sha512-j3kk71QLJuyQ/hh5F/L2t1goqzdTL0gvDzuhTuNSwihfuFUrcSji0qFZmJJPtG6Rmug153eOPsUizeirf1IIog==", + "version": "4.2.4", + "resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-4.2.4.tgz", + "integrity": "sha512-/GbIKmo8ioc+NIWIhwdecY0ge+qVBSMdgxGygevmdHj24bsfgtCmcUUcQ5ZzcylGFHsN3k4HB4Cgkl96KVnuew==", "dependencies": { - "@socket.io/component-emitter": "~3.0.0", + "@socket.io/component-emitter": "~3.1.0", "debug": "~4.3.1" }, "engines": { @@ -320,9 +313,9 @@ } }, "node_modules/ws": { - "version": "8.2.3", - "resolved": "https://registry.npmjs.org/ws/-/ws-8.2.3.tgz", - "integrity": "sha512-wBuoj1BDpC6ZQ1B7DWQBYVLphPWkm8i9Y0/3YdHjHKHiohOJ1ws+3OccDWtH+PoC9DZD5WOTrJvNbWvjS6JWaA==", + "version": "8.11.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.11.0.tgz", + "integrity": "sha512-HPG3wQd9sNQoT9xHyNCXoDUa+Xw/VevmY9FoHyQ+g+rrMn4j6FB4np7Z0OhdTgjx6MgQLK7jwSy1YecU1+4Asg==", "engines": { "node": ">=10.0.0" }, @@ -346,31 +339,25 @@ "engines": { "node": ">=0.4.0" } - }, - "node_modules/yeast": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/yeast/-/yeast-0.1.2.tgz", - "integrity": "sha1-AI4G2AlDIMNy28L47XagymyKxBk=" } }, "dependencies": { "@socket.io/component-emitter": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/@socket.io/component-emitter/-/component-emitter-3.0.0.tgz", - "integrity": "sha512-2pTGuibAXJswAPJjaKisthqS/NOK5ypG4LYT6tEAV0S/mxW0zOIvYvGK0V8w8+SHxAm6vRMSjqSalFXeBAqs+Q==" + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@socket.io/component-emitter/-/component-emitter-3.1.0.tgz", + "integrity": "sha512-+9jVqKhRSpsc591z5vX+X5Yyw+he/HCB4iQ/RYxw35CEPaY1gnsNE43nf9n9AaYjAQrTiI/mOwKUKdUs9vf7Xg==" }, "@tago-io/sdk": { - "version": "10.7.6", - "resolved": "https://registry.npmjs.org/@tago-io/sdk/-/sdk-10.7.6.tgz", - "integrity": "sha512-3EM0JO/SA5NdLgCjf3lcxfR9VBhrOjo8Aph93R/t1juLO5lOJoqARpD26vVzHiK/4VkeKrfUm3QImlIzGQ76LQ==", + "version": "11.0.6", + "resolved": "https://registry.npmjs.org/@tago-io/sdk/-/sdk-11.0.6.tgz", + "integrity": "sha512-z3pKn9nZNZ8rIvaXp2mh1UExfqrWG9hc94iJZx7rnTIqNe0XpIMywU1OMbxoaimDDYDjXI7V24XSMDd+AaK9uQ==", "requires": { - "axios": "0.26.1", + "axios": "1.4.0", "form-data": "4.0.0", - "lodash": "4.17.21", - "nanoid": "3.3.2", - "papaparse": "5.3.2", - "qs": "6.10.3", - "socket.io-client": "4.4.1" + "nanoid": "3.3.6", + "papaparse": "5.4.1", + "qs": "6.11.2", + "socket.io-client": "4.6.2" } }, "asynckit": { @@ -379,18 +366,15 @@ "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" }, "axios": { - "version": "0.26.1", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.26.1.tgz", - "integrity": "sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==", + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.4.0.tgz", + "integrity": "sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA==", "requires": { - "follow-redirects": "^1.14.8" + "follow-redirects": "^1.15.0", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" } }, - "backo2": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/backo2/-/backo2-1.0.2.tgz", - "integrity": "sha1-MasayLEpNjRj41s+u2n038+6eUc=" - }, "call-bind": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz", @@ -422,30 +406,26 @@ "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" }, "engine.io-client": { - "version": "6.1.1", - "resolved": "https://registry.npmjs.org/engine.io-client/-/engine.io-client-6.1.1.tgz", - "integrity": "sha512-V05mmDo4gjimYW+FGujoGmmmxRaDsrVr7AXA3ZIfa04MWM1jOfZfUwou0oNqhNwy/votUDvGDt4JA4QF4e0b4g==", + "version": "6.4.0", + "resolved": "https://registry.npmjs.org/engine.io-client/-/engine.io-client-6.4.0.tgz", + "integrity": "sha512-GyKPDyoEha+XZ7iEqam49vz6auPnNJ9ZBfy89f+rMMas8AuiMWOZ9PVzu8xb9ZC6rafUqiGHSCfu22ih66E+1g==", "requires": { - "@socket.io/component-emitter": "~3.0.0", + "@socket.io/component-emitter": "~3.1.0", "debug": "~4.3.1", - "engine.io-parser": "~5.0.0", - "has-cors": "1.1.0", - "parseqs": "0.0.6", - "parseuri": "0.0.6", - "ws": "~8.2.3", - "xmlhttprequest-ssl": "~2.0.0", - "yeast": "0.1.2" + "engine.io-parser": "~5.0.3", + "ws": "~8.11.0", + "xmlhttprequest-ssl": "~2.0.0" } }, "engine.io-parser": { - "version": "5.0.4", - "resolved": "https://registry.npmjs.org/engine.io-parser/-/engine.io-parser-5.0.4.tgz", - "integrity": "sha512-+nVFp+5z1E3HcToEnO7ZIj3g+3k9389DvWtvJZz0T6/eOCPIyyxehFcedoYrZQrp0LgQbD9pPXhpMBKMd5QURg==" + "version": "5.0.7", + "resolved": "https://registry.npmjs.org/engine.io-parser/-/engine.io-parser-5.0.7.tgz", + "integrity": "sha512-P+jDFbvK6lE3n1OL+q9KuzdOFWkkZ/cMV9gol/SbVfpyqfvrfrFTOFJ6fQm2VC3PZHlU3QPhVwmbsCnauHF2MQ==" }, "follow-redirects": { - "version": "1.14.9", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.9.tgz", - "integrity": "sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==" + "version": "1.15.2", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", + "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==" }, "form-data": { "version": "4.0.0", @@ -463,13 +443,14 @@ "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" }, "get-intrinsic": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.1.tgz", - "integrity": "sha512-kWZrnVM42QCiEA2Ig1bG8zjoIMOgxWwYCEeNdwY6Tv/cOSeGpcoX4pXHfKUxNKVoArnrEr2e9srnAxxGIraS9Q==", + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.1.tgz", + "integrity": "sha512-2DcsyfABl+gVHEfCOaTrWgyt+tb6MSEGmKq+kI5HwLbIYgjgmMcV8KQ41uaKz1xxUcn9tJtgFbQUEVcEbd0FYw==", "requires": { "function-bind": "^1.1.1", "has": "^1.0.3", - "has-symbols": "^1.0.1" + "has-proto": "^1.0.1", + "has-symbols": "^1.0.3" } }, "has": { @@ -480,21 +461,16 @@ "function-bind": "^1.1.1" } }, - "has-cors": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/has-cors/-/has-cors-1.1.0.tgz", - "integrity": "sha1-XkdHk/fqmEPRu5nCPu9J/xJv/zk=" + "has-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.1.tgz", + "integrity": "sha512-7qE+iP+O+bgF9clE5+UoBFzE65mlBiVj3tKCrlNQ0Ogwm0BjpT/gK4SlLYDMybDh5I3TCTKnPPa0oMG7JDYrhg==" }, "has-symbols": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==" }, - "lodash": { - "version": "4.17.21", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", - "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" - }, "mime-db": { "version": "1.52.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", @@ -514,34 +490,29 @@ "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, "nanoid": { - "version": "3.3.2", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.2.tgz", - "integrity": "sha512-CuHBogktKwpm5g2sRgv83jEy2ijFzBwMoYA60orPDR7ynsLijJDqgsi4RDGj3OJpy3Ieb+LYwiRmIOGyytgITA==" + "version": "3.3.6", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.6.tgz", + "integrity": "sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA==" }, "object-inspect": { - "version": "1.12.0", - "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.0.tgz", - "integrity": "sha512-Ho2z80bVIvJloH+YzRmpZVQe87+qASmBUKZDWgx9cu+KDrX2ZDH/3tMy+gXbZETVGs2M8YdxObOh7XAtim9Y0g==" + "version": "1.12.3", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.3.tgz", + "integrity": "sha512-geUvdk7c+eizMNUDkRpW1wJwgfOiOeHbxBR/hLXK1aT6zmVSO0jsQcs7fj6MGw89jC/cjGfLcNOrtMYtGqm81g==" }, "papaparse": { - "version": "5.3.2", - "resolved": "https://registry.npmjs.org/papaparse/-/papaparse-5.3.2.tgz", - "integrity": "sha512-6dNZu0Ki+gyV0eBsFKJhYr+MdQYAzFUGlBMNj3GNrmHxmz1lfRa24CjFObPXtjcetlOv5Ad299MhIK0znp3afw==" + "version": "5.4.1", + "resolved": "https://registry.npmjs.org/papaparse/-/papaparse-5.4.1.tgz", + "integrity": "sha512-HipMsgJkZu8br23pW15uvo6sib6wne/4woLZPlFf3rpDyMe9ywEXUsuD7+6K9PRkJlVT51j/sCOYDKGGS3ZJrw==" }, - "parseqs": { - "version": "0.0.6", - "resolved": "https://registry.npmjs.org/parseqs/-/parseqs-0.0.6.tgz", - "integrity": "sha512-jeAGzMDbfSHHA091hr0r31eYfTig+29g3GKKE/PPbEQ65X0lmMwlEoqmhzu0iztID5uJpZsFlUPDP8ThPL7M8w==" - }, - "parseuri": { - "version": "0.0.6", - "resolved": "https://registry.npmjs.org/parseuri/-/parseuri-0.0.6.tgz", - "integrity": "sha512-AUjen8sAkGgao7UyCX6Ahv0gIK2fABKmYjvP4xmy5JaKvcbTRueIqIPHLAfq30xJddqSE033IOMUSOMCcK3Sow==" + "proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" }, "qs": { - "version": "6.10.3", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.10.3.tgz", - "integrity": "sha512-wr7M2E0OFRfIfJZjKGieI8lBKb7fRCH4Fv5KNPEs7gJ8jadvotdsS08PzOKR7opXhZ/Xkjtt3WF9g38drmyRqQ==", + "version": "6.11.2", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.2.tgz", + "integrity": "sha512-tDNIz22aBzCDxLtVH++VnTfzxlfeK5CbqohpSqpJgj1Wg/cQbStNAz3NuqCs5vV+pjBsK4x4pN9HlVh7rcYRiA==", "requires": { "side-channel": "^1.0.4" } @@ -557,42 +528,35 @@ } }, "socket.io-client": { - "version": "4.4.1", - "resolved": "https://registry.npmjs.org/socket.io-client/-/socket.io-client-4.4.1.tgz", - "integrity": "sha512-N5C/L5fLNha5Ojd7Yeb/puKcPWWcoB/A09fEjjNsg91EDVr5twk/OEyO6VT9dlLSUNY85NpW6KBhVMvaLKQ3vQ==", + "version": "4.6.2", + "resolved": "https://registry.npmjs.org/socket.io-client/-/socket.io-client-4.6.2.tgz", + "integrity": "sha512-OwWrMbbA8wSqhBAR0yoPK6EdQLERQAYjXb3A0zLpgxfM1ZGLKoxHx8gVmCHA6pcclRX5oA/zvQf7bghAS11jRA==", "requires": { - "@socket.io/component-emitter": "~3.0.0", - "backo2": "~1.0.2", + "@socket.io/component-emitter": "~3.1.0", "debug": "~4.3.2", - "engine.io-client": "~6.1.1", - "parseuri": "0.0.6", - "socket.io-parser": "~4.1.1" + "engine.io-client": "~6.4.0", + "socket.io-parser": "~4.2.4" } }, "socket.io-parser": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-4.1.2.tgz", - "integrity": "sha512-j3kk71QLJuyQ/hh5F/L2t1goqzdTL0gvDzuhTuNSwihfuFUrcSji0qFZmJJPtG6Rmug153eOPsUizeirf1IIog==", + "version": "4.2.4", + "resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-4.2.4.tgz", + "integrity": "sha512-/GbIKmo8ioc+NIWIhwdecY0ge+qVBSMdgxGygevmdHj24bsfgtCmcUUcQ5ZzcylGFHsN3k4HB4Cgkl96KVnuew==", "requires": { - "@socket.io/component-emitter": "~3.0.0", + "@socket.io/component-emitter": "~3.1.0", "debug": "~4.3.1" } }, "ws": { - "version": "8.2.3", - "resolved": "https://registry.npmjs.org/ws/-/ws-8.2.3.tgz", - "integrity": "sha512-wBuoj1BDpC6ZQ1B7DWQBYVLphPWkm8i9Y0/3YdHjHKHiohOJ1ws+3OccDWtH+PoC9DZD5WOTrJvNbWvjS6JWaA==", + "version": "8.11.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.11.0.tgz", + "integrity": "sha512-HPG3wQd9sNQoT9xHyNCXoDUa+Xw/VevmY9FoHyQ+g+rrMn4j6FB4np7Z0OhdTgjx6MgQLK7jwSy1YecU1+4Asg==", "requires": {} }, "xmlhttprequest-ssl": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/xmlhttprequest-ssl/-/xmlhttprequest-ssl-2.0.0.tgz", "integrity": "sha512-QKxVRxiRACQcVuQEYFsI1hhkrMlrXHPegbbd1yn9UHOmRxY+si12nQYzri3vbzt8VdTTRviqcKxcyllFas5z2A==" - }, - "yeast": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/yeast/-/yeast-0.1.2.tgz", - "integrity": "sha1-AI4G2AlDIMNy28L47XagymyKxBk=" } } } diff --git a/package.json b/package.json index 73f610f..e7c8dd6 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,6 @@ "author": "Tago LLC", "license": "MIT", "dependencies": { - "@tago-io/sdk": "10.7.6" + "@tago-io/sdk": "^11.0.6" } } From 2d2095d7982eac6e9ab9cbf60a5aae7c6b77f804 Mon Sep 17 00:00:00 2001 From: rafaelTelesS Date: Fri, 14 Jul 2023 15:26:42 -0300 Subject: [PATCH 2/4] updating prettier --- analysis.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/analysis.js b/analysis.js index 34898a5..863f6ad 100644 --- a/analysis.js +++ b/analysis.js @@ -56,7 +56,11 @@ async function startAnalysis(context, scope) { .catch((error) => { // Send the validation to the device. // That way we create an error in the dashboard for feedback. - Resources.devices.sendDeviceData(scope[0].device, { variable: "validation", value: `Error when creating the device ${error}`, metadata: { color: "red" } }); + Resources.devices.sendDeviceData(scope[0].device, { + variable: "validation", + value: `Error when creating the device ${error}`, + metadata: { color: "red" }, + }); throw error; }); From c305fde45677fa3da56bc1d63d051cca2a8524cb Mon Sep 17 00:00:00 2001 From: Vitor Lima Date: Mon, 29 Apr 2024 10:44:44 -0300 Subject: [PATCH 3/4] Update analysis.js --- analysis.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/analysis.js b/analysis.js index 863f6ad..5a2450f 100644 --- a/analysis.js +++ b/analysis.js @@ -29,11 +29,16 @@ async function startAnalysis(context, scope) { const device_eui = scope.find((x) => x.variable === "device_eui"); if (!connector_id || !connector_id.value) { - return context.log('Missing "device_connector" in the data scope.'); + return console.log('Missing "device_connector" in the data scope.'); } else if (!network_id || !network_id.value) { - return context.log('Missing "device_network" in the data scope.'); + return console.log('Missing "device_network" in the data scope.'); } else if (!device_eui || !device_eui.value) { - return context.log('Missing "device_eui" in the data scope.'); + return console.log('Missing "device_eui" in the data scope.'); + } + + const deviceID = scope[0]?.device; + if (!deviceID) { + return console.log('Device ID not found in the data scope'); } const result = await Resources.devices @@ -56,7 +61,7 @@ async function startAnalysis(context, scope) { .catch((error) => { // Send the validation to the device. // That way we create an error in the dashboard for feedback. - Resources.devices.sendDeviceData(scope[0].device, { + Resources.devices.sendDeviceData(deviceID, { variable: "validation", value: `Error when creating the device ${error}`, metadata: { color: "red" }, @@ -65,11 +70,11 @@ async function startAnalysis(context, scope) { }); // To add Configuration Parameters to the device: - Resources.devices.paramSet(result.device_id, { key: "param_key", value: "10", sent: false }); + await Resources.devices.paramSet(result.device_id, { key: "param_key", value: "10", sent: false }); // Send feedback to the dashboard: - Resources.devices.sendDeviceData(scope[0].device, { variable: "validation", value: "Device succesfully created!", metadata: { type: "success" } }); - context.log(`Device succesfully created. ID: ${result.device_id}`); + await Resources.devices.sendDeviceData(deviceID, { variable: "validation", value: "Device succesfully created!", metadata: { type: "success" } }); + console.log(`Device succesfully created. ID: ${result.device_id}`); } module.exports = new Analysis(startAnalysis); From e9d2035b2f088fcf927d6b56e4e88a026376797f Mon Sep 17 00:00:00 2001 From: Vitor Lima Date: Mon, 29 Apr 2024 10:46:05 -0300 Subject: [PATCH 4/4] update the code comment --- analysis.js | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/analysis.js b/analysis.js index 5a2450f..4899cf5 100644 --- a/analysis.js +++ b/analysis.js @@ -1,26 +1,27 @@ /* - ** Analysis Example - ** Creating devices using dashboard - ** - ** Using an Input Widget in the dashboard, you will be able to create devices in your account. - ** You can get the dashboard template to use here: https://admin.tago.io/template/6143555a314cef001871ec78 - ** Use a dummy HTTPs device with the dashboard. - ** - ** How to use: - ** To analysis works, you need to add a new policy in your account. Steps to add a new policy: - ** 1 - Click the button "Add Policy" at this url: https://admin.tago.io/am; - ** 2 - In the Target selector, with the field set as "ID", choose your Analysis in the list; - ** 3 - Click the "Click to add a new permission" element and select "Device" with the rule "Access" with the field as "Any"; - ** 4 - To save your new Policy, click the save button in the bottom right corner; + * Example: Creating Devices via Dashboard + * This example demonstrates how to create devices in your account using an Input Widget on the dashboard. + * + * Dashboard Template: + * You can access the dashboard template needed for this operation here: https://admin.tago.io/template/6143555a314cef001871ec78 + * It's recommended to use a dummy HTTPS device alongside the dashboard for testing purposes. + * + * Usage Instructions: + * For the analysis to function correctly, you must add a new policy to your account by following these steps: + * 1. Navigate to https://admin.tago.io/am and click on the "Add Policy" button. + * 2. In the Target selector, ensure the field is set to "ID", then select your Analysis from the list. + * 3. Click on the "Click to add a new permission" option, choose "Device" as the type, and set the rule to "Access" with the scope as "Any". + * 4. Finalize by clicking the save button located in the bottom right corner to apply your new Policy. */ + const { Analysis, Resources } = require("@tago-io/sdk"); async function startAnalysis(context, scope) { if (!scope[0]) { - return context.log("The analysis must be triggered by a widget."); + return console.log("The analysis must be triggered by a widget."); } - context.log("Creating your device"); + console.log("Creating your device"); // Get the variables sent by the widget/dashboard. const network_id = scope.find((x) => x.variable === "device_network");