Skip to content

Commit e137f48

Browse files
authored
Merge pull request #435 from IQSS/434-format-option-for-download-usecases
Add format as an optional param to submitGuestbook for download use cases
2 parents 69b8a3c + 0c8eb79 commit e137f48

9 files changed

Lines changed: 210 additions & 63 deletions

docs/useCases.md

Lines changed: 61 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3018,14 +3018,18 @@ Submits guestbook answers for a datafile and returns a signed URL.
30183018
import { submitGuestbookForDatafileDownload } from '@iqss/dataverse-client-javascript'
30193019

30203020
submitGuestbookForDatafileDownload
3021-
.execute(10, {
3022-
guestbookResponse: {
3023-
answers: [
3024-
{ id: 123, value: 'Good' },
3025-
{ id: 124, value: ['Multi', 'Line'] }
3026-
]
3027-
}
3028-
})
3021+
.execute(
3022+
10,
3023+
{
3024+
guestbookResponse: {
3025+
answers: [
3026+
{ id: 123, value: 'Good' },
3027+
{ id: 124, value: ['Multi', 'Line'] }
3028+
]
3029+
}
3030+
},
3031+
'original'
3032+
)
30293033
.then((signedUrl: string) => {
30303034
/* ... */
30313035
})
@@ -3043,15 +3047,19 @@ Submits guestbook answers for multiple files and returns a signed URL.
30433047
import { submitGuestbookForDatafilesDownload } from '@iqss/dataverse-client-javascript'
30443048

30453049
submitGuestbookForDatafilesDownload
3046-
.execute([10, 11], {
3047-
guestbookResponse: {
3048-
answers: [
3049-
{ id: 123, value: 'Good' },
3050-
{ id: 124, value: ['Multi', 'Line'] },
3051-
{ id: 125, value: 'Yellow' }
3052-
]
3053-
}
3054-
})
3050+
.execute(
3051+
[10, 11],
3052+
{
3053+
guestbookResponse: {
3054+
answers: [
3055+
{ id: 123, value: 'Good' },
3056+
{ id: 124, value: ['Multi', 'Line'] },
3057+
{ id: 125, value: 'Yellow' }
3058+
]
3059+
}
3060+
},
3061+
'original'
3062+
)
30553063
.then((signedUrl: string) => {
30563064
/* ... */
30573065
})
@@ -3069,15 +3077,19 @@ Submits guestbook answers for dataset download and returns a signed URL.
30693077
import { submitGuestbookForDatasetDownload } from '@iqss/dataverse-client-javascript'
30703078

30713079
submitGuestbookForDatasetDownload
3072-
.execute('doi:10.5072/FK2/XXXXXX', {
3073-
guestbookResponse: {
3074-
answers: [
3075-
{ id: 123, value: 'Good' },
3076-
{ id: 124, value: ['Multi', 'Line'] },
3077-
{ id: 125, value: 'Yellow' }
3078-
]
3079-
}
3080-
})
3080+
.execute(
3081+
'doi:10.5072/FK2/XXXXXX',
3082+
{
3083+
guestbookResponse: {
3084+
answers: [
3085+
{ id: 123, value: 'Good' },
3086+
{ id: 124, value: ['Multi', 'Line'] },
3087+
{ id: 125, value: 'Yellow' }
3088+
]
3089+
}
3090+
},
3091+
'original'
3092+
)
30813093
.then((signedUrl: string) => {
30823094
/* ... */
30833095
})
@@ -3095,19 +3107,24 @@ Submits guestbook answers for a specific dataset version and returns a signed UR
30953107
import { submitGuestbookForDatasetVersionDownload } from '@iqss/dataverse-client-javascript'
30963108

30973109
submitGuestbookForDatasetVersionDownload
3098-
.execute(10, ':latest', {
3099-
guestbookResponse: {
3100-
name: 'Jane Doe',
3101-
email: 'jane@example.org',
3102-
institution: 'Example University',
3103-
position: 'Researcher',
3104-
answers: [
3105-
{ id: 123, value: 'Good' },
3106-
{ id: 124, value: ['Multi', 'Line'] },
3107-
{ id: 125, value: 'Yellow' }
3108-
]
3109-
}
3110-
})
3110+
.execute(
3111+
10,
3112+
':latest',
3113+
{
3114+
guestbookResponse: {
3115+
name: 'Jane Doe',
3116+
email: 'jane@example.org',
3117+
institution: 'Example University',
3118+
position: 'Researcher',
3119+
answers: [
3120+
{ id: 123, value: 'Good' },
3121+
{ id: 124, value: ['Multi', 'Line'] },
3122+
{ id: 125, value: 'Yellow' }
3123+
]
3124+
}
3125+
},
3126+
'original'
3127+
)
31113128
.then((signedUrl: string) => {
31123129
/* ... */
31133130
})
@@ -3119,4 +3136,8 @@ The `datasetId` parameter can be a string, for persistent identifiers, or a numb
31193136

