Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ldap-ts-client

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ldap-ts-client - npm Package Compare versions

Comparing version 0.2.3 to 0.3.0

43

dist/app.js

@@ -15,12 +15,39 @@ "use strict";

const client = new index_1.Client(options);
const data = await client.queryAttributes({
options: {
attributes: ["*"],
filter: "(&(userPrincipalName=sostad*))",
scope: "sub",
},
});
console.log(`File: app.ts,`, `Line: 17 => `, data[0]);
// const delResult = await client.del({
// dn: "CN=testUser2,OU=Users,OU=KII,DC=ki,DC=local",
// });
// console.log(`File: app.ts,`, `Line: 18 => `, delResult);
// const { value } = await client.extendedOp({
// oid: "1.3.6.1.4.1.4203.1.11.3",
// value: "",
// });
// console.log(`File: app.ts,`, `Line: 18 => `, value);
// const modifyDnResult = await client.modifyDn({
// dn: "CN=testUser3,OU=Users,OU=KII,DC=ki,DC=local",
// newDn: "CN=testUser4,OU=Users,OU=KII,DC=ki,DC=local",
// });
// console.log(`File: app.ts,`, `Line: 18 => `, modifyDnResult);
// const entry = {
// cn: "testUser2",
// sn: "testUser2",
// objectClass: "organizationalPerson",
// };
// const addResult = client.add({ entry, dn: "CN=testUser2,OU=Users,OU=KII,DC=ki,DC=local" });
// console.log(addResult);
// const compared = await client.compare({
// dn: "CN=testUser2,OU=Users,OU=KII,DC=ki,DC=local",
// attribute: "cn",
// value: "testUser2",
// });
// console.log(`File: app.ts,`, `Line: 22 => `, compared);
// const data = await client.queryAttributes({
// options: {
// attributes: ["*"],
// filter: "(&(objectClass=organizationalPerson)(cn=test*))",
// scope: "sub",
// },
// });
// console.log(`File: app.ts,`, `Line: 17 => `, data[0]);
await client.unbind();
})();
//# sourceMappingURL=app.js.map

@@ -20,2 +20,30 @@ import ldap, { SearchOptions, Control, SearchEntryObject } from "ldapjs";

}
interface Entry {
[key: string]: string | string[];
}
interface AddFnInput {
entry: Entry;
dn: string;
controls?: any;
}
interface CompareFnInput {
dn: string;
controls?: any;
attribute: string;
value: string;
}
interface DelFnInput {
dn: string;
controls?: any;
}
interface ExtendedOpFnInput {
oid: string;
value: string;
controls?: any;
}
interface ModifyDnFnInput {
dn: string;
newDn: string;
controls?: any;
}
/** @description this is a class to provide low level promise base interaction with ldap server */

@@ -28,5 +56,7 @@ export declare class Client {

constructor(config: IClientConfig);
/** connection status */
isConnected: () => boolean;
/** @return a connected ldap client that is useful for use flexibility of [ldap.js](http://ldapjs.org/) directly. */
bind(): Promise<ldap.Client>;
/** unbind connection and free-up memory */
unbind(): Promise<void>;

@@ -41,3 +71,27 @@ private connect;

queryAttributes({ options, controls, base, }: QueryFnInput): Promise<SearchEntryObject[]>;
/** Performs an add operation against the LDAP server.
* @description Allows you to add an entry (which is just a plain JS object)
*/
add({ entry, dn, controls }: AddFnInput): Promise<boolean>;
/** Performs an LDAP compare operation with the given attribute and value against the entry referenced by dn. */
compare({ dn, controls, attribute, value, }: CompareFnInput): Promise<boolean | undefined>;
/** Deletes an entry from the LDAP server. */
del({ dn, controls }: DelFnInput): Promise<boolean>;
/**
* @description Performs an LDAP extended operation against an LDAP server.
* @example
* const {value} = await client.extendedOp('1.3.6.1.4.1.4203.1.11.3');
* console.log('whois: ' + value);
*/
extendedOp({ oid, value, controls, }: ExtendedOpFnInput): Promise<{
value: string;
res: any;
}>;
/**
* @description Performs an LDAP modifyDN (rename) operation against an entry in the LDAP server. A couple points with this client API:
* - There is no ability to set "keep old dn." It's always going to flag the old dn to be purged.
* - The client code will automatically figure out if the request is a "new superior" request ("new superior" means move to a different part of the tree, as opposed to just renaming the leaf).
*/
modifyDn({ dn, newDn, controls, }: ModifyDnFnInput): Promise<boolean>;
}
export {};

@@ -11,2 +11,3 @@ "use strict";

