ldap-ts-client
Advanced tools
Comparing version 0.5.0 to 0.6.0
@@ -15,44 +15,45 @@ "use strict"; | ||
const client = new index_1.Client(options); | ||
// 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 = await client.add({ | ||
// entry, | ||
// dn: "CN=testUser2,OU=Users,OU=KII,DC=ki,DC=local", | ||
// }); | ||
// console.log(addResult); | ||
// const modifyResult = await client.modify({ | ||
// dn: "CN=testUser2,OU=Users,OU=KII,DC=ki,DC=local", | ||
// changes: [ | ||
// { | ||
// operation: "add", | ||
// modification: { | ||
// mail: "mymail@mydomain.com", | ||
// }, | ||
// }, | ||
// ], | ||
// }); | ||
// console.log(`File: app.ts,`, `Line: 53 => `, modifyResult); | ||
// 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 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 = await client.add({ | ||
entry, | ||
dn: "CN=testUser2,OU=Users,OU=KII,DC=ki,DC=local", | ||
}); | ||
console.log(addResult); | ||
const modifyResult = await client.modify({ | ||
dn: "CN=testUser2,OU=Users,OU=KII,DC=ki,DC=local", | ||
changes: [ | ||
{ | ||
operation: "add", | ||
modification: { | ||
mail: "mymail@mydomain.com", | ||
}, | ||
}, | ||
], | ||
}); | ||
console.log(`File: app.ts,`, `Line: 53 => `, modifyResult); | ||
const compared = await client.compare({ | ||
dn: "CN=testUser2,OU=Users,OU=KII,DC=ki,DC=local", | ||
field: { | ||
cn: "testUser2", | ||
}, | ||
}); | ||
console.log(`File: app.ts,`, `Line: 22 => `, compared); | ||
const data = await client.queryAttributes({ | ||
@@ -59,0 +60,0 @@ options: { |
@@ -24,8 +24,8 @@ import ldap, { SearchOptions, Control, SearchEntryObject } from "ldapjs"; | ||
modification: { | ||
[key in keyof T]: any; | ||
[key in keyof Partial<T>]: any; | ||
}; | ||
} | ||
interface ModifyFnInput { | ||
interface ModifyFnInput<T> { | ||
dn: string; | ||
changes: ModifyChange[]; | ||
changes: ModifyChange<T>[]; | ||
controls?: any; | ||
@@ -38,15 +38,18 @@ } | ||
} | ||
interface Entry { | ||
[key: string]: string | string[]; | ||
} | ||
interface AddFnInput { | ||
entry: Entry; | ||
interface AddFnInput<T> { | ||
entry: { | ||
[key in keyof Partial<T>]: string | string[]; | ||
}; | ||
dn: string; | ||
controls?: any; | ||
} | ||
interface CompareFnInput { | ||
interface CompareFnInput<T = any> { | ||
dn: string; | ||
controls?: any; | ||
attribute: string; | ||
value: string; | ||
/** attribute to compare | ||
* - Note: it just use first property, no matter how many property gets | ||
*/ | ||
field: { | ||
[key in keyof Partial<T>]: string; | ||
}; | ||
} | ||
@@ -91,5 +94,5 @@ interface DelFnInput { | ||
*/ | ||
add({ entry, dn, controls }: AddFnInput): Promise<boolean>; | ||
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. */ | ||
compare({ dn, controls, attribute, value, }: CompareFnInput): Promise<boolean | undefined>; | ||
compare<T = any>({ dn, controls, field, }: CompareFnInput<T>): Promise<boolean | undefined>; | ||
/** Deletes an entry from the LDAP server. */ | ||
@@ -115,4 +118,4 @@ del({ dn, controls }: DelFnInput): Promise<boolean>; | ||
*/ | ||
modify({ dn, changes, controls, }: ModifyFnInput): Promise<boolean>; | ||
modify<T = any>({ dn, changes, controls, }: ModifyFnInput<T>): Promise<boolean>; | ||
} | ||
export {}; |
@@ -86,3 +86,3 @@ "use strict"; | ||
*/ | ||
async add({ entry, dn, controls }) { | ||
async add({ entry, dn, controls, }) { | ||
var _a; | ||
@@ -111,3 +111,3 @@ (_a = this.logger) === null || _a === void 0 ? void 0 : _a.trace("add()"); | ||
/** Performs an LDAP compare operation with the given attribute and value against the entry referenced by dn. */ | ||
async compare({ dn, controls, attribute, value, }) { | ||
async compare({ dn, controls, field, }) { | ||
var _a; | ||
@@ -117,2 +117,3 @@ (_a = this.logger) === null || _a === void 0 ? void 0 : _a.trace("compare()"); | ||
return new Promise((resolve, reject) => { | ||
const [attribute, value] = Object.entries(field)[0]; | ||
if (controls) { | ||
@@ -119,0 +120,0 @@ this.client.compare(dn, attribute, value, controls, function compareCallback(err, matched) { |
{ | ||
"name": "ldap-ts-client", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"description": "Type-safe LDAP client written in typescript", | ||
@@ -5,0 +5,0 @@ "repository": { |
import { config } from "dotenv"; | ||
config(); | ||
import { Client, IClientConfig } from "./index"; | ||
import { User } from "./generated/interfaces/User"; | ||
@@ -14,49 +15,50 @@ (async () => { | ||
// 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 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 { 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 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 = await client.add({ | ||
// entry, | ||
// dn: "CN=testUser2,OU=Users,OU=KII,DC=ki,DC=local", | ||
// }); | ||
// console.log(addResult); | ||
const entry = { | ||
cn: "testUser2", | ||
sn: "testUser2", | ||
objectClass: "organizationalPerson", | ||
}; | ||
const addResult = await client.add<User>({ | ||
entry, | ||
dn: "CN=testUser2,OU=Users,OU=KII,DC=ki,DC=local", | ||
}); | ||
console.log(addResult); | ||
// const modifyResult = await client.modify({ | ||
// dn: "CN=testUser2,OU=Users,OU=KII,DC=ki,DC=local", | ||
// changes: [ | ||
// { | ||
// operation: "add", | ||
// modification: { | ||
// mail: "mymail@mydomain.com", | ||
// }, | ||
// }, | ||
// ], | ||
// }); | ||
// console.log(`File: app.ts,`, `Line: 53 => `, modifyResult); | ||
const modifyResult = await client.modify<User>({ | ||
dn: "CN=testUser2,OU=Users,OU=KII,DC=ki,DC=local", | ||
changes: [ | ||
{ | ||
operation: "add", | ||
modification: { | ||
mail: "mymail@mydomain.com", | ||
}, | ||
}, | ||
], | ||
}); | ||
console.log(`File: app.ts,`, `Line: 53 => `, modifyResult); | ||
// 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 compared = await client.compare<User>({ | ||
dn: "CN=testUser2,OU=Users,OU=KII,DC=ki,DC=local", | ||
field: { | ||
cn: "testUser2", | ||
}, | ||
}); | ||
console.log(`File: app.ts,`, `Line: 22 => `, compared); | ||
@@ -63,0 +65,0 @@ const data = await client.queryAttributes({ |
@@ -27,8 +27,8 @@ import ldap, { SearchOptions, Control, SearchEntryObject } from "ldapjs"; | ||
modification: { | ||
[key in keyof T]: any; | ||
[key in keyof Partial<T>]: any; | ||
}; | ||
} | ||
interface ModifyFnInput { | ||
interface ModifyFnInput<T> { | ||
dn: string; | ||
changes: ModifyChange[]; | ||
changes: ModifyChange<T>[]; | ||
controls?: any; | ||
@@ -41,15 +41,19 @@ } | ||
} | ||
interface Entry { | ||
[key: string]: string | string[]; | ||
} | ||
interface AddFnInput { | ||
entry: Entry; | ||
interface AddFnInput<T> { | ||
entry: { | ||
[key in keyof Partial<T>]: string | string[]; | ||
}; | ||
dn: string; | ||
controls?: any; | ||
} | ||
interface CompareFnInput { | ||
interface CompareFnInput<T = any> { | ||
dn: string; | ||
controls?: any; | ||
attribute: string; | ||
value: string; | ||
/** attribute to compare | ||
* - Note: it just use first property, no matter how many property gets | ||
*/ | ||
field: { | ||
[key in keyof Partial<T>]: string; | ||
}; | ||
} | ||
@@ -166,3 +170,7 @@ interface DelFnInput { | ||
*/ | ||
public async add({ entry, dn, controls }: AddFnInput): Promise<boolean> { | ||
public async add<T = any>({ | ||
entry, | ||
dn, | ||
controls, | ||
}: AddFnInput<T>): Promise<boolean> { | ||
this.logger?.trace("add()"); | ||
@@ -190,11 +198,11 @@ await this.connect(); | ||
/** Performs an LDAP compare operation with the given attribute and value against the entry referenced by dn. */ | ||
public async compare({ | ||
public async compare<T = any>({ | ||
dn, | ||
controls, | ||
attribute, | ||
value, | ||
}: CompareFnInput): Promise<boolean | undefined> { | ||
field, | ||
}: CompareFnInput<T>): Promise<boolean | undefined> { | ||
this.logger?.trace("compare()"); | ||
await this.connect(); | ||
return new Promise((resolve, reject) => { | ||
const [attribute, value] = Object.entries<string>(field)[0]; | ||
if (controls) { | ||
@@ -325,7 +333,7 @@ this.client.compare( | ||
*/ | ||
public async modify({ | ||
public async modify<T = any>({ | ||
dn, | ||
changes, | ||
controls, | ||
}: ModifyFnInput): Promise<boolean> { | ||
}: ModifyFnInput<T>): Promise<boolean> { | ||
this.logger?.trace("modify()"); | ||
@@ -332,0 +340,0 @@ await this.connect(); |
@@ -7,4 +7,8 @@ { | ||
"entryPoint": "index", | ||
"exclude": ["**/*+(test|.spec|.e2e).ts", "./src/app.ts"], | ||
"exclude": [ | ||
"**/*+(test|.spec|.e2e).ts", | ||
"./src/app.ts", | ||
"./src/generated/**/*.*" | ||
], | ||
"readme": "./README.md" | ||
} |
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
56403
1087