@linagora/ldap-rest-client 1.0.3 → 1.0.5

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/README.md CHANGED
@@ -38,13 +38,16 @@ const client = new LdapRestClient({
38
38
  baseUrl: 'https://ldap-rest.example.com',
39
39
  });
40
40
 
41
- // Manage users in organization
42
- await client.organizations.createUser(orgId, userData);
41
+ // Manage users in organization (returns baseDN)
42
+ const { baseDN } = await client.organizations.createUser(orgId, userData);
43
43
  await client.organizations.listUsers(orgId, { page: 1, limit: 20 });
44
44
 
45
- // Manage groups
46
- await client.groups.create(orgId, { name: 'engineering' });
45
+ // Manage groups (returns Group object)
46
+ const group = await client.groups.create(orgId, { name: 'engineering' });
47
47
  await client.groups.addMembers(orgId, groupId, { usernames: ['user1'] });
48
+
49
+ // Get user's organizations
50
+ const orgs = await client.users.getUserOrganizations(userId, 'admin');
48
51
  ```
49
52
 
50
53
  ## API Reference
@@ -57,6 +60,7 @@ client.users.disable(username)
57
60
  client.users.delete(username)
58
61
  client.users.checkAvailability({ field, value })
59
62
  client.users.fetch({ by, value, fields })
63
+ client.users.getUserOrganizations(userId, role?) // Get user's organizations by role
60
64
  ```
61
65
 
62
66
  ### Organizations
@@ -75,8 +79,12 @@ client.organizations.transferOwnership(orgId, { newOwnerUsername })
75
79
 
76
80
  ### B2B Users (within Organizations)
77
81
  ```typescript
78
- client.organizations.createUser(orgId, userData)
79
- client.organizations.updateUser(orgId, userId, updates)
82
+ // Returns baseDN of created user
83
+ const { baseDN } = await client.organizations.createUser(orgId, userData)
84
+
85
+ // Returns User object or { success: true }
86
+ const result = await client.organizations.updateUser(orgId, userId, updates)
87
+
80
88
  client.organizations.disableUser(orgId, userId)
81
89
  client.organizations.deleteUser(orgId, userId)
82
90
  client.organizations.getUser(orgId, { by, value })
@@ -89,7 +97,9 @@ client.organizations.changeUserRole(orgId, userId, { role })
89
97
 
90
98
  ### Groups
91
99
  ```typescript
92
- client.groups.create(orgId, { name, description })
100
+ // Returns Group object directly
101
+ const group = await client.groups.create(orgId, { name, description })
102
+
93
103
  client.groups.list(orgId, { page, limit })
94
104
  client.groups.get(orgId, groupId)
95
105
  client.groups.update(orgId, groupId, updates)
