zenodo 1.0.1 → 2.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 (78) hide show
  1. package/README.md +48 -0
  2. package/lib/Zenodo.d.ts +19 -0
  3. package/lib/Zenodo.d.ts.map +1 -0
  4. package/lib/Zenodo.js +55 -0
  5. package/lib/Zenodo.js.map +1 -0
  6. package/lib/ZenodoFile.d.ts +45 -0
  7. package/lib/ZenodoFile.d.ts.map +1 -0
  8. package/lib/ZenodoFile.js +37 -0
  9. package/lib/ZenodoFile.js.map +1 -0
  10. package/lib/depositions/Deposition.d.ts +14 -0
  11. package/lib/depositions/Deposition.d.ts.map +1 -0
  12. package/lib/depositions/Deposition.js +55 -0
  13. package/lib/depositions/Deposition.js.map +1 -0
  14. package/lib/depositions/ListDepositionsOptions.d.ts +32 -0
  15. package/lib/depositions/ListDepositionsOptions.d.ts.map +1 -0
  16. package/lib/depositions/ListDepositionsOptions.js +3 -0
  17. package/lib/depositions/ListDepositionsOptions.js.map +1 -0
  18. package/lib/depositions/depositionSchema.d.ts +982 -0
  19. package/lib/depositions/depositionSchema.d.ts.map +1 -0
  20. package/lib/depositions/depositionSchema.js +141 -0
  21. package/lib/depositions/depositionSchema.js.map +1 -0
  22. package/lib/fetchZenodo.d.ts +12 -0
  23. package/lib/fetchZenodo.d.ts.map +1 -0
  24. package/lib/fetchZenodo.js +34 -0
  25. package/lib/fetchZenodo.js.map +1 -0
  26. package/lib/index.d.ts +2 -0
  27. package/lib/index.d.ts.map +1 -0
  28. package/lib/index.js +18 -0
  29. package/lib/index.js.map +1 -0
  30. package/lib/responseStatuses.d.ts +8 -0
  31. package/lib/responseStatuses.d.ts.map +1 -0
  32. package/lib/responseStatuses.js +71 -0
  33. package/lib/responseStatuses.js.map +1 -0
  34. package/lib-esm/Zenodo.d.ts +19 -0
  35. package/lib-esm/Zenodo.d.ts.map +1 -0
  36. package/lib-esm/Zenodo.js +51 -0
  37. package/lib-esm/Zenodo.js.map +1 -0
  38. package/lib-esm/ZenodoFile.d.ts +45 -0
  39. package/lib-esm/ZenodoFile.d.ts.map +1 -0
  40. package/lib-esm/ZenodoFile.js +33 -0
  41. package/lib-esm/ZenodoFile.js.map +1 -0
  42. package/lib-esm/depositions/Deposition.d.ts +14 -0
  43. package/lib-esm/depositions/Deposition.d.ts.map +1 -0
  44. package/lib-esm/depositions/Deposition.js +51 -0
  45. package/lib-esm/depositions/Deposition.js.map +1 -0
  46. package/lib-esm/depositions/ListDepositionsOptions.d.ts +32 -0
  47. package/lib-esm/depositions/ListDepositionsOptions.d.ts.map +1 -0
  48. package/lib-esm/depositions/ListDepositionsOptions.js +2 -0
  49. package/lib-esm/depositions/ListDepositionsOptions.js.map +1 -0
  50. package/lib-esm/depositions/depositionSchema.d.ts +982 -0
  51. package/lib-esm/depositions/depositionSchema.d.ts.map +1 -0
  52. package/lib-esm/depositions/depositionSchema.js +138 -0
  53. package/lib-esm/depositions/depositionSchema.js.map +1 -0
  54. package/lib-esm/fetchZenodo.d.ts +12 -0
  55. package/lib-esm/fetchZenodo.d.ts.map +1 -0
  56. package/lib-esm/fetchZenodo.js +31 -0
  57. package/lib-esm/fetchZenodo.js.map +1 -0
  58. package/lib-esm/index.d.ts +2 -0
  59. package/lib-esm/index.d.ts.map +1 -0
  60. package/lib-esm/index.js +2 -0
  61. package/lib-esm/index.js.map +1 -0
  62. package/lib-esm/responseStatuses.d.ts +8 -0
  63. package/lib-esm/responseStatuses.d.ts.map +1 -0
  64. package/lib-esm/responseStatuses.js +68 -0
  65. package/lib-esm/responseStatuses.js.map +1 -0
  66. package/package.json +36 -7
  67. package/src/Zenodo.ts +68 -0
  68. package/src/ZenodoFile.ts +40 -0
  69. package/src/__tests__/Zenodo.test.ts +79 -0
  70. package/src/__tests__/getConfig.ts +9 -0
  71. package/src/depositions/Deposition.ts +60 -0
  72. package/src/depositions/ListDepositionsOptions.ts +36 -0
  73. package/src/depositions/depositionSchema.ts +154 -0
  74. package/src/fetchZenodo.ts +53 -0
  75. package/src/index.ts +1 -0
  76. package/src/responseStatuses.ts +85 -0
  77. package/History.md +0 -66
  78. package/src/index.js +0 -170
