Skip to content

Commit 5160317

Browse files
authored
fix: lgtm, removed ajv from global namespace (#93)
* chore: fixed global namespace polution, fixed lgtm * 3.8.1-0 * chore: prepare for release * chore: prepare for release 3.8.1 🎉 * chore: lgtm Closes #93
1 parent 829df63 commit 5160317

File tree

6 files changed

+18
-50
lines changed

6 files changed

+18
-50
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ flows/.config.json
5252
dist/
5353
.mc
5454
docs
55+
schema.json
56+
5557
#ignore bower, we copy the files for now to public/assets
5658
bower.json
5759
bower_components
@@ -66,4 +68,5 @@ tmp
6668
report.xml
6769

6870
# ignore istanbul code coverage
69-
.nyc_output
71+
.nyc_output
72+

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 3.8.1 (Vienna Tigers) - July 2020
4+
5+
## Bugfix 3.8.1
6+
7+
- Removed Ajv from global scope
8+
39
## 3.8.0 (Vienna Tigers) - July 2020
410

511
## New Features 3.8.0

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@mindconnect/node-red-contrib-mindconnect",
3-
"version": "3.8.0",
3+
"version": "3.8.1",
44
"description": "node red mindconnect node using mindconnect-nodejs library.",
55
"main": "index.js",
66
"scripts": {

src/mindconnect.html

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
&nbsp;&nbsp;<a href="https://opensource.mindsphere.io/docs/node-red-contrib-mindconnect/index.html" target="_new" class="headerLink" title="Documentation">
77
<i class="fa fa-globe"></i> MindConnect Node-RED Agent
88
</a>
9-
</span> <span style="color:#aaaaaa !important">v3.8.0</span>
9+
</span> <span style="color:#aaaaaa !important">v3.8.1</span>
1010
</div>
1111

1212
<div class="form-row">
@@ -249,48 +249,10 @@
249249
</ul>
250250
</p>
251251
</script>
252-
<script type="text/javascript" src="mindconnect/ajv.min.js"></script>
253252

254-
<script type="text/javascript">
255-
const configurationSchema = {
256-
type: "object",
257-
required: ["content"],
258-
properties: {
259-
content: {
260-
type: "object",
261-
required: ["baseUrl", "iat", "clientCredentialProfile", "clientId", "tenant"],
262-
properties: {
263-
baseUrl: {
264-
type: "string",
265-
},
266-
iat: {
267-
type: "string",
268-
},
269-
clientCredentialProfile: {
270-
type: "array",
271-
items: {
272-
type: "string",
273-
},
274-
},
275-
clientId: {
276-
type: "string",
277-
},
278-
tenant: {
279-
type: "string",
280-
},
281-
},
282-
},
283-
expiration: {
284-
type: "string",
285-
},
286-
},
287-
};
288-
289-
function configValidator() {
290-
const schemaValidator = new Ajv({ $data: true, allErrors: true });
291-
return schemaValidator.compile(configurationSchema);
292-
}
293253

254+
<script type="text/javascript">
255+
294256
RED.nodes.registerType("mindconnect", {
295257
category: "mindsphere",
296258
color: "#41aaaa",
@@ -310,6 +272,9 @@
310272
if (data.action === "delete" && data.clientId) {
311273
return true;
312274
}
275+
276+
// generated json schema for validation if the data type is indeed configuration object
277+
function configValidator(){"use strict";var e=function e(r,t,a,i,s){if(!r||"object"!=typeof r||Array.isArray(r))return e.errors=[{keyword:"type",dataPath:(t||"")+"",schemaPath:"#/type",params:{type:"object"},message:"should be object"}],!1;var n=r.content;if(void 0===n)return e.errors=[{keyword:"required",dataPath:(t||"")+"",schemaPath:"#/required",params:{missingProperty:"content"},message:"should have required property 'content'"}],!1;var o=0;if(!n||"object"!=typeof n||Array.isArray(n))return e.errors=[{keyword:"type",dataPath:(t||"")+".content",schemaPath:"#/properties/content/type",params:{type:"object"},message:"should be object"}],!1;if(void 0===n.baseUrl)return e.errors=[{keyword:"required",dataPath:(t||"")+".content",schemaPath:"#/properties/content/required",params:{missingProperty:"baseUrl"},message:"should have required property 'baseUrl'"}],!1;var p=0;if("string"!=typeof n.baseUrl)return e.errors=[{keyword:"type",dataPath:(t||"")+".content.baseUrl",schemaPath:"#/properties/content/properties/baseUrl/type",params:{type:"string"},message:"should be string"}],!1;if(0===p){if(void 0===n.iat)return e.errors=[{keyword:"required",dataPath:(t||"")+".content",schemaPath:"#/properties/content/required",params:{missingProperty:"iat"},message:"should have required property 'iat'"}],!1;if(p=0,"string"!=typeof n.iat)return e.errors=[{keyword:"type",dataPath:(t||"")+".content.iat",schemaPath:"#/properties/content/properties/iat/type",params:{type:"string"},message:"should be string"}],!1;if(0===p){var d=n.clientCredentialProfile;if(void 0===d)return e.errors=[{keyword:"required",dataPath:(t||"")+".content",schemaPath:"#/properties/content/required",params:{missingProperty:"clientCredentialProfile"},message:"should have required property 'clientCredentialProfile'"}],!1;if(p=0,!Array.isArray(d))return e.errors=[{keyword:"type",dataPath:(t||"")+".content.clientCredentialProfile",schemaPath:"#/properties/content/properties/clientCredentialProfile/type",params:{type:"array"},message:"should be array"}],!1;for(var y=0;y<d.length;y++)if("string"!=typeof d[y])return e.errors=[{keyword:"type",dataPath:(t||"")+".content.clientCredentialProfile["+y+"]",schemaPath:"#/properties/content/properties/clientCredentialProfile/items/type",params:{type:"string"},message:"should be string"}],!1;if(0===p){if(void 0===n.clientId)return e.errors=[{keyword:"required",dataPath:(t||"")+".content",schemaPath:"#/properties/content/required",params:{missingProperty:"clientId"},message:"should have required property 'clientId'"}],!1;if(p=0,"string"!=typeof n.clientId)return e.errors=[{keyword:"type",dataPath:(t||"")+".content.clientId",schemaPath:"#/properties/content/properties/clientId/type",params:{type:"string"},message:"should be string"}],!1;if(0===p){if(void 0===n.tenant)return e.errors=[{keyword:"required",dataPath:(t||"")+".content",schemaPath:"#/properties/content/required",params:{missingProperty:"tenant"},message:"should have required property 'tenant'"}],!1;if(p=0,"string"!=typeof n.tenant)return e.errors=[{keyword:"type",dataPath:(t||"")+".content.tenant",schemaPath:"#/properties/content/properties/tenant/type",params:{type:"string"},message:"should be string"}],!1}}}}if(0===o)if(void 0===r.expiration);else if(o=0,"string"!=typeof r.expiration)return e.errors=[{keyword:"type",dataPath:(t||"")+".expiration",schemaPath:"#/properties/expiration/type",params:{type:"string"},message:"should be string"}],!1;return e.errors=null,!0};return e.schema={type:"object",required:["content"],properties:{content:{type:"object",required:["baseUrl","iat","clientCredentialProfile","clientId","tenant"],properties:{baseUrl:{type:"string"},iat:{type:"string"},clientCredentialProfile:{type:"array",items:{type:"string"}},clientId:{type:"string"},tenant:{type:"string"}}},expiration:{type:"string"}}},e.errors=null,e}; // lgtm [js/useless-assignment-to-local]
313278
const validator = configValidator();
314279
const result = validator(data);
315280
return result;
@@ -383,7 +348,6 @@
383348
oneditprepare: function () {
384349
$("#noLinkSpan").hide();
385350
try {
386-
const node = this;
387351
const agentConfig = JSON.parse(this.agentconfig);
388352
const target =
389353
agentConfig.content.baseUrl.replace("southgate", `${agentConfig.content.tenant}-assetmanager`) +

src/mindconnect.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,6 @@ export = function (RED: any): void {
366366

367367
RED.nodes.registerType("mindconnect", nodeRedMindConnectAgent);
368368

369-
RED.httpAdmin.get("/mindconnect/ajv.min.js", function (req, res) {
370-
const filename = require.resolve("ajv/dist/ajv.min.js");
371-
res.sendFile(filename);
372-
});
373-
374369
RED.httpAdmin.get("/mindconnect/mindsphere.css", function (req, res) {
375370
const filename = path.join(__dirname, "mindsphere.css");
376371
res.sendFile(filename);

0 commit comments

Comments
 (0)