ldap-rest 0.1.7 → 0.1.9

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.
@@ -4,6 +4,23 @@
4
4
  */
5
5
  import type { Request, Response, NextFunction, RequestHandler } from 'express';
6
6
  import type { Config } from '../bin';
7
+ /**
8
+ * Get a compiled RegExp from cache, or compile and cache it
9
+ * This avoids recompiling the same regex patterns repeatedly
10
+ *
11
+ * @param pattern - The regex pattern string
12
+ * @param flags - Optional regex flags
13
+ * @returns The compiled RegExp
14
+ */
15
+ export declare function getCompiledRegex(pattern: string, flags?: string): RegExp;
16
+ /**
17
+ * Escape special regex characters in a string
18
+ * Useful when building dynamic regex patterns from user input
19
+ *
20
+ * @param str - The string to escape
21
+ * @returns The escaped string safe for use in RegExp
22
+ */
23
+ export declare function escapeRegex(str: string): string;
7
24
  export declare const launchHooks: (hooks: Function[] | undefined, ...args: unknown[]) => Promise<void>;
8
25
  export declare const launchHooksChained: <T>(hooks: Function[] | undefined, args: T) => Promise<T>;
9
26
  export declare const transformSchemas: (schemas: string | Buffer, config: Config) => string;
@@ -41,6 +58,24 @@ export declare function escapeLdapFilter(value: string): string;
41
58
  * ```
42
59
  */
43
60
  export declare function escapeDnValue(value: string): string;
61
+ /**
62
+ * Validate a value intended for use in LDAP DN attribute values
63
+ * Rejects control characters and other problematic inputs
64
+ *
65
+ * @param value - The value to validate
66
+ * @param fieldName - Name of the field (for error messages)
67
+ * @throws Error if the value contains invalid characters
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * validateDnValue('valid-user', 'uid');
72
+ * // => OK
73
+ *
74
+ * validateDnValue('user\x00name', 'uid');
75
+ * // => throws Error: uid contains invalid control characters
76
+ * ```
77
+ */
78
+ export declare function validateDnValue(value: string, fieldName: string): void;
44
79
  /**
45
80
  * Parse a Distinguished Name (DN) into its component parts (RDNs)
46
81
  * Handles escaped commas and other special characters
@@ -17,15 +17,6 @@ export default class LdapGroups extends DmPlugin {
17
17
  ldap: ldapActions;
18
18
  cn: string;
19
19
  schema?: Schema;
20
- private regexCache;
21
- /**
22
- * Get a compiled RegExp from cache, or compile and cache it
23
- */
24
- private getCompiledRegex;
25
- /**
26
- * Escape special regex characters in a string
27
- */
28
- private escapeRegex;
29
20
  constructor(server: DM);
30
21
  /**
31
22
  * Catch all deletion to remove deleted users from groups
@@ -28,4 +28,13 @@ export default class CalendarResources extends TwakePlugin {
28
28
  * Extract resource ID from DN
29
29
  */
30
30
  private getResourceId;
31
+ /**
32
+ * Delete user data from Twake Calendar WebAdmin API
33
+ * Calls POST /users/{mail}?action=deleteData
34
+ * @param mail - The user's email address
35
+ * @returns Task information or null on error
36
+ */
37
+ deleteUserData(mail: string): Promise<{
38
+ taskId: string;
39
+ } | null>;
31
40
  }
