zenodo 3.0.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Zenodo.d.ts +22 -31
- package/lib/Zenodo.d.ts.map +1 -1
- package/lib/Zenodo.js +39 -45
- package/lib/Zenodo.js.map +1 -1
- package/lib/ZenodoAuthenticationStates.d.ts +6 -5
- package/lib/ZenodoAuthenticationStates.d.ts.map +1 -1
- package/lib/ZenodoAuthenticationStates.js +3 -5
- package/lib/ZenodoAuthenticationStates.js.map +1 -1
- package/lib/ZenodoFile.d.ts +26 -1
- package/lib/ZenodoFile.d.ts.map +1 -1
- package/lib/ZenodoFile.js +2 -3
- package/lib/ZenodoFile.js.map +1 -1
- package/lib/fetchZenodo.d.ts +2 -2
- package/lib/fetchZenodo.d.ts.map +1 -1
- package/lib/fetchZenodo.js +94 -11
- package/lib/fetchZenodo.js.map +1 -1
- package/lib/index.d.ts +0 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +0 -1
- package/lib/index.js.map +1 -1
- package/lib/records/ListDepositionsOptions.d.ts.map +1 -0
- package/lib/records/ListDepositionsOptions.js.map +1 -0
- package/lib/records/Record.d.ts +36 -0
- package/lib/records/Record.d.ts.map +1 -0
- package/lib/records/Record.js +231 -0
- package/lib/records/Record.js.map +1 -0
- package/lib/records/RecordType.d.ts +518 -0
- package/lib/records/RecordType.d.ts.map +1 -0
- package/lib/records/RecordType.js +2 -0
- package/lib/records/RecordType.js.map +1 -0
- package/lib/records/RequestType.d.ts +37 -0
- package/lib/records/RequestType.d.ts.map +1 -0
- package/lib/records/RequestType.js +2 -0
- package/lib/records/RequestType.js.map +1 -0
- package/lib/utilities/zipFiles.js +1 -1
- package/lib/utilities/zipFiles.js.map +1 -1
- package/package.json +23 -22
- package/src/Zenodo.ts +59 -59
- package/src/ZenodoAuthenticationStates.ts +6 -5
- package/src/ZenodoFile.ts +24 -4
- package/src/fetchZenodo.ts +105 -18
- package/src/index.ts +0 -2
- package/src/records/Record.ts +311 -0
- package/src/records/RecordType.ts +485 -0
- package/src/records/RequestType.ts +37 -0
- package/src/utilities/zipFiles.ts +1 -1
- package/lib/depositions/Deposition.d.ts +0 -98
- package/lib/depositions/Deposition.d.ts.map +0 -1
- package/lib/depositions/Deposition.js +0 -224
- package/lib/depositions/Deposition.js.map +0 -1
- package/lib/depositions/ListDepositionsOptions.d.ts.map +0 -1
- package/lib/depositions/ListDepositionsOptions.js.map +0 -1
- package/lib/depositions/Record.d.ts +0 -10
- package/lib/depositions/Record.d.ts.map +0 -1
- package/lib/depositions/Record.js +0 -19
- package/lib/depositions/Record.js.map +0 -1
- package/lib/utilities/ZenodoDepositionSchema.d.ts +0 -473
- package/lib/utilities/ZenodoDepositionSchema.d.ts.map +0 -1
- package/lib/utilities/ZenodoDepositionSchema.js +0 -80
- package/lib/utilities/ZenodoDepositionSchema.js.map +0 -1
- package/lib/utilities/ZenodoFileSchema.d.ts +0 -39
- package/lib/utilities/ZenodoFileSchema.d.ts.map +0 -1
- package/lib/utilities/ZenodoFileSchema.js +0 -37
- package/lib/utilities/ZenodoFileSchema.js.map +0 -1
- package/lib/utilities/ZenodoMetadataSchema.d.ts +0 -400
- package/lib/utilities/ZenodoMetadataSchema.d.ts.map +0 -1
- package/lib/utilities/ZenodoMetadataSchema.js +0 -602
- package/lib/utilities/ZenodoMetadataSchema.js.map +0 -1
- package/lib/utilities/ZenodoRecordSchema.d.ts +0 -544
- package/lib/utilities/ZenodoRecordSchema.d.ts.map +0 -1
- package/lib/utilities/ZenodoRecordSchema.js +0 -70
- package/lib/utilities/ZenodoRecordSchema.js.map +0 -1
- package/lib/utilities/ZenodoReviewSchema.d.ts +0 -112
- package/lib/utilities/ZenodoReviewSchema.d.ts.map +0 -1
- package/lib/utilities/ZenodoReviewSchema.js +0 -80
- package/lib/utilities/ZenodoReviewSchema.js.map +0 -1
- package/lib/utilities/licensesEnum.d.ts +0 -4
- package/lib/utilities/licensesEnum.d.ts.map +0 -1
- package/lib/utilities/licensesEnum.js +0 -449
- package/lib/utilities/licensesEnum.js.map +0 -1
- package/lib/utilities/schemaValidation.d.ts +0 -50
- package/lib/utilities/schemaValidation.d.ts.map +0 -1
- package/lib/utilities/schemaValidation.js +0 -124
- package/lib/utilities/schemaValidation.js.map +0 -1
- package/src/depositions/Deposition.ts +0 -272
- package/src/depositions/Record.ts +0 -25
- package/src/utilities/ZenodoDepositionSchema.ts +0 -90
- package/src/utilities/ZenodoFileSchema.ts +0 -40
- package/src/utilities/ZenodoMetadataSchema.ts +0 -608
- package/src/utilities/ZenodoRecordSchema.ts +0 -75
- package/src/utilities/ZenodoReviewSchema.ts +0 -84
- package/src/utilities/licensesEnum.ts +0 -448
- package/src/utilities/schemaValidation.ts +0 -150
- /package/lib/{depositions → records}/ListDepositionsOptions.d.ts +0 -0
- /package/lib/{depositions → records}/ListDepositionsOptions.js +0 -0
- /package/src/{depositions → records}/ListDepositionsOptions.ts +0 -0
package/src/Zenodo.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import type { Logger } from 'cheminfo-types';
|
|
2
|
+
import { recursiveRemoveEmptyAndNull } from 'ml-spectra-processing';
|
|
2
3
|
|
|
3
|
-
import { ZenodoAuthenticationStates } from './ZenodoAuthenticationStates.ts';
|
|
4
4
|
import type { ZenodoAuthenticationStatesType } from './ZenodoAuthenticationStates.ts';
|
|
5
|
-
import {
|
|
6
|
-
import type { ListDepositionsOptions } from './depositions/ListDepositionsOptions.ts';
|
|
7
|
-
import { Record } from './depositions/Record.ts';
|
|
5
|
+
import { ZenodoAuthenticationStates } from './ZenodoAuthenticationStates.ts';
|
|
8
6
|
import { fetchZenodo } from './fetchZenodo.ts';
|
|
9
|
-
import type {
|
|
10
|
-
import
|
|
7
|
+
import type { ListDepositionsOptions } from './records/ListDepositionsOptions.ts';
|
|
8
|
+
import { Record } from './records/Record.ts';
|
|
9
|
+
import type {
|
|
10
|
+
Identifier,
|
|
11
|
+
ZenodoMetadata,
|
|
12
|
+
ZenodoRecordAccess,
|
|
13
|
+
} from './records/RecordType.ts';
|
|
14
|
+
import type { ZenodoReview } from './records/RequestType.ts';
|
|
11
15
|
|
|
12
16
|
interface ZenodoOptions {
|
|
13
17
|
accessToken: string;
|
|
@@ -15,7 +19,7 @@ interface ZenodoOptions {
|
|
|
15
19
|
logger?: Logger;
|
|
16
20
|
}
|
|
17
21
|
|
|
18
|
-
interface PublicRecordOptions {
|
|
22
|
+
export interface PublicRecordOptions {
|
|
19
23
|
isPublished?: boolean;
|
|
20
24
|
}
|
|
21
25
|
|
|
@@ -45,7 +49,7 @@ export class Zenodo {
|
|
|
45
49
|
static async create(options: ZenodoOptions): Promise<Zenodo> {
|
|
46
50
|
const zenodo = new Zenodo(options);
|
|
47
51
|
const response = await fetchZenodo(zenodo, {
|
|
48
|
-
route: '
|
|
52
|
+
route: 'user/records',
|
|
49
53
|
expectedStatus: 200,
|
|
50
54
|
});
|
|
51
55
|
if (!response.ok) {
|
|
@@ -62,7 +66,7 @@ export class Zenodo {
|
|
|
62
66
|
* @returns true if authentication is successful, false otherwise.
|
|
63
67
|
*/
|
|
64
68
|
async verifyAuthentication(): Promise<boolean> {
|
|
65
|
-
const url = `${this.baseURL}
|
|
69
|
+
const url = `${this.baseURL}user/records`;
|
|
66
70
|
const headers = new Headers();
|
|
67
71
|
|
|
68
72
|
if (this.accessToken) {
|
|
@@ -97,13 +101,12 @@ export class Zenodo {
|
|
|
97
101
|
}
|
|
98
102
|
|
|
99
103
|
/**
|
|
100
|
-
*
|
|
101
|
-
* @param options - options for listing
|
|
102
|
-
* @
|
|
104
|
+
* Lists all records in the Zenodo instance.
|
|
105
|
+
* @param options - options for listing records
|
|
106
|
+
* @description Lists all records in the Zenodo instance.
|
|
107
|
+
* @returns An array of Record objects representing the records in the Zenodo instance.
|
|
103
108
|
*/
|
|
104
|
-
async
|
|
105
|
-
options: ListDepositionsOptions = {},
|
|
106
|
-
): Promise<Deposition[]> {
|
|
109
|
+
async listRecords(options: ListDepositionsOptions = {}): Promise<Record[]> {
|
|
107
110
|
// all the values must be string
|
|
108
111
|
const optionsWithStrings = Object.fromEntries(
|
|
109
112
|
Object.entries(options).map(([key, value]) => {
|
|
@@ -115,48 +118,43 @@ export class Zenodo {
|
|
|
115
118
|
);
|
|
116
119
|
|
|
117
120
|
const response = await fetchZenodo(this, {
|
|
118
|
-
route: '
|
|
121
|
+
route: 'user/records',
|
|
119
122
|
searchParams: optionsWithStrings,
|
|
120
123
|
});
|
|
121
|
-
const
|
|
122
|
-
this.logger?.info(`Listed ${
|
|
123
|
-
return
|
|
124
|
-
(deposition: unknown) => new Deposition(this, deposition),
|
|
125
|
-
);
|
|
124
|
+
const records = (await response.json()) as { hits: { hits: unknown[] } };
|
|
125
|
+
this.logger?.info(`Listed ${records.hits.hits.length} records`);
|
|
126
|
+
return records.hits.hits.map((record: unknown) => new Record(this, record));
|
|
126
127
|
}
|
|
127
128
|
|
|
128
129
|
/**
|
|
129
|
-
*
|
|
130
|
-
* @param metadata - the metadata for the new
|
|
130
|
+
* Creates a new record in the Zenodo instance.
|
|
131
|
+
* @param metadata - the metadata for the new record
|
|
132
|
+
* @param options - additional options for the record
|
|
133
|
+
* @param options.access - access control settings for the new record (files visibility and optional embargo)
|
|
131
134
|
* @throws {Error} If the metadata is invalid or the request fails
|
|
132
|
-
* @
|
|
133
|
-
* @returns The created deposition object
|
|
135
|
+
* @returns The created record object
|
|
134
136
|
*/
|
|
135
|
-
async
|
|
137
|
+
async createRecord(
|
|
138
|
+
metadata: ZenodoMetadata,
|
|
139
|
+
options: { access?: ZenodoRecordAccess } = {},
|
|
140
|
+
): Promise<Record> {
|
|
141
|
+
const { access } = options;
|
|
142
|
+
recursiveRemoveEmptyAndNull(metadata);
|
|
143
|
+
const body: { metadata: ZenodoMetadata; access?: ZenodoRecordAccess } = {
|
|
144
|
+
metadata,
|
|
145
|
+
};
|
|
146
|
+
if (access) {
|
|
147
|
+
body.access = access;
|
|
148
|
+
}
|
|
136
149
|
const response = await fetchZenodo(this, {
|
|
137
|
-
route: '
|
|
150
|
+
route: 'records',
|
|
138
151
|
expectedStatus: 201,
|
|
139
152
|
method: 'POST',
|
|
140
|
-
body: JSON.stringify(
|
|
153
|
+
body: JSON.stringify(body),
|
|
141
154
|
});
|
|
142
|
-
const
|
|
143
|
-
this.logger?.info(`Created
|
|
144
|
-
return
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Retrieve a deposition by its ID
|
|
149
|
-
* @param id - the deposition id
|
|
150
|
-
* @throws {Error} If the deposition does not exist or the ID is undefined
|
|
151
|
-
* @returns The retrieved deposition object
|
|
152
|
-
*/
|
|
153
|
-
async retrieveDeposition(id: number): Promise<Deposition> {
|
|
154
|
-
const response = await fetchZenodo(this, {
|
|
155
|
-
route: `deposit/depositions/${id}`,
|
|
156
|
-
});
|
|
157
|
-
const deposition = await response.json();
|
|
158
|
-
this.logger?.info(`Retrieved deposition ${id}`);
|
|
159
|
-
return new Deposition(this, deposition);
|
|
155
|
+
const record = new Record(this, await response.json());
|
|
156
|
+
this.logger?.info(`Created record ${record.value.id}`);
|
|
157
|
+
return record;
|
|
160
158
|
}
|
|
161
159
|
|
|
162
160
|
/**
|
|
@@ -167,7 +165,7 @@ export class Zenodo {
|
|
|
167
165
|
* @returns The public deposition record
|
|
168
166
|
*/
|
|
169
167
|
async retrieveRecord(
|
|
170
|
-
id:
|
|
168
|
+
id: Identifier,
|
|
171
169
|
options: PublicRecordOptions = {},
|
|
172
170
|
): Promise<Record> {
|
|
173
171
|
const { isPublished = false } = options;
|
|
@@ -186,7 +184,7 @@ export class Zenodo {
|
|
|
186
184
|
* @returns An object containing the total number of requests and the list of requests
|
|
187
185
|
*/
|
|
188
186
|
async retrieveRequests(
|
|
189
|
-
depositionId?:
|
|
187
|
+
depositionId?: Identifier,
|
|
190
188
|
): Promise<{ hits: { total: number; hits: ZenodoReview[] } }> {
|
|
191
189
|
const response = await fetchZenodo(this, {
|
|
192
190
|
route: `requests/`,
|
|
@@ -208,7 +206,7 @@ export class Zenodo {
|
|
|
208
206
|
* @param id - the deposition id
|
|
209
207
|
* @returns unvalidated array of deposition versions
|
|
210
208
|
*/
|
|
211
|
-
async retrieveVersions(id:
|
|
209
|
+
async retrieveVersions(id: Identifier): Promise<Record[]> {
|
|
212
210
|
const response = await fetchZenodo(this, {
|
|
213
211
|
route: `records/${id}/versions`,
|
|
214
212
|
});
|
|
@@ -218,21 +216,23 @@ export class Zenodo {
|
|
|
218
216
|
this.logger?.info(
|
|
219
217
|
`Retrieved ${versions?.hits.total} versions for deposition ${id}`,
|
|
220
218
|
);
|
|
221
|
-
|
|
222
|
-
|
|
219
|
+
const records = versions.hits.hits.map(
|
|
220
|
+
(version) => new Record(this, version),
|
|
221
|
+
);
|
|
222
|
+
return records;
|
|
223
223
|
}
|
|
224
224
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
225
|
+
async deleteRecord(
|
|
226
|
+
id: Identifier,
|
|
227
|
+
options: PublicRecordOptions = {},
|
|
228
|
+
): Promise<void> {
|
|
229
|
+
const { isPublished = false } = options;
|
|
230
|
+
const route = isPublished ? `records/${id}` : `records/${id}/draft`;
|
|
231
231
|
await fetchZenodo(this, {
|
|
232
232
|
method: 'DELETE',
|
|
233
|
-
route
|
|
233
|
+
route,
|
|
234
234
|
expectedStatus: 204,
|
|
235
235
|
});
|
|
236
|
-
this.logger?.info(`Deleted
|
|
236
|
+
this.logger?.info(`Deleted record ${id}`);
|
|
237
237
|
}
|
|
238
238
|
}
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Represents the different states of Zenodo authentication for retry logic.
|
|
3
3
|
*
|
|
4
|
-
* States:
|
|
5
|
-
* - NOT_TRIED: Authentication verification has not been attempted yet
|
|
6
|
-
* - FAILED: Authentication verification has failed
|
|
7
|
-
* - SUCCEEDED: Authentication verification has succeeded
|
|
8
|
-
*
|
|
9
4
|
* Usage in retry mechanism (src/services/zenodoService.ts):
|
|
10
5
|
* The Zenodo API sometimes returns 401 Unauthorized or 403 Forbidden due to temporary issues.
|
|
11
6
|
* - If SUCCEEDED: Access token is valid, safe to retry the request
|
|
@@ -13,10 +8,16 @@
|
|
|
13
8
|
* - If NOT_TRIED: Can attempt authentication once to determine next steps
|
|
14
9
|
*/
|
|
15
10
|
export const ZenodoAuthenticationStates = {
|
|
11
|
+
/** Authentication verification has not been attempted yet. */
|
|
16
12
|
NOT_TRIED: 0,
|
|
13
|
+
/** Authentication verification has failed (token is invalid/expired). */
|
|
17
14
|
FAILED: 1,
|
|
15
|
+
/** Authentication verification has succeeded (token is valid). */
|
|
18
16
|
SUCCEEDED: 2,
|
|
19
17
|
} as const;
|
|
20
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Type representing the authentication state numeric codes.
|
|
21
|
+
*/
|
|
21
22
|
export type ZenodoAuthenticationStatesType =
|
|
22
23
|
(typeof ZenodoAuthenticationStates)[keyof typeof ZenodoAuthenticationStates];
|
package/src/ZenodoFile.ts
CHANGED
|
@@ -1,18 +1,38 @@
|
|
|
1
1
|
import type { Zenodo } from './Zenodo.ts';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
|
|
3
|
+
interface ZenodoFileType {
|
|
4
|
+
created: string;
|
|
5
|
+
updated: string;
|
|
6
|
+
mimetype: string;
|
|
7
|
+
version_id: string;
|
|
8
|
+
file_id: string;
|
|
9
|
+
bucket_id: string;
|
|
10
|
+
metadata: object;
|
|
11
|
+
access: { hidden: boolean };
|
|
12
|
+
links: {
|
|
13
|
+
self: string;
|
|
14
|
+
content: string;
|
|
15
|
+
commit: string;
|
|
16
|
+
};
|
|
17
|
+
key: string;
|
|
18
|
+
transfer: { type: string };
|
|
19
|
+
status: string;
|
|
20
|
+
checksum: string;
|
|
21
|
+
size: number;
|
|
22
|
+
storage_class: string;
|
|
23
|
+
}
|
|
4
24
|
|
|
5
25
|
export class ZenodoFile {
|
|
6
26
|
private zenodo: Zenodo;
|
|
7
27
|
public value: ZenodoFileType;
|
|
8
28
|
|
|
9
29
|
constructor(zenodo: Zenodo, file: unknown) {
|
|
10
|
-
this.value =
|
|
30
|
+
this.value = file as ZenodoFileType;
|
|
11
31
|
this.zenodo = zenodo;
|
|
12
32
|
}
|
|
13
33
|
|
|
14
34
|
async getContentResponse() {
|
|
15
|
-
const link = this.value.links.
|
|
35
|
+
const link = this.value.links.content;
|
|
16
36
|
const response = await fetch(link, {
|
|
17
37
|
headers: {
|
|
18
38
|
Authorization: `Bearer ${this.zenodo.accessToken}`,
|
package/src/fetchZenodo.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { responseStatuses } from './responseStatuses.ts';
|
|
|
5
5
|
interface FetchZenodoOptions {
|
|
6
6
|
/**
|
|
7
7
|
* The route to append to the Zenodo base URL.
|
|
8
|
-
* @default '
|
|
8
|
+
* @default 'user/records'
|
|
9
9
|
*/
|
|
10
10
|
route?: string;
|
|
11
11
|
/**
|
|
@@ -25,7 +25,7 @@ interface FetchZenodoOptions {
|
|
|
25
25
|
*/
|
|
26
26
|
expectedStatus?: number;
|
|
27
27
|
searchParams?: Record<string, string>;
|
|
28
|
-
body?: string |
|
|
28
|
+
body?: string | File;
|
|
29
29
|
/**
|
|
30
30
|
* Maximum number of retry attempts.
|
|
31
31
|
* @default 3
|
|
@@ -196,17 +196,35 @@ async function performFetchAttempt(
|
|
|
196
196
|
`Attempt ${attempt + 1} for ${requestOptions.method} ${url}`,
|
|
197
197
|
);
|
|
198
198
|
|
|
199
|
-
|
|
199
|
+
try {
|
|
200
|
+
const response = await fetch(url, requestOptions);
|
|
200
201
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
202
|
+
// Check rate limit headers
|
|
203
|
+
const rateLimitInfo = extractRateLimitInfo(response);
|
|
204
|
+
if (rateLimitInfo && zenodo.logger) {
|
|
205
|
+
zenodo.logger.debug(
|
|
206
|
+
`Rate limit status: ${rateLimitInfo.remaining}/${rateLimitInfo.limit} remaining, resets at ${rateLimitInfo.reset}`,
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Log response details for debugging
|
|
211
|
+
zenodo.logger?.debug(
|
|
212
|
+
`Response status: ${response.status} ${response.statusText}`,
|
|
206
213
|
);
|
|
207
|
-
}
|
|
208
214
|
|
|
209
|
-
|
|
215
|
+
return response;
|
|
216
|
+
} catch (fetchError) {
|
|
217
|
+
zenodo.logger?.error(
|
|
218
|
+
{
|
|
219
|
+
url,
|
|
220
|
+
method: requestOptions.method,
|
|
221
|
+
error:
|
|
222
|
+
fetchError instanceof Error ? fetchError.message : String(fetchError),
|
|
223
|
+
},
|
|
224
|
+
`Network error on attempt ${attempt + 1}:`,
|
|
225
|
+
);
|
|
226
|
+
throw fetchError;
|
|
227
|
+
}
|
|
210
228
|
}
|
|
211
229
|
|
|
212
230
|
/**
|
|
@@ -225,20 +243,84 @@ async function handleFailedResponse(
|
|
|
225
243
|
url: string,
|
|
226
244
|
method: string,
|
|
227
245
|
contentType: string | undefined,
|
|
228
|
-
body: string |
|
|
246
|
+
body: string | File | undefined,
|
|
229
247
|
): Promise<Error> {
|
|
230
|
-
const
|
|
248
|
+
const baseErrorMessage =
|
|
231
249
|
responseStatuses[response.status]?.description || response.statusText;
|
|
232
|
-
|
|
250
|
+
let detailedErrorMessage = baseErrorMessage;
|
|
251
|
+
let errorDetails: unknown = null;
|
|
252
|
+
try {
|
|
253
|
+
const responseText = await response.text();
|
|
254
|
+
if (responseText) {
|
|
255
|
+
try {
|
|
256
|
+
errorDetails = JSON.parse(responseText);
|
|
257
|
+
if (errorDetails && typeof errorDetails === 'object') {
|
|
258
|
+
const errorObj = errorDetails as Record<string, unknown>;
|
|
259
|
+
if (errorObj.message && typeof errorObj.message === 'string') {
|
|
260
|
+
detailedErrorMessage = `${baseErrorMessage}: ${errorObj.message}`;
|
|
261
|
+
} else if (errorObj.error && typeof errorObj.error === 'string') {
|
|
262
|
+
detailedErrorMessage = `${baseErrorMessage}: ${errorObj.error}`;
|
|
263
|
+
} else if (errorObj.errors && Array.isArray(errorObj.errors)) {
|
|
264
|
+
const errorMessages = errorObj.errors
|
|
265
|
+
.map((err: unknown) =>
|
|
266
|
+
typeof err === 'string'
|
|
267
|
+
? err
|
|
268
|
+
: err &&
|
|
269
|
+
typeof err === 'object' &&
|
|
270
|
+
'message' in err &&
|
|
271
|
+
typeof (err as Record<string, unknown>).message ===
|
|
272
|
+
'string'
|
|
273
|
+
? ((err as Record<string, unknown>).message as string)
|
|
274
|
+
: JSON.stringify(err),
|
|
275
|
+
)
|
|
276
|
+
.join(', ');
|
|
277
|
+
detailedErrorMessage = `${baseErrorMessage}: ${errorMessages}`;
|
|
278
|
+
} else {
|
|
279
|
+
detailedErrorMessage = `${baseErrorMessage}: ${JSON.stringify(errorDetails)}`;
|
|
280
|
+
}
|
|
281
|
+
} else {
|
|
282
|
+
detailedErrorMessage = `${baseErrorMessage}: ${responseText}`;
|
|
283
|
+
}
|
|
284
|
+
} catch {
|
|
285
|
+
detailedErrorMessage = `${baseErrorMessage}: ${responseText}`;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
} catch (textError) {
|
|
289
|
+
// If we can't read the response body, log the attempt
|
|
290
|
+
zenodo.logger?.warn(
|
|
291
|
+
`Could not read error response body: ${textError instanceof Error ? textError.message : String(textError)}`,
|
|
292
|
+
);
|
|
293
|
+
}
|
|
233
294
|
if (!(await shouldRetry(response.status, zenodo))) {
|
|
234
295
|
zenodo.logger?.error(
|
|
235
|
-
`Non-retryable error fetching ${url} with ${method}: ${
|
|
296
|
+
`Non-retryable error fetching ${url} with ${method}: ${detailedErrorMessage}`,
|
|
297
|
+
);
|
|
298
|
+
zenodo.logger?.error(
|
|
299
|
+
{
|
|
300
|
+
url,
|
|
301
|
+
method,
|
|
302
|
+
contentType,
|
|
303
|
+
status: response.status,
|
|
304
|
+
headers: Object.fromEntries(response.headers.entries()),
|
|
305
|
+
errorDetails,
|
|
306
|
+
},
|
|
307
|
+
`Request details: ${errorDetails ? JSON.stringify(errorDetails) : 'No details'}`,
|
|
236
308
|
);
|
|
237
309
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
310
|
+
const error = new Error(detailedErrorMessage, {
|
|
311
|
+
cause: {
|
|
312
|
+
url,
|
|
313
|
+
method,
|
|
314
|
+
contentType,
|
|
315
|
+
body,
|
|
316
|
+
response,
|
|
317
|
+
status: response.status,
|
|
318
|
+
statusText: response.statusText,
|
|
319
|
+
headers: Object.fromEntries(response.headers.entries()),
|
|
320
|
+
errorDetails,
|
|
321
|
+
},
|
|
241
322
|
});
|
|
323
|
+
return error;
|
|
242
324
|
}
|
|
243
325
|
|
|
244
326
|
/**
|
|
@@ -388,7 +470,7 @@ export async function fetchZenodo(
|
|
|
388
470
|
): Promise<Response> {
|
|
389
471
|
const {
|
|
390
472
|
body,
|
|
391
|
-
route = '
|
|
473
|
+
route = 'user/records',
|
|
392
474
|
method = 'GET',
|
|
393
475
|
contentType = body instanceof FormData ? undefined : 'application/json',
|
|
394
476
|
expectedStatus = 200,
|
|
@@ -417,6 +499,11 @@ export async function fetchZenodo(
|
|
|
417
499
|
if (contentType) {
|
|
418
500
|
headers.set('Content-Type', contentType);
|
|
419
501
|
}
|
|
502
|
+
if (method !== 'PUT' && !route.includes('files')) {
|
|
503
|
+
headers.set('Accept', 'application/vnd.inveniordm.v1+json');
|
|
504
|
+
} else {
|
|
505
|
+
headers.set('Accept', 'application/json');
|
|
506
|
+
}
|
|
420
507
|
|
|
421
508
|
const requestOptions: RequestInit = {
|
|
422
509
|
method,
|