# ldap-directory-manager

> schema-aware, type-safe LDAP manager, written in typescript to create hight-level functionalities

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

## Install

```sh
npm install ldap-directory-manager
pnpm add ldap-directory-manager
yarn add ldap-directory-manager
bun add ldap-directory-manager
```

## 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.16.8 |
| Published | 2022-08-17 |
| First published | 2020-04-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 110 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Saeid Ostad |
| Maintainers | saostad |
| Keywords | ldap, typescript, schema, schema-aware, client, active, directory, manager |

## Links

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

## Dependencies (6)

- [fuse.js](https://npm.io/package/fuse.js.md) ^6.6.2
- [@types/ldapjs](https://npm.io/package/@types/ldapjs.md) ^2.2.3
- [ldap-ts-client](https://npm.io/package/ldap-ts-client.md) ^0.14.8
- [fast-node-logger](https://npm.io/package/fast-node-logger.md) ^3.0.3
- [ldap-query-generator](https://npm.io/package/ldap-query-generator.md) ^0.8.7
- [ldap-schema-ts-generator](https://npm.io/package/ldap-schema-ts-generator.md) ^4.0.14

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 0.16.8 (latest) — 2022-08-17
- 0.16.7 — 2022-08-16
- 0.16.6 — 2022-08-16
- 0.16.5 — 2022-07-20
- 0.16.4 — 2022-07-14
- 0.16.3 — 2022-07-11
- 0.16.2 — 2021-03-03
- 0.16.1 — 2020-12-28
- 0.16.0 — 2020-12-28
- 0.15.1 — 2020-12-10
- 0.15.0 — 2020-06-24
- 0.14.1 — 2020-06-23
- 0.14.0 — 2020-06-23
- 0.13.1 — 2020-06-17
- 0.13.0 — 2020-06-17
- … 13 more at https://npm.io/package/ldap-directory-manager/versions

## README

# LDAP Directory Manager

schema-aware, type-safe LDAP manager, written in typescript to create hight-level functionalities.

### How to ues

```ts
import { Client, IClientConfig } from "ldap-directory-manager";
const baseDN = "DC=Domain,DC=Com";

const config: IClientConfig = {
  ldapServerUrl: process.env.AD_URI ?? "",
  user: process.env.AD_USER ?? "",
  pass: process.env.AD_Pass ?? "",
};
const client = new Client(config);

const user = await userGetOne("username*", {
  attributes: ["displayName", "userPrincipalName"],
  client,
});
console.log(user);
```

### Api Documentations

[Full API documentation](https://saostad.github.io/ldap-directory-manager/)

### Advance Uses

generate typescript interfaces from ldap schema.
(this is recommended just for first time and after each ldap schema modification)

```ts
const config = {
  ldapServerUrl: process.env.AD_URI ?? "",
  user: process.env.AD_USER ?? "",
  pass: process.env.AD_Pass ?? "",
};
const interfaceDirPath = await initial({
  generateInterfaces: true,
  useCachedInterfaces: false,
  ...config,
});
```

auto complete and type check, base on ldap schema interfaces that generated at first time.

Example 1

```ts
import { Client } from "ldap-directory-manager";
import { User } from "./generated/interfaces";

const baseDN = "DC=Domain,DC=Com";
const config: IClientConfig = {
  ldapServerUrl: process.env.AD_URI ?? "",
  user: process.env.AD_USER ?? "",
  pass: process.env.AD_Pass ?? "",
};
const client = new Client(config);

const user = await userGetOne<User>("username*", {
  attributes: [
    "displayName",
    "userPrincipalName",
    "adminDisplayName",
    "assistant",
    "manager",
  ],
  client,
});
console.log(user);
```

Example 2 (using [ldap-query-generator](https://www.npmjs.com/package/ldap-query-generator) which will be install with package):

```ts
import { QueryGenerator } from "ldap-query-generator";
import { Client } from "ldap-directory-manager";
import { User } from "./generated/interfaces";

const baseDN = "DC=Domain,DC=Com";
const config: IClientConfig = {
  ldapServerUrl: process.env.AD_URI ?? "",
  user: process.env.AD_USER ?? "",
  pass: process.env.AD_Pass ?? "",
};
const client = new Client(config);

const qGen = new QueryGenerator<User>({
  logger,
  scope: "sub",
});

const { query } = qGen
  .where({ field: "userPrincipalName", action: "substrings", criteria })
  .whereAnd({ field: "objectClass", action: "equal", criteria: "user" })
  .whereOr({ field: "objectClass", action: "equal", criteria: "person" })
  .whereNot({
    field: "objectClass",
    action: "equal",
    criteria: "computer",
  })
  .whereNot({ field: "objectClass", action: "equal", criteria: "group" })
  .select(["displayName", "userPrincipalName"]);

const data = await client.queryAttributes<User>({
  base: baseDN,
  attributes: query.attributes,
  options: {
    filter: query.toString(),
    scope: query.scope,
    paged: true,
  },
});
```

### Motivations:

Dealing with LDAP servers to get information is hard!

the goal of this package is to:

- Provide High level functions to interact with LDAP servers
- Taking advantage of typescript type safety and auto code competition

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