From 9204a0ad7a94629dc1b55eb388f7cc4f032e593a Mon Sep 17 00:00:00 2001 From: Xavi <77491413+masterprog-cmd@users.noreply.github.com> Date: Tue, 29 Aug 2023 11:47:50 +0200 Subject: [PATCH 1/7] feat(shared folders): update routes of shared endpoints --- package.json | 2 +- src/drive/share/index.ts | 77 +++++++++++++++++++++++++++++----------- src/drive/share/types.ts | 9 +++-- 3 files changed, 64 insertions(+), 24 deletions(-) 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..7b1c6852 100644 --- a/src/drive/share/index.ts +++ b/src/drive/share/index.ts @@ -172,7 +172,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 +193,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 +213,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 +234,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 +260,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(), ); } @@ -326,25 +323,65 @@ export class Share { * 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. + * @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 sharePrivateFolderWithUser({ - emailToShare, - privateFolderId, - roleId, + + public inviteUserToSharedFolder({ + itemId, + itemType, + sharedWith, encryptionKey, + encryptionAlgorithm, + type, + roleId, }: SharePrivateFolderWithUserPayload): Promise { return this.client.post( - 'private-sharing/share', + 'sharings/invite/send', { - email: emailToShare, - folderId: privateFolderId, - roleId, + itemId, + itemType, + sharedWith, encryptionKey, + encryptionAlgorithm, + type, + roleId, + }, + this.headers(), + ); + } + + /** + * Share a private folder with a user. + * @param {string} invitationId - The id of the invitation. + * @param {SharePrivateFolderWithUserPayload} 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 acceptSharedFolderInvite({ + invitationId, + body, + }: { + invitationId: string; + body: SharePrivateFolderWithUserPayload; + }): Promise { + return this.client.post( + `sharings/invites/${invitationId}/accept`, + { + body, }, this.headers(), ); diff --git a/src/drive/share/types.ts b/src/drive/share/types.ts index 47dbc417..edfc1310 100644 --- a/src/drive/share/types.ts +++ b/src/drive/share/types.ts @@ -157,10 +157,13 @@ export type ListAllSharedFoldersResponse = { }; export type SharePrivateFolderWithUserPayload = { - emailToShare: string; - privateFolderId: FolderChild['uuid']; - roleId: PrivateSharingRole['id']; + itemId: string; + itemType: 'folder' | 'file'; + sharedWith: string; encryptionKey: string; + encryptionAlgorithm: string; + type: string; + roleId: string; }; export type PrivateSharingRole = { id: string; role: string; createdAt: Date; updatedAt: Date }; From 94e84bf69b4d4e8c66873875128e5042e6a78a2d Mon Sep 17 00:00:00 2001 From: Xavi <77491413+masterprog-cmd@users.noreply.github.com> Date: Tue, 29 Aug 2023 14:31:36 +0200 Subject: [PATCH 2/7] feat: change types --- src/drive/share/index.ts | 112 +++++++++++++++++++-------------------- src/drive/share/types.ts | 9 ++-- 2 files changed, 60 insertions(+), 61 deletions(-) diff --git a/src/drive/share/index.ts b/src/drive/share/index.ts index 7b1c6852..5eea8278 100644 --- a/src/drive/share/index.ts +++ b/src/drive/share/index.ts @@ -17,7 +17,7 @@ import { SharedFolderUser, ShareDomainsResponse, ShareLink, - SharePrivateFolderWithUserPayload, + ShareFolderWithUserPayload, UpdateUserRolePayload, UpdateUserRoleResponse, UpdateShareLinkPayload, @@ -275,54 +275,47 @@ export class Share { return this.client.get(`private-sharing/by-folder-id/${folderUUID}`, this.headers()); } - /** - * Grant privileges of folder to a user. - * - * @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 - */ - public grantSharePrivilegesToUser( - userUuid: string, - privateFolderId: string, - roleId: string, - ): Promise { - return this.client.post( - 'private-sharing/grant-privileges', - { - userUuid, - privateFolderId, - roleId, - }, - this.headers(), - ); - } - /** * Update the role of a user on a 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.newRoleId - The new role Id. * @returns {Promise} A promise that resolves when the user's role is updated. */ - public updateUserRole({ folderUUID, roleId, userUUID }: UpdateUserRolePayload): Promise { + public updateUserRole({ folderUUID, roleId, newRoleId }: UpdateUserRolePayload): Promise { return this.client.put( - `private-sharing/role/${roleId}`, + `sharings/${folderUUID}/roles/${roleId}`, { - folderId: folderUUID, - userId: userUUID, + roleId: newRoleId, }, 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: PrivateSharedFolder }>} 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()); + } + /** * Share a private folder with a user. * - * @param {SharePrivateFolderWithUserPayload} options - The options for sharing the 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. @@ -333,25 +326,23 @@ export class Share { * @returns {Promise} A promise that resolves when the folder is shared with the user. */ - public inviteUserToSharedFolder({ - itemId, - itemType, - sharedWith, - encryptionKey, - encryptionAlgorithm, - type, - roleId, - }: SharePrivateFolderWithUserPayload): Promise { + public inviteUserToSharedFolder(createInviteDto: ShareFolderWithUserPayload): Promise { return this.client.post( 'sharings/invite/send', { - itemId, - itemType, - sharedWith, - encryptionKey, - encryptionAlgorithm, - type, - roleId, + ...createInviteDto, + type: 'OWNER', + }, + this.headers(), + ); + } + + public requestUserToSharedFolder(createInviteDto: ShareFolderWithUserPayload): Promise { + return this.client.post( + 'sharings/invite/request', + { + ...createInviteDto, + type: 'SELF', }, this.headers(), ); @@ -360,7 +351,7 @@ export class Share { /** * Share a private folder with a user. * @param {string} invitationId - The id of the invitation. - * @param {SharePrivateFolderWithUserPayload} options - The options for sharing the 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. @@ -373,27 +364,36 @@ export class Share { public acceptSharedFolderInvite({ invitationId, - body, + createInviteDto, }: { invitationId: string; - body: SharePrivateFolderWithUserPayload; + createInviteDto: ShareFolderWithUserPayload; }): Promise { return this.client.post( `sharings/invites/${invitationId}/accept`, { - body, + createInviteDto, }, this.headers(), ); } /** - * Fetches roles for private sharing items. + * Fetches roles for sharing items. * - * @returns {Promise} A promise containing the list of private sharing roles. + * @returns {Promise} A promise containing the list of sharing roles. */ - public getPrivateSharingRoles(): Promise { - return this.client.get('private-sharing/roles', 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()); } /** @@ -403,7 +403,7 @@ export class Share { * @returns {Promise<{ stopped: boolean }>} A promise that resolves with an object indicating whether the sharing was stopped. */ public stopSharingFolder(folderUUID: string): Promise<{ message: string }> { - return this.client.delete(`/private-sharing/stop/folder-id/${folderUUID}`, this.headers()); + return this.client.delete(`sharings/${folderUUID}`, this.headers()); } /** diff --git a/src/drive/share/types.ts b/src/drive/share/types.ts index edfc1310..09c023be 100644 --- a/src/drive/share/types.ts +++ b/src/drive/share/types.ts @@ -156,13 +156,12 @@ export type ListAllSharedFoldersResponse = { token: string; }; -export type SharePrivateFolderWithUserPayload = { +export type ShareFolderWithUserPayload = { itemId: string; itemType: 'folder' | 'file'; sharedWith: string; - encryptionKey: string; - encryptionAlgorithm: string; - type: string; + encryptionKey?: string; + encryptionAlgorithm?: string; roleId: string; }; @@ -176,7 +175,7 @@ export type UpdateUserRoleResponse = { message: string }; export type UpdateUserRolePayload = { folderUUID: string; roleId: string; - userUUID: string; + newRoleId: string; }; export type SharedFolderUser = { From e73058538781b200222eb69709afc5370363f50e Mon Sep 17 00:00:00 2001 From: Xavi <77491413+masterprog-cmd@users.noreply.github.com> Date: Tue, 29 Aug 2023 14:51:23 +0200 Subject: [PATCH 3/7] fix: invite user to Shared Folder endpoint --- src/drive/share/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/drive/share/index.ts b/src/drive/share/index.ts index 5eea8278..20456055 100644 --- a/src/drive/share/index.ts +++ b/src/drive/share/index.ts @@ -328,7 +328,7 @@ export class Share { public inviteUserToSharedFolder(createInviteDto: ShareFolderWithUserPayload): Promise { return this.client.post( - 'sharings/invite/send', + 'sharings/invites/send', { ...createInviteDto, type: 'OWNER', @@ -339,7 +339,7 @@ export class Share { public requestUserToSharedFolder(createInviteDto: ShareFolderWithUserPayload): Promise { return this.client.post( - 'sharings/invite/request', + 'sharings/invites/send', { ...createInviteDto, type: 'SELF', From ba3281d291fa11775663315404ef30e3fcf370db Mon Sep 17 00:00:00 2001 From: Sergio Gutierrez Villalba Date: Tue, 29 Aug 2023 14:56:24 +0200 Subject: [PATCH 4/7] fix(sharing): change param naming on stop sharing --- src/drive/share/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/drive/share/index.ts b/src/drive/share/index.ts index 20456055..e6a1671d 100644 --- a/src/drive/share/index.ts +++ b/src/drive/share/index.ts @@ -399,11 +399,11 @@ export class Share { /** * Stop sharing folder * - * @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. + * @param {string} sharingId - Id of the sharing to delete + * @returns */ - public stopSharingFolder(folderUUID: string): Promise<{ message: string }> { - return this.client.delete(`sharings/${folderUUID}`, this.headers()); + public async stopSharingFolder(sharingId: string): Promise { + await this.client.delete(`sharings/${sharingId}`, this.headers()); } /** From 53418b13119558ada5adc23d0d909aabf2a02568 Mon Sep 17 00:00:00 2001 From: Xavi <77491413+masterprog-cmd@users.noreply.github.com> Date: Wed, 30 Aug 2023 22:08:53 +0300 Subject: [PATCH 5/7] fix: type some objects and fix some endpoints --- src/drive/share/index.ts | 62 +++++++++++++++++++++++++++++----------- src/drive/share/types.ts | 12 +++++++- 2 files changed, 56 insertions(+), 18 deletions(-) diff --git a/src/drive/share/index.ts b/src/drive/share/index.ts index e6a1671d..a8c84c0f 100644 --- a/src/drive/share/index.ts +++ b/src/drive/share/index.ts @@ -8,7 +8,6 @@ import { GenerateShareLinkPayload, GetSharedDirectoryPayload, GetShareLinkFolderSizePayload, - GrantSharePrivilegesToUserResponse, ListAllSharedFoldersResponse, ListPrivateSharedFoldersResponse, ListShareLinksResponse, @@ -22,6 +21,8 @@ import { UpdateUserRoleResponse, UpdateShareLinkPayload, ListSharedItemsResponse, + AcceptInviteToSharedFolderPayload, + RemoveUserRolePayload, } from './types'; import { ApiSecurity, ApiUrl, AppDetails } from '../../shared'; import { HttpClient } from '../../shared/http/client'; @@ -294,6 +295,19 @@ export class Share { ); } + /** + * Update the role of a user on a 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.roleToRemove - The role Id how we want to delete. + * @returns {Promise} A promise that resolves when the user's role is updated. + */ + public removeUserRole({ folderUUID, roleId }: RemoveUserRolePayload): Promise { + return this.client.delete(`sharings/${folderUUID}/roles/${roleId}`, this.headers()); + } + /** * Get private folder data. * @@ -312,6 +326,10 @@ export class Share { return this.client.get(`sharings/${itemType}/${itemId}/invites`, this.headers()); } + public getSharedFolderInvitationsAsInvitedUser({ limit, offset }: { limit?: number; offset?: number }): Promise { + return this.client.get(`sharings/invites?limit=${limit}&offset=${offset}`, this.headers()); + } + /** * Share a private folder with a user. * @@ -337,6 +355,10 @@ export class Share { ); } + /** + * Request access to shared folder. + */ + public requestUserToSharedFolder(createInviteDto: ShareFolderWithUserPayload): Promise { return this.client.post( 'sharings/invites/send', @@ -352,32 +374,38 @@ export class Share { * 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.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. + * @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 acceptSharedFolderInvite({ invitationId, - createInviteDto, + acceptInvite, }: { invitationId: string; - createInviteDto: ShareFolderWithUserPayload; + acceptInvite?: AcceptInviteToSharedFolderPayload; }): Promise { return this.client.post( `sharings/invites/${invitationId}/accept`, { - createInviteDto, + acceptInvite, }, this.headers(), ); } + public getUsersInvitedToSharedFolder({ + itemType, + itemId, + }: { + itemType: 'file' | 'folder'; + itemId: string; + }): Promise { + return this.client.get(`sharings/${itemType}/${itemId}/invites`, this.headers()); + } + /** * Fetches roles for sharing items. * @@ -412,12 +440,12 @@ export class Share { * @param {string} userUUID - The UUID of the user to be removed. * @returns {Promise<{ removed: boolean }>} A promise indicating whether the user was removed. */ - 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 removeUserFromSharedFolder(folderUUID: string, userUUID: string): Promise<{ message: string }> { + // return this.client.delete( + // `/private-sharing/shared-with/folder-id/${folderUUID}/user-id/${userUUID}`, + // this.headers(), + // ); + // } /** * Returns the needed headers for the module requests diff --git a/src/drive/share/types.ts b/src/drive/share/types.ts index 09c023be..b44842fb 100644 --- a/src/drive/share/types.ts +++ b/src/drive/share/types.ts @@ -165,7 +165,12 @@ export type ShareFolderWithUserPayload = { roleId: string; }; -export type PrivateSharingRole = { id: string; role: string; createdAt: Date; updatedAt: Date }; +export type AcceptInviteToSharedFolderPayload = { + encryptionKey: string; + encryptionAlgorithm: string; +}; + +export type PrivateSharingRole = { id: string; name: string; createdAt: Date; updatedAt: Date }; export type PrivateSharingRolesResponse = { roles: PrivateSharingRole[] }; @@ -178,6 +183,11 @@ export type UpdateUserRolePayload = { newRoleId: string; }; +export type RemoveUserRolePayload = { + folderUUID: string; + roleId: string; +}; + export type SharedFolderUser = { avatar: string | null; email: string; From d8a35668745a4fd6db6353c9fc7b7b1a1cb37e52 Mon Sep 17 00:00:00 2001 From: Xavi <77491413+masterprog-cmd@users.noreply.github.com> Date: Thu, 31 Aug 2023 13:32:26 +0300 Subject: [PATCH 6/7] feat: add types for new sharing endpoints --- src/drive/share/index.ts | 37 +++++++++++++++++++++---------------- src/drive/share/types.ts | 20 ++++++++++++++++++++ 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/src/drive/share/index.ts b/src/drive/share/index.ts index a8c84c0f..f309440b 100644 --- a/src/drive/share/index.ts +++ b/src/drive/share/index.ts @@ -23,6 +23,8 @@ import { ListSharedItemsResponse, AcceptInviteToSharedFolderPayload, RemoveUserRolePayload, + SharingInvite, + Role, } from './types'; import { ApiSecurity, ApiUrl, AppDetails } from '../../shared'; import { HttpClient } from '../../shared/http/client'; @@ -313,7 +315,7 @@ export class Share { * * @param {string} itemId - The itemId of the folder. * @param {string} itemType - The itemType of the folder (file | folder). - * @returns {Promise<{ data: PrivateSharedFolder }>} A promise containing the private folder data. + * @returns {Promise<{ data: SharingInvite[] }>} A promise containing the private folder data. */ public getSharedFolderInvitations({ @@ -322,11 +324,24 @@ export class Share { }: { itemId: string; itemType: 'folder' | 'file'; - }): Promise { + }): Promise { return this.client.get(`sharings/${itemType}/${itemId}/invites`, this.headers()); } - public getSharedFolderInvitationsAsInvitedUser({ limit, offset }: { limit?: number; offset?: number }): Promise { + /** + * 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()); } @@ -341,10 +356,10 @@ export class Share { * @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. + * @returns {Promise} A promise that resolves when the folder is shared with the user. */ - public inviteUserToSharedFolder(createInviteDto: ShareFolderWithUserPayload): Promise { + public inviteUserToSharedFolder(createInviteDto: ShareFolderWithUserPayload): Promise { return this.client.post( 'sharings/invites/send', { @@ -396,23 +411,13 @@ export class Share { ); } - public getUsersInvitedToSharedFolder({ - itemType, - itemId, - }: { - itemType: 'file' | 'folder'; - itemId: string; - }): Promise { - return this.client.get(`sharings/${itemType}/${itemId}/invites`, this.headers()); - } - /** * Fetches roles for sharing items. * * @returns {Promise} A promise containing the list of sharing roles. */ - public getSharingRoles(): Promise { + public getSharingRoles(): Promise { return this.client.get('/sharings/roles', this.headers()); } diff --git a/src/drive/share/types.ts b/src/drive/share/types.ts index b44842fb..4b52bfbc 100644 --- a/src/drive/share/types.ts +++ b/src/drive/share/types.ts @@ -201,8 +201,28 @@ export type SharedFolderUser = { uuid: string; }; +export type Role = { + id: string; + name: string; + createdAt: Date; + updatedAt: Date; +}; + export type getSharedFolderUsersResponse = { users: SharedFolderUser[] }; +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; From a16e1834e1367230c062770a9830c30ccbc2b294 Mon Sep 17 00:00:00 2001 From: Xavi <77491413+masterprog-cmd@users.noreply.github.com> Date: Thu, 31 Aug 2023 16:59:44 +0300 Subject: [PATCH 7/7] fix: remove user role payload --- src/drive/share/index.ts | 42 ++++++++++++++-------------------------- src/drive/share/types.ts | 36 +++++++++++++++++++++++++++++++--- 2 files changed, 47 insertions(+), 31 deletions(-) diff --git a/src/drive/share/index.ts b/src/drive/share/index.ts index f309440b..262f7355 100644 --- a/src/drive/share/index.ts +++ b/src/drive/share/index.ts @@ -12,7 +12,6 @@ import { ListPrivateSharedFoldersResponse, ListShareLinksResponse, PrivateSharedFolder, - PrivateSharingRolesResponse, SharedFolderUser, ShareDomainsResponse, ShareLink, @@ -21,10 +20,10 @@ import { UpdateUserRoleResponse, UpdateShareLinkPayload, ListSharedItemsResponse, - AcceptInviteToSharedFolderPayload, + AcceptInvitationToSharedFolderPayload, RemoveUserRolePayload, - SharingInvite, Role, + SharingInvite, } from './types'; import { ApiSecurity, ApiUrl, AppDetails } from '../../shared'; import { HttpClient } from '../../shared/http/client'; @@ -298,16 +297,16 @@ export class Share { } /** - * 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.roleToRemove - The role Id how we want to delete. + * @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 removeUserRole({ folderUUID, roleId }: RemoveUserRolePayload): Promise { - return this.client.delete(`sharings/${folderUUID}/roles/${roleId}`, this.headers()); + public removeUserRole({ itemType, itemId, userId }: RemoveUserRolePayload): Promise { + return this.client.delete(`sharings/${itemType}/${itemId}/users/${userId}`, this.headers()); } /** @@ -324,7 +323,7 @@ export class Share { }: { itemId: string; itemType: 'folder' | 'file'; - }): Promise { + }): Promise { return this.client.get(`sharings/${itemType}/${itemId}/invites`, this.headers()); } @@ -400,7 +399,7 @@ export class Share { acceptInvite, }: { invitationId: string; - acceptInvite?: AcceptInviteToSharedFolderPayload; + acceptInvite?: AcceptInvitationToSharedFolderPayload; }): Promise { return this.client.post( `sharings/invites/${invitationId}/accept`, @@ -431,27 +430,14 @@ export class Share { /** * Stop sharing folder - * - * @param {string} sharingId - Id of the sharing to delete + * @param {string} itemType - Type of the sharing to delete + * @param {string} itemId - Id of the sharing to delete * @returns */ - public async stopSharingFolder(sharingId: string): Promise { - await this.client.delete(`sharings/${sharingId}`, this.headers()); + public async stopSharingFolder(itemType: string, itemId: string): Promise { + await this.client.delete(`sharings/${itemType}/${itemId}`, 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. - */ - // 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(), - // ); - // } - /** * Returns the needed headers for the module requests * @private diff --git a/src/drive/share/types.ts b/src/drive/share/types.ts index 4b52bfbc..71fac56c 100644 --- a/src/drive/share/types.ts +++ b/src/drive/share/types.ts @@ -165,7 +165,7 @@ export type ShareFolderWithUserPayload = { roleId: string; }; -export type AcceptInviteToSharedFolderPayload = { +export type AcceptInvitationToSharedFolderPayload = { encryptionKey: string; encryptionAlgorithm: string; }; @@ -184,8 +184,9 @@ export type UpdateUserRolePayload = { }; export type RemoveUserRolePayload = { - folderUUID: string; - roleId: string; + itemType: string; + itemId: string; + userId: string; }; export type SharedFolderUser = { @@ -210,6 +211,35 @@ export type Role = { 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;