@linagora/ldap-rest-client 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +122 -0
- package/dist/index.d.mts +1399 -0
- package/dist/index.d.ts +1399 -0
- package/dist/index.js +1173 -0
- package/dist/index.mjs +1134 -0
- package/package.json +69 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Linagora
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# ldap-rest-client
|
|
2
|
+
|
|
3
|
+
TypeScript client for LDAP-REST API with HMAC-SHA256 and SSO cookie authentication.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @linagora/ldap-rest-client
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
### Backend (HMAC Authentication)
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { LdapRestClient } from '@linagora/ldap-rest-client';
|
|
17
|
+
|
|
18
|
+
const client = new LdapRestClient({
|
|
19
|
+
baseUrl: 'https://ldap-rest.example.com',
|
|
20
|
+
auth: {
|
|
21
|
+
type: 'hmac',
|
|
22
|
+
serviceId: 'registration-service',
|
|
23
|
+
secret: 'your-secret-key-at-least-32-chars-long',
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// Create user
|
|
28
|
+
await client.users.create(userData);
|
|
29
|
+
|
|
30
|
+
// Create organization
|
|
31
|
+
await client.organizations.create({ id, name, domain });
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Browser (SSO Cookie)
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
const client = new LdapRestClient({
|
|
38
|
+
baseUrl: 'https://ldap-rest.example.com',
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// Manage users in organization
|
|
42
|
+
await client.organizations.createUser(orgId, userData);
|
|
43
|
+
await client.organizations.listUsers(orgId, { page: 1, limit: 20 });
|
|
44
|
+
|
|
45
|
+
// Manage groups
|
|
46
|
+
await client.groups.create(orgId, { name: 'engineering' });
|
|
47
|
+
await client.groups.addMembers(orgId, groupId, { usernames: ['user1'] });
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## API Reference
|
|
51
|
+
|
|
52
|
+
### Users (B2C)
|
|
53
|
+
```typescript
|
|
54
|
+
client.users.create(userData)
|
|
55
|
+
client.users.update(username, updates)
|
|
56
|
+
client.users.disable(username)
|
|
57
|
+
client.users.delete(username)
|
|
58
|
+
client.users.checkAvailability({ field, value })
|
|
59
|
+
client.users.fetch({ by, value, fields })
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Organizations
|
|
63
|
+
```typescript
|
|
64
|
+
client.organizations.create({ id, name, domain })
|
|
65
|
+
client.organizations.createAdmin(orgId, { username, mail })
|
|
66
|
+
client.organizations.list()
|
|
67
|
+
client.organizations.get(orgId)
|
|
68
|
+
client.organizations.update(orgId, updates)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### B2B Users (within Organizations)
|
|
72
|
+
```typescript
|
|
73
|
+
client.organizations.createUser(orgId, userData)
|
|
74
|
+
client.organizations.updateUser(orgId, userId, updates)
|
|
75
|
+
client.organizations.disableUser(orgId, userId)
|
|
76
|
+
client.organizations.deleteUser(orgId, userId)
|
|
77
|
+
client.organizations.getUser(orgId, { by, value })
|
|
78
|
+
client.organizations.listUsers(orgId, { page, limit, status, search })
|
|
79
|
+
client.organizations.checkUserAvailability(orgId, { field, value })
|
|
80
|
+
client.organizations.changeUserRole(orgId, userId, { role })
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Groups
|
|
84
|
+
```typescript
|
|
85
|
+
client.groups.create(orgId, { name, description })
|
|
86
|
+
client.groups.list(orgId, { page, limit })
|
|
87
|
+
client.groups.get(orgId, groupId)
|
|
88
|
+
client.groups.update(orgId, groupId, updates)
|
|
89
|
+
client.groups.delete(orgId, groupId)
|
|
90
|
+
client.groups.addMembers(orgId, groupId, { usernames })
|
|
91
|
+
client.groups.removeMember(orgId, groupId, userId)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Error Handling
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
import { ConflictError, NotFoundError } from '@linagora/ldap-rest-client';
|
|
98
|
+
|
|
99
|
+
try {
|
|
100
|
+
await client.users.create(userData);
|
|
101
|
+
} catch (error) {
|
|
102
|
+
if (error instanceof ConflictError) {
|
|
103
|
+
// Handle conflict (409)
|
|
104
|
+
} else if (error instanceof NotFoundError) {
|
|
105
|
+
// Handle not found (404)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Available errors: `ValidationError`, `AuthenticationError`, `AuthorizationError`, `NotFoundError`, `ConflictError`, `RateLimitError`, `NetworkError`, `ApiError`
|
|
111
|
+
|
|
112
|
+
## Development
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
npm install
|
|
116
|
+
npm test
|
|
117
|
+
npm run build
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## License
|
|
121
|
+
|
|
122
|
+
MIT
|