@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/dist/index.d.mts
ADDED
|
@@ -0,0 +1,1399 @@
|
|
|
1
|
+
import { ISettingsParam, Logger } from 'tslog';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* HMAC authentication configuration for backend services
|
|
5
|
+
*/
|
|
6
|
+
interface HmacAuthConfig {
|
|
7
|
+
type: 'hmac';
|
|
8
|
+
serviceId: string;
|
|
9
|
+
secret: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* SSO Cookie authentication configuration for browser requests
|
|
13
|
+
*/
|
|
14
|
+
interface CookieAuthConfig {
|
|
15
|
+
type: 'cookie';
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Authentication configuration union type
|
|
19
|
+
*/
|
|
20
|
+
type AuthConfig = HmacAuthConfig | CookieAuthConfig;
|
|
21
|
+
/**
|
|
22
|
+
* Configuration for LDAP-REST client
|
|
23
|
+
*/
|
|
24
|
+
interface ClientConfig {
|
|
25
|
+
baseUrl: string;
|
|
26
|
+
auth?: AuthConfig;
|
|
27
|
+
timeout?: number;
|
|
28
|
+
logger?: ISettingsParam<unknown>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* HTTP client configuration
|
|
32
|
+
*/
|
|
33
|
+
interface HttpConfig {
|
|
34
|
+
baseUrl: string;
|
|
35
|
+
timeout: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Parameters for request signature generation
|
|
40
|
+
*/
|
|
41
|
+
interface SignatureParams {
|
|
42
|
+
/** HTTP method (GET, POST, PATCH, DELETE) */
|
|
43
|
+
method: string;
|
|
44
|
+
/** Request path with query string */
|
|
45
|
+
path: string;
|
|
46
|
+
/** Request body as string (for POST/PATCH) */
|
|
47
|
+
body?: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Base authentication interface
|
|
52
|
+
*
|
|
53
|
+
* All authentication implementations must provide a sign method
|
|
54
|
+
* that returns an authorization header value or empty string.
|
|
55
|
+
*/
|
|
56
|
+
interface Auth {
|
|
57
|
+
/**
|
|
58
|
+
* Generates authorization header for a request
|
|
59
|
+
*
|
|
60
|
+
* @param {SignatureParams} params - Request parameters to sign
|
|
61
|
+
* @returns {string} Authorization header value or empty string if no header needed
|
|
62
|
+
*/
|
|
63
|
+
sign(params: SignatureParams): string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* HTTP request options
|
|
68
|
+
*/
|
|
69
|
+
interface RequestOptions {
|
|
70
|
+
/** HTTP method */
|
|
71
|
+
method: 'GET' | 'POST' | 'PATCH' | 'DELETE';
|
|
72
|
+
/** Request path (relative to base URL) */
|
|
73
|
+
path: string;
|
|
74
|
+
/** Request body (will be JSON stringified) */
|
|
75
|
+
body?: unknown;
|
|
76
|
+
/** Additional headers to include */
|
|
77
|
+
headers?: Record<string, string>;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* HTTP client with authentication and error handling
|
|
81
|
+
*
|
|
82
|
+
* Handles all HTTP communication with the LDAP-REST API including:
|
|
83
|
+
* - Optional HMAC authentication or cookie-based SSO
|
|
84
|
+
* - Error mapping and handling
|
|
85
|
+
* - Request timeouts
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* const client = new HttpClient(config, auth);
|
|
90
|
+
* const response = await client.get('/api/v1/users');
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
declare class HttpClient {
|
|
94
|
+
private readonly config;
|
|
95
|
+
private readonly auth;
|
|
96
|
+
private readonly logger;
|
|
97
|
+
/**
|
|
98
|
+
* Creates an HTTP client instance
|
|
99
|
+
*
|
|
100
|
+
* @param {HttpConfig} config - HTTP configuration (baseUrl, timeout)
|
|
101
|
+
* @param {Auth | undefined} auth - Optional authentication handler (HMAC). If undefined, uses cookies.
|
|
102
|
+
* @param {Logger<unknown>} logger - Logger instance
|
|
103
|
+
*/
|
|
104
|
+
constructor(config: HttpConfig, auth: Auth | undefined, logger: Logger<unknown>);
|
|
105
|
+
/**
|
|
106
|
+
* Makes an authenticated HTTP request
|
|
107
|
+
*
|
|
108
|
+
* @template T - Response type
|
|
109
|
+
* @param {RequestOptions} options - Request options
|
|
110
|
+
* @returns {Promise<T>} Parsed response body
|
|
111
|
+
* @throws {ApiError} When API returns an error
|
|
112
|
+
* @throws {NetworkError} When network request fails
|
|
113
|
+
*/
|
|
114
|
+
request: <T>(options: RequestOptions) => Promise<T>;
|
|
115
|
+
/**
|
|
116
|
+
* Handles HTTP response
|
|
117
|
+
*
|
|
118
|
+
* Maps HTTP status codes to specific error types and parses response body.
|
|
119
|
+
*
|
|
120
|
+
* @template T - Response type
|
|
121
|
+
* @param {Response} response - Fetch API response
|
|
122
|
+
* @returns {Promise<T>} Parsed response body
|
|
123
|
+
* @throws {ApiError} When API returns an error status
|
|
124
|
+
* @private
|
|
125
|
+
*/
|
|
126
|
+
private handleResponse;
|
|
127
|
+
/**
|
|
128
|
+
* Performs a GET request
|
|
129
|
+
*
|
|
130
|
+
* @template T - Response type
|
|
131
|
+
* @param {string} path - Request path
|
|
132
|
+
* @param {Record<string, string>} [headers] - Additional headers
|
|
133
|
+
* @returns {Promise<T>} Parsed response body
|
|
134
|
+
*/
|
|
135
|
+
get: <T>(path: string, headers?: Record<string, string>) => Promise<T>;
|
|
136
|
+
/**
|
|
137
|
+
* Performs a POST request
|
|
138
|
+
*
|
|
139
|
+
* @template T - Response type
|
|
140
|
+
* @param {string} path - Request path
|
|
141
|
+
* @param {unknown} [body] - Request body
|
|
142
|
+
* @param {Record<string, string>} [headers] - Additional headers
|
|
143
|
+
* @returns {Promise<T>} Parsed response body
|
|
144
|
+
*/
|
|
145
|
+
post: <T>(path: string, body?: unknown, headers?: Record<string, string>) => Promise<T>;
|
|
146
|
+
/**
|
|
147
|
+
* Performs a PATCH request
|
|
148
|
+
*
|
|
149
|
+
* @template T - Response type
|
|
150
|
+
* @param {string} path - Request path
|
|
151
|
+
* @param {unknown} [body] - Request body
|
|
152
|
+
* @param {Record<string, string>} [headers] - Additional headers
|
|
153
|
+
* @returns {Promise<T>} Parsed response body
|
|
154
|
+
*/
|
|
155
|
+
patch: <T>(path: string, body?: unknown, headers?: Record<string, string>) => Promise<T>;
|
|
156
|
+
/**
|
|
157
|
+
* Performs a DELETE request
|
|
158
|
+
*
|
|
159
|
+
* @template T - Response type
|
|
160
|
+
* @param {string} path - Request path
|
|
161
|
+
* @param {Record<string, string>} [headers] - Additional headers
|
|
162
|
+
* @returns {Promise<T>} Parsed response body
|
|
163
|
+
*/
|
|
164
|
+
delete: <T>(path: string, headers?: Record<string, string>) => Promise<T>;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Base class for all API resources
|
|
169
|
+
*
|
|
170
|
+
* Provides common functionality for resource classes including
|
|
171
|
+
* HTTP client access and query string building.
|
|
172
|
+
*/
|
|
173
|
+
declare abstract class BaseResource {
|
|
174
|
+
protected readonly http: HttpClient;
|
|
175
|
+
/**
|
|
176
|
+
* Creates a base resource instance
|
|
177
|
+
*
|
|
178
|
+
* @param {HttpClient} http - HTTP client for making requests
|
|
179
|
+
* @protected
|
|
180
|
+
*/
|
|
181
|
+
constructor(http: HttpClient);
|
|
182
|
+
/**
|
|
183
|
+
* Builds a query string from parameters
|
|
184
|
+
*
|
|
185
|
+
* Filters out undefined and null values, and properly encodes
|
|
186
|
+
* parameter names and values for URL use.
|
|
187
|
+
*
|
|
188
|
+
* @param {Record<string, string | number | boolean | undefined>} params - Query parameters
|
|
189
|
+
* @returns {string} Formatted query string with leading '?' or empty string
|
|
190
|
+
* @protected
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```typescript
|
|
194
|
+
* buildQueryString({ field: 'username', value: 'john' })
|
|
195
|
+
* // Returns: "?field=username&value=john"
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
protected buildQueryString: (params: Record<string, string | number | boolean | undefined>) => string;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
interface EmailAddress {
|
|
202
|
+
address: string;
|
|
203
|
+
type?: string;
|
|
204
|
+
label?: string;
|
|
205
|
+
primary?: string;
|
|
206
|
+
}
|
|
207
|
+
interface InstantMessaging {
|
|
208
|
+
uri: string;
|
|
209
|
+
protocol?: string;
|
|
210
|
+
label?: string;
|
|
211
|
+
primary?: string;
|
|
212
|
+
}
|
|
213
|
+
interface PhoneNumber {
|
|
214
|
+
number: string;
|
|
215
|
+
type?: string;
|
|
216
|
+
label?: string;
|
|
217
|
+
primary?: boolean;
|
|
218
|
+
}
|
|
219
|
+
interface ExtendedAddress {
|
|
220
|
+
locality?: string;
|
|
221
|
+
building?: string;
|
|
222
|
+
stairs?: string;
|
|
223
|
+
floor?: string;
|
|
224
|
+
apartment?: string;
|
|
225
|
+
entrycode?: string;
|
|
226
|
+
}
|
|
227
|
+
interface GeoLocation {
|
|
228
|
+
geo?: [number, number];
|
|
229
|
+
cozyCategory?: string;
|
|
230
|
+
}
|
|
231
|
+
interface Address {
|
|
232
|
+
id?: string;
|
|
233
|
+
street?: string;
|
|
234
|
+
pobox?: string;
|
|
235
|
+
city?: string;
|
|
236
|
+
region?: string;
|
|
237
|
+
number?: string;
|
|
238
|
+
code?: string;
|
|
239
|
+
country?: string;
|
|
240
|
+
type?: string;
|
|
241
|
+
label?: string;
|
|
242
|
+
primary?: boolean;
|
|
243
|
+
extendedAddress?: ExtendedAddress;
|
|
244
|
+
formattedAddress?: string;
|
|
245
|
+
geo?: GeoLocation;
|
|
246
|
+
}
|
|
247
|
+
interface UserName {
|
|
248
|
+
familyName?: string;
|
|
249
|
+
givenName?: string;
|
|
250
|
+
additionalName?: string;
|
|
251
|
+
namePrefix?: string;
|
|
252
|
+
nameSuffix?: string;
|
|
253
|
+
surname?: string;
|
|
254
|
+
}
|
|
255
|
+
interface User {
|
|
256
|
+
cn: string;
|
|
257
|
+
sn: string;
|
|
258
|
+
givenName: string;
|
|
259
|
+
displayName: string;
|
|
260
|
+
mail: string;
|
|
261
|
+
mobile: string;
|
|
262
|
+
userPassword: string;
|
|
263
|
+
scryptR: number;
|
|
264
|
+
scryptN: number;
|
|
265
|
+
scryptP: number;
|
|
266
|
+
scryptSalt: string;
|
|
267
|
+
scryptDKLength: number;
|
|
268
|
+
iterations: number;
|
|
269
|
+
domain: string;
|
|
270
|
+
publicKey: string;
|
|
271
|
+
privateKey: string;
|
|
272
|
+
protectedKey: string;
|
|
273
|
+
twoFactorEnabled?: string;
|
|
274
|
+
workspaceUrl?: string;
|
|
275
|
+
recoveryEmail?: string;
|
|
276
|
+
pwdAccountLockedTime?: string;
|
|
277
|
+
twakeOrganizationRole?: string;
|
|
278
|
+
fullname?: string;
|
|
279
|
+
name?: UserName;
|
|
280
|
+
birthday?: string;
|
|
281
|
+
gender?: string;
|
|
282
|
+
note?: string;
|
|
283
|
+
email?: EmailAddress[];
|
|
284
|
+
impp?: InstantMessaging[];
|
|
285
|
+
birthplace?: string;
|
|
286
|
+
jobTitle?: string;
|
|
287
|
+
company?: string;
|
|
288
|
+
phone?: PhoneNumber[];
|
|
289
|
+
address?: Address[];
|
|
290
|
+
}
|
|
291
|
+
interface UserCredentials {
|
|
292
|
+
userPassword: string;
|
|
293
|
+
scryptN: number;
|
|
294
|
+
scryptP: number;
|
|
295
|
+
scryptR: number;
|
|
296
|
+
scryptSalt: string;
|
|
297
|
+
scryptDKLength: number;
|
|
298
|
+
iterations: number;
|
|
299
|
+
}
|
|
300
|
+
interface UserKeys {
|
|
301
|
+
privateKey: string;
|
|
302
|
+
publicKey: string;
|
|
303
|
+
protectedKey: string;
|
|
304
|
+
}
|
|
305
|
+
type UserStatus = 'active' | 'disabled';
|
|
306
|
+
type UserSearchField = 'username' | 'phone' | 'email' | 'recoveryEmail';
|
|
307
|
+
interface CreateUserRequest extends UserCredentials, UserKeys {
|
|
308
|
+
cn: string;
|
|
309
|
+
uid: string;
|
|
310
|
+
givenName: string;
|
|
311
|
+
sn: string;
|
|
312
|
+
displayName: string;
|
|
313
|
+
mobile: string;
|
|
314
|
+
mail: string;
|
|
315
|
+
domain: string;
|
|
316
|
+
workspaceUrl?: string;
|
|
317
|
+
twoFactorEnabled?: string;
|
|
318
|
+
recoveryEmail?: string;
|
|
319
|
+
pwdAccountLockedTime?: string;
|
|
320
|
+
twakeOrganizationRole?: string;
|
|
321
|
+
fullname?: string;
|
|
322
|
+
name?: UserName;
|
|
323
|
+
birthday?: string;
|
|
324
|
+
gender?: string;
|
|
325
|
+
note?: string;
|
|
326
|
+
email?: EmailAddress[];
|
|
327
|
+
impp?: InstantMessaging[];
|
|
328
|
+
birthplace?: string;
|
|
329
|
+
jobTitle?: string;
|
|
330
|
+
company?: string;
|
|
331
|
+
phone?: PhoneNumber[];
|
|
332
|
+
address?: Address[];
|
|
333
|
+
}
|
|
334
|
+
interface UpdateUserRequest {
|
|
335
|
+
mobile?: string;
|
|
336
|
+
userPassword?: string;
|
|
337
|
+
protectedKey?: string;
|
|
338
|
+
twoFactorEnabled?: string | null;
|
|
339
|
+
recoveryEmail?: string;
|
|
340
|
+
displayName?: string;
|
|
341
|
+
pwdAccountLockedTime?: string;
|
|
342
|
+
twakeOrganizationRole?: string;
|
|
343
|
+
fullname?: string;
|
|
344
|
+
name?: UserName;
|
|
345
|
+
birthday?: string;
|
|
346
|
+
gender?: string;
|
|
347
|
+
note?: string;
|
|
348
|
+
email?: EmailAddress[];
|
|
349
|
+
impp?: InstantMessaging[];
|
|
350
|
+
birthplace?: string;
|
|
351
|
+
jobTitle?: string;
|
|
352
|
+
company?: string;
|
|
353
|
+
phone?: PhoneNumber[];
|
|
354
|
+
address?: Address[];
|
|
355
|
+
[key: string]: string | number | boolean | null | undefined | UserName | EmailAddress[] | InstantMessaging[] | PhoneNumber[] | Address[];
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Request parameters for fetching a user
|
|
359
|
+
*/
|
|
360
|
+
interface FetchUserRequest extends Record<string, string | undefined> {
|
|
361
|
+
by: UserSearchField;
|
|
362
|
+
value: string;
|
|
363
|
+
fields?: string;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Parameters for checking availability of username, email, or phone
|
|
367
|
+
*/
|
|
368
|
+
interface CheckAvailabilityParams extends Record<string, string> {
|
|
369
|
+
field: string;
|
|
370
|
+
value: string;
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Response from availability check
|
|
374
|
+
*/
|
|
375
|
+
interface CheckAvailabilityResponse {
|
|
376
|
+
available: boolean;
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Parameters for listing users in an organization with pagination and filtering
|
|
380
|
+
*/
|
|
381
|
+
interface ListUsersParams {
|
|
382
|
+
/** Page number (default: 1) */
|
|
383
|
+
page?: number;
|
|
384
|
+
/** Items per page (default: 20, max: 100) */
|
|
385
|
+
limit?: number;
|
|
386
|
+
/** Filter by status ('active' or 'disabled') */
|
|
387
|
+
status?: UserStatus;
|
|
388
|
+
/** Search by username, email, or name (min 2 characters) */
|
|
389
|
+
search?: string;
|
|
390
|
+
/** Field to sort by ('username', 'createdAt', 'mail') */
|
|
391
|
+
sortBy?: string;
|
|
392
|
+
/** Sort order ('asc' or 'desc') */
|
|
393
|
+
sortOrder?: 'asc' | 'desc';
|
|
394
|
+
[key: string]: string | number | boolean | undefined;
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Response from listing users in an organization
|
|
398
|
+
*/
|
|
399
|
+
interface ListUsersResponse {
|
|
400
|
+
/** Array of users */
|
|
401
|
+
users: User[];
|
|
402
|
+
/** Pagination information */
|
|
403
|
+
pagination: {
|
|
404
|
+
page: number;
|
|
405
|
+
limit: number;
|
|
406
|
+
total: number;
|
|
407
|
+
totalPages: number;
|
|
408
|
+
hasNextPage: boolean;
|
|
409
|
+
hasPreviousPage: boolean;
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Response from creating a B2B user in an organization
|
|
414
|
+
*/
|
|
415
|
+
interface CreateB2BUserResponse {
|
|
416
|
+
/** Base DN of the created user */
|
|
417
|
+
baseDN: string;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Organization domain model representing a B2B organization
|
|
422
|
+
*
|
|
423
|
+
* Organizations have dedicated LDAP branches (baseDN) for managing
|
|
424
|
+
* B2B users separately from B2C users in the main branch.
|
|
425
|
+
*/
|
|
426
|
+
interface Organization {
|
|
427
|
+
/** Unique organization identifier (must start with 'org_') */
|
|
428
|
+
id: string;
|
|
429
|
+
/** Organization display name */
|
|
430
|
+
name: string;
|
|
431
|
+
/** Organization domain (e.g., 'acme.example.com') */
|
|
432
|
+
domain: string;
|
|
433
|
+
/** LDAP base DN for this organization's branch (e.g., 'ou=org_abc123,dc=example,dc=com') */
|
|
434
|
+
baseDN: string;
|
|
435
|
+
/** Organization status (active or suspended) */
|
|
436
|
+
status: OrganizationStatus;
|
|
437
|
+
/** Organization creation timestamp */
|
|
438
|
+
createdAt: Date;
|
|
439
|
+
/** Optional metadata for custom organization properties */
|
|
440
|
+
metadata?: OrganizationMetadata;
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Organization status
|
|
444
|
+
*
|
|
445
|
+
* - active: Organization is operational and users can authenticate
|
|
446
|
+
* - suspended: Organization is temporarily disabled
|
|
447
|
+
*/
|
|
448
|
+
type OrganizationStatus = 'active' | 'suspended';
|
|
449
|
+
/**
|
|
450
|
+
* Optional metadata for organization customization
|
|
451
|
+
*
|
|
452
|
+
* Allows storing custom properties like industry, company size,
|
|
453
|
+
* contact information, or any other organization-specific data.
|
|
454
|
+
*/
|
|
455
|
+
interface OrganizationMetadata {
|
|
456
|
+
/** Industry/sector (e.g., 'Technology', 'Healthcare') */
|
|
457
|
+
industry?: string;
|
|
458
|
+
/** Organization size (e.g., '1-10', '11-50', '51-200') */
|
|
459
|
+
size?: string;
|
|
460
|
+
/** Primary contact information */
|
|
461
|
+
contact?: string;
|
|
462
|
+
/** Additional custom fields as key-value pairs */
|
|
463
|
+
[key: string]: string | undefined;
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Request parameters for creating an organization
|
|
467
|
+
*/
|
|
468
|
+
interface CreateOrganizationRequest {
|
|
469
|
+
id: string;
|
|
470
|
+
name: string;
|
|
471
|
+
domain: string;
|
|
472
|
+
metadata?: OrganizationMetadata;
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* Response from creating an organization
|
|
476
|
+
*/
|
|
477
|
+
interface CreateOrganizationResponse {
|
|
478
|
+
success: true;
|
|
479
|
+
organization: Organization;
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* Request parameters for linking an admin user to an organization
|
|
483
|
+
*/
|
|
484
|
+
interface CreateAdminRequest {
|
|
485
|
+
username: string;
|
|
486
|
+
mail: string;
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Request parameters for updating an organization
|
|
490
|
+
*/
|
|
491
|
+
interface UpdateOrganizationRequest {
|
|
492
|
+
/** Organization display name */
|
|
493
|
+
name?: string;
|
|
494
|
+
/** Organization status */
|
|
495
|
+
status?: OrganizationStatus;
|
|
496
|
+
/** Optional metadata updates */
|
|
497
|
+
metadata?: OrganizationMetadata;
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* User role within an organization
|
|
501
|
+
*/
|
|
502
|
+
type OrganizationRole = 'admin' | 'moderator' | 'member';
|
|
503
|
+
/**
|
|
504
|
+
* Request parameters for changing a user's role in an organization
|
|
505
|
+
*/
|
|
506
|
+
interface ChangeUserRoleRequest {
|
|
507
|
+
/** New role for the user */
|
|
508
|
+
role: OrganizationRole;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* Group domain model representing a group within a B2B organization
|
|
513
|
+
*
|
|
514
|
+
* Groups allow organizing users within an organization for access control
|
|
515
|
+
* and team management.
|
|
516
|
+
*/
|
|
517
|
+
interface Group {
|
|
518
|
+
/** Unique group identifier */
|
|
519
|
+
id: string;
|
|
520
|
+
/** Group common name */
|
|
521
|
+
cn: string;
|
|
522
|
+
/** Group description */
|
|
523
|
+
description?: string;
|
|
524
|
+
/** Organization ID this group belongs to */
|
|
525
|
+
organizationId: string;
|
|
526
|
+
/** LDAP base DN for this group */
|
|
527
|
+
baseDN: string;
|
|
528
|
+
/** Array of usernames that are members of this group */
|
|
529
|
+
members: string[];
|
|
530
|
+
/** Group creation timestamp */
|
|
531
|
+
createdAt: string;
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* Request parameters for creating a group
|
|
535
|
+
*/
|
|
536
|
+
interface CreateGroupRequest {
|
|
537
|
+
/** Group common name (unique within organization) */
|
|
538
|
+
name: string;
|
|
539
|
+
/** Optional group description */
|
|
540
|
+
description?: string;
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* Response from creating a group
|
|
544
|
+
*/
|
|
545
|
+
interface CreateGroupResponse {
|
|
546
|
+
success: true;
|
|
547
|
+
group: Group;
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* Request parameters for updating a group
|
|
551
|
+
*/
|
|
552
|
+
interface UpdateGroupRequest {
|
|
553
|
+
/** Group description */
|
|
554
|
+
description?: string;
|
|
555
|
+
/** Group common name */
|
|
556
|
+
name?: string;
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* Request parameters for adding members to a group
|
|
560
|
+
*/
|
|
561
|
+
interface AddGroupMembersRequest {
|
|
562
|
+
/** Array of usernames to add to the group */
|
|
563
|
+
usernames: string[];
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* Parameters for listing groups with pagination
|
|
567
|
+
*/
|
|
568
|
+
interface ListGroupsParams {
|
|
569
|
+
/** Page number (default: 1) */
|
|
570
|
+
page?: number;
|
|
571
|
+
/** Items per page (default: 20, max: 100) */
|
|
572
|
+
limit?: number;
|
|
573
|
+
[key: string]: string | number | boolean | undefined;
|
|
574
|
+
}
|
|
575
|
+
/**
|
|
576
|
+
* Response from listing groups
|
|
577
|
+
*/
|
|
578
|
+
interface ListGroupsResponse {
|
|
579
|
+
/** Organization identifier */
|
|
580
|
+
organizationId: string;
|
|
581
|
+
/** Array of groups */
|
|
582
|
+
groups: Group[];
|
|
583
|
+
/** Pagination information */
|
|
584
|
+
pagination: {
|
|
585
|
+
page: number;
|
|
586
|
+
limit: number;
|
|
587
|
+
total: number;
|
|
588
|
+
totalPages: number;
|
|
589
|
+
};
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* Users resource - Manages B2C users in main LDAP branch
|
|
594
|
+
*
|
|
595
|
+
* Provides methods for creating, updating, deleting, and querying users
|
|
596
|
+
* in the main LDAP branch (B2C users). All operations require HMAC authentication.
|
|
597
|
+
*
|
|
598
|
+
* @example
|
|
599
|
+
* ```typescript
|
|
600
|
+
* const client = new LdapRestClient(config);
|
|
601
|
+
*
|
|
602
|
+
* // Create user
|
|
603
|
+
* await client.users.create({
|
|
604
|
+
* cn: 'johndoe',
|
|
605
|
+
* uid: 'johndoe',
|
|
606
|
+
* // ... other fields
|
|
607
|
+
* });
|
|
608
|
+
*
|
|
609
|
+
* // Check availability
|
|
610
|
+
* const { available } = await client.users.checkAvailability({
|
|
611
|
+
* field: 'username',
|
|
612
|
+
* value: 'johndoe'
|
|
613
|
+
* });
|
|
614
|
+
* ```
|
|
615
|
+
*/
|
|
616
|
+
declare class UsersResource extends BaseResource {
|
|
617
|
+
/**
|
|
618
|
+
* Creates a new user in the main LDAP branch
|
|
619
|
+
*
|
|
620
|
+
* @param {CreateUserRequest} data - User data including credentials and profile
|
|
621
|
+
* @returns {Promise<{ success: true }>} Success response
|
|
622
|
+
* @throws {ConflictError} When username/email/phone already exists
|
|
623
|
+
* @throws {ApiError} On other API errors
|
|
624
|
+
*/
|
|
625
|
+
create: (data: CreateUserRequest) => Promise<{
|
|
626
|
+
success: true;
|
|
627
|
+
}>;
|
|
628
|
+
/**
|
|
629
|
+
* Updates an existing user
|
|
630
|
+
*
|
|
631
|
+
* @param {string} userId - User identifier (username)
|
|
632
|
+
* @param {UpdateUserRequest} data - Fields to update
|
|
633
|
+
* @returns {Promise<{ success: true }>} Success response
|
|
634
|
+
* @throws {NotFoundError} When user is not found
|
|
635
|
+
* @throws {ApiError} On other API errors
|
|
636
|
+
*/
|
|
637
|
+
update: (userId: string, data: UpdateUserRequest) => Promise<{
|
|
638
|
+
success: true;
|
|
639
|
+
}>;
|
|
640
|
+
/**
|
|
641
|
+
* Disables a user account
|
|
642
|
+
*
|
|
643
|
+
* Sets pwdAccountLockedTime to lock the account using LDAP PPolicy.
|
|
644
|
+
*
|
|
645
|
+
* @param {string} userId - User identifier (username)
|
|
646
|
+
* @returns {Promise<{ success: true }>} Success response
|
|
647
|
+
* @throws {NotFoundError} When user is not found
|
|
648
|
+
* @throws {ApiError} On other API errors
|
|
649
|
+
*/
|
|
650
|
+
disable: (userId: string) => Promise<{
|
|
651
|
+
success: true;
|
|
652
|
+
}>;
|
|
653
|
+
/**
|
|
654
|
+
* Deletes a user
|
|
655
|
+
*
|
|
656
|
+
* Permanently removes the user from LDAP.
|
|
657
|
+
*
|
|
658
|
+
* @param {string} userId - User identifier (username)
|
|
659
|
+
* @returns {Promise<{ success: true }>} Success response
|
|
660
|
+
* @throws {NotFoundError} When user is not found
|
|
661
|
+
* @throws {ApiError} On other API errors
|
|
662
|
+
*/
|
|
663
|
+
delete: (userId: string) => Promise<{
|
|
664
|
+
success: true;
|
|
665
|
+
}>;
|
|
666
|
+
/**
|
|
667
|
+
* Checks if a username, phone, or email is available
|
|
668
|
+
*
|
|
669
|
+
* @param {CheckAvailabilityParams} params - Field and value to check
|
|
670
|
+
* @returns {Promise<CheckAvailabilityResponse>} Availability status
|
|
671
|
+
* @throws {ApiError} On API errors
|
|
672
|
+
*
|
|
673
|
+
* @example
|
|
674
|
+
* ```typescript
|
|
675
|
+
* const result = await client.users.checkAvailability({
|
|
676
|
+
* field: 'username',
|
|
677
|
+
* value: 'johndoe'
|
|
678
|
+
* });
|
|
679
|
+
*
|
|
680
|
+
* ```
|
|
681
|
+
*/
|
|
682
|
+
checkAvailability: (params: CheckAvailabilityParams) => Promise<CheckAvailabilityResponse>;
|
|
683
|
+
/**
|
|
684
|
+
* Fetches a user by identifier
|
|
685
|
+
*
|
|
686
|
+
* @param {FetchUserRequest} params - Fetch parameters (by, value, fields)
|
|
687
|
+
* @returns {Promise<User>} User data
|
|
688
|
+
* @throws {NotFoundError} When user is not found
|
|
689
|
+
* @throws {ApiError} On other API errors
|
|
690
|
+
*
|
|
691
|
+
* @example
|
|
692
|
+
* ```typescript
|
|
693
|
+
* const user = await client.users.fetch({
|
|
694
|
+
* by: 'username',
|
|
695
|
+
* value: 'johndoe',
|
|
696
|
+
* fields: 'cn,mail,mobile'
|
|
697
|
+
* });
|
|
698
|
+
* ```
|
|
699
|
+
*/
|
|
700
|
+
fetch: (params: FetchUserRequest) => Promise<User>;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
/**
|
|
704
|
+
* Organizations resource - Manages organizations for B2B
|
|
705
|
+
*
|
|
706
|
+
* Provides methods for creating organizations and managing organization admins.
|
|
707
|
+
* Organizations have dedicated LDAP branches for B2B users.
|
|
708
|
+
*
|
|
709
|
+
* @example
|
|
710
|
+
* ```typescript
|
|
711
|
+
* const client = new LdapRestClient(config);
|
|
712
|
+
*
|
|
713
|
+
* // Create organization
|
|
714
|
+
* const org = await client.organizations.create({
|
|
715
|
+
* id: 'org_abc123',
|
|
716
|
+
* name: 'Acme Corp',
|
|
717
|
+
* domain: 'acme.example.com',
|
|
718
|
+
* metadata: { industry: 'Technology' }
|
|
719
|
+
* });
|
|
720
|
+
*
|
|
721
|
+
* // Link admin user
|
|
722
|
+
* await client.organizations.createAdmin('org_abc123', {
|
|
723
|
+
* username: 'admin',
|
|
724
|
+
* mail: 'admin@acme.example.com'
|
|
725
|
+
* });
|
|
726
|
+
* ```
|
|
727
|
+
*/
|
|
728
|
+
declare class OrganizationsResource extends BaseResource {
|
|
729
|
+
/**
|
|
730
|
+
* Creates a new organization with dedicated LDAP branch
|
|
731
|
+
*
|
|
732
|
+
* @param {CreateOrganizationRequest} data - Organization data
|
|
733
|
+
* @returns {Promise<CreateOrganizationResponse>} Organization details including baseDN
|
|
734
|
+
* @throws {ConflictError} When organization already exists
|
|
735
|
+
* @throws {ApiError} On other API errors
|
|
736
|
+
*/
|
|
737
|
+
create: (data: CreateOrganizationRequest) => Promise<CreateOrganizationResponse>;
|
|
738
|
+
/**
|
|
739
|
+
* Checks if an organization identifier is available
|
|
740
|
+
*
|
|
741
|
+
* @param {CheckAvailabilityParams} params - Field and value to check
|
|
742
|
+
* @returns {Promise<CheckAvailabilityResponse>} Availability status
|
|
743
|
+
* @throws {ApiError} On API errors
|
|
744
|
+
*
|
|
745
|
+
* @example
|
|
746
|
+
* ```typescript
|
|
747
|
+
* const result = await client.organizations.checkAvailability({
|
|
748
|
+
* field: 'domain',
|
|
749
|
+
* value: 'acme.example.com'
|
|
750
|
+
* });
|
|
751
|
+
* ```
|
|
752
|
+
*/
|
|
753
|
+
checkAvailability: (params: CheckAvailabilityParams) => Promise<CheckAvailabilityResponse>;
|
|
754
|
+
/**
|
|
755
|
+
* Links a user as the first admin of an organization
|
|
756
|
+
*
|
|
757
|
+
* Associates an existing user account with an organization and grants
|
|
758
|
+
* admin privileges. Typically called after organization creation.
|
|
759
|
+
*
|
|
760
|
+
* @param {string} organizationId - Organization identifier
|
|
761
|
+
* @param {CreateAdminRequest} data - Admin user details (username and email)
|
|
762
|
+
* @returns {Promise<{ success: true }>} Success response
|
|
763
|
+
* @throws {NotFoundError} When organization or user is not found
|
|
764
|
+
* @throws {ConflictError} When user is already an admin
|
|
765
|
+
* @throws {ApiError} On other API errors
|
|
766
|
+
*
|
|
767
|
+
* @example
|
|
768
|
+
* ```typescript
|
|
769
|
+
* await client.organizations.createAdmin('org_abc123', {
|
|
770
|
+
* username: 'john.doe',
|
|
771
|
+
* mail: 'john.doe@acme.example.com'
|
|
772
|
+
* });
|
|
773
|
+
* ```
|
|
774
|
+
*/
|
|
775
|
+
createAdmin: (organizationId: string, data: CreateAdminRequest) => Promise<{
|
|
776
|
+
success: true;
|
|
777
|
+
}>;
|
|
778
|
+
/**
|
|
779
|
+
* Gets a list of organizations for the authenticated user
|
|
780
|
+
*
|
|
781
|
+
* Requires SSO cookie authentication. Returns organizations where the
|
|
782
|
+
* authenticated user has admin role.
|
|
783
|
+
*
|
|
784
|
+
* @returns {Promise<Organization[]>} Array of organizations
|
|
785
|
+
* @throws {ApiError} On API errors
|
|
786
|
+
*
|
|
787
|
+
* @example
|
|
788
|
+
* ```typescript
|
|
789
|
+
* const organizations = await client.organizations.list();
|
|
790
|
+
* ```
|
|
791
|
+
*/
|
|
792
|
+
list: () => Promise<Organization[]>;
|
|
793
|
+
/**
|
|
794
|
+
* Gets details of a specific organization
|
|
795
|
+
*
|
|
796
|
+
* Requires SSO cookie authentication.
|
|
797
|
+
*
|
|
798
|
+
* @param {string} organizationId - Organization identifier
|
|
799
|
+
* @returns {Promise<Organization>} Organization details
|
|
800
|
+
* @throws {NotFoundError} When organization is not found
|
|
801
|
+
* @throws {ApiError} On other API errors
|
|
802
|
+
*
|
|
803
|
+
* @example
|
|
804
|
+
* ```typescript
|
|
805
|
+
* const org = await client.organizations.get('org_abc123');
|
|
806
|
+
* ```
|
|
807
|
+
*/
|
|
808
|
+
get: (organizationId: string) => Promise<Organization>;
|
|
809
|
+
/**
|
|
810
|
+
* Updates an organization
|
|
811
|
+
*
|
|
812
|
+
* Requires SSO cookie authentication and admin role.
|
|
813
|
+
*
|
|
814
|
+
* @param {string} organizationId - Organization identifier
|
|
815
|
+
* @param {UpdateOrganizationRequest} data - Fields to update
|
|
816
|
+
* @returns {Promise<{ success: true }>} Success response
|
|
817
|
+
* @throws {NotFoundError} When organization is not found
|
|
818
|
+
* @throws {ForbiddenError} When user lacks admin privileges
|
|
819
|
+
* @throws {ApiError} On other API errors
|
|
820
|
+
*
|
|
821
|
+
* @example
|
|
822
|
+
* ```typescript
|
|
823
|
+
* await client.organizations.update('org_abc123', {
|
|
824
|
+
* name: 'New Organization Name',
|
|
825
|
+
* status: 'active'
|
|
826
|
+
* });
|
|
827
|
+
* ```
|
|
828
|
+
*/
|
|
829
|
+
update: (organizationId: string, data: UpdateOrganizationRequest) => Promise<{
|
|
830
|
+
success: true;
|
|
831
|
+
}>;
|
|
832
|
+
/**
|
|
833
|
+
* Creates a new user in an organization's LDAP branch
|
|
834
|
+
*
|
|
835
|
+
* Requires SSO cookie authentication and admin role in the target organization.
|
|
836
|
+
*
|
|
837
|
+
* @param {string} organizationId - Organization identifier
|
|
838
|
+
* @param {CreateUserRequest} data - User data including credentials and profile
|
|
839
|
+
* @returns {Promise<CreateB2BUserResponse>} Response with user's baseDN
|
|
840
|
+
* @throws {ForbiddenError} When user lacks admin privileges
|
|
841
|
+
* @throws {NotFoundError} When organization is not found
|
|
842
|
+
* @throws {ConflictError} When username/email/phone already exists
|
|
843
|
+
* @throws {ApiError} On other API errors
|
|
844
|
+
*
|
|
845
|
+
* @example
|
|
846
|
+
* ```typescript
|
|
847
|
+
* const result = await client.organizations.createUser('org_abc123', {
|
|
848
|
+
* cn: 'john.doe',
|
|
849
|
+
* uid: 'john.doe',
|
|
850
|
+
* // ... other user fields
|
|
851
|
+
* });
|
|
852
|
+
* ```
|
|
853
|
+
*/
|
|
854
|
+
createUser: (organizationId: string, data: CreateUserRequest) => Promise<CreateB2BUserResponse>;
|
|
855
|
+
/**
|
|
856
|
+
* Updates a user in an organization
|
|
857
|
+
*
|
|
858
|
+
* Requires SSO cookie authentication and admin role in the target organization.
|
|
859
|
+
*
|
|
860
|
+
* @param {string} organizationId - Organization identifier
|
|
861
|
+
* @param {string} userId - User identifier (username)
|
|
862
|
+
* @param {UpdateUserRequest} data - Fields to update
|
|
863
|
+
* @returns {Promise<{ success: true }>} Success response
|
|
864
|
+
* @throws {NotFoundError} When user or organization is not found
|
|
865
|
+
* @throws {ForbiddenError} When user lacks admin privileges
|
|
866
|
+
* @throws {ApiError} On other API errors
|
|
867
|
+
*
|
|
868
|
+
* @example
|
|
869
|
+
* ```typescript
|
|
870
|
+
* await client.organizations.updateUser('org_abc123', 'john.doe', {
|
|
871
|
+
* mobile: '+33687654321'
|
|
872
|
+
* });
|
|
873
|
+
* ```
|
|
874
|
+
*/
|
|
875
|
+
updateUser: (organizationId: string, userId: string, data: UpdateUserRequest) => Promise<{
|
|
876
|
+
success: true;
|
|
877
|
+
}>;
|
|
878
|
+
/**
|
|
879
|
+
* Disables a user in an organization
|
|
880
|
+
*
|
|
881
|
+
* Locks the account by setting pwdAccountLockedTime using LDAP PPolicy.
|
|
882
|
+
* Requires SSO cookie authentication and admin role.
|
|
883
|
+
*
|
|
884
|
+
* @param {string} organizationId - Organization identifier
|
|
885
|
+
* @param {string} userId - User identifier (username)
|
|
886
|
+
* @returns {Promise<{ success: true }>} Success response
|
|
887
|
+
* @throws {NotFoundError} When user or organization is not found
|
|
888
|
+
* @throws {ForbiddenError} When user lacks admin privileges
|
|
889
|
+
* @throws {ApiError} On other API errors
|
|
890
|
+
*
|
|
891
|
+
* @example
|
|
892
|
+
* ```typescript
|
|
893
|
+
* await client.organizations.disableUser('org_abc123', 'john.doe');
|
|
894
|
+
* ```
|
|
895
|
+
*/
|
|
896
|
+
disableUser: (organizationId: string, userId: string) => Promise<{
|
|
897
|
+
success: true;
|
|
898
|
+
}>;
|
|
899
|
+
/**
|
|
900
|
+
* Deletes a user from an organization
|
|
901
|
+
*
|
|
902
|
+
* Permanently removes the user from the organization's LDAP branch.
|
|
903
|
+
* Requires SSO cookie authentication and admin role.
|
|
904
|
+
*
|
|
905
|
+
* @param {string} organizationId - Organization identifier
|
|
906
|
+
* @param {string} userId - User identifier (username)
|
|
907
|
+
* @returns {Promise<{ success: true }>} Success response
|
|
908
|
+
* @throws {NotFoundError} When user or organization is not found
|
|
909
|
+
* @throws {ForbiddenError} When user lacks admin privileges
|
|
910
|
+
* @throws {ApiError} On other API errors
|
|
911
|
+
*
|
|
912
|
+
* @example
|
|
913
|
+
* ```typescript
|
|
914
|
+
* await client.organizations.deleteUser('org_abc123', 'john.doe');
|
|
915
|
+
* ```
|
|
916
|
+
*/
|
|
917
|
+
deleteUser: (organizationId: string, userId: string) => Promise<{
|
|
918
|
+
success: true;
|
|
919
|
+
}>;
|
|
920
|
+
/**
|
|
921
|
+
* Fetches a user from an organization by identifier
|
|
922
|
+
*
|
|
923
|
+
* Requires SSO cookie authentication and admin role.
|
|
924
|
+
*
|
|
925
|
+
* @param {string} organizationId - Organization identifier
|
|
926
|
+
* @param {FetchUserRequest} params - Fetch parameters (by, value, fields)
|
|
927
|
+
* @returns {Promise<User>} User data
|
|
928
|
+
* @throws {NotFoundError} When user or organization is not found
|
|
929
|
+
* @throws {ForbiddenError} When user lacks admin privileges
|
|
930
|
+
* @throws {ApiError} On other API errors
|
|
931
|
+
*
|
|
932
|
+
* @example
|
|
933
|
+
* ```typescript
|
|
934
|
+
* const user = await client.organizations.getUser('org_abc123', {
|
|
935
|
+
* by: 'username',
|
|
936
|
+
* value: 'john.doe',
|
|
937
|
+
* fields: 'cn,mail,mobile'
|
|
938
|
+
* });
|
|
939
|
+
* ```
|
|
940
|
+
*/
|
|
941
|
+
getUser: (organizationId: string, params: FetchUserRequest) => Promise<User>;
|
|
942
|
+
/**
|
|
943
|
+
* Lists users in an organization with pagination and filtering
|
|
944
|
+
*
|
|
945
|
+
* Requires SSO cookie authentication and admin role.
|
|
946
|
+
*
|
|
947
|
+
* @param {string} organizationId - Organization identifier
|
|
948
|
+
* @param {ListUsersParams} params - Pagination and filter parameters
|
|
949
|
+
* @returns {Promise<ListUsersResponse>} Paginated list of users
|
|
950
|
+
* @throws {NotFoundError} When organization is not found
|
|
951
|
+
* @throws {ForbiddenError} When user lacks admin privileges
|
|
952
|
+
* @throws {ApiError} On other API errors
|
|
953
|
+
*
|
|
954
|
+
* @example
|
|
955
|
+
* ```typescript
|
|
956
|
+
* const result = await client.organizations.listUsers('org_abc123', {
|
|
957
|
+
* page: 1,
|
|
958
|
+
* limit: 20,
|
|
959
|
+
* status: 'active',
|
|
960
|
+
* search: 'john',
|
|
961
|
+
* sortBy: 'createdAt',
|
|
962
|
+
* sortOrder: 'desc'
|
|
963
|
+
* });
|
|
964
|
+
* ```
|
|
965
|
+
*/
|
|
966
|
+
listUsers: (organizationId: string, params?: ListUsersParams) => Promise<ListUsersResponse>;
|
|
967
|
+
/**
|
|
968
|
+
* Checks if a username, phone, or email is available in an organization
|
|
969
|
+
*
|
|
970
|
+
* Requires SSO cookie authentication and admin role.
|
|
971
|
+
*
|
|
972
|
+
* @param {string} organizationId - Organization identifier
|
|
973
|
+
* @param {CheckAvailabilityParams} params - Field and value to check
|
|
974
|
+
* @returns {Promise<CheckAvailabilityResponse>} Availability status
|
|
975
|
+
* @throws {NotFoundError} When organization is not found
|
|
976
|
+
* @throws {ForbiddenError} When user lacks admin privileges
|
|
977
|
+
* @throws {ApiError} On other API errors
|
|
978
|
+
*
|
|
979
|
+
* @example
|
|
980
|
+
* ```typescript
|
|
981
|
+
* const result = await client.organizations.checkUserAvailability('org_abc123', {
|
|
982
|
+
* field: 'username',
|
|
983
|
+
* value: 'john.doe'
|
|
984
|
+
* });
|
|
985
|
+
* ```
|
|
986
|
+
*/
|
|
987
|
+
checkUserAvailability: (organizationId: string, params: CheckAvailabilityParams) => Promise<CheckAvailabilityResponse>;
|
|
988
|
+
/**
|
|
989
|
+
* Changes a user's role in an organization
|
|
990
|
+
*
|
|
991
|
+
* Available roles: admin, moderator, member.
|
|
992
|
+
* Requires SSO cookie authentication and admin role.
|
|
993
|
+
* Cannot change your own role or remove the last admin.
|
|
994
|
+
*
|
|
995
|
+
* @param {string} organizationId - Organization identifier
|
|
996
|
+
* @param {string} userId - User identifier (username)
|
|
997
|
+
* @param {ChangeUserRoleRequest} data - New role
|
|
998
|
+
* @returns {Promise<{ success: true }>} Success response
|
|
999
|
+
* @throws {NotFoundError} When user or organization is not found
|
|
1000
|
+
* @throws {ForbiddenError} When attempting self-demotion or removing last admin
|
|
1001
|
+
* @throws {ApiError} On other API errors
|
|
1002
|
+
*
|
|
1003
|
+
* @example
|
|
1004
|
+
* ```typescript
|
|
1005
|
+
* await client.organizations.changeUserRole('org_abc123', 'john.doe', {
|
|
1006
|
+
* role: 'moderator'
|
|
1007
|
+
* });
|
|
1008
|
+
* ```
|
|
1009
|
+
*/
|
|
1010
|
+
changeUserRole: (organizationId: string, userId: string, data: ChangeUserRoleRequest) => Promise<{
|
|
1011
|
+
success: true;
|
|
1012
|
+
}>;
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
/**
|
|
1016
|
+
* Groups resource - Manages groups within B2B organizations
|
|
1017
|
+
*
|
|
1018
|
+
* Provides methods for creating, updating, deleting groups and managing
|
|
1019
|
+
* group memberships. All operations require SSO cookie authentication
|
|
1020
|
+
* and admin role in the target organization.
|
|
1021
|
+
*
|
|
1022
|
+
* @example
|
|
1023
|
+
* ```typescript
|
|
1024
|
+
* const client = new LdapRestClient(config);
|
|
1025
|
+
*
|
|
1026
|
+
* // Create group
|
|
1027
|
+
* const group = await client.groups.create('org_abc123', {
|
|
1028
|
+
* name: 'engineering',
|
|
1029
|
+
* description: 'Engineering team'
|
|
1030
|
+
* });
|
|
1031
|
+
*
|
|
1032
|
+
* // Add members
|
|
1033
|
+
* await client.groups.addMembers('org_abc123', 'grp_xyz789', {
|
|
1034
|
+
* usernames: ['john.doe', 'jane.smith']
|
|
1035
|
+
* });
|
|
1036
|
+
* ```
|
|
1037
|
+
*/
|
|
1038
|
+
declare class GroupsResource extends BaseResource {
|
|
1039
|
+
/**
|
|
1040
|
+
* Creates a new group in an organization
|
|
1041
|
+
*
|
|
1042
|
+
* Requires SSO cookie authentication and admin role in the target organization.
|
|
1043
|
+
*
|
|
1044
|
+
* @param {string} organizationId - Organization identifier
|
|
1045
|
+
* @param {CreateGroupRequest} data - Group data (name and optional description)
|
|
1046
|
+
* @returns {Promise<CreateGroupResponse>} Created group details
|
|
1047
|
+
* @throws {ForbiddenError} When user lacks admin privileges
|
|
1048
|
+
* @throws {NotFoundError} When organization is not found
|
|
1049
|
+
* @throws {ConflictError} When group name already exists
|
|
1050
|
+
* @throws {ApiError} On other API errors
|
|
1051
|
+
*
|
|
1052
|
+
* @examples
|
|
1053
|
+
* ```typescript
|
|
1054
|
+
* const result = await client.groups.create('org_abc123', {
|
|
1055
|
+
* name: 'engineering',
|
|
1056
|
+
* description: 'Engineering team'
|
|
1057
|
+
* });
|
|
1058
|
+
* ```
|
|
1059
|
+
*/
|
|
1060
|
+
create: (organizationId: string, data: CreateGroupRequest) => Promise<CreateGroupResponse>;
|
|
1061
|
+
/**
|
|
1062
|
+
* Lists all groups in an organization with pagination
|
|
1063
|
+
*
|
|
1064
|
+
* Requires SSO cookie authentication and admin role.
|
|
1065
|
+
*
|
|
1066
|
+
* @param {string} organizationId - Organization identifier
|
|
1067
|
+
* @param {ListGroupsParams} params - Pagination parameters (page, limit)
|
|
1068
|
+
* @returns {Promise<ListGroupsResponse>} Paginated list of groups
|
|
1069
|
+
* @throws {NotFoundError} When organization is not found
|
|
1070
|
+
* @throws {ForbiddenError} When user lacks admin privileges
|
|
1071
|
+
* @throws {ApiError} On other API errors
|
|
1072
|
+
*
|
|
1073
|
+
* @example
|
|
1074
|
+
* ```typescript
|
|
1075
|
+
* const result = await client.groups.list('org_abc123', {
|
|
1076
|
+
* page: 1,
|
|
1077
|
+
* limit: 20
|
|
1078
|
+
* });
|
|
1079
|
+
* ```
|
|
1080
|
+
*/
|
|
1081
|
+
list: (organizationId: string, params?: ListGroupsParams) => Promise<ListGroupsResponse>;
|
|
1082
|
+
/**
|
|
1083
|
+
* Gets details of a specific group
|
|
1084
|
+
*
|
|
1085
|
+
* Requires SSO cookie authentication and admin role.
|
|
1086
|
+
*
|
|
1087
|
+
* @param {string} organizationId - Organization identifier
|
|
1088
|
+
* @param {string} groupId - Group identifier
|
|
1089
|
+
* @returns {Promise<Group>} Group details including members
|
|
1090
|
+
* @throws {NotFoundError} When organization or group is not found
|
|
1091
|
+
* @throws {ForbiddenError} When user lacks admin privileges
|
|
1092
|
+
* @throws {ApiError} On other API errors
|
|
1093
|
+
*
|
|
1094
|
+
* @example
|
|
1095
|
+
* ```typescript
|
|
1096
|
+
* const group = await client.groups.get('org_abc123', 'grp_xyz789');
|
|
1097
|
+
* ```
|
|
1098
|
+
*/
|
|
1099
|
+
get: (organizationId: string, groupId: string) => Promise<Group>;
|
|
1100
|
+
/**
|
|
1101
|
+
* Updates a group's properties
|
|
1102
|
+
*
|
|
1103
|
+
* Requires SSO cookie authentication and admin role.
|
|
1104
|
+
*
|
|
1105
|
+
* @param {string} organizationId - Organization identifier
|
|
1106
|
+
* @param {string} groupId - Group identifier
|
|
1107
|
+
* @param {UpdateGroupRequest} data - Fields to update (name, description)
|
|
1108
|
+
* @returns {Promise<{ success: true }>} Success response
|
|
1109
|
+
* @throws {NotFoundError} When organization or group is not found
|
|
1110
|
+
* @throws {ForbiddenError} When user lacks admin privileges
|
|
1111
|
+
* @throws {ConflictError} When new group name already exists
|
|
1112
|
+
* @throws {ApiError} On other API errors
|
|
1113
|
+
*
|
|
1114
|
+
* @example
|
|
1115
|
+
* ```typescript
|
|
1116
|
+
* await client.groups.update('org_abc123', 'grp_xyz789', {
|
|
1117
|
+
* description: 'Updated description'
|
|
1118
|
+
* });
|
|
1119
|
+
* ```
|
|
1120
|
+
*/
|
|
1121
|
+
update: (organizationId: string, groupId: string, data: UpdateGroupRequest) => Promise<{
|
|
1122
|
+
success: true;
|
|
1123
|
+
}>;
|
|
1124
|
+
/**
|
|
1125
|
+
* Deletes a group from an organization
|
|
1126
|
+
*
|
|
1127
|
+
* Permanently removes the group. Members are not deleted, only the group itself.
|
|
1128
|
+
* Requires SSO cookie authentication and admin role.
|
|
1129
|
+
*
|
|
1130
|
+
* @param {string} organizationId - Organization identifier
|
|
1131
|
+
* @param {string} groupId - Group identifier
|
|
1132
|
+
* @returns {Promise<{ success: true }>} Success response
|
|
1133
|
+
* @throws {NotFoundError} When organization or group is not found
|
|
1134
|
+
* @throws {ForbiddenError} When user lacks admin privileges
|
|
1135
|
+
* @throws {ApiError} On other API errors
|
|
1136
|
+
*
|
|
1137
|
+
* @example
|
|
1138
|
+
* ```typescript
|
|
1139
|
+
* await client.groups.delete('org_abc123', 'grp_xyz789');
|
|
1140
|
+
* ```
|
|
1141
|
+
*/
|
|
1142
|
+
delete: (organizationId: string, groupId: string) => Promise<{
|
|
1143
|
+
success: true;
|
|
1144
|
+
}>;
|
|
1145
|
+
/**
|
|
1146
|
+
* Adds users to a group
|
|
1147
|
+
*
|
|
1148
|
+
* Adds one or more users to the group's member list.
|
|
1149
|
+
* Requires SSO cookie authentication and admin role.
|
|
1150
|
+
*
|
|
1151
|
+
* @param {string} organizationId - Organization identifier
|
|
1152
|
+
* @param {string} groupId - Group identifier
|
|
1153
|
+
* @param {AddGroupMembersRequest} data - Usernames to add
|
|
1154
|
+
* @returns {Promise<{ success: true }>} Success response
|
|
1155
|
+
* @throws {NotFoundError} When organization, group, or users are not found
|
|
1156
|
+
* @throws {ForbiddenError} When user lacks admin privileges
|
|
1157
|
+
* @throws {ApiError} On other API errors
|
|
1158
|
+
*
|
|
1159
|
+
* @example
|
|
1160
|
+
* ```typescript
|
|
1161
|
+
* await client.groups.addMembers('org_abc123', 'grp_xyz789', {
|
|
1162
|
+
* usernames: ['alice.johnson', 'bob.wilson']
|
|
1163
|
+
* });
|
|
1164
|
+
* ```
|
|
1165
|
+
*/
|
|
1166
|
+
addMembers: (organizationId: string, groupId: string, data: AddGroupMembersRequest) => Promise<{
|
|
1167
|
+
success: true;
|
|
1168
|
+
}>;
|
|
1169
|
+
/**
|
|
1170
|
+
* Removes a user from a group
|
|
1171
|
+
*
|
|
1172
|
+
* Removes a specific user from the group's member list.
|
|
1173
|
+
* Requires SSO cookie authentication and admin role.
|
|
1174
|
+
*
|
|
1175
|
+
* @param {string} organizationId - Organization identifier
|
|
1176
|
+
* @param {string} groupId - Group identifier
|
|
1177
|
+
* @param {string} userId - User identifier (username) to remove
|
|
1178
|
+
* @returns {Promise<{ success: true }>} Success response
|
|
1179
|
+
* @throws {NotFoundError} When organization, group, or user is not found
|
|
1180
|
+
* @throws {ForbiddenError} When user lacks admin privileges
|
|
1181
|
+
* @throws {ApiError} On other API errors
|
|
1182
|
+
*
|
|
1183
|
+
* @example
|
|
1184
|
+
* ```typescript
|
|
1185
|
+
* await client.groups.removeMember('org_abc123', 'grp_xyz789', 'bob.wilson');
|
|
1186
|
+
* ```
|
|
1187
|
+
*/
|
|
1188
|
+
removeMember: (organizationId: string, groupId: string, userId: string) => Promise<{
|
|
1189
|
+
success: true;
|
|
1190
|
+
}>;
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
/**
|
|
1194
|
+
* LDAP-REST API Client
|
|
1195
|
+
*
|
|
1196
|
+
* Main client class for interacting with the LDAP-REST API.
|
|
1197
|
+
* Provides access to Users, Organizations, and Groups resources with HMAC or Cookie authentication.
|
|
1198
|
+
*
|
|
1199
|
+
* @example
|
|
1200
|
+
* ```typescript
|
|
1201
|
+
* // HMAC authentication for backend services
|
|
1202
|
+
* const client = new LdapRestClient({
|
|
1203
|
+
* baseUrl: 'https://ldap-rest.example.com',
|
|
1204
|
+
* auth: {
|
|
1205
|
+
* type: 'hmac',
|
|
1206
|
+
* serviceId: 'my-service',
|
|
1207
|
+
* secret: 'my-secret-key-at-least-32-chars',
|
|
1208
|
+
* }
|
|
1209
|
+
* });
|
|
1210
|
+
*
|
|
1211
|
+
* // Cookie authentication for browser (SSO)
|
|
1212
|
+
* const browserClient = new LdapRestClient({
|
|
1213
|
+
* baseUrl: 'https://ldap-rest.example.com'
|
|
1214
|
+
* });
|
|
1215
|
+
*
|
|
1216
|
+
* await client.users.create({ ... });
|
|
1217
|
+
* await client.groups.create('org_abc123', { name: 'engineering' });
|
|
1218
|
+
* ```
|
|
1219
|
+
*/
|
|
1220
|
+
declare class LdapRestClient {
|
|
1221
|
+
readonly users: UsersResource;
|
|
1222
|
+
readonly organizations: OrganizationsResource;
|
|
1223
|
+
readonly groups: GroupsResource;
|
|
1224
|
+
private readonly config;
|
|
1225
|
+
/**
|
|
1226
|
+
* Creates a new LDAP-REST client instance
|
|
1227
|
+
*
|
|
1228
|
+
* @param {ClientConfig} config - Client configuration
|
|
1229
|
+
* @throws {Error} When configuration is invalid
|
|
1230
|
+
*/
|
|
1231
|
+
constructor(config: ClientConfig);
|
|
1232
|
+
/**
|
|
1233
|
+
* Gets the configured base URL
|
|
1234
|
+
*
|
|
1235
|
+
* @returns {string} The base URL of the LDAP-REST API
|
|
1236
|
+
*/
|
|
1237
|
+
getBaseUrl: () => string;
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
/**
|
|
1241
|
+
* Base error class for all LDAP-REST client errors
|
|
1242
|
+
*
|
|
1243
|
+
* All errors thrown by the client extend from this base class,
|
|
1244
|
+
* providing consistent error handling with status codes and error codes.
|
|
1245
|
+
*/
|
|
1246
|
+
declare class LdapRestError extends Error {
|
|
1247
|
+
/** Error class name (automatically set to constructor name) */
|
|
1248
|
+
readonly name: string;
|
|
1249
|
+
/** HTTP status code associated with the error (if applicable) */
|
|
1250
|
+
readonly statusCode?: number;
|
|
1251
|
+
/** Machine-readable error code for programmatic handling */
|
|
1252
|
+
readonly code?: string;
|
|
1253
|
+
/**
|
|
1254
|
+
* Creates a new LDAP-REST error
|
|
1255
|
+
*
|
|
1256
|
+
* @param {string} message - Human-readable error message
|
|
1257
|
+
* @param {number} [statusCode] - HTTP status code
|
|
1258
|
+
* @param {string} [code] - Machine-readable error code
|
|
1259
|
+
*/
|
|
1260
|
+
constructor(message: string, statusCode?: number, code?: string);
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
/**
|
|
1264
|
+
* Error thrown when the API returns an error response
|
|
1265
|
+
*
|
|
1266
|
+
* Generic API error for non-specific HTTP errors that don't fall
|
|
1267
|
+
* into other specialized error categories.
|
|
1268
|
+
*/
|
|
1269
|
+
declare class ApiError extends LdapRestError {
|
|
1270
|
+
/**
|
|
1271
|
+
* Creates a new API error
|
|
1272
|
+
*
|
|
1273
|
+
* @param {string} message - Human-readable error message
|
|
1274
|
+
* @param {number} statusCode - HTTP status code
|
|
1275
|
+
* @param {string} code - Machine-readable error code
|
|
1276
|
+
*/
|
|
1277
|
+
constructor(message: string, statusCode: number, code: string);
|
|
1278
|
+
/**
|
|
1279
|
+
* Creates an ApiError from an API response body
|
|
1280
|
+
*
|
|
1281
|
+
* @param {number} statusCode - HTTP status code from response
|
|
1282
|
+
* @param {{ error: string; code: string }} body - Response body containing error details
|
|
1283
|
+
* @returns {ApiError} New ApiError instance
|
|
1284
|
+
*/
|
|
1285
|
+
static fromResponse(statusCode: number, body: {
|
|
1286
|
+
error: string;
|
|
1287
|
+
code: string;
|
|
1288
|
+
}): ApiError;
|
|
1289
|
+
}
|
|
1290
|
+
/**
|
|
1291
|
+
* Error thrown when request validation fails (HTTP 400)
|
|
1292
|
+
*
|
|
1293
|
+
* Indicates that the request parameters or body failed validation
|
|
1294
|
+
* before being sent to the server, or the server rejected the request
|
|
1295
|
+
* due to invalid data.
|
|
1296
|
+
*/
|
|
1297
|
+
declare class ValidationError extends LdapRestError {
|
|
1298
|
+
/**
|
|
1299
|
+
* Creates a new validation error
|
|
1300
|
+
*
|
|
1301
|
+
* @param {string} message - Description of what validation failed
|
|
1302
|
+
*/
|
|
1303
|
+
constructor(message: string);
|
|
1304
|
+
}
|
|
1305
|
+
/**
|
|
1306
|
+
* Error thrown when authentication fails (HTTP 401)
|
|
1307
|
+
*
|
|
1308
|
+
* Indicates that the HMAC signature is invalid or the request
|
|
1309
|
+
* lacks proper authentication credentials.
|
|
1310
|
+
*/
|
|
1311
|
+
declare class AuthenticationError extends LdapRestError {
|
|
1312
|
+
/**
|
|
1313
|
+
* Creates a new authentication error
|
|
1314
|
+
*
|
|
1315
|
+
* @param {string} message - Authentication failure reason
|
|
1316
|
+
*/
|
|
1317
|
+
constructor(message: string);
|
|
1318
|
+
}
|
|
1319
|
+
/**
|
|
1320
|
+
* Error thrown when authorization fails (HTTP 403)
|
|
1321
|
+
*
|
|
1322
|
+
* Indicates that the authenticated service lacks permission
|
|
1323
|
+
* to perform the requested operation.
|
|
1324
|
+
*/
|
|
1325
|
+
declare class AuthorizationError extends LdapRestError {
|
|
1326
|
+
/**
|
|
1327
|
+
* Creates a new authorization error
|
|
1328
|
+
*
|
|
1329
|
+
* @param {string} message - Authorization failure reason
|
|
1330
|
+
*/
|
|
1331
|
+
constructor(message: string);
|
|
1332
|
+
}
|
|
1333
|
+
/**
|
|
1334
|
+
* Error thrown when a resource is not found (HTTP 404)
|
|
1335
|
+
*
|
|
1336
|
+
* Indicates that the requested user, organization, or other
|
|
1337
|
+
* resource does not exist in the LDAP directory.
|
|
1338
|
+
*/
|
|
1339
|
+
declare class NotFoundError extends LdapRestError {
|
|
1340
|
+
/**
|
|
1341
|
+
* Creates a new not found error
|
|
1342
|
+
*
|
|
1343
|
+
* @param {string} message - Description of what was not found
|
|
1344
|
+
* @param {string} [code] - Optional specific error code (defaults to 'NOT_FOUND')
|
|
1345
|
+
*/
|
|
1346
|
+
constructor(message: string, code?: string);
|
|
1347
|
+
}
|
|
1348
|
+
/**
|
|
1349
|
+
* Error thrown when a resource conflict occurs (HTTP 409)
|
|
1350
|
+
*
|
|
1351
|
+
* Indicates that the operation conflicts with existing data,
|
|
1352
|
+
* such as attempting to create a user with a duplicate username,
|
|
1353
|
+
* email, or phone number.
|
|
1354
|
+
*/
|
|
1355
|
+
declare class ConflictError extends LdapRestError {
|
|
1356
|
+
/**
|
|
1357
|
+
* Creates a new conflict error
|
|
1358
|
+
*
|
|
1359
|
+
* @param {string} message - Description of the conflict
|
|
1360
|
+
* @param {string} [code] - Optional specific error code (e.g., 'USERNAME_EXISTS', 'EMAIL_EXISTS')
|
|
1361
|
+
*/
|
|
1362
|
+
constructor(message: string, code?: string);
|
|
1363
|
+
}
|
|
1364
|
+
/**
|
|
1365
|
+
* Error thrown when rate limit is exceeded (HTTP 429)
|
|
1366
|
+
*
|
|
1367
|
+
* Indicates that too many requests have been sent in a given
|
|
1368
|
+
* time period. The client should wait before retrying.
|
|
1369
|
+
*/
|
|
1370
|
+
declare class RateLimitError extends LdapRestError {
|
|
1371
|
+
/** Number of seconds to wait before retrying (from Retry-After header) */
|
|
1372
|
+
readonly retryAfter?: number;
|
|
1373
|
+
/**
|
|
1374
|
+
* Creates a new rate limit error
|
|
1375
|
+
*
|
|
1376
|
+
* @param {string} message - Rate limit error message
|
|
1377
|
+
* @param {number} [retryAfter] - Seconds to wait before retrying
|
|
1378
|
+
*/
|
|
1379
|
+
constructor(message: string, retryAfter?: number);
|
|
1380
|
+
}
|
|
1381
|
+
/**
|
|
1382
|
+
* Error thrown when a network request fails
|
|
1383
|
+
*
|
|
1384
|
+
* Indicates connection failures, timeouts, or other network-level
|
|
1385
|
+
* errors that prevent the request from reaching the server.
|
|
1386
|
+
*/
|
|
1387
|
+
declare class NetworkError extends LdapRestError {
|
|
1388
|
+
/** Original error that caused the network failure */
|
|
1389
|
+
readonly cause?: Error;
|
|
1390
|
+
/**
|
|
1391
|
+
* Creates a new network error
|
|
1392
|
+
*
|
|
1393
|
+
* @param {string} message - Network error description
|
|
1394
|
+
* @param {Error} [cause] - Original error that caused the failure
|
|
1395
|
+
*/
|
|
1396
|
+
constructor(message: string, cause?: Error);
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
export { type AddGroupMembersRequest, type Address, ApiError, AuthenticationError, AuthorizationError, type ChangeUserRoleRequest, type CheckAvailabilityParams, type CheckAvailabilityResponse, type ClientConfig, ConflictError, type CreateAdminRequest, type CreateB2BUserResponse, type CreateGroupRequest, type CreateGroupResponse, type CreateOrganizationRequest, type CreateOrganizationResponse, type CreateUserRequest, type EmailAddress, type ExtendedAddress, type FetchUserRequest, type GeoLocation, type Group, GroupsResource, type InstantMessaging, LdapRestClient, LdapRestError, type ListGroupsParams, type ListGroupsResponse, type ListUsersParams, type ListUsersResponse, NetworkError, NotFoundError, type Organization, type OrganizationMetadata, type OrganizationRole, type OrganizationStatus, OrganizationsResource, type PhoneNumber, RateLimitError, type UpdateGroupRequest, type UpdateOrganizationRequest, type UpdateUserRequest, type User, type UserCredentials, type UserKeys, type UserName, type UserSearchField, type UserStatus, UsersResource, ValidationError };
|