# ldap-query-generator

> LDAP query generator

Latest version **0.8.7** (published 2022-08-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install ldap-query-generator
pnpm add ldap-query-generator
yarn add ldap-query-generator
bun add ldap-query-generator
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.8.7 |
| Published | 2022-08-17 |
| First published | 2020-04-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 49.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Saeid Ostad |
| Maintainers | saostad |
| Keywords | ldap, typescript, query, generator, schema, aware |

## Links

- npm: https://www.npmjs.com/package/ldap-query-generator
- Repository: https://github.com/saostad/ldap-query-generator
- Homepage: https://github.com/saostad/ldap-query-generator#readme
- Issues: https://github.com/saostad/ldap-query-generator/issues
- npm.io page: https://npm.io/package/ldap-query-generator

## Dependencies (1)

- [fast-node-logger](https://npm.io/package/fast-node-logger.md) ^3.0.3

## Alternatives

- [gamedig](https://npm.io/package/gamedig.md) — 29.3K weekly downloads
- [join-monster](https://npm.io/package/join-monster.md) — 12.8K weekly downloads
- [masked](https://npm.io/package/masked.md) — 5.5K weekly downloads
- [@comunica/actor-query-process-explain-logical](https://npm.io/package/@comunica/actor-query-process-explain-logical.md) — 4.7K weekly downloads
- [@veracity/vui](https://npm.io/package/@veracity/vui.md) — 4.6K weekly downloads

## Recent versions

- 0.8.7 (latest) — 2022-08-17
- 0.8.6 — 2022-08-16
- 0.8.5 — 2022-08-16
- 0.8.4 — 2022-07-20
- 0.8.3 — 2021-03-03
- 0.8.2 — 2020-12-28
- 0.8.1 — 2020-06-07
- 0.8.0 — 2020-04-26
- 0.7.2 — 2020-04-19
- 0.7.1 — 2020-04-19
- 0.7.0 — 2020-04-19
- 0.6.5 — 2020-04-19
- 0.6.4 — 2020-04-19
- 0.6.3 — 2020-04-18
- 0.6.2 — 2020-04-17
- … 16 more at https://npm.io/package/ldap-query-generator/versions

## README

# LDAP query generator

Writing LDAP queries is hard!
this is a tool to generate LDAP operations defined in [RFC 4511](https://tools.ietf.org/html/rfc4511)

## AS Easy AS

```ts
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))
```

### Note:

to generate interfaces from ldap schema, use [ldap-schema-ts-generator](https://www.npmjs.com/package/ldap-schema-ts-generator)

### Api Documentations

API documentation [API Website](https://saostad.github.io/ldap-query-generator/)

## TODO

- [ ] LDAP Search Filters [RFC4515](https://tools.ietf.org/html/rfc4515)
  - [x] where
  - [x] whereAnd
  - [x] whereOr
  - [x] whereNot
  - [x] select
  - [x] toString
  - [x] whereRaw
  - [ ] Absence of attribute (!(attribute=_)) , e.g. (!proxyAddresses=_)
  - [ ] Filter boolean attributes the consideration of the upper/ lower case will be crucial. The use of TRUE or FALSE is absolutely necessary for filtering such booleans.
  - [ ] Special characters: characters ( ) & | = ! > < ~ \* / \ play a special role for the declaration of LDAP filters.
  - [ ] Hex Numbers
  - [ ] Binary Values
  - [ ] Filtering for Bit Fields
  - [ ] Filtering with Ambiguous Name Resolution (ANR)
- [ ] LDAP Search Filter Validator
  - [ ] No quotation marks Comparative strings do NOT appear in quotation marks. A filter for the displayName 'Philipp Foeckeler' would read as follows: (displayName=Philipp Foeckeler)
  - [ ] correct parentheses
  - [ ] you can't use wildcards in LDAP filters for attributes containing LDAP distinguished names (attributes with DN-string syntax / ADSI attribute data type ADSTYPE_DN_STRING = 1). The same applies for ADS: Filters in which DN attributes are searched with wildcards do not work. the following filter won't work!
        (distinguishedName=\*,ou=Sydney,dc=cerrotorre,dc=org)

## Inspired By:

- [PHP LdapTools](http://www.phpldaptools.com/tutorials/Building-LDAP-Queries/)
- [knex.js](http://knexjs.org/)
- [ldap.js](http://ldapjs.org/filters.html)
- [Adldap2](https://github.com/Adldap2/Adldap2)

### Useful Resources

- [ldapexplorer](http://www.ldapexplorer.com/en/manual/109010000-ldap-filter-syntax.htm)

---
_Source: https://npm.io/package/ldap-query-generator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