constructor(config) {
/** connection status */
this.isConnected = () => {

@@ -32,2 +33,3 @@ return this.client.connected;

}
/** unbind connection and free-up memory */
async unbind() {

@@ -83,4 +85,135 @@ var _a;

}
/** Performs an add operation against the LDAP server.
* @description Allows you to add an entry (which is just a plain JS object)
*/
async add({ entry, dn, controls }) {
var _a;
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.trace("add()");
await this.connect();
return new Promise((resolve, reject) => {
if (controls) {
this.client.add(dn, entry, controls, function addCallback(err) {
if (err) {
reject(err);
}
resolve(true);
});
}
else {
this.client.add(dn, entry, function addCallback(err) {
if (err) {
reject(err);
}
resolve(true);
});
}
});
}
/** Performs an LDAP compare operation with the given attribute and value against the entry referenced by dn. */
async compare({ dn, controls, attribute, value, }) {
var _a;
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.trace("compare()");
await this.connect();
return new Promise((resolve, reject) => {
if (controls) {
this.client.compare(dn, attribute, value, controls, function compareCallback(err, matched) {
if (err) {
reject(err);
}
resolve(matched);
});
}
else {
this.client.compare(dn, attribute, value, function compareCallback(err, matched) {
if (err) {
reject(err);
}
resolve(matched);
});
}
});
}
/** Deletes an entry from the LDAP server. */
async del({ dn, controls }) {
var _a;
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.trace("del()");
await this.connect();
return new Promise((resolve, reject) => {
if (controls) {
this.client.del(dn, controls, function delCallback(err) {
if (err) {
reject(err);
}
resolve(true);
});
}
else {
this.client.del(dn, function delCallback(err) {
if (err) {
reject(err);
}
resolve(true);
});
}
});
}
/**
* @description Performs an LDAP extended operation against an LDAP server.
* @example
* const {value} = await client.extendedOp('1.3.6.1.4.1.4203.1.11.3');
* console.log('whois: ' + value);
*/
async extendedOp({ oid, value, controls, }) {
var _a;
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.trace("extendedOp()");
await this.connect();
return new Promise((resolve, reject) => {
if (controls) {
this.client.exop(oid, value, controls, function extendedOpCallback(err, value, res) {
if (err) {
reject(err);
}
resolve({ value, res });
});
}
else {
this.client.exop(oid, value, function extendedOpCallback(err, value, res) {
if (err) {
reject(err);
}
resolve({ value, res });
});
}
});
}
/**
* @description Performs an LDAP modifyDN (rename) operation against an entry in the LDAP server. A couple points with this client API:
* - There is no ability to set "keep old dn." It's always going to flag the old dn to be purged.
* - The client code will automatically figure out if the request is a "new superior" request ("new superior" means move to a different part of the tree, as opposed to just renaming the leaf).
*/
async modifyDn({ dn, newDn, controls, }) {
var _a;
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.trace("modifyDn()");
await this.connect();
return new Promise((resolve, reject) => {
if (controls) {
this.client.modifyDN(dn, newDn, controls, function modifyDnCallback(err) {
if (err) {
reject(err);
}
resolve(true);
});
}
else {
this.client.modifyDN(dn, newDn, function modifyDNCallback(err) {
if (err) {
reject(err);
}
resolve(true);
});
}
});
}
}
exports.Client = Client;
//# sourceMappingURL=index.js.map

4

package.json
{
"name": "ldap-ts-client",
"version": "0.2.3",
"version": "0.3.0",
"description": "Type-safe LDAP client written in typescript",

@@ -59,6 +59,6 @@ "repository": {

"dependencies": {
"fast-node-logger": "^1.3.4",
"@types/ldapjs": "^1.0.7",
"fast-node-logger": "^1.4.0",
"ldapjs": "^1.0.2"
}
}

@@ -12,13 +12,46 @@ import { config } from "dotenv";

};
const client = new Client(options);
const client = new Client(options);
const data = await client.queryAttributes({
options: {
attributes: ["*"],
filter: "(&(userPrincipalName=sostad*))",
scope: "sub",
},
});
console.log(`File: app.ts,`, `Line: 17 => `, data[0]);
// const delResult = await client.del({
// dn: "CN=testUser2,OU=Users,OU=KII,DC=ki,DC=local",
// });
// console.log(`File: app.ts,`, `Line: 18 => `, delResult);
// const { value } = await client.extendedOp({
// oid: "1.3.6.1.4.1.4203.1.11.3",
// value: "",
// });
// console.log(`File: app.ts,`, `Line: 18 => `, value);
// const modifyDnResult = await client.modifyDn({
// dn: "CN=testUser3,OU=Users,OU=KII,DC=ki,DC=local",
// newDn: "CN=testUser4,OU=Users,OU=KII,DC=ki,DC=local",
// });
// console.log(`File: app.ts,`, `Line: 18 => `, modifyDnResult);
// const entry = {
// cn: "testUser2",
// sn: "testUser2",
// objectClass: "organizationalPerson",
// };
// const addResult = client.add({ entry, dn: "CN=testUser2,OU=Users,OU=KII,DC=ki,DC=local" });
// console.log(addResult);
// const compared = await client.compare({
// dn: "CN=testUser2,OU=Users,OU=KII,DC=ki,DC=local",
// attribute: "cn",
// value: "testUser2",
// });
// console.log(`File: app.ts,`, `Line: 22 => `, compared);
// const data = await client.queryAttributes({
// options: {
// attributes: ["*"],
// filter: "(&(objectClass=organizationalPerson)(cn=test*))",
// scope: "sub",
// },
// });
// console.log(`File: app.ts,`, `Line: 17 => `, data[0]);
await client.unbind();
})();