package/dist/index.d.mts CHANGED
@@ -341,6 +341,8 @@ interface UserName {
341
341
  * Complete user model with all profile fields, credentials, and encryption keys
342
342
  */
343
343
  interface User {
344
+ /** Unique user identifier (mapped from LDAP entryUUID) */
345
+ _id?: string;
344
346
  /** Common name (username) */
345
347
  cn: string;
346
348
  /** Surname or last name */
@@ -736,13 +738,6 @@ interface CreateGroupRequest {
736
738
  /** Optional group description */
737
739
  description?: string;
738
740
  }
739
- /**
740
- * Response from creating a group
741
- */
742
- interface CreateGroupResponse {
743
- success: true;
744
- group: Group;
745
- }
746
741
  /**
747
742
  * Request parameters for updating a group
748
743
  */
@@ -895,6 +890,27 @@ declare class UsersResource extends BaseResource {
895
890
  * ```
896
891
  */
897
892
  fetch: (params: FetchUserRequest) => Promise<User>;
893
+ /**
894
+ * Gets organizations where a user has a role
895
+ *
896
+ * Returns organizations where the user is an admin or owner.
897
+ * Optionally filter by specific role.
898
+ *
899
+ * @param {string} userId - User identifier (username)
900
+ * @param {string} [role] - Optional role filter ('owner', 'admin', 'moderator', 'member')
901
+ * @returns {Promise<Organization[]>} Array of organizations
902
+ * @throws {ApiError} On API errors
903
+ *
904
+ * @example
905
+ * ```typescript
906
+ * // Get all organizations where user has any role
907
+ * const orgs = await client.users.getUserOrganizations('johndoe');
908
+ *
909
+ * // Get only organizations where user is owner
910
+ * const ownedOrgs = await client.users.getUserOrganizations('johndoe', 'owner');
911
+ * ```
912
+ */
913
+ getUserOrganizations: (userId: string, role?: string) => Promise<Organization[]>;
898
914
  }
899
915
 
900
916
  /**
@@ -1147,19 +1163,19 @@ declare class OrganizationsResource extends BaseResource {
1147
1163
  * @param {string} organizationId - Organization identifier
1148
1164
  * @param {string} userId - User identifier (username)
1149
1165
  * @param {UpdateUserRequest} data - Fields to update
1150
- * @returns {Promise<{ success: true }>} Success response
1166
+ * @returns {Promise<User | { success: true }>} Updated user object or success response
1151
1167
  * @throws {NotFoundError} When user or organization is not found
1152
1168
  * @throws {ForbiddenError} When user lacks admin privileges
1153
1169
  * @throws {ApiError} On other API errors
1154
1170
  *
1155
1171
  * @example
1156
1172
  * ```typescript
1157
- * await client.organizations.updateUser('org_abc123', 'john.doe', {
1173
+ * const result = await client.organizations.updateUser('org_abc123', 'john.doe', {
1158
1174
  * mobile: '+33687654321'
1159
1175
  * });
1160
1176
  * ```
1161
1177
  */
1162
- updateUser: (organizationId: string, userId: string, data: UpdateUserRequest) => Promise<{
1178
+ updateUser: (organizationId: string, userId: string, data: UpdateUserRequest) => Promise<User | {
1163
1179
  success: true;
1164
1180
  }>;
1165
1181
  /**
@@ -1330,7 +1346,7 @@ declare class GroupsResource extends BaseResource {
1330
1346
  *
1331
1347
  * @param {string} organizationId - Organization identifier
1332
1348
  * @param {CreateGroupRequest} data - Group data (name and optional description)
1333
- * @returns {Promise<CreateGroupResponse>} Created group details
1349
+ * @returns {Promise<Group>} Created group object
1334
1350
  * @throws {ForbiddenError} When user lacks admin privileges
1335
1351
  * @throws {NotFoundError} When organization is not found
1336
1352
  * @throws {ConflictError} When group name already exists
@@ -1338,13 +1354,13 @@ declare class GroupsResource extends BaseResource {
1338
1354
  *
1339
1355
  * @examples
1340
1356
  * ```typescript
1341
- * const result = await client.groups.create('org_abc123', {
1357
+ * const group = await client.groups.create('org_abc123', {
1342
1358
  * name: 'engineering',
1343
1359
  * description: 'Engineering team'
1344
1360
  * });
1345
1361
  * ```
1346
1362
  */
1347
- create: (organizationId: string, data: CreateGroupRequest) => Promise<CreateGroupResponse>;
1363
+ create: (organizationId: string, data: CreateGroupRequest) => Promise<Group>;
1348
1364
  /**
1349
1365
  * Lists all groups in an organization with pagination
1350
1366
  *
@@ -1683,4 +1699,4 @@ declare class NetworkError extends LdapRestError {
1683
1699
  constructor(message: string, cause?: Error);
1684
1700
  }
1685
1701
 
1686
- export { type AddGroupMembersRequest, type Address, ApiError, AuthenticationError, AuthorizationError, type ChangeUserRoleRequest, type CheckAvailabilityParams, type CheckAvailabilityResponse, type CheckOrganizationAvailabilityParams, 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 GetOwnerResponse, type Group, GroupsResource, type InstantMessaging, LdapRestClient, LdapRestError, type ListGroupsParams, type ListGroupsResponse, type ListUsersParams, type ListUsersResponse, NetworkError, NotFoundError, type Organization, type OrganizationMetadata, type OrganizationOwner, type OrganizationRole, type OrganizationSearchField, type OrganizationStatus, OrganizationsResource, type PhoneNumber, RateLimitError, type SetOwnerRequest, type TransferOwnershipRequest, type UpdateGroupRequest, type UpdateOrganizationRequest, type UpdateUserRequest, type User, type UserCredentials, type UserKeys, type UserName, type UserSearchField, type UserStatus, UsersResource, ValidationError };
1702
+ export { type AddGroupMembersRequest, type Address, ApiError, AuthenticationError, AuthorizationError, type ChangeUserRoleRequest, type CheckAvailabilityParams, type CheckAvailabilityResponse, type CheckOrganizationAvailabilityParams, type ClientConfig, ConflictError, type CreateAdminRequest, type CreateB2BUserResponse, type CreateGroupRequest, type CreateOrganizationRequest, type CreateOrganizationResponse, type CreateUserRequest, type EmailAddress, type ExtendedAddress, type FetchUserRequest, type GeoLocation, type GetOwnerResponse, type Group, GroupsResource, type InstantMessaging, LdapRestClient, LdapRestError, type ListGroupsParams, type ListGroupsResponse, type ListUsersParams, type ListUsersResponse, NetworkError, NotFoundError, type Organization, type OrganizationMetadata, type OrganizationOwner, type OrganizationRole, type OrganizationSearchField, type OrganizationStatus, OrganizationsResource, type PhoneNumber, RateLimitError, type SetOwnerRequest, type TransferOwnershipRequest, type UpdateGroupRequest, type UpdateOrganizationRequest, type UpdateUserRequest, type User, type UserCredentials, type UserKeys, type UserName, type UserSearchField, type UserStatus, UsersResource, ValidationError };
package/dist/index.d.ts CHANGED
@@ -341,6 +341,8 @@ interface UserName {
341
341
  * Complete user model with all profile fields, credentials, and encryption keys
342
342
  */
343
343
  interface User {
344
+ /** Unique user identifier (mapped from LDAP entryUUID) */
345
+ _id?: string;
344
346
  /** Common name (username) */
345
347
  cn: string;
346
348
  /** Surname or last name */
@@ -736,13 +738,6 @@ interface CreateGroupRequest {
736
738
  /** Optional group description */
737
739
  description?: string;
738
740
  }
739
- /**
740
- * Response from creating a group
741
- */
742
- interface CreateGroupResponse {
743
- success: true;
744
- group: Group;
745
- }
746
741
  /**
747
742
  * Request parameters for updating a group
748
743
  */
@@ -895,6 +890,27 @@ declare class UsersResource extends BaseResource {
895
890
  * ```
896
891
  */
897
892
  fetch: (params: FetchUserRequest) => Promise<User>;
893
+ /**
894
+ * Gets organizations where a user has a role
895
+ *
896
+ * Returns organizations where the user is an admin or owner.
897
+ * Optionally filter by specific role.
898
+ *
899
+ * @param {string} userId - User identifier (username)
900
+ * @param {string} [role] - Optional role filter ('owner', 'admin', 'moderator', 'member')
901
+ * @returns {Promise<Organization[]>} Array of organizations
902
+ * @throws {ApiError} On API errors
903
+ *
904
+ * @example
905
+ * ```typescript
906
+ * // Get all organizations where user has any role
907
+ * const orgs = await client.users.getUserOrganizations('johndoe');
908
+ *
909
+ * // Get only organizations where user is owner
910
+ * const ownedOrgs = await client.users.getUserOrganizations('johndoe', 'owner');
911
+ * ```
912
+ */
913
+ getUserOrganizations: (userId: string, role?: string) => Promise<Organization[]>;
898
914
  }
899
915
 
900
916
  /**
@@ -1147,19 +1163,19 @@ declare class OrganizationsResource extends BaseResource {
1147
1163
  * @param {string} organizationId - Organization identifier
1148
1164
  * @param {string} userId - User identifier (username)
1149
1165
  * @param {UpdateUserRequest} data - Fields to update
1150
- * @returns {Promise<{ success: true }>} Success response
1166
+ * @returns {Promise<User | { success: true }>} Updated user object or success response
1151
1167
  * @throws {NotFoundError} When user or organization is not found
1152
1168
  * @throws {ForbiddenError} When user lacks admin privileges
1153
1169
  * @throws {ApiError} On other API errors
1154
1170
  *
1155
1171
  * @example
1156
1172
  * ```typescript
1157
- * await client.organizations.updateUser('org_abc123', 'john.doe', {
1173
+ * const result = await client.organizations.updateUser('org_abc123', 'john.doe', {
1158
1174
  * mobile: '+33687654321'
1159
1175
  * });
1160
1176
  * ```
1161
1177
  */
1162
- updateUser: (organizationId: string, userId: string, data: UpdateUserRequest) => Promise<{
1178
+ updateUser: (organizationId: string, userId: string, data: UpdateUserRequest) => Promise<User | {
1163
1179
  success: true;
1164
1180
  }>;
1165
1181
  /**
@@ -1330,7 +1346,7 @@ declare class GroupsResource extends BaseResource {
1330
1346
  *
1331
1347
  * @param {string} organizationId - Organization identifier
1332
1348
  * @param {CreateGroupRequest} data - Group data (name and optional description)
1333
- * @returns {Promise<CreateGroupResponse>} Created group details
1349
+ * @returns {Promise<Group>} Created group object
1334
1350
  * @throws {ForbiddenError} When user lacks admin privileges
1335
1351
  * @throws {NotFoundError} When organization is not found
1336
1352
  * @throws {ConflictError} When group name already exists
@@ -1338,13 +1354,13 @@ declare class GroupsResource extends BaseResource {
1338
1354
  *
1339
1355
  * @examples
1340
1356
  * ```typescript
1341
- * const result = await client.groups.create('org_abc123', {
1357
+ * const group = await client.groups.create('org_abc123', {
1342
1358
  * name: 'engineering',
1343
1359
  * description: 'Engineering team'
1344
1360
  * });
1345
1361
  * ```
1346
1362
  */
1347
- create: (organizationId: string, data: CreateGroupRequest) => Promise<CreateGroupResponse>;
1363
+ create: (organizationId: string, data: CreateGroupRequest) => Promise<Group>;
1348
1364
  /**
1349
1365
  * Lists all groups in an organization with pagination
1350
1366
  *
@@ -1683,4 +1699,4 @@ declare class NetworkError extends LdapRestError {
1683
1699
  constructor(message: string, cause?: Error);
1684
1700
  }
1685
1701
 
1686
- export { type AddGroupMembersRequest, type Address, ApiError, AuthenticationError, AuthorizationError, type ChangeUserRoleRequest, type CheckAvailabilityParams, type CheckAvailabilityResponse, type CheckOrganizationAvailabilityParams, 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 GetOwnerResponse, type Group, GroupsResource, type InstantMessaging, LdapRestClient, LdapRestError, type ListGroupsParams, type ListGroupsResponse, type ListUsersParams, type ListUsersResponse, NetworkError, NotFoundError, type Organization, type OrganizationMetadata, type OrganizationOwner, type OrganizationRole, type OrganizationSearchField, type OrganizationStatus, OrganizationsResource, type PhoneNumber, RateLimitError, type SetOwnerRequest, type TransferOwnershipRequest, type UpdateGroupRequest, type UpdateOrganizationRequest, type UpdateUserRequest, type User, type UserCredentials, type UserKeys, type UserName, type UserSearchField, type UserStatus, UsersResource, ValidationError };
1702
+ export { type AddGroupMembersRequest, type Address, ApiError, AuthenticationError, AuthorizationError, type ChangeUserRoleRequest, type CheckAvailabilityParams, type CheckAvailabilityResponse, type CheckOrganizationAvailabilityParams, type ClientConfig, ConflictError, type CreateAdminRequest, type CreateB2BUserResponse, type CreateGroupRequest, type CreateOrganizationRequest, type CreateOrganizationResponse, type CreateUserRequest, type EmailAddress, type ExtendedAddress, type FetchUserRequest, type GeoLocation, type GetOwnerResponse, type Group, GroupsResource, type InstantMessaging, LdapRestClient, LdapRestError, type ListGroupsParams, type ListGroupsResponse, type ListUsersParams, type ListUsersResponse, NetworkError, NotFoundError, type Organization, type OrganizationMetadata, type OrganizationOwner, type OrganizationRole, type OrganizationSearchField, type OrganizationStatus, OrganizationsResource, type PhoneNumber, RateLimitError, type SetOwnerRequest, type TransferOwnershipRequest, type UpdateGroupRequest, type UpdateOrganizationRequest, type UpdateUserRequest, type User, type UserCredentials, type UserKeys, type UserName, type UserSearchField, type UserStatus, UsersResource, ValidationError };
package/dist/index.js CHANGED
@@ -632,6 +632,30 @@ var UsersResource = class extends BaseResource {
632
632
  const query = this.buildQueryString(params);
633
633
  return this.http.get(`/api/v1/users${query}`);
634
634
  };
635
+ /**
636
+ * Gets organizations where a user has a role
637
+ *
638
+ * Returns organizations where the user is an admin or owner.
639
+ * Optionally filter by specific role.
640
+ *
641
+ * @param {string} userId - User identifier (username)
642
+ * @param {string} [role] - Optional role filter ('owner', 'admin', 'moderator', 'member')
643
+ * @returns {Promise<Organization[]>} Array of organizations
644
+ * @throws {ApiError} On API errors
645
+ *
646
+ * @example
647
+ * ```typescript
648
+ * // Get all organizations where user has any role
649
+ * const orgs = await client.users.getUserOrganizations('johndoe');
650
+ *
651
+ * // Get only organizations where user is owner
652
+ * const ownedOrgs = await client.users.getUserOrganizations('johndoe', 'owner');
653
+ * ```
654
+ */
655
+ getUserOrganizations = async (userId, role) => {
656
+ const query = role ? this.buildQueryString({ role }) : "";
657
+ return this.http.get(`/api/v1/users/${encodeURIComponent(userId)}/organizations${query}`);
658
+ };
635
659
  };
636
660
 
637
661
  // src/resources/OrganizationsResource.ts
@@ -883,14 +907,14 @@ var OrganizationsResource = class extends BaseResource {
883
907
  * @param {string} organizationId - Organization identifier
884
908
  * @param {string} userId - User identifier (username)
885
909
  * @param {UpdateUserRequest} data - Fields to update
886
- * @returns {Promise<{ success: true }>} Success response
910
+ * @returns {Promise<User | { success: true }>} Updated user object or success response
887
911
  * @throws {NotFoundError} When user or organization is not found
888
912
  * @throws {ForbiddenError} When user lacks admin privileges
889
913
  * @throws {ApiError} On other API errors
890
914
  *
891
915
  * @example
892
916
  * ```typescript
893
- * await client.organizations.updateUser('org_abc123', 'john.doe', {
917
+ * const result = await client.organizations.updateUser('org_abc123', 'john.doe', {
894
918
  * mobile: '+33687654321'
895
919
  * });
896
920
  * ```
@@ -1069,7 +1093,7 @@ var GroupsResource = class extends BaseResource {
1069
1093
  *
1070
1094
  * @param {string} organizationId - Organization identifier
1071
1095
  * @param {CreateGroupRequest} data - Group data (name and optional description)
1072
- * @returns {Promise<CreateGroupResponse>} Created group details
1096
+ * @returns {Promise<Group>} Created group object
1073
1097
  * @throws {ForbiddenError} When user lacks admin privileges
1074
1098
  * @throws {NotFoundError} When organization is not found
1075
1099
  * @throws {ConflictError} When group name already exists
@@ -1077,7 +1101,7 @@ var GroupsResource = class extends BaseResource {
1077
1101
  *
1078
1102
  * @examples
1079
1103
  * ```typescript
1080
- * const result = await client.groups.create('org_abc123', {
1104
+ * const group = await client.groups.create('org_abc123', {
1081
1105
  * name: 'engineering',
1082
1106
  * description: 'Engineering team'
1083
1107
  * });
package/dist/index.mjs CHANGED
@@ -594,6 +594,30 @@ var UsersResource = class extends BaseResource {
594
594
  const query = this.buildQueryString(params);
595
595
  return this.http.get(`/api/v1/users${query}`);
596
596
  };
597
+ /**
598
+ * Gets organizations where a user has a role
599
+ *
600
+ * Returns organizations where the user is an admin or owner.
601
+ * Optionally filter by specific role.
602
+ *
603
+ * @param {string} userId - User identifier (username)
604
+ * @param {string} [role] - Optional role filter ('owner', 'admin', 'moderator', 'member')
605
+ * @returns {Promise<Organization[]>} Array of organizations
606
+ * @throws {ApiError} On API errors
607
+ *
608
+ * @example
609
+ * ```typescript
610
+ * // Get all organizations where user has any role
611
+ * const orgs = await client.users.getUserOrganizations('johndoe');
612
+ *
613
+ * // Get only organizations where user is owner
614
+ * const ownedOrgs = await client.users.getUserOrganizations('johndoe', 'owner');
615
+ * ```
616
+ */
617
+ getUserOrganizations = async (userId, role) => {
618
+ const query = role ? this.buildQueryString({ role }) : "";
619
+ return this.http.get(`/api/v1/users/${encodeURIComponent(userId)}/organizations${query}`);
620
+ };
597
621
  };
598
622
 
599
623
  // src/resources/OrganizationsResource.ts
@@ -845,14 +869,14 @@ var OrganizationsResource = class extends BaseResource {
845
869
  * @param {string} organizationId - Organization identifier
846
870
  * @param {string} userId - User identifier (username)
847
871
  * @param {UpdateUserRequest} data - Fields to update
848
- * @returns {Promise<{ success: true }>} Success response
872
+ * @returns {Promise<User | { success: true }>} Updated user object or success response
849
873
  * @throws {NotFoundError} When user or organization is not found
850
874
  * @throws {ForbiddenError} When user lacks admin privileges
851
875
  * @throws {ApiError} On other API errors
852
876
  *
853
877
  * @example
854
878
  * ```typescript
855
- * await client.organizations.updateUser('org_abc123', 'john.doe', {
879
+ * const result = await client.organizations.updateUser('org_abc123', 'john.doe', {
856
880
  * mobile: '+33687654321'
857
881
  * });
858
882
  * ```
@@ -1031,7 +1055,7 @@ var GroupsResource = class extends BaseResource {
1031
1055
  *
1032
1056
  * @param {string} organizationId - Organization identifier
1033
1057
  * @param {CreateGroupRequest} data - Group data (name and optional description)
1034
- * @returns {Promise<CreateGroupResponse>} Created group details
1058
+ * @returns {Promise<Group>} Created group object
1035
1059
  * @throws {ForbiddenError} When user lacks admin privileges
1036
1060
  * @throws {NotFoundError} When organization is not found
1037
1061
  * @throws {ConflictError} When group name already exists
@@ -1039,7 +1063,7 @@ var GroupsResource = class extends BaseResource {
1039
1063
  *
1040
1064
  * @examples
1041
1065
  * ```typescript
1042
- * const result = await client.groups.create('org_abc123', {
1066
+ * const group = await client.groups.create('org_abc123', {
1043
1067
  * name: 'engineering',
1044
1068
  * description: 'Engineering team'
1045
1069
  * });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@linagora/ldap-rest-client",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "TypeScript API client for LDAP-REST",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",