Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-ews

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-ews - npm Package Compare versions

Comparing version 3.0.5 to 3.0.6

165

lib/ews.js
"use strict";
var request = require('request');
var when = require('when');
var ntlm = require('httpntlm');
var soap = require('soap');
var _ = require('lodash');
const request = require('request');
const debug = require('debug')('ews');
const when = require('when');
const ntlm = require('httpntlm');
const soap = require('soap');
const _ = require('lodash');
var path = require('path');
var tmp = require('tmp');
var fs = require('fs');
const path = require('path');
const tmp = require('tmp');
const fs = require('fs');
var NtlmSecurity = require('./ntlmSecurity');
var HttpClient = require('./http');
const NtlmSecurity = require('./ntlmSecurity');
const HttpClient = require('./http');

@@ -24,2 +25,6 @@ function EWS(config, options) {

// define class vars
this.auth;
this.tempDir;
// if required config found...

@@ -32,3 +37,3 @@ if(configIsValid) {

authProfile: new NtlmSecurity(config.username, config.password, options),
getFile: function(url, filePath) {
getUrl: function(url, filePath) {
var ntlmOptions = { 'username': config.username, 'password': config.password };

@@ -39,3 +44,3 @@ ntlmOptions = _.merge(ntlmOptions, _.clone(options));

return when.promise((resolve, reject) => {
ntlm.get(ntlmOptions, function (err, res) {
ntlm.get(ntlmOptions, function(err, res) {
if(err) reject(err);

@@ -56,3 +61,3 @@ else if(res.statusCode == 401) reject(new Error('NTLM StatusCode 401: Unauthorized.'));

authProfile: new soap.BasicAuthSecurity(config.username, config.password, options),
getFile: function(url, filePath) {
getUrl: function(url, filePath) {
// request options

@@ -64,3 +69,3 @@ var requestOptions = { 'auth': { 'user': config.username, 'pass': config.password, 'sendImmediately': false } };

return when.promise((resolve, reject) => {
request(requestOptions, (err, res, body) => {
request(requestOptions, function(err, res, body) {
if(err) reject(err);

@@ -87,4 +92,2 @@ else if(res.statusCode == 401) reject(new Error('Basic Auth StatusCode 401: Unauthorized.'));

this.tempDir = config.temp;
} else {
this.tempDir;
}

@@ -110,13 +113,36 @@

var urlServices = this.urlServices;
var urlMessages = this.urlMessages;
var urlTypes = this.urlTypes;
var urlApi = this.urlApi;
var getFile = this.auth.getFile;
var ews = this;
// if file exists, return fullfilled promise with filePath, else reject
function ifFileExists(filePath) {
if(!filePath) return when.reject(new Error('File not specified'));
else return when.promise((resolve, reject) => {
fs.stat(filePath, function(err, stats) {
if(err) reject(new Error('File does not exist.'));
else if(stats.isFile()) resolve(filePath);
else reject(new Error('Invalid file at' + filePath));
})
});
}
// if dir exists, return fullfilled promise with dirPath, else reject
function ifDirExists(dirPath) {
if(!dirPath) return when.reject(new Error('Directory not specified'));
else return when.promise((resolve, reject) => {
fs.stat(dirPath, function(err, stats) {
if(err) reject(new Error('Directory does not exist.'));
else if(stats.isDirectory()) resolve(dirPath);
else reject(new Error('Invalid directory at ' + dirPath));
})
});
}
// apply fix to wsdl at file path
function fixWsdl(filePath) {
// wsdl fix
var wsdlFix = '\n<wsdl:service name="ExchangeServices">\n<wsdl:port name="ExchangeServicePort" binding="tns:ExchangeServiceBinding">\n<soap:address location="' + urlApi + '"/>\n</wsdl:port>\n</wsdl:service>\n</wsdl:definitions>';
// wsdl service definition
var wsdlService = '<wsdl:service name="ExchangeServices"><wsdl:port name="ExchangeServicePort" binding="tns:ExchangeServiceBinding"><soap:address location="' + ews.urlApi + '"/></wsdl:port></wsdl:service>';
// fix ms wdsl...

@@ -129,14 +155,29 @@ // https://msdn.microsoft.com/en-us/library/office/aa580675.aspx

fs.readFile(filePath, 'utf8', function(err, wsdl) {
if(err) reject(err);
if(err) {
reject(err);
} else {
// wsdl malformed
var isMalformed = (wsdl.search('<wsdl:definitions') == -1);
// error on malformed wsdl file
else if(wsdl.search('<wsdl:definitions') == -1) reject(new Error('Invalid or malformed wsdl file: ' + filePath));
// wsdl already fixed
var isFixed = (wsdl.search('<wsdl:service name="ExchangeServices">') >= 0);
else {
// Remove </wsdl:definitions> and replace with our fix and
// write file back to disk
fs.writeFile(filePath, wsdl.replace("</wsdl:definitions>",wsdlFix), function(err) {
if(err) reject(err);
else resolve(filePath);
});
// if error on malformed wsdl file
if(isMalformed) {
reject(new Error('Invalid or malformed wsdl file: ' + filePath));
}
// else, if wsdl fix is already in place
else if(isFixed) {
resolve(filePath);
}
// else, insert wsdl service
else {
debug('inserting service definition into services.wsdl...');
fs.writeFile(filePath, wsdl.replace('</wsdl:definitions>', '\n' + wsdlService + '\n</wsdl:definitions>'), function(err) {
if(err) reject(err);
else resolve(filePath);
});
}
}

@@ -150,42 +191,18 @@ });

// if file exists...
function ifFileExists(filePath) {
if(!filePath) return when.reject(new Error('File not specified'));
else return when.promise((resolve, reject) => {
fs.stat(filePath, (err, stats) => {
if(err) reject(new Error('File does not exist.'));
else if(stats.isFile()) resolve(filePath);
else reject(new Error('Invalid file at' + filePath));
})
});
}
// if dir exists
function ifDirExists(dirPath) {
if(!dirPath) return when.reject(new Error('Directory not specified'));
else return when.promise((resolve, reject) => {
fs.stat(dirPath, (err, stats) => {
if(err) reject(new Error('Directory does not exist.'));
else if(stats.isDirectory()) resolve(dirPath);
else reject(new Error('Invalid directory at ' + dirPath));
})
});
}
return ifDirExists(tempDir)
// verify messages.wsd
// verify messages.xsd
.then(() => {
var messageswsdPath = path.join(tempDir, path.basename(urlMessages));
debug('validating messages.xsd...');
var messageswsdPath = path.join(tempDir, path.basename(ews.urlMessages));
return ifFileExists(messageswsdPath)
.catch(() => getFile(urlMessages, messageswsdPath));
.catch(() => ews.auth.getUrl(ews.urlMessages, messageswsdPath));
})
// verify types.wsd
// verify types.xsd
.then(() => {
var typeswsdPath = path.join(tempDir, path.basename(urlTypes));
debug('validating types.xsd...');
var typeswsdPath = path.join(tempDir, path.basename(ews.urlTypes));
return ifFileExists(typeswsdPath)
.catch(() => getFile(urlTypes, typeswsdPath));
.catch(() => ews.auth.getUrl(ews.urlTypes, typeswsdPath));
})

@@ -195,5 +212,6 @@

.then(() => {
var serviceswsdlPath = path.join(tempDir, path.basename(urlServices));
debug('validating services.wsdl...');
var serviceswsdlPath = path.join(tempDir, path.basename(ews.urlServices));
return ifFileExists(serviceswsdlPath)
.catch(() => getFile(urlServices, serviceswsdlPath));
.catch(() => ews.auth.getUrl(ews.urlServices, serviceswsdlPath));
})

@@ -208,6 +226,7 @@

return when.promise((resolve, reject) => {
tmp.dir({unsafeCleanup: false}, (err, temp) => {
tmp.dir({unsafeCleanup: false}, function(err, temp) {
if(err) {
reject(err);
} else {
debug('created temp dir at "%s"', temp);
resolve(temp);

@@ -219,10 +238,10 @@ }

return initFiles(this.tempDir)
return initFiles(ews.tempDir)
.catch(() => {
console.log('EWS temp directory not sepcified or does not exist. Using system temp directory instead.');
debug('temp directory not sepcified or does not exist');
return getTempDir()
.then(temp => {
this.tempDir = temp;
return initFiles(temp);
ews.tempDir = temp;
return initFiles(ews.tempDir);
});

@@ -266,3 +285,3 @@ });

// run ews soap function
client[ewsFunction](ewsArgs, (err, result) => {
client[ewsFunction](ewsArgs, function(err, result) {
if(err) reject(err);

@@ -269,0 +288,0 @@ else resolve(result);

{
"name": "node-ews",
"version": "3.0.5",
"version": "3.0.6",
"description": "A simple JSON wrapper for the Exchange Web Services (EWS) SOAP API",

@@ -12,2 +12,3 @@ "main": "./index.js",

"dependencies": {
"debug": "2.3.3",
"httpntlm": "1.7.3",

@@ -14,0 +15,0 @@ "lodash": "4.17.2",

@@ -7,3 +7,5 @@ # node-ews

```
#### Updates in patch 3.0.3 (new)
#### Updates in patch 3.0.6 (new)
- Addressed issues in PR #38, cleaned up code.
- Merged PR for issues #37
- Merged PR for issues #36 to fix typo in 3.0.2

@@ -10,0 +12,0 @@ - Merged PR for issues #34 to fix typo in 3.0.1

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc