Skip to content

Commit f83be6b

Browse files
committed
refactor: Update fetchURL types
1 parent 49cbad7 commit f83be6b

File tree

4 files changed

+83
-23
lines changed

4 files changed

+83
-23
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
[cozy-client](../README.md) / [models](../modules/models.md) / [note](../modules/models.note.md) / FetchURLOptions
2+
3+
# Interface: FetchURLOptions<>
4+
5+
[models](../modules/models.md).[note](../modules/models.note.md).FetchURLOptions
6+
7+
## Properties
8+
9+
### driveId
10+
11+
**driveId**: `string`
12+
13+
Shared drive ID used to fetched the URL
14+
15+
*Defined in*
16+
17+
[packages/cozy-client/src/models/note.js:7](https://github.com/linagora/cozy-client/blob/master/packages/cozy-client/src/models/note.js#L7)
18+
19+
***
20+
21+
### pathname
22+
23+
**pathname**: `string`
24+
25+
Pathname to use in the URL
26+
27+
*Defined in*
28+
29+
[packages/cozy-client/src/models/note.js:6](https://github.com/linagora/cozy-client/blob/master/packages/cozy-client/src/models/note.js#L6)
30+
31+
***
32+
33+
### returnUrl
34+
35+
**returnUrl**: `string`
36+
37+
Return URL to add in query string
38+
39+
*Defined in*
40+
41+
[packages/cozy-client/src/models/note.js:8](https://github.com/linagora/cozy-client/blob/master/packages/cozy-client/src/models/note.js#L8)

docs/api/cozy-client/modules/models.note.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44

55
[models](models.md).note
66

7+
## Interfaces
8+
9+
* [FetchURLOptions](../interfaces/models.note.FetchURLOptions.md)
10+
711
## Functions
812

913
### fetchURL
1014

11-
**fetchURL**(`client`, `file`, `options?`): `Promise`<`string`>
15+
**fetchURL**(`client`, `file`, `[options]?`): `Promise`<`string`>
1216

1317
Fetch and build an URL to open a note.
1418

@@ -18,10 +22,7 @@ Fetch and build an URL to open a note.
1822
| :------ | :------ | :------ |
1923
| `client` | `any` | CozyClient instance |
2024
| `file` | `any` | io.cozy.file object |
21-
| `options` | `Object` | Options |
22-
| `options.driveId` | `string` | - |
23-
| `options.pathname` | `string` | - |
24-
| `options.returnUrl` | `string` | - |
25+
| `[options]` | [`FetchURLOptions`](../interfaces/models.note.FetchURLOptions.md) | Options |
2526

2627
*Returns*
2728

@@ -31,7 +32,7 @@ url
3132

3233
*Defined in*
3334

34-
[packages/cozy-client/src/models/note.js:35](https://github.com/linagora/cozy-client/blob/master/packages/cozy-client/src/models/note.js#L35)
35+
[packages/cozy-client/src/models/note.js:39](https://github.com/linagora/cozy-client/blob/master/packages/cozy-client/src/models/note.js#L39)
3536

3637
***
3738

@@ -53,7 +54,7 @@ url
5354

5455
*Defined in*
5556

56-
[packages/cozy-client/src/models/note.js:9](https://github.com/linagora/cozy-client/blob/master/packages/cozy-client/src/models/note.js#L9)
57+
[packages/cozy-client/src/models/note.js:16](https://github.com/linagora/cozy-client/blob/master/packages/cozy-client/src/models/note.js#L16)
5758

5859
***
5960

@@ -74,4 +75,4 @@ url
7475

7576
*Defined in*
7677

77-
[packages/cozy-client/src/models/note.js:18](https://github.com/linagora/cozy-client/blob/master/packages/cozy-client/src/models/note.js#L18)
78+
[packages/cozy-client/src/models/note.js:25](https://github.com/linagora/cozy-client/blob/master/packages/cozy-client/src/models/note.js#L25)

packages/cozy-client/src/models/note.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import { generateWebLink } from '../helpers'
22
import logger from '../logger'
33

4+
/**
5+
* @typedef {Object} FetchURLOptions
6+
* @property {string} [pathname] - Pathname to use in the URL
7+
* @property {string} [driveId] - Shared drive ID used to fetched the URL
8+
* @property {string} [returnUrl] - Return URL to add in query string
9+
*/
10+
411
/**
512
*
613
* @param {string} notesAppUrl URL to the Notes App (https://notes.foo.mycozy.cloud)
@@ -26,18 +33,19 @@ export const generateUrlForNote = (notesAppUrl, file) => {
2633
*
2734
* @param {object} client CozyClient instance
2835
* @param {object} file io.cozy.file object
29-
* @param {object} options Options
30-
* @param {string} [options.pathname] Pathname to use in the URL
31-
* @param {string} [options.driveId] Shared drive ID used to fetched the URL
32-
* @param {string} [options.returnUrl] Return URL to add in query string
36+
* @param {FetchURLOptions} [options] Options
3337
* @returns {Promise<string>} url
3438
*/
35-
export const fetchURL = async (client, file, options = {}) => {
39+
export const fetchURL = async (
40+
client,
41+
file,
42+
{ pathname, driveId, returnUrl } = {}
43+
) => {
3644
const {
3745
data: { note_id, subdomain, protocol, instance, sharecode, public_name }
3846
} = await client
3947
.getStackClient()
40-
.collection('io.cozy.notes', { driveId: options.driveId })
48+
.collection('io.cozy.notes', { driveId })
4149
.fetchURL({ _id: file.id })
4250
if (sharecode) {
4351
const searchParams = [['id', note_id]]
@@ -47,21 +55,21 @@ export const fetchURL = async (client, file, options = {}) => {
4755
searchParams.push(['username', public_name])
4856
}
4957

50-
if (options.returnUrl) {
51-
searchParams.push(['returnUrl', options.returnUrl])
58+
if (returnUrl) {
59+
searchParams.push(['returnUrl', returnUrl])
5260
}
5361

5462
return generateWebLink({
5563
cozyUrl: `${protocol}://${instance}`,
5664
searchParams,
57-
pathname: options.pathname ?? '/public/',
65+
pathname: pathname ?? '/public/',
5866
slug: 'notes',
5967
subDomainType: subdomain
6068
})
6169
} else {
6270
return generateWebLink({
6371
cozyUrl: `${protocol}://${instance}`,
64-
pathname: options.pathname ?? '',
72+
pathname: pathname ?? '',
6573
slug: 'notes',
6674
subDomainType: subdomain,
6775
hash: `/n/${note_id}`
Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
export function generatePrivateUrl(notesAppUrl: string, file: object, options?: {}): string;
22
export function generateUrlForNote(notesAppUrl: any, file: any): string;
3-
export function fetchURL(client: object, file: object, options?: {
4-
pathname: string;
5-
driveId: string;
6-
returnUrl: string;
7-
}): Promise<string>;
3+
export function fetchURL(client: object, file: object, { pathname, driveId, returnUrl }?: FetchURLOptions): Promise<string>;
4+
export type FetchURLOptions = {
5+
/**
6+
* - Pathname to use in the URL
7+
*/
8+
pathname?: string;
9+
/**
10+
* - Shared drive ID used to fetched the URL
11+
*/
12+
driveId?: string;
13+
/**
14+
* - Return URL to add in query string
15+
*/
16+
returnUrl?: string;
17+
};

0 commit comments

Comments
 (0)