futurosenso-lang
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -0,0 +0,0 @@ // For a detailed explanation regarding each configuration property, visit: |
41
lang.js
const fs = require('fs'); | ||
const xml2js = require('xml2js'); | ||
const logger = require("futurosenso-log"); | ||
const Client = require('node-rest-client').Client; | ||
const client = new Client(); | ||
@@ -10,2 +13,4 @@ var exports = module.exports = {}; | ||
var webService; | ||
exports.loadViewContentFromFile = function (view, file, endEventCallback) { | ||
@@ -62,4 +67,40 @@ | ||
exports.setRemoteHost = function (remoteHost) { | ||
webService = remoteHost; | ||
} | ||
// resultCallback(content, remotePath) | ||
exports.getRemoteText = function (language, view, label, resultCallback) { | ||
if(!language) | ||
language = "EN"; | ||
let remotePath = `${webService}/${language}/${view}`; | ||
if(label) | ||
remotePath += `/${label}`; | ||
let request = client.get(remotePath, function (data) { | ||
if(data && data.success) { | ||
resultCallback(data.content, remotePath); | ||
} | ||
else | ||
resultCallback(undefined, remotePath); | ||
}); | ||
request.on('error', function (req) { | ||
logger.log("error occured accessing path: " + remotePath); | ||
resultCallback(undefined, remotePath); | ||
}); | ||
request.on('requestTimeout', function (req) { | ||
logger.log("request has expired for path: " + remotePath); | ||
req.abort(); | ||
resultCallback(undefined, remotePath); | ||
}); | ||
request.on('responseTimeout', function (res) { | ||
logger.log("response has expired for path: " + remotePath); | ||
resultCallback(undefined, remotePath); | ||
}); | ||
} | ||
//exports.loadViewContentFromFile("View1", "xml/testView1.xml"); | ||
//console.dir(contents); |
@@ -55,1 +55,20 @@ const fs = require("fs"); | ||
test("Test getting content from remote host", (done) => { | ||
let remoteHost = "http://localhost:8787"; | ||
lang.setRemoteHost(remoteHost); | ||
lang.getRemoteText("EN","view-home1", null, (content, remotePath)=>{ | ||
expect(content).toBeDefined(); | ||
expect(remotePath).toEqual(remoteHost + "/EN/view-home1"); | ||
done(); | ||
}); | ||
}); | ||
test("Test getting content from not existing remote host", (done) => { | ||
let remoteHost = "http://localhost:9087"; | ||
lang.setRemoteHost(remoteHost); | ||
lang.getRemoteText("EN","view-home1", null, (content, remotePath)=>{ | ||
expect(content).toBeUndefined(); | ||
expect(remotePath).toEqual(remoteHost + "/EN/view-home1"); | ||
done(); | ||
}); | ||
}); |
@@ -5,3 +5,3 @@ { | ||
"email": "dev@futurosenso.com", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Language content utility, load content translations from xml file exported from access file.", | ||
@@ -15,5 +15,9 @@ "license": "ISC", | ||
], | ||
"engines": { | ||
"node": ">=8.15" | ||
}, | ||
"main": "lang.js", | ||
"dependencies": { | ||
"xml2js": "0.4.19" | ||
"xml2js": "0.4.19", | ||
"node-rest-client": "3.1.0" | ||
}, | ||
@@ -20,0 +24,0 @@ "devDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16869
8
322
2
+ Addednode-rest-client@3.1.0
+ Addeddebug@2.2.0(transitive)
+ Addedfollow-redirects@1.15.9(transitive)
+ Addedms@0.7.1(transitive)
+ Addednode-rest-client@3.1.0(transitive)