diff --git a/package.json b/package.json index 3a3f66c4..c0fc5fdd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@internxt/sdk", - "version": "1.4.43", + "version": "1.4.44", "description": "An sdk for interacting with Internxt's services", "repository": { "type": "git", diff --git a/src/drive/share/index.ts b/src/drive/share/index.ts index 1140454b..262f7355 100644 --- a/src/drive/share/index.ts +++ b/src/drive/share/index.ts @@ -8,20 +8,22 @@ import { GenerateShareLinkPayload, GetSharedDirectoryPayload, GetShareLinkFolderSizePayload, - GrantSharePrivilegesToUserResponse, ListAllSharedFoldersResponse, ListPrivateSharedFoldersResponse, ListShareLinksResponse, PrivateSharedFolder, - PrivateSharingRolesResponse, SharedFolderUser, ShareDomainsResponse, ShareLink, - SharePrivateFolderWithUserPayload, + ShareFolderWithUserPayload, UpdateUserRolePayload, UpdateUserRoleResponse, UpdateShareLinkPayload, ListSharedItemsResponse, + AcceptInvitationToSharedFolderPayload, + RemoveUserRolePayload, + Role, + SharingInvite, } from './types'; import { ApiSecurity, ApiUrl, AppDetails } from '../../shared'; import { HttpClient } from '../../shared/http/client'; @@ -172,7 +174,7 @@ export class Share { const orderByQueryParam = orderBy ? `&orderBy=${orderBy}` : ''; return this.client.get( - `private-sharing/sent/folders?page=${page}&perPage=${perPage}${orderByQueryParam}`, + `sharings/shared-by-me/folders?page=${page}&perPage=${perPage}${orderByQueryParam}`, this.headers(), ); } @@ -193,7 +195,7 @@ export class Share { const orderByQueryParam = orderBy ? `&orderBy=${orderBy}` : ''; return this.client.get( - `private-sharing/receive/folders?page=${page}&perPage=${perPage}${orderByQueryParam}`, + `sharings/shared-with-me/folders?page=${page}&perPage=${perPage}${orderByQueryParam}`, this.headers(), ); } @@ -213,10 +215,7 @@ export class Share { ): Promise { const orderByQueryParam = orderBy ? `&orderBy=${orderBy}` : ''; - return this.client.get( - `private-sharing/folders?page=${page}&perPage=${perPage}${orderByQueryParam}`, - this.headers(), - ); + return this.client.get(`sharings/folders?page=${page}&perPage=${perPage}${orderByQueryParam}`, this.headers()); } /** @@ -237,7 +236,7 @@ export class Share { const orderByQueryParam = orderBy ? `&orderBy=${orderBy}` : ''; return this.client.get( - `private-sharing/shared-with/${folderUUID}?page=${page}&perPage=${perPage}${orderByQueryParam}`, + `sharings/shared-with/${folderUUID}?page=${page}&perPage=${perPage}${orderByQueryParam}`, this.headers(), ); } @@ -263,7 +262,7 @@ export class Share { return this.client.get( // eslint-disable-next-line max-len - `private-sharing/items/${sharedFolderId}/${type}?token=${token}&page=${page}&perPage=${perPage}${orderByQueryParam}`, + `sharings/items/${sharedFolderId}/${type}?token=${token}&page=${page}&perPage=${perPage}${orderByQueryParam}`, this.headers(), ); } @@ -279,107 +278,164 @@ export class Share { } /** - * Grant privileges of folder to a user. + * Update the role of a user on a folder. * - * @param {string} userUuid - The UUID of the user. - * @param {string} privateFolderId - The UUID of the shared folder. - * @param {string} roleId - The id of the role. - * @returns {Promise} A promise with message field + * @param {UpdateUserRolePayload} options - The options for updating the user's role on the folder. + * @param {string} options.folderUUID - The unique identifier of the folder. + * @param {string} options.roleId - The identifier of the role to assign to the user. + * @param {string} options.newRoleId - The new role Id. + * @returns {Promise} A promise that resolves when the user's role is updated. */ - public grantSharePrivilegesToUser( - userUuid: string, - privateFolderId: string, - roleId: string, - ): Promise { - return this.client.post( - 'private-sharing/grant-privileges', + public updateUserRole({ folderUUID, roleId, newRoleId }: UpdateUserRolePayload): Promise { + return this.client.put( + `sharings/${folderUUID}/roles/${roleId}`, { - userUuid, - privateFolderId, - roleId, + roleId: newRoleId, }, this.headers(), ); } /** - * Update the role of a user on a folder. + * Remove user from shared folder. * * @param {UpdateUserRolePayload} options - The options for updating the user's role on the folder. - * @param {string} options.folderUUID - The unique identifier of the folder. - * @param {string} options.roleId - The identifier of the role to assign to the user. - * @param {string} options.userUUID - The email address of the user. + * @param {string} options.itemType - The unique identifier of the folder. + * @param {string} options.itemId - The identifier of the role to assign to the user. + * @param {string} options.userId - The role Id how we want to delete. * @returns {Promise} A promise that resolves when the user's role is updated. */ - public updateUserRole({ folderUUID, roleId, userUUID }: UpdateUserRolePayload): Promise { - return this.client.put( - `private-sharing/role/${roleId}`, + public removeUserRole({ itemType, itemId, userId }: RemoveUserRolePayload): Promise { + return this.client.delete(`sharings/${itemType}/${itemId}/users/${userId}`, this.headers()); + } + + /** + * Get private folder data. + * + * @param {string} itemId - The itemId of the folder. + * @param {string} itemType - The itemType of the folder (file | folder). + * @returns {Promise<{ data: SharingInvite[] }>} A promise containing the private folder data. + */ + + public getSharedFolderInvitations({ + itemId, + itemType, + }: { + itemId: string; + itemType: 'folder' | 'file'; + }): Promise { + return this.client.get(`sharings/${itemType}/${itemId}/invites`, this.headers()); + } + + /** + * Get all invitations for a user. + * @param limit - The number of items per page for pagination. + * @param offset - The page number for pagination. + * @returns {Promise} A promise containing the list of invitations. + */ + + public getSharedFolderInvitationsAsInvitedUser({ + limit, + offset, + }: { + limit?: number; + offset?: number; + }): Promise<{ invites: any }> { + return this.client.get(`sharings/invites?limit=${limit}&offset=${offset}`, this.headers()); + } + + /** + * Share a private folder with a user. + * + * @param {ShareFolderWithUserPayload} options - The options for sharing the private folder with a user. + * @param {string} options.itemId - The id of the item to share. + * @param {string} options.itemType - The type of the item to share (folder | file). + * @param {string} options.sharedWith - The email address of the user to share the folder with. + * @param {string} options.encryptionKey - Owner\'s encryption key encrypted with the invited user\'s public key. This field should not be empty if the invitation type is "OWNER". + * @param {string} options.encryptionAlgorithm - Encryption algorithm used to encrypt the encryption key. This field should not be empty if the invitation type is "OWNER". + * @param {string} options.type - Owner's encryption key encrypted with the invited user's public key. + * @param {string} options.roleId - The id of the role to assign to the user. + * @returns {Promise} A promise that resolves when the folder is shared with the user. + */ + + public inviteUserToSharedFolder(createInviteDto: ShareFolderWithUserPayload): Promise { + return this.client.post( + 'sharings/invites/send', { - folderId: folderUUID, - userId: userUUID, + ...createInviteDto, + type: 'OWNER', }, this.headers(), ); } /** - * Share a private folder with a user. - * - * @param {SharePrivateFolderWithUserPayload} options - The options for sharing the private folder with a user. - * @param {string} options.emailToShare - The email address of the user to share the folder with. - * @param {string} options.privateFolderId - The unique identifier of the private folder. - * @param {string} options.roleId - The identifier of the role to assign to the user for the shared folder. - * @param {string} options.encryptionKey - The encryption key for the shared folder. - * @returns {Promise} A promise that resolves when the folder is shared with the user. + * Request access to shared folder. */ - public sharePrivateFolderWithUser({ - emailToShare, - privateFolderId, - roleId, - encryptionKey, - }: SharePrivateFolderWithUserPayload): Promise { + + public requestUserToSharedFolder(createInviteDto: ShareFolderWithUserPayload): Promise { return this.client.post( - 'private-sharing/share', + 'sharings/invites/send', { - email: emailToShare, - folderId: privateFolderId, - roleId, - encryptionKey, + ...createInviteDto, + type: 'SELF', }, this.headers(), ); } /** - * Fetches roles for private sharing items. - * - * @returns {Promise} A promise containing the list of private sharing roles. + * Share a private folder with a user. + * @param {string} invitationId - The id of the invitation. + * @param {ShareFolderWithUserPayload} options - The options for sharing the private folder with a user. + * @param {string} options.encryptionKey - The encryption key (just in case the invitation is a request). + * @param {string} options.itemType - The encryption algorithm (just in case the invitation is a request). + + * @returns {Promise} A promise that resolves when the folder is shared with the user. */ - public getPrivateSharingRoles(): Promise { - return this.client.get('private-sharing/roles', this.headers()); + + public acceptSharedFolderInvite({ + invitationId, + acceptInvite, + }: { + invitationId: string; + acceptInvite?: AcceptInvitationToSharedFolderPayload; + }): Promise { + return this.client.post( + `sharings/invites/${invitationId}/accept`, + { + acceptInvite, + }, + this.headers(), + ); } /** - * Stop sharing folder + * Fetches roles for sharing items. * - * @param {string} folderUUID - The unique identifier of the folder. - * @returns {Promise<{ stopped: boolean }>} A promise that resolves with an object indicating whether the sharing was stopped. + * @returns {Promise} A promise containing the list of sharing roles. */ - public stopSharingFolder(folderUUID: string): Promise<{ message: string }> { - return this.client.delete(`/private-sharing/stop/folder-id/${folderUUID}`, this.headers()); + + public getSharingRoles(): Promise { + return this.client.get('/sharings/roles', this.headers()); + } + + public getAllAccessUsers({ + folderId, + }: { + folderId: string; + }): Promise | Record<'error', string>> { + return this.client.get(`sharings/shared-with/${folderId}`, this.headers()); } /** - * Remove user from the shared users list of a folder. - * @param {string} folderUUID - The UUID of the shared folder. - * @param {string} userUUID - The UUID of the user to be removed. - * @returns {Promise<{ removed: boolean }>} A promise indicating whether the user was removed. + * Stop sharing folder + * @param {string} itemType - Type of the sharing to delete + * @param {string} itemId - Id of the sharing to delete + * @returns */ - public removeUserFromSharedFolder(folderUUID: string, userUUID: string): Promise<{ message: string }> { - return this.client.delete( - `/private-sharing/shared-with/folder-id/${folderUUID}/user-id/${userUUID}`, - this.headers(), - ); + public async stopSharingFolder(itemType: string, itemId: string): Promise { + await this.client.delete(`sharings/${itemType}/${itemId}`, this.headers()); } /** diff --git a/src/drive/share/types.ts b/src/drive/share/types.ts index 47dbc417..71fac56c 100644 --- a/src/drive/share/types.ts +++ b/src/drive/share/types.ts @@ -156,14 +156,21 @@ export type ListAllSharedFoldersResponse = { token: string; }; -export type SharePrivateFolderWithUserPayload = { - emailToShare: string; - privateFolderId: FolderChild['uuid']; - roleId: PrivateSharingRole['id']; +export type ShareFolderWithUserPayload = { + itemId: string; + itemType: 'folder' | 'file'; + sharedWith: string; + encryptionKey?: string; + encryptionAlgorithm?: string; + roleId: string; +}; + +export type AcceptInvitationToSharedFolderPayload = { encryptionKey: string; + encryptionAlgorithm: string; }; -export type PrivateSharingRole = { id: string; role: string; createdAt: Date; updatedAt: Date }; +export type PrivateSharingRole = { id: string; name: string; createdAt: Date; updatedAt: Date }; export type PrivateSharingRolesResponse = { roles: PrivateSharingRole[] }; @@ -173,7 +180,13 @@ export type UpdateUserRoleResponse = { message: string }; export type UpdateUserRolePayload = { folderUUID: string; roleId: string; - userUUID: string; + newRoleId: string; +}; + +export type RemoveUserRolePayload = { + itemType: string; + itemId: string; + userId: string; }; export type SharedFolderUser = { @@ -189,8 +202,57 @@ export type SharedFolderUser = { uuid: string; }; +export type Role = { + id: string; + name: string; + createdAt: Date; + updatedAt: Date; +}; + export type getSharedFolderUsersResponse = { users: SharedFolderUser[] }; +export type SharingInvitation = { + id: number; + userId: string; + name: string; + lastname: string; + email: string; + username: string; + bridgeUser: string; + password: string; + mnemonic: string; + rootFolderId: number; + hKey: Buffer | string; + secret_2FA: string; + errorLoginCount: number; + isEmailActivitySended: number; + referralCode: string; + referrer: string; + syncDate: Date; + uuid: string; + lastResend: Date; + credit: number; + welcomePack: boolean; + registerCompleted: boolean; + backupsBucket: string; + sharedWorkspace: boolean; + tempKey: string; + avatar: string; +}; + +export type SharingInvite = { + id: string; + itemId: string; + itemType: 'file' | 'folder'; + sharedWith: string; + encryptionKey: string; + encryptionAlgorithm: string; + type: 'SELF' | 'OWNER'; + roleId: string; + createdAt: Date; + updatedAt: Date; +}; + export type PrivateSharedFolder = { id: string; folderId: string;