@@ -39,6 +39,14 @@ export default class James extends TwakePlugin {
39
39
  getDisplayNameFromDN(dn: string): Promise<string | null>;
40
40
  generateSignature(dn: string): Promise<string | null>;
41
41
  updateJamesIdentity(dn: string, mail: string, displayName: string): Promise<void>;
42
+ /**
43
+ * Delete user data via James WebAdmin API
44
+ * Calls POST /users/{mail}?action=deleteData
45
+ * Returns task information from the response
46
+ */
47
+ deleteUserData(mail: string, fromStep?: string): Promise<{
48
+ taskId: string;
49
+ } | null>;
42
50
  /**
43
51
  * Type guard to check if delete operation is an AttributesList
44
52
  */
@@ -146,3 +146,46 @@ Ensure `DM_CALENDAR_WEBADMIN_TOKEN` is set and valid. The token is sent as a Bea
146
146
  ### Wrong resources being synced
147
147
 
148
148
  Use `DM_CALENDAR_RESOURCE_BASE` and `DM_CALENDAR_RESOURCE_OBJECTCLASS` to filter which LDAP entries are considered resources.
149
+
150
+ ## Public Methods
151
+
152
+ Public methods available on the CalendarResources plugin instance.
153
+
154
+ ### Usage
155
+
156
+ ```typescript
157
+ import type { DM } from 'ldap-rest';
158
+ import type CalendarResources from 'ldap-rest/plugin-twake-calendarresources';
159
+
160
+ // Get the plugin instance from another plugin
161
+ const calendar = this.server.getPlugin(
162
+ 'calendarResources'
163
+ ) as CalendarResources;
164
+ ```
165
+
166
+ ### deleteUserData(mail)
167
+
168
+ Delete all user data from Twake Calendar via WebAdmin API. Useful for GDPR "right to be forgotten" compliance.
169
+
170
+ **Signature:**
171
+
172
+ ```typescript
173
+ async deleteUserData(mail: string): Promise<{ taskId: string } | null>
174
+ ```
175
+
176
+ **Parameters:**
177
+
178
+ - `mail` (string): User's email address
179
+
180
+ **Returns:** Task information with `taskId`, or `null` on error.
181
+
182
+ **Example:**
183
+
184
+ ```typescript
185
+ const result = await calendar.deleteUserData('user@example.com');
186
+ if (result) {
187
+ console.log(`Deletion task started: ${result.taskId}`);
188
+ }
189
+ ```
190
+
191
+ **Reference:** [Twake Calendar deleteData API](https://github.com/linagora/twake-calendar-side-service/blob/main/docs/apis/webadmin.md#deleting-user-data)
@@ -303,6 +303,244 @@ curl http://localhost:8081/api/v1/users/jdoe/quota-usage \
303
303
  -H "Authorization: Bearer admin-token"
304
304
  ```
305
305
 
306
+ ## Public Methods
307
+
308
+ Public methods available on the James plugin instance. Useful for building GDPR workflows, custom integrations, or calling from other plugins.
309
+
310
+ ### Usage
311
+
312
+ ```typescript
313
+ import type { DM } from 'ldap-rest';
314
+ import type James from 'ldap-rest/plugin-twake-james';
315
+
316
+ // Get the James plugin instance
317
+ const james = server.getPlugin('james') as James;
318
+ ```
319
+
320
+ ### deleteUserData(mail, fromStep?)
321
+
322
+ Delete all user data via James WebAdmin API. Useful for GDPR "right to be forgotten" compliance.
323
+
324
+ **Signature:**
325
+
326
+ ```typescript
327
+ async deleteUserData(mail: string, fromStep?: string): Promise<{ taskId: string } | null>
328
+ ```
329
+
330
+ **Parameters:**
331
+
332
+ - `mail` (string): User's email address
333
+ - `fromStep` (string, optional): Resume deletion from a specific step if a previous attempt failed
334
+
335
+ **Returns:** Task information with `taskId`, or `null` on error.
336
+
337
+ **Example:**
338
+
339
+ ```typescript
340
+ const result = await james.deleteUserData('user@example.com');
341
+ if (result) {
342
+ console.log(`Deletion task started: ${result.taskId}`);
343
+ }
344
+
345
+ // Resume from a failed step
346
+ const resumed = await james.deleteUserData(
347
+ 'user@example.com',
348
+ 'DeleteMailboxesStep'
349
+ );
350
+ ```
351
+
352
+ **Reference:** [James deleteData API](https://james.apache.org/server/manage-webadmin.html#delete-data-of-a-user)
353
+
354
+ ---
355
+
356
+ ### getMailFromDN(dn)
357
+
358
+ Retrieve the email address for a user given their LDAP DN.
359
+
360
+ **Signature:**
361
+
362
+ ```typescript
363
+ async getMailFromDN(dn: string): Promise<string | null>
364
+ ```
365
+
366
+ **Parameters:**
367
+
368
+ - `dn` (string): LDAP Distinguished Name of the user
369
+
370
+ **Returns:** Email address string, or `null` if not found.
371
+
372
+ **Example:**
373
+
374
+ ```typescript
375
+ const mail = await james.getMailFromDN('uid=jdoe,ou=users,dc=example,dc=com');
376
+ // Returns: "jdoe@example.com"
377
+ ```
378
+
379
+ ---
380
+
381
+ ### getDisplayNameFromDN(dn)
382
+
383
+ Retrieve the display name for a user given their LDAP DN. Uses fallback logic: `displayName` → `cn` → `givenName sn` → `mail`.
384
+
385
+ **Signature:**
386
+
387
+ ```typescript
388
+ async getDisplayNameFromDN(dn: string): Promise<string | null>
389
+ ```
390
+
391
+ **Parameters:**
392
+
393
+ - `dn` (string): LDAP Distinguished Name of the user
394
+
395
+ **Returns:** Display name string, or `null` if not found.
396
+
397
+ **Example:**
398
+
399
+ ```typescript
400
+ const name = await james.getDisplayNameFromDN(
401
+ 'uid=jdoe,ou=users,dc=example,dc=com'
402
+ );
403
+ // Returns: "John Doe"
404
+ ```
405
+
406
+ ---
407
+
408
+ ### generateSignature(dn)
409
+
410
+ Generate an HTML email signature for a user using the configured template (`--james-signature-template`).
411
+
412
+ **Signature:**
413
+
414
+ ```typescript
415
+ async generateSignature(dn: string): Promise<string | null>
416
+ ```
417
+
418
+ **Parameters:**
419
+
420
+ - `dn` (string): LDAP Distinguished Name of the user
421
+
422
+ **Returns:** HTML signature string with placeholders replaced, or `null` if no template configured.
423
+
424
+ **Example:**
425
+
426
+ ```typescript
427
+ // With template: "<p>{displayName}</p><p>{title} - {department}</p>"
428
+ const signature = await james.generateSignature(
429
+ 'uid=jdoe,ou=users,dc=example,dc=com'
430
+ );
431
+ // Returns: "<p>John Doe</p><p>Engineer - IT</p>"
432
+ ```
433
+
434
+ ---
435
+
436
+ ### updateJamesIdentity(dn, mail, displayName)
437
+
438
+ Update a user's JMAP identity in James (name and optional signature).
439
+
440
+ **Signature:**
441
+
442
+ ```typescript
443
+ async updateJamesIdentity(dn: string, mail: string, displayName: string): Promise<void>
444
+ ```
445
+
446
+ **Parameters:**
447
+
448
+ - `dn` (string): LDAP Distinguished Name (used for signature generation)
449
+ - `mail` (string): User's email address
450
+ - `displayName` (string): New display name for the identity
451
+
452
+ **Example:**
453
+
454
+ ```typescript
455
+ await james.updateJamesIdentity(
456
+ 'uid=jdoe,ou=users,dc=example,dc=com',
457
+ 'jdoe@example.com',
458
+ 'John Doe'
459
+ );
460
+ ```
461
+
462
+ ---
463
+
464
+ ### getMemberEmails(memberDns)
465
+
466
+ Retrieve email addresses for multiple LDAP members. Useful for bulk operations on groups.
467
+
468
+ **Signature:**
469
+
470
+ ```typescript
471
+ async getMemberEmails(memberDns: string[]): Promise<string[]>
472
+ ```
473
+
474
+ **Parameters:**
475
+
476
+ - `memberDns` (string[]): Array of LDAP Distinguished Names
477
+
478
+ **Returns:** Array of email addresses (excludes members without mail attribute).
479
+
480
+ **Example:**
481
+
482
+ ```typescript
483
+ const emails = await james.getMemberEmails([
484
+ 'uid=alice,ou=users,dc=example,dc=com',
485
+ 'uid=bob,ou=users,dc=example,dc=com',
486
+ ]);
487
+ // Returns: ["alice@example.com", "bob@example.com"]
488
+ ```
489
+
490
+ ---
491
+
492
+ ### getGroupMail(groupDn)
493
+
494
+ Retrieve the email address for a group given its LDAP DN.
495
+
496
+ **Signature:**
497
+
498
+ ```typescript
499
+ async getGroupMail(groupDn: string): Promise<string | null>
500
+ ```
501
+
502
+ **Parameters:**
503
+
504
+ - `groupDn` (string): LDAP Distinguished Name of the group
505
+
506
+ **Returns:** Group email address, or `null` if not found.
507
+
508
+ **Example:**
509
+
510
+ ```typescript
511
+ const mail = await james.getGroupMail(
512
+ 'cn=engineering,ou=groups,dc=example,dc=com'
513
+ );
514
+ // Returns: "engineering@example.com"
515
+ ```
516
+
517
+ ---
518
+
519
+ ### getGroupMailboxType(groupDn)
520
+
521
+ Retrieve the mailbox type for a group (mailing list, team mailbox, or simple group).
522
+
523
+ **Signature:**
524
+
525
+ ```typescript
526
+ async getGroupMailboxType(groupDn: string): Promise<'group' | 'mailingList' | 'teamMailbox' | null>
527
+ ```
528
+
529
+ **Parameters:**
530
+
531
+ - `groupDn` (string): LDAP Distinguished Name of the group
532
+
533
+ **Returns:** Mailbox type string, or `null` if not determinable.
534
+
535
+ **Example:**
536
+
537
+ ```typescript
538
+ const type = await james.getGroupMailboxType(
539
+ 'cn=engineering,ou=groups,dc=example,dc=com'
540
+ );
541
+ // Returns: "mailingList" or "teamMailbox" or "group"
542
+ ```
543
+
306
544
  ## James WebAdmin API
307
545
 
308
546
  ### Endpoints Used