From 7d768de8842cf6ec95554abcae0900c9ccca97e0 Mon Sep 17 00:00:00 2001 From: Alexis G Date: Fri, 1 Dec 2023 10:31:50 +0100 Subject: [PATCH] feat: Remove `isFlatDomain` from `getSharingLink` BREAKING CHANGE: The client already carries this information, if need to change this value, please update the client. --- .../api/cozy-client/modules/models.sharing.md | 5 ++-- packages/cozy-client/src/models/sharing.js | 5 ++-- .../cozy-client/src/models/sharing.spec.js | 23 ++++++++----------- .../cozy-client/types/models/sharing.d.ts | 2 +- 4 files changed, 15 insertions(+), 20 deletions(-) diff --git a/docs/api/cozy-client/modules/models.sharing.md b/docs/api/cozy-client/modules/models.sharing.md index 0959c5a64..7c85d76e0 100644 --- a/docs/api/cozy-client/modules/models.sharing.md +++ b/docs/api/cozy-client/modules/models.sharing.md @@ -8,7 +8,7 @@ ### getSharingLink -▸ **getSharingLink**(`client`, `filesIds`, `isFlatDomain`): `Promise`<`string`> +▸ **getSharingLink**(`client`, `filesIds`): `Promise`<`string`> Generate Sharing link for one or many files @@ -18,7 +18,6 @@ Generate Sharing link for one or many files | :------ | :------ | :------ | | `client` | [`CozyClient`](../classes/CozyClient.md) | Instance of CozyClient | | `filesIds` | `string`\[] | Array of io.cozy.files ids | -| `isFlatDomain` | `boolean` | - | *Returns* @@ -28,4 +27,4 @@ Shared link *Defined in* -[packages/cozy-client/src/models/sharing.js:13](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/sharing.js#L13) +[packages/cozy-client/src/models/sharing.js:12](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/sharing.js#L12) diff --git a/packages/cozy-client/src/models/sharing.js b/packages/cozy-client/src/models/sharing.js index 05b3228c0..e09622850 100644 --- a/packages/cozy-client/src/models/sharing.js +++ b/packages/cozy-client/src/models/sharing.js @@ -7,10 +7,9 @@ import { generateWebLink } from '../helpers' * * @param {CozyClient} client - Instance of CozyClient * @param {string[]} filesIds - Array of io.cozy.files ids - * @param {boolean} [isFlatDomain] - * @returns {Promise} Shared link */ -export const getSharingLink = async (client, filesIds, isFlatDomain) => { +export const getSharingLink = async (client, filesIds) => { const PERMS = { _type: DOCTYPE_PERMISSIONS, permissions: { @@ -24,7 +23,7 @@ export const getSharingLink = async (client, filesIds, isFlatDomain) => { searchParams: [['sharecode', sharedLink?.attributes?.shortcodes?.code]], pathname: '/public', slug: 'drive', - subDomainType: isFlatDomain ? 'flat' : 'nested' + subDomainType: client.capabilities.flat_subdomains ? 'flat' : 'nested' }) return webLink diff --git a/packages/cozy-client/src/models/sharing.spec.js b/packages/cozy-client/src/models/sharing.spec.js index bef01f2d2..a86b10f63 100644 --- a/packages/cozy-client/src/models/sharing.spec.js +++ b/packages/cozy-client/src/models/sharing.spec.js @@ -2,17 +2,18 @@ import { getSharingLink } from './sharing' describe('getSharingLink', () => { const mockSharecode = { attributes: { shortcodes: { code: 'shortcode' } } } - const mockClient = { + const mockClient = ({ isFlatDomain = false } = {}) => ({ save: jest.fn(() => ({ data: mockSharecode })), - getStackClient: jest.fn(() => ({ uri: 'http://cozy.cloud' })) - } + getStackClient: jest.fn(() => ({ uri: 'http://cozy.cloud' })), + capabilities: { flat_subdomains: isFlatDomain } + }) const mockFiles = [ { id: 'fileId01', name: 'File 01' }, { id: 'fileId02', name: 'File 02' } ] it('should generate the right share link if "isFlatDomain" param is not defined', async () => { - const sharingLink = await getSharingLink(mockClient, mockFiles) + const sharingLink = await getSharingLink(mockClient(), mockFiles) expect(sharingLink).toBe( 'http://drive.cozy.cloud/public?sharecode=shortcode#/' @@ -20,11 +21,9 @@ describe('getSharingLink', () => { }) it('should generate the right share link to a nested cozy', async () => { - const isFlatDomain = false const sharingLink = await getSharingLink( - mockClient, - mockFiles, - isFlatDomain + mockClient({ isFlatDomain: false }), + mockFiles ) expect(sharingLink).toBe( @@ -33,11 +32,9 @@ describe('getSharingLink', () => { }) it('should generate the right share link to a flat cozy', async () => { - const isFlatDomain = true const sharingLink = await getSharingLink( - mockClient, - mockFiles, - isFlatDomain + mockClient({ isFlatDomain: true }), + mockFiles ) expect(sharingLink).toBe( @@ -46,7 +43,7 @@ describe('getSharingLink', () => { }) it('should generate the right share link with an correct sharecode', async () => { - const sharingLink = await getSharingLink(mockClient, mockFiles) + const sharingLink = await getSharingLink(mockClient(), mockFiles) expect(sharingLink).toContain('sharecode=shortcode') }) diff --git a/packages/cozy-client/types/models/sharing.d.ts b/packages/cozy-client/types/models/sharing.d.ts index 49fe14f2f..b639ca988 100644 --- a/packages/cozy-client/types/models/sharing.d.ts +++ b/packages/cozy-client/types/models/sharing.d.ts @@ -1,2 +1,2 @@ -export function getSharingLink(client: CozyClient, filesIds: string[], isFlatDomain?: boolean): Promise; +export function getSharingLink(client: CozyClient, filesIds: string[]): Promise; import CozyClient from "../CozyClient";