I want to use ldapjs to search a Microsoft Active Directory (AD) server.
This appears to be a three step procedure. First you need to bind to the server (authenticate), then you need to search & filter the information you are looking for, and then you need to get the results out of the returned Event Emitter.
The SO answer here is very informative, and I have been able to get the desired results server side, but I want to return the searchEntry to the client instead of printing to console. How can I do that?
As I understand the problem: I want to use the Meteor.wrapAsync method server side in order to turn the asynchronous LDAP response from ldapjs synchronous. Meteor.wrapAsync returns a promise and returning that in a Meteor method will resolve that promise and send the result to the client via DPP. Unfortunately, the result contains a circular object that cannot be serialised. So I need to somehow resolve the promise server side and deal with the circular object before returning to the client.
Meteor.wrapAsync does not return a Promise. It just ensures that the wrapped code runs in a Fiber. It also expects the wrapped code to have a callback with the “standard” (error, result) signature. The (asynchronous) wrapped code may then be treated like any other Meteor sync-style code,
If you are seeing Promise-related errors, then as @fg1 suggests, maybe the ldapjs library automatically returns a Promise if a callback is not used (I’ve not used it, so can’t be certain). In that situation, use async/await. So, in a Meteor method:
The callback signature of search.on is not (error, result), so Meteor.wrapAsync will not work as expected. Wrapping the callback in Meteor.bindEnvironment is the way to resolve that. However, it looks like something in there is using Promises, or you would not be getting an UnhandledPromiseRejectionWarning exception,