@@ -24,2 +24,31 @@ import ldap, { SearchOptions, Control, SearchEntryObject } from "ldapjs";

interface Entry {
[key: string]: string | string[];
}
interface AddFnInput {
entry: Entry;
dn: string;
controls?: any;
}
interface CompareFnInput {
dn: string;
controls?: any;
attribute: string;
value: string;
}
interface DelFnInput {
dn: string;
controls?: any;
}
interface ExtendedOpFnInput {
oid: string;
value: string;
controls?: any;
}
interface ModifyDnFnInput {
dn: string;
newDn: string;
controls?: any;
}
/** @description this is a class to provide low level promise base interaction with ldap server */

@@ -41,2 +70,3 @@ export class Client {

/** connection status */
public isConnected = (): boolean => {

@@ -60,2 +90,3 @@ return this.client.connected;

/** unbind connection and free-up memory */
public async unbind(): Promise<void> {

@@ -117,2 +148,159 @@ this.logger?.trace("unbind()");

}
/** Performs an add operation against the LDAP server.
* @description Allows you to add an entry (which is just a plain JS object)
*/
public async add({ entry, dn, controls }: AddFnInput): Promise<boolean> {
this.logger?.trace("add()");
await this.connect();
return new Promise((resolve, reject) => {
if (controls) {
this.client.add(dn, entry, controls, function addCallback(err) {
if (err) {
reject(err);
}
resolve(true);
});
} else {
this.client.add(dn, entry, function addCallback(err) {
if (err) {
reject(err);
}
resolve(true);
});
}
});
}
/** Performs an LDAP compare operation with the given attribute and value against the entry referenced by dn. */
public async compare({
dn,
controls,
attribute,
value,
}: CompareFnInput): Promise<boolean | undefined> {
this.logger?.trace("compare()");
await this.connect();
return new Promise((resolve, reject) => {
if (controls) {
this.client.compare(
dn,
attribute,
value,
controls,
function compareCallback(err, matched) {
if (err) {
reject(err);
}
resolve(matched);
},
);
} else {
this.client.compare(dn, attribute, value, function compareCallback(
err,
matched,
) {
if (err) {
reject(err);
}
resolve(matched);
});
}
});
}
/** Deletes an entry from the LDAP server. */
public async del({ dn, controls }: DelFnInput): Promise<boolean> {
this.logger?.trace("del()");
await this.connect();
return new Promise((resolve, reject) => {
if (controls) {
this.client.del(dn, controls, function delCallback(err) {
if (err) {
reject(err);
}
resolve(true);
});
} else {
this.client.del(dn, function delCallback(err) {
if (err) {
reject(err);
}
resolve(true);
});
}
});
}
/**
* @description Performs an LDAP extended operation against an LDAP server.
* @example
* const {value} = await client.extendedOp('1.3.6.1.4.1.4203.1.11.3');
* console.log('whois: ' + value);
*/
public async extendedOp({
oid,
value,
controls,
}: ExtendedOpFnInput): Promise<{ value: string; res: any }> {
this.logger?.trace("extendedOp()");
await this.connect();
return new Promise((resolve, reject) => {
if (controls) {
this.client.exop(oid, value, controls, function extendedOpCallback(
err,
value,
res,
) {
if (err) {
reject(err);
}
resolve({ value, res });
});
} else {
this.client.exop(oid, value, function extendedOpCallback(
err,
value,
res,
) {
if (err) {
reject(err);
}
resolve({ value, res });
});
}
});
}
/**
* @description Performs an LDAP modifyDN (rename) operation against an entry in the LDAP server. A couple points with this client API:
* - There is no ability to set "keep old dn." It's always going to flag the old dn to be purged.
* - The client code will automatically figure out if the request is a "new superior" request ("new superior" means move to a different part of the tree, as opposed to just renaming the leaf).
*/
public async modifyDn({
dn,
newDn,
controls,
}: ModifyDnFnInput): Promise<boolean> {
this.logger?.trace("modifyDn()");
await this.connect();
return new Promise((resolve, reject) => {
if (controls) {
this.client.modifyDN(dn, newDn, controls, function modifyDnCallback(
err,
) {
if (err) {
reject(err);
}
resolve(true);
});
} else {
this.client.modifyDN(dn, newDn, function modifyDNCallback(err) {
if (err) {
reject(err);
}
resolve(true);
});
}
});
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc