nmarus / node-ews

A simple JSON wrapper for the Exchange Web Services (EWS) SOAP API.
MIT License
116 stars 52 forks source link

TypeError: Cannot read property 'wsdlOptions' of undefined #90

Open christiannguyen opened 6 years ago

christiannguyen commented 6 years ago

Issue with push listener. Here's how i set it up not sure if 100% correct.

const fs = require('fs');
const os = require('os');
const EWS = require('node-ews');

// exchange server connection info

const ewsConfig = {
  username: 'myusername',
  password: 'mypassword',
  host: 'https://outlook.office365.com',
  auth: 'basic'
};

// initialize node-ews
const ews = new EWS(ewsConfig);

// specify listener service options
const serviceOptions = {
  port: 8080, // defaults to port 8000
  path: '/', // defaults to '/notification'
  // If you do not have NotificationService.wsdl it can be found via a quick Google search
  xml: fs.readFileSync('NotificationService.wsdl', 'utf8') // the xml field is required
};

// create the listener service
ews.notificationService(serviceOptions, function(response) {
  console.log(new Date().toISOString(), '| Received EWS Push Notification');
  console.log(new Date().toISOString(), '| Response:', JSON.stringify(response));
  // Do something with response
  return {SendNotificationResult: { SubscriptionStatus: 'OK' } }; // respond with 'OK' to keep subscription alive
  // return {SendNotificationResult: { SubscriptionStatus: 'UNSUBSCRIBE' } }; // respond with 'UNSUBSCRIBE' to unsubscribe
})

// The soap.listen object is passed through the promise so you can optionally use the .log() functionality
// https://github.com/vpulim/node-soap#server-logging
.then(server => {
  server.log = function(type, data) {
    console.log(new Date().toISOString(), '| ', type, ':', data);
  };
});

// create a push notification subscription
// https://msdn.microsoft.com/en-us/library/office/aa566188
const ewsParams = {
  PushSubscriptionRequest: {
    FolderIds: {
      DistinguishedFolderId: {
        attributes: {
          Id: 'inbox'
        }
      }
    },
    EventTypes: {
      EventType: ['CreatedEvent']
    },
    StatusFrequency: 1,
    // subscription notifications will be sent to our listener service
    URL: 'http://' + os.hostname() + ':' + serviceOptions.port + serviceOptions.path
  }
};
ews.run('Subscribe', ewsParams);

Issue im getting is regarding this line here options = _.merge(ews[ews.auth].wsdlOptions, { port: 8000, path:'/notification' }, options);. Should this be ews[ews.auth] or just ews.auth.wsdlOptions?

Jashepp commented 6 years ago

I also just came across this issue. I think it's a typo that should be ews.auth.wsdlOptions? My quick little workaround in my own code is to set toString after creating the EWS object. ews.auth.toString = ()=>'auth';

ghost commented 4 years ago

Thanks @Jashepp - it was working for me but I still don't understand the flow.