zenodo 1.0.2 → 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.
- package/README.md +48 -0
- package/lib/Zenodo.d.ts +19 -0
- package/lib/Zenodo.d.ts.map +1 -0
- package/lib/Zenodo.js +55 -0
- package/lib/Zenodo.js.map +1 -0
- package/lib/ZenodoFile.d.ts +45 -0
- package/lib/ZenodoFile.d.ts.map +1 -0
- package/lib/ZenodoFile.js +37 -0
- package/lib/ZenodoFile.js.map +1 -0
- package/lib/depositions/Deposition.d.ts +14 -0
- package/lib/depositions/Deposition.d.ts.map +1 -0
- package/lib/depositions/Deposition.js +55 -0
- package/lib/depositions/Deposition.js.map +1 -0
- package/lib/depositions/ListDepositionsOptions.d.ts +32 -0
- package/lib/depositions/ListDepositionsOptions.d.ts.map +1 -0
- package/lib/depositions/ListDepositionsOptions.js +3 -0
- package/lib/depositions/ListDepositionsOptions.js.map +1 -0
- package/lib/depositions/depositionSchema.d.ts +982 -0
- package/lib/depositions/depositionSchema.d.ts.map +1 -0
- package/lib/depositions/depositionSchema.js +141 -0
- package/lib/depositions/depositionSchema.js.map +1 -0
- package/lib/fetchZenodo.d.ts +12 -0
- package/lib/fetchZenodo.d.ts.map +1 -0
- package/lib/fetchZenodo.js +34 -0
- package/lib/fetchZenodo.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +18 -0
- package/lib/index.js.map +1 -0
- package/lib/responseStatuses.d.ts +8 -0
- package/lib/responseStatuses.d.ts.map +1 -0
- package/lib/responseStatuses.js +71 -0
- package/lib/responseStatuses.js.map +1 -0
- package/lib-esm/Zenodo.d.ts +19 -0
- package/lib-esm/Zenodo.d.ts.map +1 -0
- package/lib-esm/Zenodo.js +51 -0
- package/lib-esm/Zenodo.js.map +1 -0
- package/lib-esm/ZenodoFile.d.ts +45 -0
- package/lib-esm/ZenodoFile.d.ts.map +1 -0
- package/lib-esm/ZenodoFile.js +33 -0
- package/lib-esm/ZenodoFile.js.map +1 -0
- package/lib-esm/depositions/Deposition.d.ts +14 -0
- package/lib-esm/depositions/Deposition.d.ts.map +1 -0
- package/lib-esm/depositions/Deposition.js +51 -0
- package/lib-esm/depositions/Deposition.js.map +1 -0
- package/lib-esm/depositions/ListDepositionsOptions.d.ts +32 -0
- package/lib-esm/depositions/ListDepositionsOptions.d.ts.map +1 -0
- package/lib-esm/depositions/ListDepositionsOptions.js +2 -0
- package/lib-esm/depositions/ListDepositionsOptions.js.map +1 -0
- package/lib-esm/depositions/depositionSchema.d.ts +982 -0
- package/lib-esm/depositions/depositionSchema.d.ts.map +1 -0
- package/lib-esm/depositions/depositionSchema.js +138 -0
- package/lib-esm/depositions/depositionSchema.js.map +1 -0
- package/lib-esm/fetchZenodo.d.ts +12 -0
- package/lib-esm/fetchZenodo.d.ts.map +1 -0
- package/lib-esm/fetchZenodo.js +31 -0
- package/lib-esm/fetchZenodo.js.map +1 -0
- package/lib-esm/index.d.ts +2 -0
- package/lib-esm/index.d.ts.map +1 -0
- package/lib-esm/index.js +2 -0
- package/lib-esm/index.js.map +1 -0
- package/lib-esm/responseStatuses.d.ts +8 -0
- package/lib-esm/responseStatuses.d.ts.map +1 -0
- package/lib-esm/responseStatuses.js +68 -0
- package/lib-esm/responseStatuses.js.map +1 -0
- package/package.json +36 -9
- package/src/Zenodo.ts +68 -0
- package/src/ZenodoFile.ts +40 -0
- package/src/__tests__/Zenodo.test.ts +79 -0
- package/src/__tests__/getConfig.ts +9 -0
- package/src/depositions/Deposition.ts +60 -0
- package/src/depositions/ListDepositionsOptions.ts +36 -0
- package/src/depositions/depositionSchema.ts +154 -0
- package/src/fetchZenodo.ts +53 -0
- package/src/index.ts +1 -0
- package/src/responseStatuses.ts +85 -0
- package/History.md +0 -73
- package/src/index.js +0 -171
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export interface ListDepositionsOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Search query (using Elasticsearch query string syntax).
|
|
4
|
+
* Some characters have special meaning here, including `/`, which is also present in full DOIs.
|
|
5
|
+
*/
|
|
6
|
+
q?: string;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Filter result based on deposit status.
|
|
10
|
+
* Possible values: 'draft' | 'published'
|
|
11
|
+
*/
|
|
12
|
+
status?: 'draft' | 'published';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Sort order.
|
|
16
|
+
* Possible values: 'bestmatch' | 'mostrecent'
|
|
17
|
+
* Prefix with minus to change from ascending to descending (e.g., '-mostrecent').
|
|
18
|
+
*/
|
|
19
|
+
sort?: 'bestmatch' | 'mostrecent' | `-${'bestmatch' | 'mostrecent'}`;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Page number for pagination.
|
|
23
|
+
*/
|
|
24
|
+
page?: number;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Number of results to return per page.
|
|
28
|
+
*/
|
|
29
|
+
size?: number;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Show or hide all versions of deposits.
|
|
33
|
+
* Possible values: 'true' | 'false' | 1 | 0
|
|
34
|
+
*/
|
|
35
|
+
all_versions?: 'true' | 'false' | 1 | 0;
|
|
36
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
import { zenodoFileSchema } from '../ZenodoFile';
|
|
4
|
+
|
|
5
|
+
const creatorSchema = z.object({
|
|
6
|
+
name: z.string(),
|
|
7
|
+
affiliation: z.union([z.string().optional(), z.null()]),
|
|
8
|
+
orcid: z.string().optional(),
|
|
9
|
+
gnd: z.string().optional(),
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const relatedIdentifierSchema = z.object({
|
|
13
|
+
identifier: z.string(),
|
|
14
|
+
relation: z.string(),
|
|
15
|
+
resource_type: z.string().optional(),
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const contributorSchema = z.object({
|
|
19
|
+
name: z.string(),
|
|
20
|
+
type: z.string(),
|
|
21
|
+
affiliation: z.string().optional(),
|
|
22
|
+
orcid: z.string().optional(),
|
|
23
|
+
gnd: z.string().optional(),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const communitySchema = z.object({
|
|
27
|
+
identifier: z.string(),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const grantSchema = z.object({
|
|
31
|
+
id: z.string(),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const subjectSchema = z.object({
|
|
35
|
+
term: z.string(),
|
|
36
|
+
identifier: z.string(),
|
|
37
|
+
scheme: z.string(),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const locationSchema = z.object({
|
|
41
|
+
lat: z.number().optional(),
|
|
42
|
+
lon: z.number().optional(),
|
|
43
|
+
place: z.string(),
|
|
44
|
+
description: z.string().optional(),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const dateIntervalSchema = z.object({
|
|
48
|
+
start: z.string().optional(),
|
|
49
|
+
end: z.string().optional(),
|
|
50
|
+
type: z.string(),
|
|
51
|
+
description: z.string().optional(),
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// API returns microseconds in timestamps that is not supported for ISO 8601 default validation
|
|
55
|
+
const iso8601WithMicroseconds = z
|
|
56
|
+
.string()
|
|
57
|
+
.refine((value) => !Number.isNaN(Date.parse(value)), {
|
|
58
|
+
message: 'Invalid datetime format',
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const linksSchema = z
|
|
62
|
+
.object({
|
|
63
|
+
self: z.string().url(),
|
|
64
|
+
html: z.string().url(),
|
|
65
|
+
badge: z.string().url(),
|
|
66
|
+
files: z.string().url(),
|
|
67
|
+
latest_draft: z.string().url(),
|
|
68
|
+
latest_draft_html: z.string().url(),
|
|
69
|
+
publish: z.string().url(),
|
|
70
|
+
edit: z.string().url(),
|
|
71
|
+
discard: z.string().url(),
|
|
72
|
+
newversion: z.string().url(),
|
|
73
|
+
registerconceptdoi: z.string().url(),
|
|
74
|
+
})
|
|
75
|
+
.catchall(z.string().url()); // Allows extra keys with URL values
|
|
76
|
+
|
|
77
|
+
export const depositionMetadataSchema = z.object({
|
|
78
|
+
upload_type: z.enum([
|
|
79
|
+
'publication',
|
|
80
|
+
'poster',
|
|
81
|
+
'presentation',
|
|
82
|
+
'dataset',
|
|
83
|
+
'image',
|
|
84
|
+
'video',
|
|
85
|
+
'software',
|
|
86
|
+
'lesson',
|
|
87
|
+
'physicalobject',
|
|
88
|
+
'other',
|
|
89
|
+
]),
|
|
90
|
+
publication_type: z.string().optional(),
|
|
91
|
+
image_type: z.string().optional(),
|
|
92
|
+
publication_date: z.string().optional(),
|
|
93
|
+
title: z.string(),
|
|
94
|
+
creators: z.array(creatorSchema),
|
|
95
|
+
description: z.string(),
|
|
96
|
+
access_right: z.enum(['open', 'embargoed', 'restricted', 'closed']),
|
|
97
|
+
license: z.string().optional(),
|
|
98
|
+
embargo_date: z.string().optional(),
|
|
99
|
+
access_conditions: z.string().optional(),
|
|
100
|
+
doi: z.string().optional(),
|
|
101
|
+
prereserve_doi: z.union([z.boolean(), z.record(z.unknown())]).optional(),
|
|
102
|
+
keywords: z.array(z.string()).optional(),
|
|
103
|
+
notes: z.string().optional(),
|
|
104
|
+
related_identifiers: z.array(relatedIdentifierSchema).optional(),
|
|
105
|
+
contributors: z.array(contributorSchema).optional(),
|
|
106
|
+
references: z.array(z.string()).optional(),
|
|
107
|
+
communities: z.array(communitySchema).optional(),
|
|
108
|
+
grants: z.array(grantSchema).optional(),
|
|
109
|
+
journal_title: z.string().optional(),
|
|
110
|
+
journal_volume: z.string().optional(),
|
|
111
|
+
journal_issue: z.string().optional(),
|
|
112
|
+
journal_pages: z.string().optional(),
|
|
113
|
+
conference_title: z.string().optional(),
|
|
114
|
+
conference_acronym: z.string().optional(),
|
|
115
|
+
conference_dates: z.string().optional(),
|
|
116
|
+
conference_place: z.string().optional(),
|
|
117
|
+
conference_url: z.string().optional(),
|
|
118
|
+
conference_session: z.string().optional(),
|
|
119
|
+
conference_session_part: z.string().optional(),
|
|
120
|
+
imprint_publisher: z.string().optional(),
|
|
121
|
+
imprint_isbn: z.string().optional(),
|
|
122
|
+
imprint_place: z.string().optional(),
|
|
123
|
+
partof_title: z.string().optional(),
|
|
124
|
+
partof_pages: z.string().optional(),
|
|
125
|
+
thesis_supervisors: z.array(creatorSchema).optional(),
|
|
126
|
+
thesis_university: z.string().optional(),
|
|
127
|
+
subjects: z.array(subjectSchema).optional(),
|
|
128
|
+
version: z.string().optional(),
|
|
129
|
+
language: z.string().optional(),
|
|
130
|
+
locations: z.array(locationSchema).optional(),
|
|
131
|
+
dates: z.array(dateIntervalSchema).optional(),
|
|
132
|
+
method: z.string().optional(),
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
export type DepositionMetadata = z.infer<typeof depositionMetadataSchema>;
|
|
136
|
+
|
|
137
|
+
export const zenodoDepositionSchema = z.object({
|
|
138
|
+
created: iso8601WithMicroseconds, // ISO8601 timestamp
|
|
139
|
+
modified: iso8601WithMicroseconds, // ISO8601 timestamp
|
|
140
|
+
id: z.number(),
|
|
141
|
+
metadata: depositionMetadataSchema,
|
|
142
|
+
title: z.string(),
|
|
143
|
+
doi: z.string().optional(), // Present only for published depositions
|
|
144
|
+
doi_url: z.string().url().optional(), // URL to DOI
|
|
145
|
+
record_url: z.string().url().optional(), // URL to public version of record
|
|
146
|
+
links: linksSchema,
|
|
147
|
+
record_id: z.number().optional(), // Present only for published depositions
|
|
148
|
+
owner: z.number(),
|
|
149
|
+
files: z.array(zenodoFileSchema),
|
|
150
|
+
state: z.enum(['unsubmitted', 'inprogress', 'done', 'error']),
|
|
151
|
+
submitted: z.boolean(),
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
export type ZenodoDeposition = z.infer<typeof zenodoDepositionSchema>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { Zenodo } from './Zenodo';
|
|
2
|
+
import { responseStatuses } from './responseStatuses';
|
|
3
|
+
|
|
4
|
+
interface FetchZenodoOptions {
|
|
5
|
+
route?: string;
|
|
6
|
+
method?: string;
|
|
7
|
+
contentType?: string;
|
|
8
|
+
expectedStatus?: number;
|
|
9
|
+
searchParams?: Record<string, string>;
|
|
10
|
+
body?: string | FormData;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export async function fetchZenodo(zenodo: Zenodo, options: FetchZenodoOptions) {
|
|
14
|
+
const {
|
|
15
|
+
body,
|
|
16
|
+
route = 'deposit/depositions',
|
|
17
|
+
method = 'GET',
|
|
18
|
+
contentType = body instanceof FormData ? undefined : 'application/json',
|
|
19
|
+
expectedStatus = 200,
|
|
20
|
+
searchParams,
|
|
21
|
+
} = options;
|
|
22
|
+
|
|
23
|
+
let url;
|
|
24
|
+
if (searchParams) {
|
|
25
|
+
const urlSearchParams = new URLSearchParams(searchParams);
|
|
26
|
+
url =
|
|
27
|
+
zenodo.baseURL +
|
|
28
|
+
route +
|
|
29
|
+
(urlSearchParams ? `?${urlSearchParams.toString()}` : '');
|
|
30
|
+
} else {
|
|
31
|
+
url = zenodo.baseURL + route;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const headers = new Headers({
|
|
35
|
+
Authorization: `Bearer ${zenodo.accessToken}`,
|
|
36
|
+
});
|
|
37
|
+
if (contentType) {
|
|
38
|
+
headers.set('Content-Type', contentType);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const response = await fetch(url, {
|
|
42
|
+
method,
|
|
43
|
+
headers,
|
|
44
|
+
body,
|
|
45
|
+
});
|
|
46
|
+
if (response.status !== expectedStatus) {
|
|
47
|
+
throw new Error(
|
|
48
|
+
responseStatuses[response.status]?.description || response.statusText,
|
|
49
|
+
{ cause: { url, method, contentType, body, response } },
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
return response;
|
|
53
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Zenodo';
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
interface ResponseStatusInfo {
|
|
2
|
+
code: number;
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const responseStatuses: Record<number, ResponseStatusInfo> = {
|
|
8
|
+
200: {
|
|
9
|
+
code: 200,
|
|
10
|
+
name: 'OK',
|
|
11
|
+
description:
|
|
12
|
+
'Request succeeded. Response included. Usually sent for GET/PUT/PATCH requests.',
|
|
13
|
+
},
|
|
14
|
+
201: {
|
|
15
|
+
code: 201,
|
|
16
|
+
name: 'Created',
|
|
17
|
+
description:
|
|
18
|
+
'Request succeeded. Response included. Usually sent for POST requests.',
|
|
19
|
+
},
|
|
20
|
+
202: {
|
|
21
|
+
code: 202,
|
|
22
|
+
name: 'Accepted',
|
|
23
|
+
description:
|
|
24
|
+
'Request succeeded. Response included. Usually sent for POST requests, where background processing is needed to fulfill the request.',
|
|
25
|
+
},
|
|
26
|
+
204: {
|
|
27
|
+
code: 204,
|
|
28
|
+
name: 'No Content',
|
|
29
|
+
description:
|
|
30
|
+
'Request succeeded. No response included. Usually sent for DELETE requests.',
|
|
31
|
+
},
|
|
32
|
+
400: {
|
|
33
|
+
code: 400,
|
|
34
|
+
name: 'Bad Request',
|
|
35
|
+
description: 'Request failed. Error response included.',
|
|
36
|
+
},
|
|
37
|
+
401: {
|
|
38
|
+
code: 401,
|
|
39
|
+
name: 'Unauthorized',
|
|
40
|
+
description:
|
|
41
|
+
'Request failed, due to an invalid access token. Error response included.',
|
|
42
|
+
},
|
|
43
|
+
403: {
|
|
44
|
+
code: 403,
|
|
45
|
+
name: 'Forbidden',
|
|
46
|
+
description:
|
|
47
|
+
'Request failed, due to missing authorization (e.g. deleting an already submitted upload or missing scopes for your access token). Error response included.',
|
|
48
|
+
},
|
|
49
|
+
404: {
|
|
50
|
+
code: 404,
|
|
51
|
+
name: 'Not Found',
|
|
52
|
+
description:
|
|
53
|
+
'Request failed, due to the resource not being found. Error response included.',
|
|
54
|
+
},
|
|
55
|
+
405: {
|
|
56
|
+
code: 405,
|
|
57
|
+
name: 'Method Not Allowed',
|
|
58
|
+
description:
|
|
59
|
+
'Request failed, due to unsupported HTTP method. Error response included.',
|
|
60
|
+
},
|
|
61
|
+
409: {
|
|
62
|
+
code: 409,
|
|
63
|
+
name: 'Conflict',
|
|
64
|
+
description:
|
|
65
|
+
'Request failed, due to the current state of the resource (e.g. edit a deposition which is not fully integrated). Error response included.',
|
|
66
|
+
},
|
|
67
|
+
415: {
|
|
68
|
+
code: 415,
|
|
69
|
+
name: 'Unsupported Media Type',
|
|
70
|
+
description:
|
|
71
|
+
'Request failed, due to missing or invalid request header Content-Type. Error response included.',
|
|
72
|
+
},
|
|
73
|
+
429: {
|
|
74
|
+
code: 429,
|
|
75
|
+
name: 'Too Many Requests',
|
|
76
|
+
description:
|
|
77
|
+
'Request failed, due to rate limiting. Error response included.',
|
|
78
|
+
},
|
|
79
|
+
500: {
|
|
80
|
+
code: 500,
|
|
81
|
+
name: 'Internal Server Error',
|
|
82
|
+
description:
|
|
83
|
+
'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.',
|
|
84
|
+
},
|
|
85
|
+
};
|
package/History.md
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
### [1.0.2](https://github.com/cheminfo/zenodo/compare/v1.0.1...v1.0.2) (2021-02-25)
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
### Bug Fixes
|
|
5
|
-
|
|
6
|
-
* update axios ([2c121db](https://github.com/cheminfo/zenodo/commit/2c121db6e24bccd94468dad9ed2698463a19b5a4))
|
|
7
|
-
|
|
8
|
-
<a name="1.0.1"></a>
|
|
9
|
-
## [1.0.1](https://github.com/cheminfo/zenodo/compare/v1.0.0...v1.0.1) (2018-04-26)
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
<a name="1.0.0"></a>
|
|
14
|
-
# [1.0.0](https://github.com/cheminfo/zenodo/compare/v0.4.1...v1.0.0) (2018-04-26)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
### Features
|
|
18
|
-
|
|
19
|
-
* add depositions.newversion ([534b816](https://github.com/cheminfo/zenodo/commit/534b816)), closes [#2](https://github.com/cheminfo/zenodo/issues/2)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
<a name="0.4.1"></a>
|
|
24
|
-
## [0.4.1](https://github.com/cheminfo/zenodo/compare/v0.4.0...v0.4.1) (2018-04-11)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
<a name="0.4.0"></a>
|
|
29
|
-
# [0.4.0](https://github.com/cheminfo/zenodo/compare/v0.3.0...v0.4.0) (2018-04-11)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
### Features
|
|
33
|
-
|
|
34
|
-
* add method to get list of files and sort files ([709876b](https://github.com/cheminfo/zenodo/commit/709876b))
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
<a name="0.3.0"></a>
|
|
39
|
-
# [0.3.0](https://github.com/cheminfo/zenodo/compare/v0.2.0...v0.3.0) (2018-04-11)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
### Features
|
|
43
|
-
|
|
44
|
-
* specify maxContentLength to Infinity ([f131a0d](https://github.com/cheminfo/zenodo/commit/f131a0d))
|
|
45
|
-
* specify maxContentLength to Infinity ([c1ec338](https://github.com/cheminfo/zenodo/commit/c1ec338))
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
<a name="0.2.0"></a>
|
|
50
|
-
# [0.2.0](https://github.com/cheminfo/zenodo/compare/v0.1.1...v0.2.0) (2018-04-11)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
### Features
|
|
54
|
-
|
|
55
|
-
* switch request library to axios ([4f2be59](https://github.com/cheminfo/zenodo/commit/4f2be59))
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
<a name="0.1.1"></a>
|
|
60
|
-
## [0.1.1](https://github.com/cheminfo/zenodo/compare/v0.1.0...v0.1.1) (2017-12-01)
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
### Bug Fixes
|
|
64
|
-
|
|
65
|
-
* remove slash at the end of urls ([5b526b2](https://github.com/cheminfo/zenodo/commit/5b526b2))
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
<a name="0.1.0"></a>
|
|
70
|
-
# 0.1.0 (2017-04-03)
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
package/src/index.js
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const axios = require('axios');
|
|
4
|
-
|
|
5
|
-
const defaultOptions = {
|
|
6
|
-
protocol: 'https',
|
|
7
|
-
host: 'zenodo.org',
|
|
8
|
-
pathPrefix: '/api/'
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
const kBaseRequest = Symbol('baseRequest');
|
|
12
|
-
const kBaseUrl = Symbol('baseUrl');
|
|
13
|
-
const kBaseHeaders = Symbol('baseHeaders');
|
|
14
|
-
const kRequest = Symbol('request');
|
|
15
|
-
const kSublevel = Symbol('sublevel');
|
|
16
|
-
|
|
17
|
-
function getAxios(options) {
|
|
18
|
-
return axios.create(
|
|
19
|
-
Object.assign(
|
|
20
|
-
{
|
|
21
|
-
maxContentLength: Infinity,
|
|
22
|
-
maxBodyLength: Infinity
|
|
23
|
-
},
|
|
24
|
-
options
|
|
25
|
-
)
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
class ZenodoApi {
|
|
30
|
-
constructor(options) {
|
|
31
|
-
options = Object.assign({}, defaultOptions, options);
|
|
32
|
-
if (!options.token) {
|
|
33
|
-
throw new Error('token option must be provided');
|
|
34
|
-
}
|
|
35
|
-
const baseURL =
|
|
36
|
-
options.protocol + '://' + options.host + options.pathPrefix;
|
|
37
|
-
const baseHeaders = {
|
|
38
|
-
Accept: 'application/json',
|
|
39
|
-
Authorization: 'Bearer:' + options.token
|
|
40
|
-
};
|
|
41
|
-
this[kBaseUrl] = baseURL;
|
|
42
|
-
this[kBaseHeaders] = baseHeaders;
|
|
43
|
-
this[kRequest] = this[kBaseRequest];
|
|
44
|
-
this[kSublevel] = {};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
get depositions() {
|
|
48
|
-
return (
|
|
49
|
-
this[kSublevel].depositions ||
|
|
50
|
-
(this[kSublevel].depositions = new ZenodoApiDepositions(
|
|
51
|
-
this[kBaseUrl],
|
|
52
|
-
this[kBaseHeaders]
|
|
53
|
-
))
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
get files() {
|
|
58
|
-
return (
|
|
59
|
-
this[kSublevel].files ||
|
|
60
|
-
(this[kSublevel].files = new ZenodoApiFiles(
|
|
61
|
-
this[kBaseUrl],
|
|
62
|
-
this[kBaseHeaders]
|
|
63
|
-
))
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
class ZenodoApiDepositions {
|
|
69
|
-
constructor(baseUrl, baseHeaders) {
|
|
70
|
-
this[kRequest] = getAxios({
|
|
71
|
-
baseURL: baseUrl + 'deposit/depositions',
|
|
72
|
-
headers: baseHeaders
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
list(options) {
|
|
77
|
-
return this[kRequest].get('', {
|
|
78
|
-
params: options
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
create(options = {}) {
|
|
83
|
-
const { metadata = {} } = options;
|
|
84
|
-
return this[kRequest].post('', { metadata });
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
retrieve(options = {}) {
|
|
88
|
-
const { id } = options;
|
|
89
|
-
return this[kRequest].get(`/${id}`);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
update(options = {}) {
|
|
93
|
-
const { id, metadata = {} } = options;
|
|
94
|
-
return this[kRequest].put(`/${id}`, { metadata });
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
delete(options) {
|
|
98
|
-
const { id } = options;
|
|
99
|
-
return this[kRequest].delete(`/${id}`);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
publish(options = {}) {
|
|
103
|
-
const { id } = options;
|
|
104
|
-
return this[kRequest].post(`/${id}/actions/publish`);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
edit(options = {}) {
|
|
108
|
-
const { id } = options;
|
|
109
|
-
return this[kRequest].post(`/${id}/actions/edit`);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
discard(options = {}) {
|
|
113
|
-
const { id } = options;
|
|
114
|
-
return this[kRequest].post(`/${id}/actions/discard`);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
newversion(options = {}) {
|
|
118
|
-
const { id } = options;
|
|
119
|
-
return this[kRequest].post(`/${id}/actions/newversion`);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
files(options = {}) {
|
|
123
|
-
const { id } = options;
|
|
124
|
-
return this[kRequest].get(`/${id}/files`);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
sort(options = {}) {
|
|
128
|
-
const { id, data } = options;
|
|
129
|
-
return this[kRequest].put(`/${id}/files`, data);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
class ZenodoApiFiles {
|
|
134
|
-
constructor(baseUrl, baseHeaders) {
|
|
135
|
-
this[kRequest] = getAxios({
|
|
136
|
-
baseURL: baseUrl + 'files',
|
|
137
|
-
headers: baseHeaders
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
upload(options = {}) {
|
|
142
|
-
const {
|
|
143
|
-
deposition,
|
|
144
|
-
filename,
|
|
145
|
-
contentType = 'application/octet-stream',
|
|
146
|
-
data
|
|
147
|
-
} = options;
|
|
148
|
-
const bucketId = deposition ? getBucketId(deposition) : options.bucketId;
|
|
149
|
-
return this[kRequest].put(`/${bucketId}/${filename}`, data, {
|
|
150
|
-
headers: {
|
|
151
|
-
'Content-Type': contentType
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
delete(options = {}) {
|
|
157
|
-
const { deposition, versionId, filename } = options;
|
|
158
|
-
const bucketId = deposition ? getBucketId(deposition) : options.bucketId;
|
|
159
|
-
return this[kRequest].delete(`/${bucketId}/${filename}`, {
|
|
160
|
-
params: {
|
|
161
|
-
versionId
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
function getBucketId(deposition) {
|
|
168
|
-
return deposition.links.bucket.replace(/.*\//, '');
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
module.exports = ZenodoApi;
|