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.
Files changed (96) hide show
  1. package/lib/Zenodo.d.ts +22 -31
  2. package/lib/Zenodo.d.ts.map +1 -1
  3. package/lib/Zenodo.js +39 -45
  4. package/lib/Zenodo.js.map +1 -1
  5. package/lib/ZenodoAuthenticationStates.d.ts +6 -5
  6. package/lib/ZenodoAuthenticationStates.d.ts.map +1 -1
  7. package/lib/ZenodoAuthenticationStates.js +3 -5
  8. package/lib/ZenodoAuthenticationStates.js.map +1 -1
  9. package/lib/ZenodoFile.d.ts +26 -1
  10. package/lib/ZenodoFile.d.ts.map +1 -1
  11. package/lib/ZenodoFile.js +2 -3
  12. package/lib/ZenodoFile.js.map +1 -1
  13. package/lib/fetchZenodo.d.ts +2 -2
  14. package/lib/fetchZenodo.d.ts.map +1 -1
  15. package/lib/fetchZenodo.js +94 -11
  16. package/lib/fetchZenodo.js.map +1 -1
  17. package/lib/index.d.ts +0 -1
  18. package/lib/index.d.ts.map +1 -1
  19. package/lib/index.js +0 -1
  20. package/lib/index.js.map +1 -1
  21. package/lib/records/ListDepositionsOptions.d.ts.map +1 -0
  22. package/lib/records/ListDepositionsOptions.js.map +1 -0
  23. package/lib/records/Record.d.ts +36 -0
  24. package/lib/records/Record.d.ts.map +1 -0
  25. package/lib/records/Record.js +231 -0
  26. package/lib/records/Record.js.map +1 -0
  27. package/lib/records/RecordType.d.ts +518 -0
  28. package/lib/records/RecordType.d.ts.map +1 -0
  29. package/lib/records/RecordType.js +2 -0
  30. package/lib/records/RecordType.js.map +1 -0
  31. package/lib/records/RequestType.d.ts +37 -0
  32. package/lib/records/RequestType.d.ts.map +1 -0
  33. package/lib/records/RequestType.js +2 -0
  34. package/lib/records/RequestType.js.map +1 -0
  35. package/lib/utilities/zipFiles.js +1 -1
  36. package/lib/utilities/zipFiles.js.map +1 -1
  37. package/package.json +23 -22
  38. package/src/Zenodo.ts +59 -59
  39. package/src/ZenodoAuthenticationStates.ts +6 -5
  40. package/src/ZenodoFile.ts +24 -4
  41. package/src/fetchZenodo.ts +105 -18
  42. package/src/index.ts +0 -2
  43. package/src/records/Record.ts +311 -0
  44. package/src/records/RecordType.ts +485 -0
  45. package/src/records/RequestType.ts +37 -0
  46. package/src/utilities/zipFiles.ts +1 -1
  47. package/lib/depositions/Deposition.d.ts +0 -98
  48. package/lib/depositions/Deposition.d.ts.map +0 -1
  49. package/lib/depositions/Deposition.js +0 -224
  50. package/lib/depositions/Deposition.js.map +0 -1
  51. package/lib/depositions/ListDepositionsOptions.d.ts.map +0 -1
  52. package/lib/depositions/ListDepositionsOptions.js.map +0 -1
  53. package/lib/depositions/Record.d.ts +0 -10
  54. package/lib/depositions/Record.d.ts.map +0 -1
  55. package/lib/depositions/Record.js +0 -19
  56. package/lib/depositions/Record.js.map +0 -1
  57. package/lib/utilities/ZenodoDepositionSchema.d.ts +0 -473
  58. package/lib/utilities/ZenodoDepositionSchema.d.ts.map +0 -1
  59. package/lib/utilities/ZenodoDepositionSchema.js +0 -80
  60. package/lib/utilities/ZenodoDepositionSchema.js.map +0 -1
  61. package/lib/utilities/ZenodoFileSchema.d.ts +0 -39
  62. package/lib/utilities/ZenodoFileSchema.d.ts.map +0 -1
  63. package/lib/utilities/ZenodoFileSchema.js +0 -37
  64. package/lib/utilities/ZenodoFileSchema.js.map +0 -1
  65. package/lib/utilities/ZenodoMetadataSchema.d.ts +0 -400
  66. package/lib/utilities/ZenodoMetadataSchema.d.ts.map +0 -1
  67. package/lib/utilities/ZenodoMetadataSchema.js +0 -602
  68. package/lib/utilities/ZenodoMetadataSchema.js.map +0 -1
  69. package/lib/utilities/ZenodoRecordSchema.d.ts +0 -544
  70. package/lib/utilities/ZenodoRecordSchema.d.ts.map +0 -1
  71. package/lib/utilities/ZenodoRecordSchema.js +0 -70
  72. package/lib/utilities/ZenodoRecordSchema.js.map +0 -1
  73. package/lib/utilities/ZenodoReviewSchema.d.ts +0 -112
  74. package/lib/utilities/ZenodoReviewSchema.d.ts.map +0 -1
  75. package/lib/utilities/ZenodoReviewSchema.js +0 -80
  76. package/lib/utilities/ZenodoReviewSchema.js.map +0 -1
  77. package/lib/utilities/licensesEnum.d.ts +0 -4
  78. package/lib/utilities/licensesEnum.d.ts.map +0 -1
  79. package/lib/utilities/licensesEnum.js +0 -449
  80. package/lib/utilities/licensesEnum.js.map +0 -1
  81. package/lib/utilities/schemaValidation.d.ts +0 -50
  82. package/lib/utilities/schemaValidation.d.ts.map +0 -1
  83. package/lib/utilities/schemaValidation.js +0 -124
  84. package/lib/utilities/schemaValidation.js.map +0 -1
  85. package/src/depositions/Deposition.ts +0 -272
  86. package/src/depositions/Record.ts +0 -25
  87. package/src/utilities/ZenodoDepositionSchema.ts +0 -90
  88. package/src/utilities/ZenodoFileSchema.ts +0 -40
  89. package/src/utilities/ZenodoMetadataSchema.ts +0 -608
  90. package/src/utilities/ZenodoRecordSchema.ts +0 -75
  91. package/src/utilities/ZenodoReviewSchema.ts +0 -84
  92. package/src/utilities/licensesEnum.ts +0 -448
  93. package/src/utilities/schemaValidation.ts +0 -150
  94. /package/lib/{depositions → records}/ListDepositionsOptions.d.ts +0 -0
  95. /package/lib/{depositions → records}/ListDepositionsOptions.js +0 -0
  96. /package/src/{depositions → records}/ListDepositionsOptions.ts +0 -0
@@ -1,272 +0,0 @@
1
- /* eslint-disable no-await-in-loop */
2
- import type { Zenodo } from '../Zenodo.ts';
3
- import { ZenodoFile } from '../ZenodoFile.ts';
4
- import { fetchZenodo } from '../fetchZenodo.ts';
5
- import type { ZenodoDeposition } from '../utilities/ZenodoDepositionSchema.ts';
6
- import type { ZenodoMetadata } from '../utilities/ZenodoMetadataSchema.ts';
7
- import type { ZenodoReview } from '../utilities/ZenodoReviewSchema.ts';
8
- import { validateZenodoDeposition } from '../utilities/schemaValidation.ts';
9
- import { zipFiles } from '../utilities/zipFiles.ts';
10
-
11
- export class Deposition {
12
- private zenodo: Zenodo;
13
- public value: ZenodoDeposition;
14
-
15
- constructor(zenodo: Zenodo, deposition: unknown) {
16
- this.zenodo = zenodo;
17
- this.value = validateZenodoDeposition(deposition, zenodo.logger);
18
- }
19
-
20
- /**
21
- * This method creates a new file in the deposition. If the file is already it will first
22
- * delete the existing file and then create a new one.
23
- * @param file - the file to create in the deposition
24
- * @returns the created file object
25
- */
26
- async createFile(file: File): Promise<ZenodoFile> {
27
- const createdFile = await this.createFiles([file]);
28
- if (!createdFile[0]) {
29
- throw new Error('Failed to create file: No status object returned.');
30
- }
31
- return createdFile[0];
32
- }
33
-
34
- /**
35
- * Creates multiple files in the deposition. It will attempt to create each file
36
- * multiple times with delays in between until all files are successfully created or
37
- * the maximum number of attempts is reached.
38
- * @param filesAndNames - an array of File objects to be created in the deposition
39
- * @returns an array of the created ZenodoFile objects
40
- */
41
- async createFiles(filesAndNames: File[]): Promise<ZenodoFile[]> {
42
- const promises = filesAndNames.map((file) => this.uploadFile(file));
43
- return await Promise.all(promises);
44
- }
45
-
46
- /**
47
- * Creates a zip file from multiple files and uploads it to the deposition.
48
- * @param filesAndNames - an array of File objects to be created in the deposition
49
- * @param zipName - the name of the zip file to be created
50
- * @returns an array of the created ZenodoFile objects
51
- */
52
- async createFilesAsZip(
53
- filesAndNames: File[],
54
- zipName: string,
55
- ): Promise<ZenodoFile[]> {
56
- const zippedFile = await zipFiles(filesAndNames, zipName);
57
- return this.createFiles([zippedFile]);
58
- }
59
-
60
- /**
61
- * List all files in the deposition
62
- * @returns an array of ZenodoFile objects
63
- */
64
- async listFiles(): Promise<ZenodoFile[]> {
65
- const response = await fetchZenodo(this.zenodo, {
66
- route: `deposit/depositions/${this.value.id}/files`,
67
- });
68
- const files = (await response.json()) as unknown[];
69
- this.zenodo.logger?.info(
70
- `Listed ${files.length} files for deposition ${this.value.id}`,
71
- );
72
- return files.map((file) => new ZenodoFile(this.zenodo, file));
73
- }
74
-
75
- /**
76
- * Delete a file from the deposition
77
- * @param id - the ID or the name of the file to delete
78
- */
79
- async deleteFile(id: string): Promise<void> {
80
- await fetchZenodo(this.zenodo, {
81
- route: `deposit/depositions/${this.value.id}/files/${id}`,
82
- method: 'DELETE',
83
- expectedStatus: 204,
84
- });
85
- this.zenodo.logger?.info(
86
- `Deleted file ${id} for deposition ${this.value.id}`,
87
- );
88
- }
89
-
90
- /**
91
- * delete all files from the deposition
92
- */
93
- async deleteAllFiles(): Promise<void> {
94
- const files = await this.listFiles();
95
- for (const file of files) {
96
- await this.deleteFile(file.value.id);
97
- }
98
- this.zenodo.logger?.info(
99
- `Deleted all files for deposition ${this.value.id}`,
100
- );
101
- }
102
-
103
- /**
104
- * Retrieve a file from the deposition
105
- * @param id - the ID or the name of the file to retrieve
106
- * @returns the file object
107
- */
108
- async retrieveFile(id: string): Promise<ZenodoFile> {
109
- const response = await fetchZenodo(this.zenodo, {
110
- route: `deposit/depositions/${this.value.id}/files/${id}`,
111
- });
112
- const file = new ZenodoFile(this.zenodo, await response.json());
113
- this.zenodo.logger?.info(
114
- `Retrieved file ${id} for deposition ${this.value.id}`,
115
- );
116
- return file;
117
- }
118
-
119
- /**
120
- * Update the metadata of the deposition
121
- * @param metadata - the new metadata to update the deposition with
122
- * @returns the updated deposition object
123
- */
124
- async update(metadata: ZenodoMetadata): Promise<Deposition> {
125
- const response = await fetchZenodo(this.zenodo, {
126
- route: `deposit/depositions/${this.value.id}`,
127
- method: 'PUT',
128
- body: JSON.stringify({ metadata }),
129
- });
130
- const deposition = new Deposition(this.zenodo, await response.json());
131
- this.zenodo.logger?.info(`Updated deposition ${this.value.id}`);
132
- return deposition;
133
- }
134
-
135
- /**
136
- * Publish the deposition. This will make it publicly available.
137
- * !!! Note that the deposition cannot be deleted after it is published.
138
- * @returns the updated deposition object after publishing
139
- */
140
- async publish(): Promise<Deposition> {
141
- const response = await fetchZenodo(this.zenodo, {
142
- route: `deposit/depositions/${this.value.id}/actions/publish`,
143
- method: 'POST',
144
- expectedStatus: 202,
145
- });
146
- const deposition = new Deposition(this.zenodo, await response.json());
147
- this.zenodo.logger?.info(`Published deposition ${this.value.id}`);
148
- return deposition;
149
- }
150
-
151
- /**
152
- * Creates a new version of a published deposition.
153
- * This is useful for updating the deposition with new files or metadata.
154
- * The new version will have a new ID and will not overwrite the existing deposition.
155
- * @returns a new deposition object that is a new version of the current deposition
156
- */
157
- async newVersion(): Promise<Deposition> {
158
- const response = await fetchZenodo(this.zenodo, {
159
- route: `deposit/depositions/${this.value.id}/actions/newversion`,
160
- method: 'POST',
161
- expectedStatus: 201,
162
- });
163
- const deposition = new Deposition(this.zenodo, await response.json());
164
- if (
165
- deposition.value.metadata &&
166
- !deposition.value.metadata?.publication_date
167
- ) {
168
- deposition.value.metadata.publication_date = new Date()
169
- .toISOString()
170
- .split('T')[0];
171
- await deposition.update(deposition.value.metadata);
172
- }
173
- this.zenodo.logger?.info(
174
- `Created new version for deposition ${this.value.id}`,
175
- );
176
- return deposition;
177
- }
178
-
179
- /**
180
- * Upload a file to the deposition
181
- * @param file - the file to upload to the deposition
182
- * @returns the created file object
183
- */
184
- async uploadFile(file: File): Promise<ZenodoFile> {
185
- const formData = new FormData();
186
- formData.append('file', file);
187
- const response = await fetchZenodo(this.zenodo, {
188
- route: `deposit/depositions/${this.value.id}/files`,
189
- method: 'POST',
190
- body: formData,
191
- expectedStatus: 201,
192
- });
193
- const zenodoFile = new ZenodoFile(this.zenodo, await response.json());
194
- this.zenodo.logger?.info(
195
- `Created file ${zenodoFile.value.id} for deposition ${this.value.id}`,
196
- );
197
- this.value.files?.push(zenodoFile.value);
198
- return zenodoFile;
199
- }
200
-
201
- /**
202
- * Submits the deposition for review via browser.
203
- * CORS request won't work from the other endpoint when using a browser.
204
- * If a URL is provided, it will use that URL to submit the request.
205
- * Otherwise, it will find the request for the current deposition and submit it.
206
- * This is not the intended endpoint for submitting requests via browser.
207
- * But the base endpoint is not CORS enabled.
208
- * You can find the method with the right endpoint at:
209
- * https://github.com/cheminfo/zenodo/blob/7fbf3e8bb44246b3465b94b68c21cd3f4fee3bf6/src/depositions/Deposition.ts#L286-L301
210
- * @param url - optional URL to submit the request
211
- * @returns The submitted Zenodo request object
212
- */
213
- async submitForReview(url?: string): Promise<ZenodoReview> {
214
- if (url) {
215
- // If a URL is provided, we assume it's a full API endpoint for submitting the request
216
- url = url.replace(/.*requests\//, 'requests/');
217
- const response = await fetchZenodo(this.zenodo, {
218
- route: url,
219
- method: 'POST',
220
- });
221
- this.zenodo.logger?.info(
222
- `Submitted deposition ${this.value.id} for review via URL ${url}`,
223
- );
224
- return (await response.json()) as ZenodoReview;
225
- } else {
226
- const response = await fetchZenodo(this.zenodo, {
227
- route: `requests`,
228
- });
229
- const requests = (await response.json()) as {
230
- hits: {
231
- total: number;
232
- hits: ZenodoReview[];
233
- };
234
- };
235
- const request = requests.hits.hits.find(
236
- (req) => req.topic.record === String(this.value.id),
237
- );
238
- await fetchZenodo(this.zenodo, {
239
- route: request?.links.actions?.submit,
240
- method: 'POST',
241
- expectedStatus: 202,
242
- });
243
- this.zenodo.logger?.info(
244
- `Submitted deposition ${this.value.id} for review`,
245
- );
246
- return request as ZenodoReview;
247
- }
248
- }
249
-
250
- /**
251
- * Adds the deposition to a community.
252
- * This method adds the deposition to a community by creating a review request.
253
- * @param communityId - the ID of the community to add the deposition to
254
- * @returns the response from the Zenodo API
255
- */
256
- async addToCommunity(communityId: string): Promise<unknown> {
257
- const body = JSON.stringify({
258
- receiver: { community: communityId },
259
- type: 'community-submission',
260
- });
261
- const response = await fetchZenodo(this.zenodo, {
262
- route: `records/${this.value.id}/draft/review`,
263
- method: 'PUT',
264
- body,
265
- expectedStatus: 200,
266
- });
267
- this.zenodo.logger?.info(
268
- `Added deposition ${this.value.id} to community ${communityId}`,
269
- );
270
- return await response.json();
271
- }
272
- }
@@ -1,25 +0,0 @@
1
- import type { Zenodo } from '../Zenodo.ts';
2
- import type { ZenodoRecord } from '../utilities/ZenodoRecordSchema.ts';
3
- import { validateZenodoRecord } from '../utilities/schemaValidation.ts';
4
-
5
- import type { Deposition } from './Deposition.ts';
6
-
7
- export class Record {
8
- public value: ZenodoRecord;
9
- private zenodo: Zenodo;
10
-
11
- constructor(zenodo: Zenodo, value: unknown) {
12
- this.zenodo = zenodo;
13
- this.value = validateZenodoRecord(value);
14
- }
15
-
16
- async getDeposition(): Promise<Deposition> {
17
- if (this.value.id === undefined) {
18
- throw new Error('Deposition ID is undefined');
19
- }
20
- if (this.zenodo.accessToken === undefined) {
21
- throw new Error('Access token is required to retrieve a deposition');
22
- }
23
- return await this.zenodo.retrieveDeposition(this.value.id);
24
- }
25
- }
@@ -1,90 +0,0 @@
1
- import type { FromSchema } from 'json-schema-to-ts';
2
-
3
- import { zenodoMetadataSchema } from './ZenodoMetadataSchema.ts';
4
-
5
- export const zenodoDepositionSchema = {
6
- $schema: 'http://json-schema.org/draft-07/schema#',
7
- title: 'Deposition',
8
- type: 'object',
9
- properties: {
10
- created: {
11
- type: 'string',
12
- format: 'date-time',
13
- description: 'Creation time of deposition (ISO8601 format).',
14
- },
15
- modified: {
16
- type: 'string',
17
- format: 'date-time',
18
- description: 'Last modification time of deposition (ISO8601 format).',
19
- },
20
- doi: {
21
- type: 'string',
22
- description:
23
- 'Digital Object Identifier (DOI). Present only for published depositions.',
24
- },
25
- doi_url: {
26
- type: 'string',
27
- format: 'uri',
28
- description:
29
- 'Persistent link to your published deposition. Present only for published depositions.',
30
- },
31
- files: {
32
- type: 'array',
33
- description: 'A list of deposition files resources.',
34
- items: {
35
- type: 'object',
36
- },
37
- },
38
- id: {
39
- type: 'integer',
40
- description: 'Deposition identifier.',
41
- },
42
- metadata: zenodoMetadataSchema,
43
-
44
- owner: {
45
- type: 'integer',
46
- description: 'User identifier of the owner of the deposition.',
47
- },
48
- record_id: {
49
- type: 'integer',
50
- description: 'Record identifier. Present only for published depositions.',
51
- },
52
- record_url: {
53
- type: 'string',
54
- format: 'uri',
55
- description:
56
- 'URL to public version of record for this deposition. Present only for published depositions.',
57
- },
58
- state: {
59
- type: 'string',
60
- enum: ['inprogress', 'done', 'error', 'unsubmitted'],
61
- description: 'State of deposition: inprogress, done, or error.',
62
- },
63
- submitted: {
64
- type: 'boolean',
65
- description:
66
- 'True if the deposition has been published, False otherwise.',
67
- },
68
- title: {
69
- type: 'string',
70
- description:
71
- 'Title of deposition (automatically set from metadata). Defaults to empty string.',
72
- },
73
- conceptrecid: {
74
- type: 'string',
75
- description: 'Concept record ID.',
76
- },
77
- links: {
78
- type: 'object',
79
- description: 'Links related to the deposition.',
80
- },
81
- conceptdoi: {
82
- type: 'string',
83
- description: 'Concept DOI.',
84
- },
85
- },
86
- required: [],
87
- additionalProperties: false,
88
- } as const;
89
-
90
- export type ZenodoDeposition = FromSchema<typeof zenodoDepositionSchema>;
@@ -1,40 +0,0 @@
1
- import type { FromSchema } from 'json-schema-to-ts';
2
-
3
- export const zenodoFileSchema = {
4
- $schema: 'http://json-schema.org/draft-07/schema#',
5
- title: 'Zenodo File',
6
- type: 'object',
7
- properties: {
8
- id: {
9
- type: 'string',
10
- },
11
- filename: {
12
- type: 'string',
13
- },
14
- filesize: {
15
- type: 'number',
16
- },
17
- checksum: {
18
- type: 'string',
19
- },
20
- links: {
21
- type: 'object',
22
- properties: {
23
- download: {
24
- type: 'string',
25
- format: 'uri',
26
- },
27
- self: {
28
- type: 'string',
29
- format: 'uri',
30
- },
31
- },
32
- required: ['download', 'self'],
33
- additionalProperties: false,
34
- },
35
- },
36
- required: ['id', 'filename', 'filesize', 'checksum', 'links'],
37
- additionalProperties: false,
38
- } as const;
39
-
40
- export type ZenodoFileType = FromSchema<typeof zenodoFileSchema>;