Writing LDAP queries is hard! this is a tool to generate LDAP operations defined in RFC 4511
import { QueryGenerator } from "ldap-query-generator";
/** User Fields */
interface User {}
/** You can use it with or without generic type */
const qGen = new QueryGenerator<User>();
const { query } = qGen
.select(["USNIntersite", "aCSPolicyName"])
.where({ field: "mobile", action: "substrings", criteria: "404*999*" })
.whereAnd({ field: "memberOf", action: "startWith", criteria: "admin" })
.whereAnd({ field: "memberOf", action: "endWith", criteria: "office" })
.whereAnd({ field: "badPwdCount", action: "lessOrEqual", criteria: "2" })
.whereAnd({ field: "info", action: "approxMatch", criteria: "my-info" })
.whereOr({ field: "mail", action: "present", criteria: "*@domain.com" })
.whereOr({
field: "homePostalAddress",
action: "substrings",
criteria: "Georgia",
})
.whereNot({
field: "delivContLength",
action: "greaterOrEqual",
criteria: "6",
})
.whereNot({
field: "middleName",
action: "extensible",
criteria: "joe",
extensibleConfig: {
dn: true,
ignoreField: true,
matchingRuleId: "1.2.840.113556.1.4.1941",
},
})
.whereNot({
field: "userAccountControl",
action: "extensible",
criteria: "2",
extensibleConfig: {
dn: false,
ignoreField: false,
matchingRuleId: "1.2.840.113556.1.4.803",
},
})
.whereRaw("&(cn=3)(dn=*)")
.whereRaw("phone=*11");
console.log(query.toString());
Output:
(&(mobile=404*999*)(&(memberOf=admin*))(&(memberOf=*office))(&(badPwdCount<=2))(&(info~=my-info))(|(mail=*))(|(homePostalAddress=Georgia))(!(delivContLength>=6))(!(:dn:1.2.840.113556.1.4.1941:=joe))(!(userAccountControl:1.2.840.113556.1.4.803:=2))(&(cn=3)(dn=*))(phone=*11))
to generate interfaces from ldap schema, use ldap-schema-ts-generator
API documentation API Website
Generated using TypeDoc