zenodo 2.0.0 → 3.0.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 (122) hide show
  1. package/README.md +12 -0
  2. package/lib/Zenodo.d.ts +76 -4
  3. package/lib/Zenodo.d.ts.map +1 -1
  4. package/lib/Zenodo.js +150 -19
  5. package/lib/Zenodo.js.map +1 -1
  6. package/lib/ZenodoAuthenticationStates.d.ts +21 -0
  7. package/lib/ZenodoAuthenticationStates.d.ts.map +1 -0
  8. package/lib/ZenodoAuthenticationStates.js +20 -0
  9. package/lib/ZenodoAuthenticationStates.js.map +1 -0
  10. package/lib/ZenodoFile.d.ts +2 -38
  11. package/lib/ZenodoFile.d.ts.map +1 -1
  12. package/lib/ZenodoFile.js +3 -18
  13. package/lib/ZenodoFile.js.map +1 -1
  14. package/lib/depositions/Deposition.d.ts +90 -6
  15. package/lib/depositions/Deposition.d.ts.map +1 -1
  16. package/lib/depositions/Deposition.js +198 -29
  17. package/lib/depositions/Deposition.js.map +1 -1
  18. package/lib/depositions/ListDepositionsOptions.d.ts +4 -2
  19. package/lib/depositions/ListDepositionsOptions.d.ts.map +1 -1
  20. package/lib/depositions/ListDepositionsOptions.js +1 -2
  21. package/lib/depositions/Record.d.ts +10 -0
  22. package/lib/depositions/Record.d.ts.map +1 -0
  23. package/lib/depositions/Record.js +19 -0
  24. package/lib/depositions/Record.js.map +1 -0
  25. package/lib/fetchZenodo.d.ts +44 -1
  26. package/lib/fetchZenodo.d.ts.map +1 -1
  27. package/lib/fetchZenodo.js +214 -15
  28. package/lib/fetchZenodo.js.map +1 -1
  29. package/lib/index.d.ts +3 -1
  30. package/lib/index.d.ts.map +1 -1
  31. package/lib/index.js +3 -17
  32. package/lib/index.js.map +1 -1
  33. package/lib/responseStatuses.js +1 -4
  34. package/lib/responseStatuses.js.map +1 -1
  35. package/lib/utilities/ZenodoDepositionSchema.d.ts +473 -0
  36. package/lib/utilities/ZenodoDepositionSchema.d.ts.map +1 -0
  37. package/lib/utilities/ZenodoDepositionSchema.js +80 -0
  38. package/lib/utilities/ZenodoDepositionSchema.js.map +1 -0
  39. package/lib/utilities/ZenodoFileSchema.d.ts +39 -0
  40. package/lib/utilities/ZenodoFileSchema.d.ts.map +1 -0
  41. package/lib/utilities/ZenodoFileSchema.js +37 -0
  42. package/lib/utilities/ZenodoFileSchema.js.map +1 -0
  43. package/lib/utilities/ZenodoMetadataSchema.d.ts +400 -0
  44. package/lib/utilities/ZenodoMetadataSchema.d.ts.map +1 -0
  45. package/lib/utilities/ZenodoMetadataSchema.js +602 -0
  46. package/lib/utilities/ZenodoMetadataSchema.js.map +1 -0
  47. package/lib/utilities/ZenodoRecordSchema.d.ts +544 -0
  48. package/lib/utilities/ZenodoRecordSchema.d.ts.map +1 -0
  49. package/lib/utilities/ZenodoRecordSchema.js +70 -0
  50. package/lib/utilities/ZenodoRecordSchema.js.map +1 -0
  51. package/lib/utilities/ZenodoReviewSchema.d.ts +112 -0
  52. package/lib/utilities/ZenodoReviewSchema.d.ts.map +1 -0
  53. package/lib/utilities/ZenodoReviewSchema.js +80 -0
  54. package/lib/utilities/ZenodoReviewSchema.js.map +1 -0
  55. package/lib/utilities/licensesEnum.d.ts +4 -0
  56. package/lib/utilities/licensesEnum.d.ts.map +1 -0
  57. package/lib/utilities/licensesEnum.js +449 -0
  58. package/lib/utilities/licensesEnum.js.map +1 -0
  59. package/lib/utilities/schemaValidation.d.ts +50 -0
  60. package/lib/utilities/schemaValidation.d.ts.map +1 -0
  61. package/lib/utilities/schemaValidation.js +124 -0
  62. package/lib/utilities/schemaValidation.js.map +1 -0
  63. package/lib/utilities/zipFiles.d.ts +9 -0
  64. package/lib/utilities/zipFiles.d.ts.map +1 -0
  65. package/lib/utilities/zipFiles.js +28 -0
  66. package/lib/utilities/zipFiles.js.map +1 -0
  67. package/package.json +28 -22
  68. package/src/Zenodo.ts +180 -10
  69. package/src/ZenodoAuthenticationStates.ts +22 -0
  70. package/src/ZenodoFile.ts +4 -18
  71. package/src/depositions/Deposition.ts +236 -24
  72. package/src/depositions/ListDepositionsOptions.ts +4 -2
  73. package/src/depositions/Record.ts +25 -0
  74. package/src/fetchZenodo.ts +402 -16
  75. package/src/index.ts +5 -1
  76. package/src/utilities/ZenodoDepositionSchema.ts +90 -0
  77. package/src/utilities/ZenodoFileSchema.ts +40 -0
  78. package/src/utilities/ZenodoMetadataSchema.ts +608 -0
  79. package/src/utilities/ZenodoRecordSchema.ts +75 -0
  80. package/src/utilities/ZenodoReviewSchema.ts +84 -0
  81. package/src/utilities/licensesEnum.ts +448 -0
  82. package/src/utilities/schemaValidation.ts +150 -0
  83. package/src/utilities/zipFiles.ts +36 -0
  84. package/lib/depositions/depositionSchema.d.ts +0 -982
  85. package/lib/depositions/depositionSchema.d.ts.map +0 -1
  86. package/lib/depositions/depositionSchema.js +0 -141
  87. package/lib/depositions/depositionSchema.js.map +0 -1
  88. package/lib-esm/Zenodo.d.ts +0 -19
  89. package/lib-esm/Zenodo.d.ts.map +0 -1
  90. package/lib-esm/Zenodo.js +0 -51
  91. package/lib-esm/Zenodo.js.map +0 -1
  92. package/lib-esm/ZenodoFile.d.ts +0 -45
  93. package/lib-esm/ZenodoFile.d.ts.map +0 -1
  94. package/lib-esm/ZenodoFile.js +0 -33
  95. package/lib-esm/ZenodoFile.js.map +0 -1
  96. package/lib-esm/depositions/Deposition.d.ts +0 -14
  97. package/lib-esm/depositions/Deposition.d.ts.map +0 -1
  98. package/lib-esm/depositions/Deposition.js +0 -51
  99. package/lib-esm/depositions/Deposition.js.map +0 -1
  100. package/lib-esm/depositions/ListDepositionsOptions.d.ts +0 -32
  101. package/lib-esm/depositions/ListDepositionsOptions.d.ts.map +0 -1
  102. package/lib-esm/depositions/ListDepositionsOptions.js +0 -2
  103. package/lib-esm/depositions/ListDepositionsOptions.js.map +0 -1
  104. package/lib-esm/depositions/depositionSchema.d.ts +0 -982
  105. package/lib-esm/depositions/depositionSchema.d.ts.map +0 -1
  106. package/lib-esm/depositions/depositionSchema.js +0 -138
  107. package/lib-esm/depositions/depositionSchema.js.map +0 -1
  108. package/lib-esm/fetchZenodo.d.ts +0 -12
  109. package/lib-esm/fetchZenodo.d.ts.map +0 -1
  110. package/lib-esm/fetchZenodo.js +0 -31
  111. package/lib-esm/fetchZenodo.js.map +0 -1
  112. package/lib-esm/index.d.ts +0 -2
  113. package/lib-esm/index.d.ts.map +0 -1
  114. package/lib-esm/index.js +0 -2
  115. package/lib-esm/index.js.map +0 -1
  116. package/lib-esm/responseStatuses.d.ts +0 -8
  117. package/lib-esm/responseStatuses.d.ts.map +0 -1
  118. package/lib-esm/responseStatuses.js +0 -68
  119. package/lib-esm/responseStatuses.js.map +0 -1
  120. package/src/__tests__/Zenodo.test.ts +0 -79
  121. package/src/__tests__/getConfig.ts +0 -9
  122. package/src/depositions/depositionSchema.ts +0 -154
@@ -1,55 +1,224 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Deposition = void 0;
4
- const ZenodoFile_1 = require("../ZenodoFile");
5
- const fetchZenodo_1 = require("../fetchZenodo");
6
- const depositionSchema_1 = require("./depositionSchema");
7
- class Deposition {
1
+ import { ZenodoFile } from "../ZenodoFile.js";
2
+ import { fetchZenodo } from "../fetchZenodo.js";
3
+ import { validateZenodoDeposition } from "../utilities/schemaValidation.js";
4
+ import { zipFiles } from "../utilities/zipFiles.js";
5
+ export class Deposition {
8
6
  zenodo;
9
7
  value;
10
8
  constructor(zenodo, deposition) {
11
9
  this.zenodo = zenodo;
12
- this.value = depositionSchema_1.zenodoDepositionSchema.parse(deposition);
10
+ this.value = validateZenodoDeposition(deposition, zenodo.logger);
13
11
  }
12
+ /**
13
+ * This method creates a new file in the deposition. If the file is already it will first
14
+ * delete the existing file and then create a new one.
15
+ * @param file - the file to create in the deposition
16
+ * @returns the created file object
17
+ */
14
18
  async createFile(file) {
15
- const formData = new FormData();
16
- formData.append('file', file);
17
- const response = await (0, fetchZenodo_1.fetchZenodo)(this.zenodo, {
18
- route: `deposit/depositions/${this.value.id}/files`,
19
- method: 'POST',
20
- body: formData,
21
- expectedStatus: 201,
22
- });
23
- return new ZenodoFile_1.ZenodoFile(this.zenodo, await response.json());
19
+ const createdFile = await this.createFiles([file]);
20
+ if (!createdFile[0]) {
21
+ throw new Error('Failed to create file: No status object returned.');
22
+ }
23
+ return createdFile[0];
24
+ }
25
+ /**
26
+ * Creates multiple files in the deposition. It will attempt to create each file
27
+ * multiple times with delays in between until all files are successfully created or
28
+ * the maximum number of attempts is reached.
29
+ * @param filesAndNames - an array of File objects to be created in the deposition
30
+ * @returns an array of the created ZenodoFile objects
31
+ */
32
+ async createFiles(filesAndNames) {
33
+ const promises = filesAndNames.map((file) => this.uploadFile(file));
34
+ return await Promise.all(promises);
24
35
  }
36
+ /**
37
+ * Creates a zip file from multiple files and uploads it to the deposition.
38
+ * @param filesAndNames - an array of File objects to be created in the deposition
39
+ * @param zipName - the name of the zip file to be created
40
+ * @returns an array of the created ZenodoFile objects
41
+ */
42
+ async createFilesAsZip(filesAndNames, zipName) {
43
+ const zippedFile = await zipFiles(filesAndNames, zipName);
44
+ return this.createFiles([zippedFile]);
45
+ }
46
+ /**
47
+ * List all files in the deposition
48
+ * @returns an array of ZenodoFile objects
49
+ */
25
50
  async listFiles() {
26
- const response = await (0, fetchZenodo_1.fetchZenodo)(this.zenodo, {
51
+ const response = await fetchZenodo(this.zenodo, {
27
52
  route: `deposit/depositions/${this.value.id}/files`,
28
53
  });
29
54
  const files = (await response.json());
30
- return files.map((file) => new ZenodoFile_1.ZenodoFile(this.zenodo, file));
55
+ this.zenodo.logger?.info(`Listed ${files.length} files for deposition ${this.value.id}`);
56
+ return files.map((file) => new ZenodoFile(this.zenodo, file));
31
57
  }
32
- async deleteFile(fileId) {
33
- await (0, fetchZenodo_1.fetchZenodo)(this.zenodo, {
34
- route: `deposit/depositions/${this.value.id}/files/${fileId}`,
58
+ /**
59
+ * Delete a file from the deposition
60
+ * @param id - the ID or the name of the file to delete
61
+ */
62
+ async deleteFile(id) {
63
+ await fetchZenodo(this.zenodo, {
64
+ route: `deposit/depositions/${this.value.id}/files/${id}`,
35
65
  method: 'DELETE',
36
66
  expectedStatus: 204,
37
67
  });
68
+ this.zenodo.logger?.info(`Deleted file ${id} for deposition ${this.value.id}`);
69
+ }
70
+ /**
71
+ * delete all files from the deposition
72
+ */
73
+ async deleteAllFiles() {
74
+ const files = await this.listFiles();
75
+ for (const file of files) {
76
+ await this.deleteFile(file.value.id);
77
+ }
78
+ this.zenodo.logger?.info(`Deleted all files for deposition ${this.value.id}`);
38
79
  }
39
- async retrieveFile(fileId) {
40
- const response = await (0, fetchZenodo_1.fetchZenodo)(this.zenodo, {
41
- route: `deposit/depositions/${this.value.id}/files/${fileId}`,
80
+ /**
81
+ * Retrieve a file from the deposition
82
+ * @param id - the ID or the name of the file to retrieve
83
+ * @returns the file object
84
+ */
85
+ async retrieveFile(id) {
86
+ const response = await fetchZenodo(this.zenodo, {
87
+ route: `deposit/depositions/${this.value.id}/files/${id}`,
42
88
  });
43
- return new ZenodoFile_1.ZenodoFile(this.zenodo, await response.json());
89
+ const file = new ZenodoFile(this.zenodo, await response.json());
90
+ this.zenodo.logger?.info(`Retrieved file ${id} for deposition ${this.value.id}`);
91
+ return file;
44
92
  }
93
+ /**
94
+ * Update the metadata of the deposition
95
+ * @param metadata - the new metadata to update the deposition with
96
+ * @returns the updated deposition object
97
+ */
45
98
  async update(metadata) {
46
- const response = await (0, fetchZenodo_1.fetchZenodo)(this.zenodo, {
99
+ const response = await fetchZenodo(this.zenodo, {
47
100
  route: `deposit/depositions/${this.value.id}`,
48
101
  method: 'PUT',
49
102
  body: JSON.stringify({ metadata }),
50
103
  });
51
- return new Deposition(this.zenodo, await response.json());
104
+ const deposition = new Deposition(this.zenodo, await response.json());
105
+ this.zenodo.logger?.info(`Updated deposition ${this.value.id}`);
106
+ return deposition;
107
+ }
108
+ /**
109
+ * Publish the deposition. This will make it publicly available.
110
+ * !!! Note that the deposition cannot be deleted after it is published.
111
+ * @returns the updated deposition object after publishing
112
+ */
113
+ async publish() {
114
+ const response = await fetchZenodo(this.zenodo, {
115
+ route: `deposit/depositions/${this.value.id}/actions/publish`,
116
+ method: 'POST',
117
+ expectedStatus: 202,
118
+ });
119
+ const deposition = new Deposition(this.zenodo, await response.json());
120
+ this.zenodo.logger?.info(`Published deposition ${this.value.id}`);
121
+ return deposition;
122
+ }
123
+ /**
124
+ * Creates a new version of a published deposition.
125
+ * This is useful for updating the deposition with new files or metadata.
126
+ * The new version will have a new ID and will not overwrite the existing deposition.
127
+ * @returns a new deposition object that is a new version of the current deposition
128
+ */
129
+ async newVersion() {
130
+ const response = await fetchZenodo(this.zenodo, {
131
+ route: `deposit/depositions/${this.value.id}/actions/newversion`,
132
+ method: 'POST',
133
+ expectedStatus: 201,
134
+ });
135
+ const deposition = new Deposition(this.zenodo, await response.json());
136
+ if (deposition.value.metadata &&
137
+ !deposition.value.metadata?.publication_date) {
138
+ deposition.value.metadata.publication_date = new Date()
139
+ .toISOString()
140
+ .split('T')[0];
141
+ await deposition.update(deposition.value.metadata);
142
+ }
143
+ this.zenodo.logger?.info(`Created new version for deposition ${this.value.id}`);
144
+ return deposition;
145
+ }
146
+ /**
147
+ * Upload a file to the deposition
148
+ * @param file - the file to upload to the deposition
149
+ * @returns the created file object
150
+ */
151
+ async uploadFile(file) {
152
+ const formData = new FormData();
153
+ formData.append('file', file);
154
+ const response = await fetchZenodo(this.zenodo, {
155
+ route: `deposit/depositions/${this.value.id}/files`,
156
+ method: 'POST',
157
+ body: formData,
158
+ expectedStatus: 201,
159
+ });
160
+ const zenodoFile = new ZenodoFile(this.zenodo, await response.json());
161
+ this.zenodo.logger?.info(`Created file ${zenodoFile.value.id} for deposition ${this.value.id}`);
162
+ this.value.files?.push(zenodoFile.value);
163
+ return zenodoFile;
164
+ }
165
+ /**
166
+ * Submits the deposition for review via browser.
167
+ * CORS request won't work from the other endpoint when using a browser.
168
+ * If a URL is provided, it will use that URL to submit the request.
169
+ * Otherwise, it will find the request for the current deposition and submit it.
170
+ * This is not the intended endpoint for submitting requests via browser.
171
+ * But the base endpoint is not CORS enabled.
172
+ * You can find the method with the right endpoint at:
173
+ * https://github.com/cheminfo/zenodo/blob/7fbf3e8bb44246b3465b94b68c21cd3f4fee3bf6/src/depositions/Deposition.ts#L286-L301
174
+ * @param url - optional URL to submit the request
175
+ * @returns The submitted Zenodo request object
176
+ */
177
+ async submitForReview(url) {
178
+ if (url) {
179
+ // If a URL is provided, we assume it's a full API endpoint for submitting the request
180
+ url = url.replace(/.*requests\//, 'requests/');
181
+ const response = await fetchZenodo(this.zenodo, {
182
+ route: url,
183
+ method: 'POST',
184
+ });
185
+ this.zenodo.logger?.info(`Submitted deposition ${this.value.id} for review via URL ${url}`);
186
+ return (await response.json());
187
+ }
188
+ else {
189
+ const response = await fetchZenodo(this.zenodo, {
190
+ route: `requests`,
191
+ });
192
+ const requests = (await response.json());
193
+ const request = requests.hits.hits.find((req) => req.topic.record === String(this.value.id));
194
+ await fetchZenodo(this.zenodo, {
195
+ route: request?.links.actions?.submit,
196
+ method: 'POST',
197
+ expectedStatus: 202,
198
+ });
199
+ this.zenodo.logger?.info(`Submitted deposition ${this.value.id} for review`);
200
+ return request;
201
+ }
202
+ }
203
+ /**
204
+ * Adds the deposition to a community.
205
+ * This method adds the deposition to a community by creating a review request.
206
+ * @param communityId - the ID of the community to add the deposition to
207
+ * @returns the response from the Zenodo API
208
+ */
209
+ async addToCommunity(communityId) {
210
+ const body = JSON.stringify({
211
+ receiver: { community: communityId },
212
+ type: 'community-submission',
213
+ });
214
+ const response = await fetchZenodo(this.zenodo, {
215
+ route: `records/${this.value.id}/draft/review`,
216
+ method: 'PUT',
217
+ body,
218
+ expectedStatus: 200,
219
+ });
220
+ this.zenodo.logger?.info(`Added deposition ${this.value.id} to community ${communityId}`);
221
+ return await response.json();
52
222
  }
53
223
  }
54
- exports.Deposition = Deposition;
55
224
  //# sourceMapp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AAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CACrC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,KAAK,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CACpD,CAAC;YACF,MAAM,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE;gBAC7B,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,MAAM;gBACrC,MAAM,EAAE,MAAM;gBACd,cAAc,EAAE,GAAG;aACpB,CAAC,CAAC;YACH,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CACtB,wBAAwB,IAAI,CAAC,KAAK,CAAC,EAAE,aAAa,CACnD,CAAC;YACF,OAAO,OAAuB,CAAC;QACjC,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,cAAc,CAAC,WAAmB;QACtC,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC;YAC1B,QAAQ,EAAE,EAAE,SAAS,EAAE,WAAW,EAAE;YACpC,IAAI,EAAE,sBAAsB;SAC7B,CAAC,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE;YAC9C,KAAK,EAAE,WAAW,IAAI,CAAC,KAAK,CAAC,EAAE,eAAe;YAC9C,MAAM,EAAE,KAAK;YACb,IAAI;YACJ,cAAc,EAAE,GAAG;SACpB,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CACtB,oBAAoB,IAAI,CAAC,KAAK,CAAC,EAAE,iBAAiB,WAAW,EAAE,CAChE,CAAC;QACF,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IAC/B,CAAC;CACF"}
@@ -14,7 +14,7 @@ export interface ListDepositionsOptions {
14
14
  * Possible values: 'bestmatch' | 'mostrecent'
15
15
  * Prefix with minus to change from ascending to descending (e.g., '-mostrecent').
16
16
  */
17
- sort?: 'bestmatch' | 'mostrecent' | `-${'bestmatch' | 'mostrecent'}`;
17
+ sort?: 'bestmatch' | 'mostrecent' | '-bestmatch' | '-mostrecent';
18
18
  /**
19
19
  * Page number for pagination.
20
20
  */
@@ -25,8 +25,10 @@ export interface ListDepositionsOptions {
25
25
  size?: number;
26
26
  /**
27
27
  * Show or hide all versions of deposits.
28
+ * the query is not camelCase but for consistency with other options.
29
+ * the query is translated to `all_versions` in this library.
28
30
  * Possible values: 'true' | 'false' | 1 | 0
29
31
  */
30
- all_versions?: 'true' | 'false' | 1 | 0;
32
+ allVersions?: 'true' | 'false' | 1 | 0;
31
33
  }
32
34
  //# sourceMappingURL=ListDepositionsOptions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ListDepositionsOptions.d.ts","sourceRoot":"","sources":["../../src/depositions/ListDepositionsOptions.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,CAAC,CAAC,EAAE,MAAM,CAAC;IAEX;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,GAAG,WAAW,CAAC;IAE/B;;;;OAIG;IACH,IAAI,CAAC,EAAE,WAAW,GAAG,YAAY,GAAG,IAAI,WAAW,GAAG,YAAY,EAAE,CAAC;IAErE;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC;CACzC"}
1
+ {"version":3,"file":"ListDepositionsOptions.d.ts","sourceRoot":"","sources":["../../src/depositions/ListDepositionsOptions.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,CAAC,CAAC,EAAE,MAAM,CAAC;IAEX;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,GAAG,WAAW,CAAC;IAE/B;;;;OAIG;IACH,IAAI,CAAC,EAAE,WAAW,GAAG,YAAY,GAAG,YAAY,GAAG,aAAa,CAAC;IAEjE;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC;CACxC"}
@@ -1,3 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
3
2
  //# sourceMappingURL=ListDepositionsOptions.js.map
@@ -0,0 +1,10 @@
1
+ import type { Zenodo } from '../Zenodo.ts';
2
+ import type { ZenodoRecord } from '../utilities/ZenodoRecordSchema.ts';
3
+ import type { Deposition } from './Deposition.ts';
4
+ export declare class Record {
5
+ value: ZenodoRecord;
6
+ private zenodo;
7
+ constructor(zenodo: Zenodo, value: unknown);
8
+ getDeposition(): Promise<Deposition>;
9
+ }
10
+ //# sourceMappingURL=Record.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Record.d.ts","sourceRoot":"","sources":["../../src/depositions/Record.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAGvE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,qBAAa,MAAM;IACV,KAAK,EAAE,YAAY,CAAC;IAC3B,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO;IAKpC,aAAa,IAAI,OAAO,CAAC,UAAU,CAAC;CAS3C"}
@@ -0,0 +1,19 @@
1
+ import { validateZenodoRecord } from "../utilities/schemaValidation.js";
2
+ export class Record {
3
+ value;
4
+ zenodo;
5
+ constructor(zenodo, value) {
6
+ this.zenodo = zenodo;
7
+ this.value = validateZenodoRecord(value);
8
+ }
9
+ async getDeposition() {
10
+ if (this.value.id === undefined) {
11
+ throw new Error('Deposition ID is undefined');
12
+ }
13
+ if (this.zenodo.accessToken === undefined) {
14
+ throw new Error('Access token is required to retrieve a deposition');
15
+ }
16
+ return await this.zenodo.retrieveDeposition(this.value.id);
17
+ }
18
+ }
19
+ //# sourceMappingURL=Record.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Record.js","sourceRoot":"","sources":["../../src/depositions/Record.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAIxE,MAAM,OAAO,MAAM;IACV,KAAK,CAAe;IACnB,MAAM,CAAS;IAEvB,YAAY,MAAc,EAAE,KAAc;QACxC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,oBAAoB,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC;IAED,KAAK,CAAC,aAAa;QACjB,IAAI,IAAI,CAAC,KAAK,CAAC,EAAE,KAAK,SAAS,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;QAChD,CAAC;QACD,IAAI,IAAI,CAAC,MAAM,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;YAC1C,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;QACvE,CAAC;QACD,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAC7D,CAAC;CACF"}
@@ -1,12 +1,55 @@
1
- import type { Zenodo } from './Zenodo';
1
+ import type { Zenodo } from './Zenodo.ts';
2
2
  interface FetchZenodoOptions {
3
+ /**
4
+ * The route to append to the Zenodo base URL.
5
+ * @default 'deposit/depositions'
6
+ */
3
7
  route?: string;
8
+ /**
9
+ * The HTTP method to use for the request.
10
+ * @default 'GET'
11
+ */
4
12
  method?: string;
13
+ /**
14
+ * The content type of the request body.
15
+ * @default 'application/json' if body is not a FormData, undefined otherwise
16
+ */
5
17
  contentType?: string;
18
+ /**
19
+ * The expected status code of the response. If the response status code does not match this
20
+ * value, we will retry.
21
+ * @default 200
22
+ */
6
23
  expectedStatus?: number;
7
24
  searchParams?: Record<string, string>;
8
25
  body?: string | FormData;
26
+ /**
27
+ * Maximum number of retry attempts.
28
+ * @default 3
29
+ */
30
+ maxRetries?: number;
31
+ /**
32
+ * Base delay between retries in milliseconds.
33
+ * @default 1000
34
+ */
35
+ baseDelay?: number;
36
+ /**
37
+ * Whether to use exponential backoff for retry delays.
38
+ * @default true
39
+ */
40
+ useExponentialBackoff?: boolean;
41
+ /**
42
+ * Whether to respect rate limit headers and wait accordingly.
43
+ * @default true
44
+ */
45
+ respectRateLimit?: boolean;
9
46
  }
47
+ /**
48
+ * Fetch data from the Zenodo API with retry logic.
49
+ * @param zenodo - The Zenodo instance containing the base URL and access token.
50
+ * @param options - The options for the fetch request.
51
+ * @returns The response from the Zenodo API.
52
+ */
10
53
  export declare function fetchZenodo(zenodo: Zenodo, options: FetchZenodoOptions): Promise<Response>;
11
54
  export {};
12
55
  //# sourceMappingURL=fetchZenodo.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetchZenodo.d.ts","sourceRoot":"","sources":["../src/fetchZenodo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAGvC,UAAU,kBAAkB;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,IAAI,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC;CAC1B;AAED,wBAAsB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB,qBAwC5E"}
1
+ {"version":3,"file":"fetchZenodo.d.ts","sourceRoot":"","sources":["../src/fetchZenodo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAI1C,UAAU,kBAAkB;IAC1B;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,IAAI,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC;IACzB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AA0UD;;;;;GAKG;AACH,wBAAsB,WAAW,CAC/B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,QAAQ,CAAC,CAmDnB"}
@@ -1,9 +1,200 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fetchZenodo = fetchZenodo;
4
- const responseStatuses_1 = require("./responseStatuses");
5
- async function fetchZenodo(zenodo, options) {
6
- const { body, route = 'deposit/depositions', method = 'GET', contentType = body instanceof FormData ? undefined : 'application/json', expectedStatus = 200, searchParams, } = options;
1
+ import { ZenodoAuthenticationStates } from "./ZenodoAuthenticationStates.js";
2
+ import { responseStatuses } from "./responseStatuses.js";
3
+ /**
4
+ * Extract rate limit information from response headers.
5
+ * @param response - The fetch response object.
6
+ * @returns The rate limit information or null if not present.
7
+ */
8
+ function extractRateLimitInfo(response) {
9
+ const limit = response.headers.get('X-RateLimit-Limit');
10
+ const remaining = response.headers.get('X-RateLimit-Remaining');
11
+ const reset = response.headers.get('X-RateLimit-Reset');
12
+ if (!limit || !remaining || !reset) {
13
+ return null;
14
+ }
15
+ return {
16
+ limit: Number.parseInt(limit, 10),
17
+ remaining: Number.parseInt(remaining, 10),
18
+ reset: Number.parseInt(reset, 10),
19
+ };
20
+ }
21
+ /**
22
+ * Calculate delay based on rate limit information.
23
+ * @param rateLimitInfo - The rate limit information extracted from response headers.
24
+ * @returns Delay in milliseconds to wait before retrying.
25
+ */
26
+ function calculateRateLimitDelay(rateLimitInfo) {
27
+ if (rateLimitInfo.remaining > 0) {
28
+ return 0;
29
+ }
30
+ const now = Math.floor(Date.now() / 1000);
31
+ const waitTime = Math.max(0, rateLimitInfo.reset - now);
32
+ return (waitTime + 1) * 1000;
33
+ }
34
+ /**
35
+ * Determine if an error is retryable based on status code.
36
+ * @param status - The HTTP status code of the response.
37
+ * @param zenodo - The Zenodo instance
38
+ * @returns True if the error is retryable, false otherwise.
39
+ */
40
+ async function shouldRetry(status, zenodo) {
41
+ if (status === 429 || (status >= 500 && status < 600) || status === 408) {
42
+ zenodo.logger?.debug(`Retrying status ${status} - server/rate limit error`);
43
+ return true;
44
+ }
45
+ const isAuthError = (status === 401 || status === 403) &&
46
+ (zenodo.authenticationState === ZenodoAuthenticationStates.NOT_TRIED ||
47
+ zenodo.authenticationState === ZenodoAuthenticationStates.SUCCEEDED);
48
+ if (isAuthError) {
49
+ zenodo.logger?.debug(`Auth error detected (${status}), current state: ${zenodo.authenticationState}`);
50
+ zenodo.logger?.debug('Attempting to verify authentication...');
51
+ try {
52
+ await zenodo.verifyAuthentication();
53
+ zenodo.logger?.debug(`Authentication verification completed, new state: ${zenodo.authenticationState}`);
54
+ return true;
55
+ }
56
+ catch (error) {
57
+ zenodo.logger?.error(`Authentication verification failed: ${error instanceof Error ? error.message : String(error)}`);
58
+ return false;
59
+ }
60
+ }
61
+ return false;
62
+ }
63
+ /**
64
+ * Sleep for a specified number of milliseconds.
65
+ * @param ms - The number of milliseconds to sleep
66
+ */
67
+ function sleep(ms) {
68
+ return new Promise((resolve) => {
69
+ setTimeout(resolve, ms);
70
+ });
71
+ }
72
+ /**
73
+ * Calculate the appropriate delay for a retry attempt.
74
+ * @param attempt - Current attempt number (0-based)
75
+ * @param response - The failed response
76
+ * @param rateLimitInfo - Rate limit information from headers
77
+ * @param options - Retry options
78
+ * @returns Delay in milliseconds
79
+ */
80
+ function calculateRetryDelay(attempt, response, rateLimitInfo, options) {
81
+ const { baseDelay = 1000, useExponentialBackoff = true, respectRateLimit = true, } = options;
82
+ if (response.status === 429 && respectRateLimit && rateLimitInfo) {
83
+ // Rate limit hit - respect the rate limit headers
84
+ return calculateRateLimitDelay(rateLimitInfo);
85
+ }
86
+ // Other retryable error - use exponential backoff
87
+ const delay = useExponentialBackoff ? baseDelay * 2 ** attempt : baseDelay;
88
+ // Add jitter to prevent thundering herd
89
+ return delay + Math.random() * 1000;
90
+ }
91
+ /**
92
+ * Perform a single fetch attempt.
93
+ * @param zenodo - The Zenodo instance
94
+ * @param url - The URL to fetch
95
+ * @param requestOptions - The fetch options
96
+ * @param expectedStatus - The expected response status
97
+ * @param attempt - Current attempt number (0-based)
98
+ * @returns The response or throws an error
99
+ */
100
+ async function performFetchAttempt(zenodo, url, requestOptions, expectedStatus, attempt) {
101
+ zenodo.logger?.debug(`Attempt ${attempt + 1} for ${requestOptions.method} ${url}`);
102
+ const response = await fetch(url, requestOptions);
103
+ // Check rate limit headers
104
+ const rateLimitInfo = extractRateLimitInfo(response);
105
+ if (rateLimitInfo && zenodo.logger) {
106
+ zenodo.logger.debug(`Rate limit status: ${rateLimitInfo.remaining}/${rateLimitInfo.limit} remaining, resets at ${rateLimitInfo.reset}`);
107
+ }
108
+ return response;
109
+ }
110
+ /**
111
+ * Handle a failed response and determine if retry is appropriate.
112
+ * @param zenodo - The Zenodo instance
113
+ * @param response - The failed response
114
+ * @param url - The request URL
115
+ * @param method - The request method
116
+ * @param contentType - The request content type
117
+ * @param body - The request body
118
+ * @returns Error to throw
119
+ */
120
+ async function handleFailedResponse(zenodo, response, url, method, contentType, body) {
121
+ const errorMessage = responseStatuses[response.status]?.description || response.statusText;
122
+ if (!(await shouldRetry(response.status, zenodo))) {
123
+ zenodo.logger?.error(`Non-retryable error fetching ${url} with ${method}: ${errorMessage}`);
124
+ }
125
+ return new Error(errorMessage, {
126
+ cause: { url, method, contentType, body, response },
127
+ });
128
+ }
129
+ /**
130
+ * Retry logic using recursive approach to avoid await in loops.
131
+ * @param zenodo - The Zenodo instance
132
+ * @param url - The URL to fetch
133
+ * @param requestOptions - The fetch options
134
+ * @param fetchOptions - The original fetch options
135
+ * @param attempt - Current attempt number (0-based)
136
+ * @returns The successful response
137
+ */
138
+ async function retryFetch(zenodo, url, requestOptions, fetchOptions, attempt) {
139
+ const { expectedStatus, maxRetries, method = 'GET', contentType, body, } = fetchOptions;
140
+ try {
141
+ const response = await performFetchAttempt(zenodo, url, requestOptions, expectedStatus, attempt);
142
+ if (response.status === expectedStatus) {
143
+ if (attempt > 0) {
144
+ zenodo.logger?.info(`Request succeeded after ${attempt} retries`);
145
+ }
146
+ return response;
147
+ }
148
+ if (!(await shouldRetry(response.status, zenodo))) {
149
+ throw await handleFailedResponse(zenodo, response, url, method, contentType, body);
150
+ }
151
+ if (attempt >= maxRetries) {
152
+ throw await handleFailedResponse(zenodo, response, url, method, contentType, body);
153
+ }
154
+ const rateLimitInfo = extractRateLimitInfo(response);
155
+ const delay = calculateRetryDelay(attempt, response, rateLimitInfo, fetchOptions);
156
+ if (response.status === 429 &&
157
+ fetchOptions.respectRateLimit &&
158
+ rateLimitInfo) {
159
+ zenodo.logger?.warn(`Rate limit exceeded. Waiting ${delay}ms before retry (attempt ${attempt + 1}/${maxRetries + 1})`);
160
+ }
161
+ else {
162
+ zenodo.logger?.warn(`Retryable error (${response.status}). Waiting ${delay}ms before retry (attempt ${attempt + 1}/${maxRetries + 1})`);
163
+ }
164
+ await sleep(delay);
165
+ return await retryFetch(zenodo, url, requestOptions, fetchOptions, attempt + 1);
166
+ }
167
+ catch (error) {
168
+ if (error instanceof Error) {
169
+ if (error.cause &&
170
+ typeof error.cause === 'object' &&
171
+ 'response' in error.cause) {
172
+ throw error;
173
+ }
174
+ if (attempt >= maxRetries) {
175
+ zenodo.logger?.error(`All ${maxRetries + 1} attempts failed for ${method} ${url}`);
176
+ throw error;
177
+ }
178
+ const delay = fetchOptions.useExponentialBackoff
179
+ ? fetchOptions.baseDelay * 2 ** attempt
180
+ : fetchOptions.baseDelay;
181
+ zenodo.logger?.warn(`Network error: ${error.message}. Waiting ${delay}ms before retry (attempt ${attempt + 1}/${maxRetries + 1})`);
182
+ await sleep(delay);
183
+ return retryFetch(zenodo, url, requestOptions, fetchOptions, attempt + 1);
184
+ }
185
+ else {
186
+ throw error;
187
+ }
188
+ }
189
+ }
190
+ /**
191
+ * Fetch data from the Zenodo API with retry logic.
192
+ * @param zenodo - The Zenodo instance containing the base URL and access token.
193
+ * @param options - The options for the fetch request.
194
+ * @returns The response from the Zenodo API.
195
+ */
196
+ export async function fetchZenodo(zenodo, options) {
197
+ const { body, route = 'deposit/depositions', method = 'GET', contentType = body instanceof FormData ? undefined : 'application/json', expectedStatus = 200, searchParams, maxRetries = 3, baseDelay = 1000, useExponentialBackoff = true, respectRateLimit = true, } = options;
7
198
  let url;
8
199
  if (searchParams) {
9
200
  const urlSearchParams = new URLSearchParams(searchParams);
@@ -15,20 +206,28 @@ async function fetchZenodo(zenodo, options) {
15
206
  else {
16
207
  url = zenodo.baseURL + route;
17
208
  }
18
- const headers = new Headers({
19
- Authorization: `Bearer ${zenodo.accessToken}`,
20
- });
209
+ const headers = new Headers();
210
+ if (zenodo.accessToken) {
211
+ headers.set('Authorization', `Bearer ${zenodo.accessToken}`);
212
+ }
21
213
  if (contentType) {
22
214
  headers.set('Content-Type', contentType);
23
215
  }
24
- const response = await fetch(url, {
216
+ const requestOptions = {
25
217
  method,
26
218
  headers,
27
219
  body,
28
- });
29
- if (response.status !== expectedStatus) {
30
- throw new Error(responseStatuses_1.responseStatuses[response.status]?.description || response.statusText, { cause: { url, method, contentType, body, response } });
31
- }
32
- return response;
220
+ };
221
+ const fetchOptionsWithDefaults = {
222
+ expectedStatus,
223
+ maxRetries,
224
+ baseDelay,
225
+ useExponentialBackoff,
226
+ respectRateLimit,
227
+ method,
228
+ contentType,
229
+ body,
230
+ };
231
+ return retryFetch(zenodo, url, requestOptions, fetchOptionsWithDefaults, 0);
33
232
  }
34
233
  //# sourceMappingURL=fetchZenodo.js.map