DefinitelyTyped/types/ldapjs-client/ldapjs-client-tests.ts
Valerio Coltrè eae899753b [ldapjs-client] Basic Typings (#36243)
* initialized ldapjs-client typings

* client is a Class, not a factory function

* removed JSDOC, fixed linting

* fix tsconfig and typescript version. lint should go green

* removing unnecessary generic

* unknown type is supported after TS 3.0

* enabling npm-naming and complying to it

* exporting interface in commonjs style, and minor cleanup
2019-07-08 14:48:17 -07:00

45 lines
952 B
TypeScript

import LdapJS = require('ldapjs-client');
const clientOptions: LdapJS.ClientOptions = {
url: 'ldap://anyserver:389',
};
const client = new LdapJS(clientOptions);
const dn = 'cn=foo, o=example';
interface LdapObject {
cn: string;
ou: string;
}
(async () => {
await client.add(dn, { cn: 'foo' });
await client.bind(dn, 'pazzvord');
await client.del(dn);
const change: LdapJS.Change = {
operation: 'add',
modification: {
pets: ['cat', 'dog'],
},
};
await client.modify(dn, change);
await client.modifyDN(dn, 'cn=baz, o=example');
const options: LdapJS.SearchOptions = {
filter: '(&(l=Seattle)(email=*@foo.com))',
scope: 'sub',
attributes: ['dn', 'sn', 'cn'],
};
const searchResult = await client.search(dn, options) as LdapObject[];
type resultType = typeof searchResult;
await client.unbind();
client.destroy();
})();