31203137
The `versionId` parameter accepts a numbered version such as `'1.0'` or a non-numbered version such as `':latest'`.
31213138

3122-
The third parameter must match [GuestbookResponseDTO](../src/access/domain/dtos/GuestbookResponseDTO.ts). The resolved value is a signed download URL as a string.
3139+
The `guestbookResponse` parameter must match [GuestbookResponseDTO](../src/access/domain/dtos/GuestbookResponseDTO.ts).
3140+
3141+
The optional `format` parameter is sent as a query parameter on the download endpoint. For example, pass `'original'` to request the original dataset or file format.
3142+
3143+
The resolved value is a signed download URL as a string.

src/access/domain/repositories/IAccessRepository.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,26 @@ import { GuestbookResponseDTO } from '../dtos/GuestbookResponseDTO'
33
export interface IAccessRepository {
44
submitGuestbookForDatafileDownload(
55
fileId: number | string,
6-
guestbookResponse: GuestbookResponseDTO
6+
guestbookResponse: GuestbookResponseDTO,
7+
format?: string
78
): Promise<string>
89

910
submitGuestbookForDatafilesDownload(
1011
fileIds: string | Array<number | string>,
11-
guestbookResponse: GuestbookResponseDTO
12+
guestbookResponse: GuestbookResponseDTO,
13+
format?: string
1214
): Promise<string>
1315

1416
submitGuestbookForDatasetDownload(
1517
datasetId: number | string,
16-
guestbookResponse: GuestbookResponseDTO
18+
guestbookResponse: GuestbookResponseDTO,
19+
format?: string
1720
): Promise<string>
1821

1922
submitGuestbookForDatasetVersionDownload(
2023
datasetId: number | string,
2124
versionId: string,
22-
guestbookResponse: GuestbookResponseDTO
25+
guestbookResponse: GuestbookResponseDTO,
26+
format?: string
2327
): Promise<string>
2428
}

src/access/domain/useCases/SubmitGuestbookForDatafileDownload.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,18 @@ export class SubmitGuestbookForDatafileDownload implements UseCase<string> {
1010
*
1111
* @param {number | string} fileId - Datafile identifier (numeric id or persistent id).
1212
* @param {GuestbookResponseDTO} guestbookResponse - Guestbook response payload.
13+
* @param {string} [format] - Optional download format passed as a query parameter.
1314
* @returns {Promise<string>} - Signed URL for the download.
1415
*/
15-
async execute(fileId: number | string, guestbookResponse: GuestbookResponseDTO): Promise<string> {
16-
return await this.accessRepository.submitGuestbookForDatafileDownload(fileId, guestbookResponse)
16+
async execute(
17+
fileId: number | string,
18+
guestbookResponse: GuestbookResponseDTO,
19+
format?: string
20+
): Promise<string> {
21+
return await this.accessRepository.submitGuestbookForDatafileDownload(
22+
fileId,
23+
guestbookResponse,
24+
format
25+
)
1726
}
1827
}

src/access/domain/useCases/SubmitGuestbookForDatafilesDownload.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@ export class SubmitGuestbookForDatafilesDownload implements UseCase<string> {
1010
*
1111
* @param {string | Array<number | string>} fileIds - Comma-separated string or array of file ids.
1212
* @param {GuestbookResponseDTO} guestbookResponse - Guestbook response payload.
13+
* @param {string} [format] - Optional download format passed as a query parameter.
1314
* @returns {Promise<string>} - Signed URL for the download.
1415
*/
1516
async execute(
1617
fileIds: string | Array<number | string>,
17-
guestbookResponse: GuestbookResponseDTO
18+
guestbookResponse: GuestbookResponseDTO,
19+
format?: string
1820
): Promise<string> {
1921
return await this.accessRepository.submitGuestbookForDatafilesDownload(
2022
fileIds,
21-
guestbookResponse
23+
guestbookResponse,
24+
format
2225
)
2326
}
2427
}

src/access/domain/useCases/SubmitGuestbookForDatasetDownload.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@ export class SubmitGuestbookForDatasetDownload implements UseCase<string> {
1010
*
1111
* @param {number | string} datasetId - Dataset identifier (numeric id or persistent id).
1212
* @param {GuestbookResponseDTO} guestbookResponse - Guestbook response payload.
13+
* @param {string} [format] - Optional download format passed as a query parameter.
1314
* @returns {Promise<string>} - Signed URL for the download.
1415
*/
1516
async execute(
1617
datasetId: number | string,
17-
guestbookResponse: GuestbookResponseDTO
18+
guestbookResponse: GuestbookResponseDTO,
19+
format?: string
1820
): Promise<string> {
1921
return await this.accessRepository.submitGuestbookForDatasetDownload(
2022
datasetId,
21-
guestbookResponse
23+
guestbookResponse,
24+
format
2225
)
2326
}
2427
}

src/access/domain/useCases/SubmitGuestbookForDatasetVersionDownload.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,20 @@ export class SubmitGuestbookForDatasetVersionDownload implements UseCase<string>
1111
* @param {number | string} datasetId - Dataset identifier (numeric id or persistent id).
1212
* @param {string} versionId - Dataset version identifier (for example, ':latest' or '1.0').
1313
* @param {GuestbookResponseDTO} guestbookResponse - Guestbook response payload.
14+
* @param {string} [format] - Optional download format passed as a query parameter.
1415
* @returns {Promise<string>} - Signed URL for the download.
1516
*/
1617
async execute(
1718
datasetId: number | string,
1819
versionId: string,
19-
guestbookResponse: GuestbookResponseDTO
20+
guestbookResponse: GuestbookResponseDTO,
21+
format?: string
2022
): Promise<string> {
2123
return await this.accessRepository.submitGuestbookForDatasetVersionDownload(
2224
datasetId,
2325
versionId,
24-
guestbookResponse
26+
guestbookResponse,
27+
format
2528
)
2629
}
2730
}

