Add promised-ldap@0.3

This commit is contained in:
Alan Plum
2018-11-24 00:09:31 +01:00
parent 36a32d8a72
commit 3df7d2836e
4 changed files with 151 additions and 0 deletions
+95
View File
@@ -0,0 +1,95 @@
// Type definitions for promised-ldap 0.3
// Project: https://github.com/stewartml/promised-ldap#readme
// Definitions by: My Self <https://github.com/me>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
import { EventEmitter } from "events";
import * as ldap from "ldapjs";
declare class Client extends EventEmitter {
constructor({ url }: { url: string });
search(
base: string,
options: ldap.SearchOptions,
controls?: ldap.Control | ldap.Control[]
): Promise<{
entries: any[];
references: any[];
}>;
authenticate(base: string, dn: string, password: string): Promise<any>;
authenticateUser(
base: string,
dn: string,
password: string
): Promise<{ name: string; email: string; groups: string[] } | null>;
bind(
dn: string,
password: string,
controls?: ldap.Control | ldap.Control[]
): Promise<any>;
add(
name: string,
entry: object,
controls?: ldap.Control | ldap.Control[]
): Promise<any>;
compare(
name: string,
attr: string,
value: string,
controls?: ldap.Control | ldap.Control[]
): Promise<boolean>;
del(name: string, controls?: ldap.Control | ldap.Control[]): Promise<any>;
exop(
name: string,
value: string,
controls?: ldap.Control | ldap.Control[]
): Promise<any>;
modify(
name: string,
change: ldap.Change | ldap.Change[],
controls?: ldap.Control | ldap.Control[]
): Promise<any>;
modifyDN(
name: string,
newName: string,
controls?: ldap.Control | ldap.Control[]
): Promise<any>;
_search(
base: string,
options: ldap.SearchOptions,
controls?: ldap.Control | ldap.Control[],
_bypass?: boolean
): Promise<EventEmitter>;
_search(
base: string,
options: ldap.SearchOptions,
_bypass: boolean
): Promise<EventEmitter>;
starttls(
options: object,
controls: ldap.Control | ldap.Control[],
_bypass?: boolean
): Promise<any>;
unbind(): Promise<void>;
destroy(err?: any): void;
}
declare namespace Client {
type SearchOptions = ldap.SearchOptions;
}
export = Client;
@@ -0,0 +1,39 @@
import ldap = require("promised-ldap");
import ldapjs = require("ldapjs");
const client = new ldap({
url: "ldap://127.0.0.1:1389"
});
client.authenticate("test", "cn=root", "secret").then((res: any) => {
console.log(res);
});
client.authenticateUser("test", "cn=root", "secret").then((res: any) => {
console.log(res);
});
client.bind("cn=root", "secret").catch((err: Error) => {
console.error(err);
});
const opts: ldap.SearchOptions = {
filter: "(&(l=Seattle)(email=*@foo.com))",
scope: "sub",
attributes: ["dn", "sn", "cn"]
};
client._search("o=example", opts).then((res: NodeJS.EventEmitter) => {
console.log(res);
});
const change = new ldapjs.Change({
operation: "add",
modification: {
pets: ["cat", "dog"]
}
});
client.modify("cn=foo, o=example", change).catch((err: Error) => {
console.error(err);
});
+16
View File
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es6"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": ["../"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": ["index.d.ts", "promised-ldap-tests.ts"]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }