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
package/README.md CHANGED
@@ -1,2 +1,50 @@
1
1
  # zenodo
2
+
2
3
  Node.js library to access the Zenodo API
4
+
5
+ ## Zenodo API Documentation
6
+
7
+ https://developers.zenodo.org/
8
+
9
+ ## Testing the project
10
+
11
+ In order to test the project you will have to create a .env file that contains an API key to the sandbox.
12
+
13
+ https://developers.zenodo.org/#authentication
14
+
15
+ ## Usage
16
+
17
+ ```js
18
+ // by default we set the host to 'sandbox.zenodo.org' so that you can easily play around with this library without damage
19
+ const zenodo = new Zenodo({ accessToken, host: 'zenodo.org' });
20
+
21
+ // retrieve the list of all the depositions
22
+ const depositions = await zenodo.listDepositions();
23
+ for (const deposition of depoositions) {
24
+ console.log(deposition);
25
+ }
26
+
27
+ // create a new deposition
28
+ const deposition = zenodo.createDeposition({
29
+ upload_type: 'dataset',
30
+ description: 'test',
31
+ access_right: 'open',
32
+ creators: [
33
+ {
34
+ name: 'test',
35
+ },
36
+ ],
37
+ });
38
+ const firstDeposition = await zenodo.createDeposition(depositionMetadata);
39
+
40
+ const firstFile = new File(['Hello, world!'], 'example.txt', {
41
+ type: 'text/plain',
42
+ });
43
+ const newFile = await firstDeposition.createFile(firstFile);
44
+
45
+ const secondFile = new File(['Hello, world 2!'], 'example2.txt', {
46
+ type: 'text/plain',
47
+ });
48
+ ```
49
+
50
+ ## Development
@@ -0,0 +1,19 @@
1
+ import { Deposition } from './depositions/Deposition';
2
+ import type { ListDepositionsOptions } from './depositions/ListDepositionsOptions';
3
+ import type { DepositionMetadata } from './depositions/depositionSchema';
4
+ interface ZenodoOptions {
5
+ accessToken: string;
6
+ host?: string;
7
+ }
8
+ export declare class Zenodo {
9
+ host: string;
10
+ accessToken: string;
11
+ baseURL: string;
12
+ constructor(options: ZenodoOptions);
13
+ listDepositions(options?: ListDepositionsOptions): Promise<Deposition[]>;
14
+ createDeposition(metadata: DepositionMetadata): Promise<Deposition>;
15
+ retrieveDeposition(id: number): Promise<Deposition>;
16
+ deleteDeposition(id: number): Promise<void>;
17
+ }
18
+ export {};
19
+ //# sourceMappingURL=Zenodo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Zenodo.d.ts","sourceRoot":"","sources":["../src/Zenodo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AACnF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAGzE,UAAU,aAAa;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AACD,qBAAa,MAAM;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;gBAEJ,OAAO,EAAE,aAAa;IAU5B,eAAe,CACnB,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,UAAU,EAAE,CAAC;IAelB,gBAAgB,CAAC,QAAQ,EAAE,kBAAkB,GAAG,OAAO,CAAC,UAAU,CAAC;IAWnE,kBAAkB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAQnD,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAOlD"}
package/lib/Zenodo.js ADDED
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Zenodo = void 0;
4
+ const Deposition_1 = require("./depositions/Deposition");
5
+ const fetchZenodo_1 = require("./fetchZenodo");
6
+ class Zenodo {
7
+ host;
8
+ accessToken;
9
+ baseURL;
10
+ constructor(options) {
11
+ const { accessToken, host = 'sandbox.zenodo.org' } = options;
12
+ this.host = host;
13
+ this.baseURL = `https://${host}/api/`;
14
+ if (!accessToken) {
15
+ throw new Error('accessToken is required');
16
+ }
17
+ this.accessToken = accessToken;
18
+ }
19
+ async listDepositions(options = {}) {
20
+ // all the values must be string
21
+ const optionsWithStrings = Object.fromEntries(Object.entries(options).map(([key, value]) => [key, String(value)]));
22
+ const response = await (0, fetchZenodo_1.fetchZenodo)(this, {
23
+ route: 'deposit/depositions',
24
+ searchParams: optionsWithStrings,
25
+ });
26
+ const depositions = (await response.json());
27
+ return depositions.map((deposition) => new Deposition_1.Deposition(this, deposition));
28
+ }
29
+ async createDeposition(metadata) {
30
+ const response = await (0, fetchZenodo_1.fetchZenodo)(this, {
31
+ route: 'deposit/depositions',
32
+ expectedStatus: 201,
33
+ method: 'POST',
34
+ body: JSON.stringify({ metadata }),
35
+ });
36
+ const deposition = new Deposition_1.Deposition(this, await response.json());
37
+ return deposition;
38
+ }
39
+ async retrieveDeposition(id) {
40
+ const response = await (0, fetchZenodo_1.fetchZenodo)(this, {
41
+ route: `deposit/depositions/${id}`,
42
+ });
43
+ const deposition = await response.json();
44
+ return new Deposition_1.Deposition(this, deposition);
45
+ }
46
+ async deleteDeposition(id) {
47
+ await (0, fetchZenodo_1.fetchZenodo)(this, {
48
+ method: 'DELETE',
49
+ route: `deposit/depositions/${id}`,
50
+ expectedStatus: 204,
51
+ });
52
+ }
53
+ }
54
+ exports.Zenodo = Zenodo;
55
+ //# sourceMappingURL=Zenodo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Zenodo.js","sourceRoot":"","sources":["../src/Zenodo.ts"],"names":[],"mappings":";;;AAAA,yDAAsD;AAGtD,+CAA4C;AAM5C,MAAa,MAAM;IACjB,IAAI,CAAS;IACb,WAAW,CAAS;IACpB,OAAO,CAAS;IAEhB,YAAY,OAAsB;QAChC,MAAM,EAAE,WAAW,EAAE,IAAI,GAAG,oBAAoB,EAAE,GAAG,OAAO,CAAC;QAC7D,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB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K,CAAC,kBAAkB,CAAC,EAAU;QACjC,MAAM,QAAQ,GAAG,MAAM,IAAA,yBAAW,EAAC,IAAI,EAAE;YACvC,KAAK,EAAE,uBAAuB,EAAE,EAAE;SACnC,CAAC,CAAC;QACH,MAAM,UAAU,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QACzC,OAAO,IAAI,uBAAU,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IAC1C,CAAC;IAED,KAAK,CAAC,gBAAgB,CAAC,EAAU;QAC/B,MAAM,IAAA,yBAAW,EAAC,IAAI,EAAE;YACtB,MAAM,EAAE,QAAQ;YAChB,KAAK,EAAE,uBAAuB,EAAE,EAAE;YAClC,cAAc,EAAE,GAAG;SACpB,CAAC,CAAC;IACL,CAAC;CACF;AA1DD,wBA0DC"}
@@ -0,0 +1,45 @@
1
+ import { z } from 'zod';
2
+ import type { Zenodo } from './Zenodo';
3
+ export declare const zenodoFileSchema: z.ZodObject<{
4
+ id: z.ZodString;
5
+ filename: z.ZodString;
6
+ filesize: z.ZodNumber;
7
+ checksum: z.ZodString;
8
+ links: z.ZodObject<{
9
+ download: z.ZodString;
10
+ self: z.ZodString;
11
+ }, "strip", z.ZodTypeAny, {
12
+ download: string;
13
+ self: string;
14
+ }, {
15
+ download: string;
16
+ self: string;
17
+ }>;
18
+ }, "strip", z.ZodTypeAny, {
19
+ id: string;
20
+ filename: string;
21
+ filesize: number;
22
+ checksum: string;
23
+ links: {
24
+ download: string;
25
+ self: string;
26
+ };
27
+ }, {
28
+ id: string;
29
+ filename: string;
30
+ filesize: number;
31
+ checksum: string;
32
+ links: {
33
+ download: string;
34
+ self: string;
35
+ };
36
+ }>;
37
+ type ZenodoFileType = z.infer<typeof zenodoFileSchema>;
38
+ export declare class ZenodoFile {
39
+ private zenodo;
40
+ value: ZenodoFileType;
41
+ constructor(zenodo: Zenodo, file: unknown);
42
+ getContentResponse(): Promise<Response>;
43
+ }
44
+ export {};
45
+ //# sourceMappingURL=ZenodoFile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ZenodoFile.d.ts","sourceRoot":"","sources":["../src/ZenodoFile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAGvC,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAS3B,CAAC;AAEH,KAAK,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAEvD,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAS;IAChB,KAAK,EAAE,cAAc,CAAC;gBAEjB,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO;IAKnC,kBAAkB;CAYzB"}
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ZenodoFile = exports.zenodoFileSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ // Define the Zod schema
6
+ exports.zenodoFileSchema = zod_1.z.object({
7
+ id: zod_1.z.string(),
8
+ filename: zod_1.z.string(),
9
+ filesize: zod_1.z.number(),
10
+ checksum: zod_1.z.string(),
11
+ links: zod_1.z.object({
12
+ download: zod_1.z.string().url(),
13
+ self: zod_1.z.string().url(),
14
+ }),
15
+ });
16
+ class ZenodoFile {
17
+ zenodo;
18
+ value;
19
+ constructor(zenodo, file) {
20
+ this.value = exports.zenodoFileSchema.parse(file);
21
+ this.zenodo = zenodo;
22
+ }
23
+ async getContentResponse() {
24
+ const link = this.value.links.download;
25
+ const response = await fetch(link, {
26
+ headers: {
27
+ Authorization: `Bearer ${this.zenodo.accessToken}`,
28
+ },
29
+ });
30
+ if (!response.ok) {
31
+ throw new Error(`Failed to fetch ${link}`);
32
+ }
33
+ return response;
34
+ }
35
+ }
36
+ exports.ZenodoFile = ZenodoFile;
37
+ //# sourceMappingURL=Zenod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o } from '../Zenodo';
2
+ import { ZenodoFile } from '../ZenodoFile';
3
+ import type { DepositionMetadata, ZenodoDeposition } from './depositionSchema';
4
+ export declare class Deposition {
5
+ private zenodo;
6
+ value: ZenodoDeposition;
7
+ constructor(zenodo: Zenodo, deposition: unknown);
8
+ createFile(file: File): Promise<ZenodoFile>;
9
+ listFiles(): Promise<ZenodoFile[]>;
10
+ deleteFile(fileId: string): Promise<void>;
11
+ retrieveFile(fileId: string): Promise<ZenodoFile>;
12
+ update(metadata: DepositionMetadata): Promise<Deposition>;
13
+ }
14
+ //# sourceMappingURL=Deposition.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Deposition.d.ts","sourceRoot":"","sources":["../../src/depositions/Deposition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAI3C,OAAO,KAAK,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE/E,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAS;IAChB,KAAK,EAAE,gBAAgB,CAAC;gBAEnB,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO;IAKzC,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,UAAU,CAAC;IAY3C,SAAS,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;IAQlC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQzC,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAOjD,MAAM,CAAC,QAAQ,EAAE,kBAAkB,GAAG,OAAO,CAAC,UAAU,CAAC;CAQhE"}
@@ -0,0 +1,55 @@
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 {
8
+ zenodo;
9
+ value;
10
+ constructor(zenodo, deposition) {
11
+ this.zenodo = zenodo;
12
+ this.value = depositionSchema_1.zenodoDepositionSchema.parse(deposition);
13
+ }
14
+ 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());
24
+ }
25
+ async listFiles() {
26
+ const response = await (0, fetchZenodo_1.fetchZenodo)(this.zenodo, {
27
+ route: `deposit/depositions/${this.value.id}/files`,
28
+ });
29
+ const files = (await response.json());
30
+ return files.map((file) => new ZenodoFile_1.ZenodoFile(this.zenodo, file));
31
+ }
32
+ async deleteFile(fileId) {
33
+ await (0, fetchZenodo_1.fetchZenodo)(this.zenodo, {
34
+ route: `deposit/depositions/${this.value.id}/files/${fileId}`,
35
+ method: 'DELETE',
36
+ expectedStatus: 204,
37
+ });
38
+ }
39
+ async retrieveFile(fileId) {
40
+ const response = await (0, fetchZenodo_1.fetchZenodo)(this.zenodo, {
41
+ route: `deposit/depositions/${this.value.id}/files/${fileId}`,
42
+ });
43
+ return new ZenodoFile_1.ZenodoFile(this.zenodo, await response.json());
44
+ }
45
+ async update(metadata) {
46
+ const response = await (0, fetchZenodo_1.fetchZenodo)(this.zenodo, {
47
+ route: `deposit/depositions/${this.value.id}`,
48
+ method: 'PUT',
49
+ body: JSON.stringify({ metadata }),
50
+ });
51
+ return new Deposition(this.zenodo, await response.json());
52
+ }
53
+ }
54
+ exports.Deposition = Deposition;
55
+ //# sourceMappingURL=Deposition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Deposition.js","sourceRoot":"","sources":["../../src/depositions/Deposition.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C,IAAI,CAAC,MAAM,EAAE;YAC7B,KAAK,EAAE,uBAAuB,IAAI,CAAC,KAAK,CAAC,EAAE,UAAU,MAAM,EAAE;YAC7D,MAAM,EAAE,QAAQ;YAChB,cAAc,EAAE,GAAG;SACpB,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,MAAc;QAC/B,MAAM,QAAQ,GAAG,MAAM,IAAA,yBAAW,EAAC,IAAI,CAAC,MAAM,EAAE;YAC9C,KAAK,EAAE,uBAAuB,IAAI,CAAC,KAAK,CAAC,EAAE,UAAU,MAAM,EAAE;SAC9D,CAAC,CAAC;QACH,OAAO,IAAI,uBAAU,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IAC5D,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,QAA4B;QACvC,MAAM,QAAQ,GAAG,MAAM,IAAA,yBAAW,EAAC,IAAI,CAAC,MAAM,EAAE;YAC9C,KAAK,EAAE,uBAAuB,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE;YAC7C,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAC;SACnC,CAAC,CAAC;QACH,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IAC5D,CAAC;CACF;AApDD,gCAoDC"}
@@ -0,0 +1,32 @@
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
+ * Filter result based on deposit status.
9
+ * Possible values: 'draft' | 'published'
10
+ */
11
+ status?: 'draft' | 'published';
12
+ /**
13
+ * Sort order.
14
+ * Possible values: 'bestmatch' | 'mostrecent'
15
+ * Prefix with minus to change from ascending to descending (e.g., '-mostrecent').
16
+ */
17
+ sort?: 'bestmatch' | 'mostrecent' | `-${'bestmatch' | 'mostrecent'}`;
18
+ /**
19
+ * Page number for pagination.
20
+ */
21
+ page?: number;
22
+ /**
23
+ * Number of results to return per page.
24
+ */
25
+ size?: number;
26
+ /**
27
+ * Show or hide all versions of deposits.
28
+ * Possible values: 'true' | 'false' | 1 | 0
29
+ */
30
+ all_versions?: 'true' | 'false' | 1 | 0;
31
+ }
32
+ //# sourceMappingURL=ListDepositionsOptions.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=ListDepositionsOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ListDepositionsOptions.js","sourceRoot":"","sources":["../../src/depositions/ListDepositionsOptions.ts"],"names":[],"mappings":""}