src/access/infra/repositories/AccessRepository.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ export class AccessRepository extends ApiRepository implements IAccessRepository
77

88
public async submitGuestbookForDatafileDownload(
99
fileId: number | string,
10-
guestbookResponse: GuestbookResponseDTO
10+
guestbookResponse: GuestbookResponseDTO,
11+
format?: string
1112
): Promise<string> {
1213
const endpoint = this.buildApiEndpoint(`${this.accessResourceName}/datafile`, undefined, fileId)
13-
return this.doPost(endpoint, guestbookResponse, { signed: true })
14+
const queryParams = format ? { signed: true, format } : { signed: true }
15+
16+
return this.doPost(endpoint, guestbookResponse, queryParams)
1417
.then((response) => {
1518
const signedUrl = response.data.data.signedUrl
1619
return signedUrl
@@ -22,15 +25,18 @@ export class AccessRepository extends ApiRepository implements IAccessRepository
2225

2326
public async submitGuestbookForDatafilesDownload(
2427
fileIds: Array<number>,
25-
guestbookResponse: GuestbookResponseDTO
28+
guestbookResponse: GuestbookResponseDTO,
29+
format?: string
2630
): Promise<string> {
31+
const queryParams = format ? { signed: true, format } : { signed: true }
32+
2733
return this.doPost(
2834
this.buildApiEndpoint(
2935
this.accessResourceName,
3036
`datafiles/${Array.isArray(fileIds) ? fileIds.join(',') : fileIds}`
3137
),
3238
guestbookResponse,
33-
{ signed: true }
39+
queryParams
3440
)
3541
.then((response) => {
3642
const signedUrl = response.data.data.signedUrl
@@ -43,14 +49,17 @@ export class AccessRepository extends ApiRepository implements IAccessRepository
4349

4450
public async submitGuestbookForDatasetDownload(
4551
datasetId: number | string,
46-
guestbookResponse: GuestbookResponseDTO
52+
guestbookResponse: GuestbookResponseDTO,
53+
format?: string
4754
): Promise<string> {
4855
const endpoint = this.buildApiEndpoint(
4956
`${this.accessResourceName}/dataset`,
5057
undefined,
5158
datasetId
5259
)
53-
return this.doPost(endpoint, guestbookResponse, { signed: true })
60+
const queryParams = format ? { signed: true, format } : { signed: true }
61+
62+
return this.doPost(endpoint, guestbookResponse, queryParams)
5463
.then((response) => {
5564
const signedUrl = response.data.data.signedUrl
5665
return signedUrl
@@ -63,14 +72,17 @@ export class AccessRepository extends ApiRepository implements IAccessRepository
6372
public async submitGuestbookForDatasetVersionDownload(
6473
datasetId: number | string,
6574
versionId: string,
66-
guestbookResponse: GuestbookResponseDTO
75+
guestbookResponse: GuestbookResponseDTO,
76+
format?: string
6777
): Promise<string> {
6878
const endpoint = this.buildApiEndpoint(
6979
`${this.accessResourceName}/dataset`,
7080
`versions/${versionId}`,
7181
datasetId
7282
)
73-
return this.doPost(endpoint, guestbookResponse, { signed: true })
83+
const queryParams = format ? { signed: true, format } : { signed: true }
84+
85+
return this.doPost(endpoint, guestbookResponse, queryParams)
7486
.then((response) => {
7587
const signedUrl = response.data.data.signedUrl
7688
return signedUrl

test/integration/access/AccessRepository.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,17 @@ describe('AccessRepository', () => {
9797
expect(() => new URL(actual)).not.toThrow()
9898
})
9999

100+
test('should preserve format=original in signed url for dataset download', async () => {
101+
const actual = await sut.submitGuestbookForDatasetDownload(
102+
testDatasetIds.numericId,
103+
guestbookResponse,
104+
'original'
105+
)
106+
const signedUrl = new URL(actual)
107+
108+
expect(signedUrl.searchParams.get('format')).toEqual('original')
109+
})
110+
100111
test('should return error when dataset does not exist', async () => {
101112
const nonExistentId = 999999999
102113
await expect(

0 commit comments

Comments
 (0)