@@ -0,0 +1 @@
1
+ {"version":3,"file":"depositionSchema.d.ts","sourceRoot":"","sources":["../../src/depositions/depositionSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AA4ExB,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAwDnC,CAAC;AAEH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAE1E,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAejC,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC"}
@@ -0,0 +1,138 @@
1
+ import { z } from 'zod';
2
+ import { zenodoFileSchema } from '../ZenodoFile';
3
+ const creatorSchema = z.object({
4
+ name: z.string(),
5
+ affiliation: z.union([z.string().optional(), z.null()]),
6
+ orcid: z.string().optional(),
7
+ gnd: z.string().optional(),
8
+ });
9
+ const relatedIdentifierSchema = z.object({
10
+ identifier: z.string(),
11
+ relation: z.string(),
12
+ resource_type: z.string().optional(),
13
+ });
14
+ const contributorSchema = z.object({
15
+ name: z.string(),
16
+ type: z.string(),
17
+ affiliation: z.string().optional(),
18
+ orcid: z.string().optional(),
19
+ gnd: z.string().optional(),
20
+ });
21
+ const communitySchema = z.object({
22
+ identifier: z.string(),
23
+ });
24
+ const grantSchema = z.object({
25
+ id: z.string(),
26
+ });
27
+ const subjectSchema = z.object({
28
+ term: z.string(),
29
+ identifier: z.string(),
30
+ scheme: z.string(),
31
+ });
32
+ const locationSchema = z.object({
33
+ lat: z.number().optional(),
34
+ lon: z.number().optional(),
35
+ place: z.string(),
36
+ description: z.string().optional(),
37
+ });
38
+ const dateIntervalSchema = z.object({
39
+ start: z.string().optional(),
40
+ end: z.string().optional(),
41
+ type: z.string(),
42
+ description: z.string().optional(),
43
+ });
44
+ // API returns microseconds in timestamps that is not supported for ISO 8601 default validation
45
+ const iso8601WithMicroseconds = z
46
+ .string()
47
+ .refine((value) => !Number.isNaN(Date.parse(value)), {
48
+ message: 'Invalid datetime format',
49
+ });
50
+ const linksSchema = z
51
+ .object({
52
+ self: z.string().url(),
53
+ html: z.string().url(),
54
+ badge: z.string().url(),
55
+ files: z.string().url(),
56
+ latest_draft: z.string().url(),
57
+ latest_draft_html: z.string().url(),
58
+ publish: z.string().url(),
59
+ edit: z.string().url(),
60
+ discard: z.string().url(),
61
+ newversion: z.string().url(),
62
+ registerconceptdoi: z.string().url(),
63
+ })
64
+ .catchall(z.string().url()); // Allows extra keys with URL values
65
+ export const depositionMetadataSchema = z.object({
66
+ upload_type: z.enum([
67
+ 'publication',
68
+ 'poster',
69
+ 'presentation',
70
+ 'dataset',
71
+ 'image',
72
+ 'video',
73
+ 'software',
74
+ 'lesson',
75
+ 'physicalobject',
76
+ 'other',
77
+ ]),
78
+ publication_type: z.string().optional(),
79
+ image_type: z.string().optional(),
80
+ publication_date: z.string().optional(),
81
+ title: z.string(),
82
+ creators: z.array(creatorSchema),
83
+ description: z.string(),
84
+ access_right: z.enum(['open', 'embargoed', 'restricted', 'closed']),
85
+ license: z.string().optional(),
86
+ embargo_date: z.string().optional(),
87
+ access_conditions: z.string().optional(),
88
+ doi: z.string().optional(),
89
+ prereserve_doi: z.union([z.boolean(), z.record(z.unknown())]).optional(),
90
+ keywords: z.array(z.string()).optional(),
91
+ notes: z.string().optional(),
92
+ related_identifiers: z.array(relatedIdentifierSchema).optional(),
93
+ contributors: z.array(contributorSchema).optional(),
94
+ references: z.array(z.string()).optional(),
95
+ communities: z.array(communitySchema).optional(),
96
+ grants: z.array(grantSchema).optional(),
97
+ journal_title: z.string().optional(),
98
+ journal_volume: z.string().optional(),
99
+ journal_issue: z.string().optional(),
100
+ journal_pages: z.string().optional(),
101
+ conference_title: z.string().optional(),
102
+ conference_acronym: z.string().optional(),
103
+ conference_dates: z.string().optional(),
104
+ conference_place: z.string().optional(),
105
+ conference_url: z.string().optional(),
106
+ conference_session: z.string().optional(),
107
+ conference_session_part: z.string().optional(),
108
+ imprint_publisher: z.string().optional(),
109
+ imprint_isbn: z.string().optional(),
110
+ imprint_place: z.string().optional(),
111
+ partof_title: z.string().optional(),
112
+ partof_pages: z.string().optional(),
113
+ thesis_supervisors: z.array(creatorSchema).optional(),
114
+ thesis_university: z.string().optional(),
115
+ subjects: z.array(subjectSchema).optional(),
116
+ version: z.string().optional(),
117
+ language: z.string().optional(),
118
+ locations: z.array(locationSchema).optional(),
119
+ dates: z.array(dateIntervalSchema).optional(),
120
+ method: z.string().optional(),
121
+ });
122
+ export const zenodoDepositionSchema = z.object({
123
+ created: iso8601WithMicroseconds, // ISO8601 timestamp
124
+ modified: iso8601WithMicroseconds, // ISO8601 timestamp
125
+ id: z.number(),
126
+ metadata: depositionMetadataSchema,
127
+ title: z.string(),
128
+ doi: z.string().optional(), // Present only for published depositions
129
+ doi_url: z.string().url().optional(), // URL to DOI
130
+ record_url: z.string().url().optional(), // URL to public version of record
131
+ links: linksSchema,
132
+ record_id: z.number().optional(), // Present only for published depositions
133
+ owner: z.number(),
134
+ files: z.array(zenodoFileSchema),
135
+ state: z.enum(['unsubmitted', 'inprogress', 'done', 'error']),
136
+ submitted: z.boolean(),
137
+ });
138
+ //# sourceMappingURL=depositionSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"depositionSchema.js","sourceRoot":"","sources":["../../src/depositions/depositionSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEjD,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7B,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,WAAW,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,IAAI,E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IACd,QAAQ,EAAE,wBAAwB;IAClC,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;IACjB,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,EAAE,yCAAyC;IACrE,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,EAAE,aAAa;IACnD,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,EAAE,kCAAkC;IAC3E,KAAK,EAAE,WAAW;IAClB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,EAAE,yCAAyC;IAC3E,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;IACjB,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,gBAAgB,CAAC;IAChC,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,aAAa,EAAE,YAAY,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7D,SAAS,EAAE,CAAC,CAAC,OAAO,EAAE;CACvB,CAAC,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { Zenodo } from './Zenodo';
2
+ interface FetchZenodoOptions {
3
+ route?: string;
4
+ method?: string;
5
+ contentType?: string;
6
+ expectedStatus?: number;
7
+ searchParams?: Record<string, string>;
8
+ body?: string | FormData;
9
+ }
10
+ export declare function fetchZenodo(zenodo: Zenodo, options: FetchZenodoOptions): Promise<Response>;
11
+ export {};
12
+ //# sourceMappingURL=fetchZenodo.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,31 @@
1
+ import { responseStatuses } from './responseStatuses';
2
+ export async function fetchZenodo(zenodo, options) {
3
+ const { body, route = 'deposit/depositions', method = 'GET', contentType = body instanceof FormData ? undefined : 'application/json', expectedStatus = 200, searchParams, } = options;
4
+ let url;
5
+ if (searchParams) {
6
+ const urlSearchParams = new URLSearchParams(searchParams);
7
+ url =
8
+ zenodo.baseURL +
9
+ route +
10
+ (urlSearchParams ? `?${urlSearchParams.toString()}` : '');
11
+ }
12
+ else {
13
+ url = zenodo.baseURL + route;
14
+ }
15
+ const headers = new Headers({
16
+ Authorization: `Bearer ${zenodo.accessToken}`,
17
+ });
18
+ if (contentType) {
19
+ headers.set('Content-Type', contentType);
20
+ }
21
+ const response = await fetch(url, {
22
+ method,
23
+ headers,
24
+ body,
25
+ });
26
+ if (response.status !== expectedStatus) {
27
+ throw new Error(responseStatuses[response.status]?.description || response.statusText, { cause: { url, method, contentType, body, response } });
28
+ }
29
+ return response;
30
+ }
31
+ //# sourceMappingURL=fetchZenodo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetchZenodo.js","sourceRoot":"","sources":["../src/fetchZenodo.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAWtD,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,MAAc,EAAE,OAA2B;IAC3E,MAAM,EACJ,IAAI,EACJ,KAAK,GAAG,qBAAqB,EAC7B,MAAM,GAAG,KAAK,EACd,WAAW,GAAG,IAAI,YAAY,QAAQ,CAAC,CAAC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],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './Zenodo';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
@@ -0,0 +1,8 @@
1
+ interface ResponseStatusInfo {
2
+ code: number;
3
+ name: string;
4
+ description: string;
5
+ }
6
+ export declare const responseStatuses: Record<number, ResponseStatusInfo>;
7
+ export {};
8
+ //# sourceMappingURL=responseStatuses.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"responseStatuses.d.ts","sourceRoot":"","sources":["../src/responseStatuses.ts"],"names":[],"mappings":"AAAA,UAAU,kBAAkB;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CA8E/D,CAAC"}
@@ -0,0 +1,68 @@
1
+ export const responseStatuses = {
2
+ 200: {
3
+ code: 200,
4
+ name: 'OK',
5
+ description: 'Request succeeded. Response included. Usually sent for GET/PUT/PATCH requests.',
6
+ },
7
+ 201: {
8
+ code: 201,
9
+ name: 'Created',
10
+ description: 'Request succeeded. Response included. Usually sent for POST requests.',
11
+ },
12
+ 202: {
13
+ code: 202,
14
+ name: 'Accepted',
15
+ description: 'Request succeeded. Response included. Usually sent for POST requests, where background processing is needed to fulfill the request.',
16
+ },
17
+ 204: {
18
+ code: 204,
19
+ name: 'No Content',
20
+ description: 'Request succeeded. No response included. Usually sent for DELETE requests.',
21
+ },
22
+ 400: {
23
+ code: 400,
24
+ name: 'Bad Request',
25
+ description: 'Request failed. Error response included.',
26
+ },
27
+ 401: {
28
+ code: 401,
29
+ name: 'Unauthorized',
30
+ description: 'Request failed, due to an invalid access token. Error response included.',
31
+ },
32
+ 403: {
33
+ code: 403,
34
+ name: 'Forbidden',
35
+ description: 'Request failed, due to missing authorization (e.g. deleting an already submitted upload or missing scopes for your access token). Error response included.',
36
+ },
37
+ 404: {
38
+ code: 404,
39
+ name: 'Not Found',
40
+ description: 'Request failed, due to the resource not being found. Error response included.',
41
+ },
42
+ 405: {
43
+ code: 405,
44
+ name: 'Method Not Allowed',
45
+ description: 'Request failed, due to unsupported HTTP method. Error response included.',
46
+ },
47
+ 409: {
48
+ code: 409,
49
+ name: 'Conflict',
50
+ description: 'Request failed, due to the current state of the resource (e.g. edit a deposition which is not fully integrated). Error response included.',
51
+ },
52
+ 415: {
53
+ code: 415,
54
+ name: 'Unsupported Media Type',
55
+ description: 'Request failed, due to missing or invalid request header Content-Type. Error response included.',
56
+ },
57
+ 429: {
58
+ code: 429,
59
+ name: 'Too Many Requests',
60
+ description: 'Request failed, due to rate limiting. Error response included.',
61
+ },
62
+ 500: {
63
+ code: 500,
64
+ name: 'Internal Server Error',
65
+ description: 'Request failed, due to an internal server error. Error response NOT included. Don’t worry, Zenodo admins have been notified and will be dealing with the problem ASAP.',
66
+ },
67
+ };
68
+ //# sourceMappingURL=responseStatuses.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"responseStatuses.js","sourceRoot":"","sources":["../src/responseStatuses.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,MAAM,gBAAgB,GAAuC;IAClE,GAAG,EAAE;QACH,IAAI,EAAE,GAAG;QACT,IAAI,EAAE,IAAI;QACV,WAAW,EACT,gFAAgF;KACnF;IACD,GAAG,EAAE;QACH,IAAI,EAAE,GAAG;QACT,IAAI,EAAE,SAAS;QACf,WAAW,EACT,uEAAuE;KAC1E;IACD,GAAG,EAAE;QACH,IAAI,EAAE,GAAG;QACT,IAAI,EAAE,UAAU;QAChB,WAAW,EACT,qIAAqI;KACxI;IACD,GAAG,EAAE;QACH,IAAI,EAAE,GAAG;QACT,IAAI,EAAE,YAAY;QAClB,WAAW,EACT,4EAA4E;KAC/E;IACD,GAAG,EAAE;QACH,IAAI,EAAE,GAAG;QACT,IAAI,EAAE,aAAa;QACnB,WAAW,EAAE,0CAA0C;KACxD;IACD,GAAG,EAAE;QACH,IAAI,EAAE,GAAG;QACT,IAAI,EAAE,cAAc;QACpB,WAAW,EACT,0EAA0E;KAC7E;IACD,GAAG,EAAE;QACH,IAAI,EAAE,GAAG;QACT,IAAI,EAAE,WAAW;QACjB,WAAW,EACT,4JAA4J;KAC/J;IACD,GAAG,EAAE;QACH,IAAI,EAAE,GAAG;QACT,IAAI,EAAE,WAAW;QACjB,WAAW,EACT,+EAA+E;KAClF;IACD,GAAG,EAAE;QACH,IAAI,EAAE,GAAG;QACT,IAAI,EAAE,oBAAoB;QAC1B,WAAW,EACT,0EAA0E;KAC7E;IACD,GAAG,EAAE;QACH,IAAI,EAAE,GAAG;QACT,IAAI,EAAE,UAAU;QAChB,WAAW,EACT,2IAA2I;KAC9I;IACD,GAAG,EAAE;QACH,IAAI,EAAE,GAAG;QACT,IAAI,EAAE,wBAAwB;QAC9B,WAAW,EACT,iGAAiG;KACpG;IACD,GAAG,EAAE;QACH,IAAI,EAAE,GAAG;QACT,IAAI,EAAE,mBAAmB;QACzB,WAAW,EACT,gEAAgE;KACnE;IACD,GAAG,EAAE;QACH,IAAI,EAAE,GAAG;QACT,IAAI,EAAE,uBAAuB;QAC7B,WAAW,EACT,wKAAwK;KAC3K;CACF,CAAC"}
package/package.json CHANGED
@@ -1,16 +1,35 @@
1
1
  {
2
2
  "name": "zenodo",
3
- "version": "1.0.1",
3
+ "version": "2.0.0",
4
4
  "description": "Node.js library to access the Zenodo API",
5
- "main": "src/index.js",
5
+ "main": "./lib/index.js",
6
+ "module": "./lib-esm/index.js",
7
+ "types": "./lib/index.d.ts",
8
+ "files": [
9
+ "src",
10
+ "lib",
11
+ "lib-esm"
12
+ ],
6
13
  "scripts": {
7
- "test": "echo OK"
14
+ "build": "npm run tsc-esm && cheminfo-build --entry lib-esm/index.js --root Zenodo",
15
+ "build-watch": "fswatch -o src | xargs -n1 -I{} npm run build",
16
+ "check-types": "tsc --noEmit",
17
+ "clean": "rimraf lib lib-esm",
18
+ "eslint": "eslint src",
19
+ "eslint-fix": "npm run eslint -- --fix",
20
+ "prepack": "npm run tsc",
21
+ "prettier": "prettier --check src",
22
+ "prettier-write": "prettier --write src",
23
+ "test": "npm run test-only && npm run eslint && npm run prettier && npm run check-types",
24
+ "test-only": "vitest run --coverage",
25
+ "tsc": "npm run clean && npm run tsc-cjs && npm run tsc-esm",
26
+ "tsc-cjs": "tsc --project tsconfig.cjs.json",
27
+ "tsc-esm": "tsc --project tsconfig.esm.json"
8
28
  },
9
29
  "repository": {
10
30
  "type": "git",
11
31
  "url": "git+https://github.com/cheminfo/zenodo.git"
12
32
  },
13
- "files": ["src"],
14
33
  "keywords": [],
15
34
  "author": "Michaël Zasso",
16
35
  "license": "MIT",
@@ -18,8 +37,18 @@
18
37
  "url": "https://github.com/cheminfo/zenodo/issues"
19
38
  },
20
39
  "homepage": "https://github.com/cheminfo/zenodo#readme",
21
- "dependencies": {
22
- "axios": "^0.18.0"
40
+ "devDependencies": {
41
+ "@types/node": "^22.13.4",
42
+ "@vitest/coverage-v8": "^3.0.5",
43
+ "cheminfo-build": "^1.2.1",
44
+ "dotenv": "^16.4.7",
45
+ "eslint": "^9.20.1",
46
+ "eslint-config-cheminfo-typescript": "^17.0.0",
47
+ "prettier": "^3.5.1",
48
+ "rimraf": "^6.0.1",
49
+ "vitest": "^3.0.5"
23
50
  },
24
- "devDependencies": {}
51
+ "dependencies": {
52
+ "zod": "^3.24.2"
53
+ }
25
54
  }
package/src/Zenodo.ts ADDED
@@ -0,0 +1,68 @@
1
+ import { Deposition } from './depositions/Deposition';
2
+ import type { ListDepositionsOptions } from './depositions/ListDepositionsOptions';
3
+ import type { DepositionMetadata } from './depositions/depositionSchema';
4
+ import { fetchZenodo } from './fetchZenodo';
5
+
6
+ interface ZenodoOptions {
7
+ accessToken: string;
8
+ host?: string;
9
+ }
10
+ export class Zenodo {
11
+ host: string;
12
+ accessToken: string;
13
+ baseURL: string;
14
+
15
+ constructor(options: ZenodoOptions) {
16
+ const { accessToken, host = 'sandbox.zenodo.org' } = options;
17
+ this.host = host;
18
+ this.baseURL = `https://${host}/api/`;
19
+ if (!accessToken) {
20
+ throw new Error('accessToken is required');
21
+ }
22
+ this.accessToken = accessToken;
23
+ }
24
+
25
+ async listDepositions(
26
+ options: ListDepositionsOptions = {},
27
+ ): Promise<Deposition[]> {
28
+ // all the values must be string
29
+ const optionsWithStrings = Object.fromEntries(
30
+ Object.entries(options).map(([key, value]) => [key, String(value)]),
31
+ );
32
+ const response = await fetchZenodo(this, {
33
+ route: 'deposit/depositions',
34
+ searchParams: optionsWithStrings,
35
+ });
36
+ const depositions = (await response.json()) as unknown[];
37
+ return depositions.map(
38
+ (deposition: unknown) => new Deposition(this, deposition),
39
+ );
40
+ }
41
+
42
+ async createDeposition(metadata: DepositionMetadata): Promise<Deposition> {
43
+ const response = await fetchZenodo(this, {
44
+ route: 'deposit/depositions',
45
+ expectedStatus: 201,
46
+ method: 'POST',
47
+ body: JSON.stringify({ metadata }),
48
+ });
49
+ const deposition = new Deposition(this, await response.json());
50
+ return deposition;
51
+ }
52
+
53
+ async retrieveDeposition(id: number): Promise<Deposition> {
54
+ const response = await fetchZenodo(this, {
55
+ route: `deposit/depositions/${id}`,
56
+ });
57
+ const deposition = await response.json();
58
+ return new Deposition(this, deposition);
59
+ }
60
+
61
+ async deleteDeposition(id: number): Promise<void> {
62
+ await fetchZenodo(this, {
63
+ method: 'DELETE',
64
+ route: `deposit/depositions/${id}`,
65
+ expectedStatus: 204,
66
+ });
67
+ }
68
+ }
@@ -0,0 +1,40 @@
1
+ import { z } from 'zod';
2
+
3
+ import type { Zenodo } from './Zenodo';
4
+
5
+ // Define the Zod schema
6
+ export const zenodoFileSchema = z.object({
7
+ id: z.string(),
8
+ filename: z.string(),
9
+ filesize: z.number(),
10
+ checksum: z.string(),
11
+ links: z.object({
12
+ download: z.string().url(),
13
+ self: z.string().url(),
14
+ }),
15
+ });
16
+
17
+ type ZenodoFileType = z.infer<typeof zenodoFileSchema>;
18
+
19
+ export class ZenodoFile {
20
+ private zenodo: Zenodo;
21
+ public value: ZenodoFileType;
22
+
23
+ constructor(zenodo: Zenodo, file: unknown) {
24
+ this.value = zenodoFileSchema.parse(file);
25
+ this.zenodo = zenodo;
26
+ }
27
+
28
+ async getContentResponse() {
29
+ const link = this.value.links.download;
30
+ const response = await fetch(link, {
31
+ headers: {
32
+ Authorization: `Bearer ${this.zenodo.accessToken}`,
33
+ },
34
+ });
35
+ if (!response.ok) {
36
+ throw new Error(`Failed to fetch ${link}`);
37
+ }
38
+ return response;
39
+ }
40
+ }
@@ -0,0 +1,79 @@
1
+ /* eslint-disable no-await-in-loop */
2
+ /* eslint-disable no-new */
3
+ import { test, expect } from 'vitest';
4
+
5
+ import { Zenodo } from '../Zenodo';
6
+ import type { DepositionMetadata } from '../depositions/depositionSchema';
7
+
8
+ import { getConfig } from './getConfig';
9
+
10
+ const config = getConfig();
11
+
12
+ test('no token', async () => {
13
+ expect(() => {
14
+ // @ts-expect-error we are testing the error
15
+ new Zenodo({
16
+ host: 'sandbox.zenodo.org',
17
+ });
18
+ }).toThrow('accessToken is required');
19
+ });
20
+
21
+ test('authenticate', async () => {
22
+ const zenodo = new Zenodo({
23
+ host: 'sandbox.zenodo.org',
24
+ accessToken: config.accessToken || '',
25
+ });
26
+
27
+ const existing = await zenodo.listDepositions();
28
+
29
+ const depositionMetadata: DepositionMetadata = {
30
+ upload_type: 'dataset',
31
+ description: 'test',
32
+ access_right: 'open',
33
+ title: 'test dataset from npm library zenodo',
34
+ creators: [
35
+ {
36
+ name: 'test',
37
+ },
38
+ ],
39
+ };
40
+
41
+ const firstDeposition = await zenodo.createDeposition(depositionMetadata);
42
+ // we could attach a file. We need a 'native' web file
43
+ const firstFileData = new File(['Hello, world!'], 'example.txt', {
44
+ type: 'text/plain',
45
+ });
46
+ const firstFile = await firstDeposition.createFile(firstFileData);
47
+ expect(firstFile.value.filesize).toBe(13);
48
+ expect(firstFile.value.checksum).toBe('6cd3556deb0da54bca060b4c39479839');
49
+
50
+ const secondFileData = new File(['Hello, world 2!'], 'example2.txt', {
51
+ type: 'text/plain',
52
+ });
53
+ const secondFile = await firstDeposition.createFile(secondFileData);
54
+ expect(secondFile.value.filesize).toBe(15);
55
+ expect(secondFile.value.checksum).toBe('9500d92e2fa89ecbdc90cd890ca16ed0');
56
+
57
+ const files = await firstDeposition.listFiles();
58
+ files.sort((a, b) => a.value.filename.localeCompare(b.value.filename));
59
+
60
+ expect(files).toHaveLength(2);
61
+
62
+ await firstDeposition.deleteFile(files[1].value.id);
63
+ const filesAfterDelete = await firstDeposition.listFiles();
64
+ expect(filesAfterDelete).toHaveLength(1);
65
+
66
+ const retrievedFile = await firstDeposition.retrieveFile(files[0].value.id);
67
+ expect(retrievedFile.value.filename).toBe('example.txt');
68
+
69
+ const content = await retrievedFile
70
+ .getContentResponse()
71
+ .then((response) => response.text());
72
+
73
+ expect(content).toBe('Hello, world!');
74
+
75
+ // we delete everything
76
+ for (const deposition of existing) {
77
+ await zenodo.deleteDeposition(deposition.value.id);
78
+ }
79
+ });
@@ -0,0 +1,9 @@
1
+ import dotenv from 'dotenv';
2
+
3
+ dotenv.config();
4
+
5
+ export function getConfig(): { accessToken?: string } {
6
+ return {
7
+ accessToken: process.env.ACCESS_TOKEN,
8
+ };
9
+ }
@@ -0,0 +1,60 @@
1
+ import type { Zenodo } from '../Zenodo';
2
+ import { ZenodoFile } from '../ZenodoFile';
3
+ import { fetchZenodo } from '../fetchZenodo';
4
+
5
+ import { zenodoDepositionSchema } from './depositionSchema';
6
+ import type { DepositionMetadata, ZenodoDeposition } from './depositionSchema';
7
+
8
+ export class Deposition {
9
+ private zenodo: Zenodo;
10
+ public value: ZenodoDeposition;
11
+
12
+ constructor(zenodo: Zenodo, deposition: unknown) {
13
+ this.zenodo = zenodo;
14
+ this.value = zenodoDepositionSchema.parse(deposition);
15
+ }
16
+
17
+ async createFile(file: File): Promise<ZenodoFile> {
18
+ const formData = new FormData();
19
+ formData.append('file', file);
20
+ const response = await fetchZenodo(this.zenodo, {
21
+ route: `deposit/depositions/${this.value.id}/files`,
22
+ method: 'POST',
23
+ body: formData,
24
+ expectedStatus: 201,
25
+ });
26
+ return new ZenodoFile(this.zenodo, await response.json());
27
+ }
28
+
29
+ async listFiles(): Promise<ZenodoFile[]> {
30
+ const response = await fetchZenodo(this.zenodo, {
31
+ route: `deposit/depositions/${this.value.id}/files`,
32
+ });
33
+ const files = (await response.json()) as any[];
34
+ return files.map((file) => new ZenodoFile(this.zenodo, file));
35
+ }
36
+
37
+ async deleteFile(fileId: string): Promise<void> {
38
+ await fetchZenodo(this.zenodo, {
39
+ route: `deposit/depositions/${this.value.id}/files/${fileId}`,
40
+ method: 'DELETE',
41
+ expectedStatus: 204,
42
+ });
43
+ }
44
+
45
+ async retrieveFile(fileId: string): Promise<ZenodoFile> {
46
+ const response = await fetchZenodo(this.zenodo, {
47
+ route: `deposit/depositions/${this.value.id}/files/${fileId}`,
48
+ });
49
+ return new ZenodoFile(this.zenodo, await response.json());
50
+ }
51
+
52
+ async update(metadata: DepositionMetadata): Promise<Deposition> {
53
+ const response = await fetchZenodo(this.zenodo, {
54
+ route: `deposit/depositions/${this.value.id}`,
55
+ method: 'PUT',
56
+ body: JSON.stringify({ metadata }),
57
+ });
58
+ return new Deposition(this.zenodo, await response.json());
59
+ }
60
+ }