ldap-ts-client
Advanced tools
Comparing version 0.13.1 to 0.14.0
@@ -7,2 +7,9 @@ ### Changelog | ||
#### [v0.13.1](https://github.com/saostad/ldap-ts-client/compare/v0.13.0...v0.13.1) | ||
> 4 June 2020 | ||
- fix: default value assignment to reconnect option [`7aa7bc5`](https://github.com/saostad/ldap-ts-client/commit/7aa7bc519933fe3f1b9614b73a79eed637b9282c) | ||
- doc: change log [`95103f1`](https://github.com/saostad/ldap-ts-client/commit/95103f1cbcabd74050fd99b70e5fc64bb8197dec) | ||
#### [v0.13.0](https://github.com/saostad/ldap-ts-client/compare/v0.12.0...v0.13.0) | ||
@@ -9,0 +16,0 @@ |
@@ -8,2 +8,3 @@ "use strict"; | ||
var _a, _b, _c; | ||
const base = "DC=ki,DC=local"; | ||
const options = { | ||
@@ -13,6 +14,6 @@ ldapServerUrl: (_a = process.env.AD_URI) !== null && _a !== void 0 ? _a : "", | ||
pass: (_c = process.env.AD_Pass) !== null && _c !== void 0 ? _c : "", | ||
baseDN: "DC=ki,DC=local", | ||
}; | ||
const client = new index_1.Client(options); | ||
const data1 = await client.queryAttributes({ | ||
base, | ||
attributes: ["cn"], | ||
@@ -27,2 +28,3 @@ options: { | ||
const data2 = await client.queryAttributes({ | ||
base, | ||
attributes: ["*", "USNIntersite"], | ||
@@ -35,3 +37,3 @@ options: { | ||
}); | ||
console.log(`File: app.ts,`, `Line: 17 => `, data2.length); | ||
console.log(`File: app.ts,`, `Line: 35 => `, data2.length); | ||
// const delResult = await client.del({ | ||
@@ -81,2 +83,3 @@ // dn: "CN=testUser2,OU=Users,OU=KII,DC=ki,DC=local", | ||
const data = await client.queryAttributes({ | ||
base, | ||
attributes: ["cn"], | ||
@@ -89,5 +92,5 @@ options: { | ||
}); | ||
console.log(`File: app.ts,`, `Line: 17 => `, data.length); | ||
console.log(`File: app.ts,`, `Line: 95 => `, data.length); | ||
client.unbind(); | ||
})(); | ||
//# sourceMappingURL=app.js.map |
@@ -5,10 +5,8 @@ import ldap, { SearchOptions, Control, SearchEntryObject } from "ldapjs"; | ||
export interface IClientConfig extends Omit<ldap.ClientOptions, "url" | "bindDN"> { | ||
/** Domain name with format: ldap://{domain.com} */ | ||
ldapServerUrl: string; | ||
/** Password to connect to AD */ | ||
pass: string; | ||
pass?: string; | ||
/** User to connect to AD */ | ||
user: string; | ||
/** Root of tree for search */ | ||
baseDN: string; | ||
/** Domain name with format: ldap://{domain.com} */ | ||
ldapServerUrl: string; | ||
user?: string; | ||
/** instance of pino logger */ | ||
@@ -23,3 +21,3 @@ logger?: Logger; | ||
modification is just a plain old JS object with the values you want. */ | ||
export interface ModifyChange<T = any> { | ||
export declare type ModifyChange<T = any> = { | ||
operation: "add" | "delete" | "replace"; | ||
@@ -29,9 +27,9 @@ modification: { | ||
}; | ||
} | ||
interface ModifyAttributeFnInput<T> { | ||
}; | ||
declare type ModifyAttributeFnInput<T> = { | ||
dn: string; | ||
changes: ModifyChange<T>[]; | ||
controls?: any; | ||
} | ||
interface QueryFnInput<T> { | ||
}; | ||
declare type QueryFnInput<T> = { | ||
options?: Omit<SearchOptions, "attributes">; | ||
@@ -44,5 +42,5 @@ /** select return attributes | ||
/** base dn to search */ | ||
base?: string; | ||
} | ||
interface AddFnInput<T> { | ||
base: string; | ||
}; | ||
declare type AddFnInput<T> = { | ||
entry: { | ||
@@ -53,4 +51,4 @@ [key in keyof Partial<T>]: string | string[]; | ||
controls?: any; | ||
} | ||
interface CompareFnInput<T = any> { | ||
}; | ||
declare type CompareFnInput<T = any> = { | ||
dn: string; | ||
@@ -64,17 +62,21 @@ controls?: any; | ||
}; | ||
} | ||
interface DelFnInput { | ||
}; | ||
declare type DelFnInput = { | ||
dn: string; | ||
controls?: any; | ||
} | ||
interface ExtendedOpFnInput { | ||
}; | ||
declare type ExtendedOpFnInput = { | ||
oid: string; | ||
value: string; | ||
controls?: any; | ||
} | ||
interface ModifyDnFnInput { | ||
}; | ||
declare type ModifyDnFnInput = { | ||
dn: string; | ||
newDn: string; | ||
controls?: any; | ||
} | ||
}; | ||
declare type BindFnInput = { | ||
user?: string; | ||
pass?: string; | ||
}; | ||
/** @description this is a class to provide low level promise base interaction with ldap server */ | ||
@@ -85,3 +87,2 @@ export declare class Client { | ||
private logger?; | ||
baseDN: string; | ||
constructor(config: IClientConfig); | ||
@@ -91,3 +92,3 @@ /** connection status */ | ||
/** @return a connected ldap client that is useful for use flexibility of [ldap.js](http://ldapjs.org/) directly. */ | ||
bind(): Promise<ldap.Client>; | ||
bind(input?: BindFnInput): Promise<ldap.Client>; | ||
/** unbind connection */ | ||
@@ -110,3 +111,3 @@ unbind(): Promise<void>; | ||
add<T = any>({ entry, dn, controls, }: AddFnInput<T>): Promise<boolean>; | ||
/** Performs an LDAP compare operation with the given attribute and value against the entry referenced by dn. */ | ||
/** Performs a LDAP compare operation with the given attribute and value against the entry referenced by dn. */ | ||
compare<T = any>({ dn, controls, field, }: CompareFnInput<T>): Promise<boolean | undefined>; | ||
@@ -116,3 +117,3 @@ /** Deletes an entry from the LDAP server. */ | ||
/** | ||
* @description Performs an LDAP extended operation against an LDAP server. | ||
* @description Performs an extended operation against LDAP server. | ||
* @example | ||
@@ -127,3 +128,3 @@ * const {value} = await client.extendedOp('1.3.6.1.4.1.4203.1.11.3'); | ||
/** | ||
* @description Performs an LDAP modifyDN (rename) operation against an entry in the LDAP server. A couple points with this client API: | ||
* @description Performs a 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. | ||
@@ -133,5 +134,5 @@ * - 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>; | ||
/** Performs an LDAP modify operation against attributes of the existing LDAP entity. This API requires you to pass in a Change object. | ||
/** Performs a LDAP modify operation against attributes of the existing LDAP entity. This API requires you to pass in a Change object. | ||
*/ | ||
modifyAttribute<T = any>({ dn, changes, controls, }: ModifyAttributeFnInput<T>): Promise<boolean>; | ||
} |
@@ -17,3 +17,2 @@ "use strict"; | ||
this.config = config; | ||
this.baseDN = config.baseDN; | ||
let reconnect = true; | ||
@@ -26,6 +25,7 @@ if (typeof config.reconnect !== "undefined") { | ||
/** @return a connected ldap client that is useful for use flexibility of [ldap.js](http://ldapjs.org/) directly. */ | ||
async bind() { | ||
async bind(input) { | ||
var _a; | ||
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.trace("bind()"); | ||
return new Promise((resolve, reject) => { | ||
var _a, _b; | ||
if (this.client) { | ||
@@ -40,8 +40,15 @@ this.client.destroy((err) => { | ||
}); | ||
this.client.bind(this.config.user, this.config.pass, (err, result) => { | ||
if (err) { | ||
reject(err); | ||
} | ||
resolve(this.client); | ||
}); | ||
const user = (_a = input === null || input === void 0 ? void 0 : input.user) !== null && _a !== void 0 ? _a : this.config.user; | ||
const pass = (_b = input === null || input === void 0 ? void 0 : input.pass) !== null && _b !== void 0 ? _b : this.config.pass; | ||
if (user && pass) { | ||
this.client.bind(user, pass, (err, result) => { | ||
if (err) { | ||
reject(err); | ||
} | ||
resolve(this.client); | ||
}); | ||
} | ||
else { | ||
reject(new Error(`user or pass not provided! you can provide in either bind function or when create new instance of client.`)); | ||
} | ||
}); | ||
@@ -68,2 +75,3 @@ } | ||
}); | ||
resolve(); | ||
}); | ||
@@ -88,3 +96,3 @@ } | ||
client: this.client, | ||
base: base !== null && base !== void 0 ? base : this.config.baseDN, | ||
base, | ||
options: Object.assign(Object.assign({}, options), { attributes: attributes }), | ||
@@ -105,3 +113,3 @@ controls, | ||
client: this.client, | ||
base: base !== null && base !== void 0 ? base : this.config.baseDN, | ||
base, | ||
options: Object.assign(Object.assign({}, options), { attributes: attributes }), | ||
@@ -138,3 +146,3 @@ controls, | ||
} | ||
/** Performs an LDAP compare operation with the given attribute and value against the entry referenced by dn. */ | ||
/** Performs a LDAP compare operation with the given attribute and value against the entry referenced by dn. */ | ||
async compare({ dn, controls, field, }) { | ||
@@ -189,3 +197,3 @@ var _a; | ||
/** | ||
* @description Performs an LDAP extended operation against an LDAP server. | ||
* @description Performs an extended operation against LDAP server. | ||
* @example | ||
@@ -219,3 +227,3 @@ * const {value} = await client.extendedOp('1.3.6.1.4.1.4203.1.11.3'); | ||
/** | ||
* @description Performs an LDAP modifyDN (rename) operation against an entry in the LDAP server. A couple points with this client API: | ||
* @description Performs a 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. | ||
@@ -247,3 +255,3 @@ * - 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). | ||
} | ||
/** Performs an LDAP modify operation against attributes of the existing LDAP entity. This API requires you to pass in a Change object. | ||
/** Performs a LDAP modify operation against attributes of the existing LDAP entity. This API requires you to pass in a Change object. | ||
*/ | ||
@@ -250,0 +258,0 @@ async modifyAttribute({ dn, changes, controls, }) { |
{ | ||
"name": "ldap-ts-client", | ||
"version": "0.13.1", | ||
"version": "0.14.0", | ||
"description": "Type-safe LDAP client written in typescript", | ||
@@ -43,9 +43,9 @@ "repository": { | ||
"devDependencies": { | ||
"@types/jest": "^25.2.3", | ||
"@types/node": "^14.0.11", | ||
"@typescript-eslint/eslint-plugin": "^3.1.0", | ||
"@typescript-eslint/parser": "^3.1.0", | ||
"@types/jest": "^26.0.0", | ||
"@types/node": "^14.0.13", | ||
"@typescript-eslint/eslint-plugin": "^3.2.0", | ||
"@typescript-eslint/parser": "^3.2.0", | ||
"auto-changelog": "^2.0.0", | ||
"dotenv": "^8.2.0", | ||
"eslint": "^7.1.0", | ||
"eslint": "^7.2.0", | ||
"eslint-config-prettier": "^6.11.0", | ||
@@ -52,0 +52,0 @@ "eslint-plugin-prettier": "^3.1.3", |
@@ -7,2 +7,3 @@ import { config } from "dotenv"; | ||
(async () => { | ||
const base = "DC=ki,DC=local"; | ||
const options: IClientConfig = { | ||
@@ -12,3 +13,2 @@ ldapServerUrl: process.env.AD_URI ?? "", | ||
pass: process.env.AD_Pass ?? "", | ||
baseDN: "DC=ki,DC=local", | ||
}; | ||
@@ -18,2 +18,3 @@ const client = new Client(options); | ||
const data1 = await client.queryAttributes<User>({ | ||
base, | ||
attributes: ["cn"], | ||
@@ -29,2 +30,3 @@ options: { | ||
const data2 = await client.queryAttributes<User>({ | ||
base, | ||
attributes: ["*", "USNIntersite"], | ||
@@ -37,3 +39,3 @@ options: { | ||
}); | ||
console.log(`File: app.ts,`, `Line: 17 => `, data2.length); | ||
console.log(`File: app.ts,`, `Line: 35 => `, data2.length); | ||
@@ -90,2 +92,3 @@ // const delResult = await client.del({ | ||
const data = await client.queryAttributes<User>({ | ||
base, | ||
attributes: ["cn"], | ||
@@ -98,5 +101,5 @@ options: { | ||
}); | ||
console.log(`File: app.ts,`, `Line: 17 => `, data.length); | ||
console.log(`File: app.ts,`, `Line: 95 => `, data.length); | ||
client.unbind(); | ||
})(); |
@@ -9,10 +9,8 @@ import ldap, { SearchOptions, Control, SearchEntryObject } from "ldapjs"; | ||
extends Omit<ldap.ClientOptions, "url" | "bindDN"> { | ||
/** Domain name with format: ldap://{domain.com} */ | ||
ldapServerUrl: string; | ||
/** Password to connect to AD */ | ||
pass: string; | ||
pass?: string; | ||
/** User to connect to AD */ | ||
user: string; | ||
/** Root of tree for search */ | ||
baseDN: string; | ||
/** Domain name with format: ldap://{domain.com} */ | ||
ldapServerUrl: string; | ||
user?: string; | ||
/** instance of pino logger */ | ||
@@ -28,3 +26,3 @@ logger?: Logger; | ||
modification is just a plain old JS object with the values you want. */ | ||
export interface ModifyChange<T = any> { | ||
export type ModifyChange<T = any> = { | ||
operation: "add" | "delete" | "replace"; | ||
@@ -34,9 +32,9 @@ modification: { | ||
}; | ||
} | ||
interface ModifyAttributeFnInput<T> { | ||
}; | ||
type ModifyAttributeFnInput<T> = { | ||
dn: string; | ||
changes: ModifyChange<T>[]; | ||
controls?: any; | ||
} | ||
interface QueryFnInput<T> { | ||
}; | ||
type QueryFnInput<T> = { | ||
options?: Omit<SearchOptions, "attributes">; | ||
@@ -49,5 +47,5 @@ /** select return attributes | ||
/** base dn to search */ | ||
base?: string; | ||
} | ||
interface AddFnInput<T> { | ||
base: string; | ||
}; | ||
type AddFnInput<T> = { | ||
entry: { | ||
@@ -58,4 +56,4 @@ [key in keyof Partial<T>]: string | string[]; | ||
controls?: any; | ||
} | ||
interface CompareFnInput<T = any> { | ||
}; | ||
type CompareFnInput<T = any> = { | ||
dn: string; | ||
@@ -69,17 +67,21 @@ controls?: any; | ||
}; | ||
} | ||
interface DelFnInput { | ||
}; | ||
type DelFnInput = { | ||
dn: string; | ||
controls?: any; | ||
} | ||
interface ExtendedOpFnInput { | ||
}; | ||
type ExtendedOpFnInput = { | ||
oid: string; | ||
value: string; | ||
controls?: any; | ||
} | ||
interface ModifyDnFnInput { | ||
}; | ||
type ModifyDnFnInput = { | ||
dn: string; | ||
newDn: string; | ||
controls?: any; | ||
} | ||
}; | ||
type BindFnInput = { | ||
user?: string; | ||
pass?: string; | ||
}; | ||
@@ -91,7 +93,5 @@ /** @description this is a class to provide low level promise base interaction with ldap server */ | ||
private logger?: Logger; | ||
public baseDN: string; | ||
constructor(config: IClientConfig) { | ||
this.config = config; | ||
this.baseDN = config.baseDN; | ||
@@ -117,3 +117,3 @@ let reconnect: any = true; | ||
/** @return a connected ldap client that is useful for use flexibility of [ldap.js](http://ldapjs.org/) directly. */ | ||
public async bind(): Promise<ldap.Client> { | ||
public async bind(input?: BindFnInput): Promise<ldap.Client> { | ||
this.logger?.trace("bind()"); | ||
@@ -137,9 +137,18 @@ return new Promise((resolve, reject) => { | ||
this.client.bind(this.config.user, this.config.pass, (err, result) => { | ||
if (err) { | ||
reject(err); | ||
} | ||
resolve(this.client); | ||
}); | ||
const user = input?.user ?? this.config.user; | ||
const pass = input?.pass ?? this.config.pass; | ||
if (user && pass) { | ||
this.client.bind(user, pass, (err, result) => { | ||
if (err) { | ||
reject(err); | ||
} | ||
resolve(this.client); | ||
}); | ||
} else { | ||
reject( | ||
new Error( | ||
`user or pass not provided! you can provide in either bind function or when create new instance of client.`, | ||
), | ||
); | ||
} | ||
}); | ||
@@ -156,3 +165,2 @@ } | ||
} | ||
resolve(); | ||
@@ -169,2 +177,3 @@ }); | ||
}); | ||
resolve(); | ||
}); | ||
@@ -195,3 +204,3 @@ } | ||
client: this.client, | ||
base: base ?? this.config.baseDN, | ||
base, | ||
options: { | ||
@@ -221,3 +230,3 @@ ...options, | ||
client: this.client, | ||
base: base ?? this.config.baseDN, | ||
base, | ||
options: { | ||
@@ -260,3 +269,3 @@ ...options, | ||
/** Performs an LDAP compare operation with the given attribute and value against the entry referenced by dn. */ | ||
/** Performs a LDAP compare operation with the given attribute and value against the entry referenced by dn. */ | ||
public async compare<T = any>({ | ||
@@ -322,3 +331,3 @@ dn, | ||
/** | ||
* @description Performs an LDAP extended operation against an LDAP server. | ||
* @description Performs an extended operation against LDAP server. | ||
* @example | ||
@@ -363,3 +372,3 @@ * const {value} = await client.extendedOp('1.3.6.1.4.1.4203.1.11.3'); | ||
/** | ||
* @description Performs an LDAP modifyDN (rename) operation against an entry in the LDAP server. A couple points with this client API: | ||
* @description Performs a 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. | ||
@@ -396,3 +405,3 @@ * - 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). | ||
/** Performs an LDAP modify operation against attributes of the existing LDAP entity. This API requires you to pass in a Change object. | ||
/** Performs a LDAP modify operation against attributes of the existing LDAP entity. This API requires you to pass in a Change object. | ||
*/ | ||
@@ -399,0 +408,0 @@ public async modifyAttribute<T = any>({ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
65403
1250