zotero-lib 1.0.79 → 1.0.83

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 (49) hide show
  1. package/README.md +132 -73
  2. package/build/decorations.d.ts +35 -0
  3. package/build/decorations.js +38 -0
  4. package/build/decorations.js.map +1 -0
  5. package/build/http.client.d.ts +19 -0
  6. package/build/http.client.js +195 -0
  7. package/build/http.client.js.map +1 -0
  8. package/build/local-db/api.d.ts +6 -0
  9. package/build/local-db/api.js +53 -0
  10. package/build/local-db/api.js.map +1 -0
  11. package/build/local-db/db.d.ts +24 -0
  12. package/build/local-db/db.js +204 -0
  13. package/build/local-db/db.js.map +1 -0
  14. package/build/local-db/saveToFile.d.ts +1 -0
  15. package/build/local-db/saveToFile.js +8 -0
  16. package/build/local-db/saveToFile.js.map +1 -0
  17. package/build/local-db/types.d.ts +21 -0
  18. package/build/local-db/types.js +3 -0
  19. package/build/local-db/types.js.map +1 -0
  20. package/build/lock.utils.d.ts +3 -0
  21. package/build/lock.utils.js +30 -0
  22. package/build/lock.utils.js.map +1 -0
  23. package/build/logger.js +1 -1
  24. package/build/logger.js.map +1 -1
  25. package/build/readConfigFile.d.ts +1 -0
  26. package/build/readConfigFile.js +20 -0
  27. package/build/readConfigFile.js.map +1 -0
  28. package/build/sub-commands.d.ts +1 -0
  29. package/build/sub-commands.js +779 -0
  30. package/build/sub-commands.js.map +1 -0
  31. package/build/utils/formatAsCrossRefXML.js +32 -3
  32. package/build/utils/formatAsCrossRefXML.js.map +1 -1
  33. package/build/utils/formatAsZenodoJson.js +39 -21
  34. package/build/utils/formatAsZenodoJson.js.map +1 -1
  35. package/build/utils/index.d.ts +7 -0
  36. package/build/utils/index.js +70 -0
  37. package/build/utils/index.js.map +1 -0
  38. package/build/utils/md5-file.d.ts +13 -0
  39. package/build/utils/md5-file.js +27 -0
  40. package/build/utils/md5-file.js.map +1 -0
  41. package/build/utils/md5-file.test.d.ts +1 -0
  42. package/build/utils/md5-file.test.js +28 -0
  43. package/build/utils/md5-file.test.js.map +1 -0
  44. package/build/zotero-cli.js +170 -16
  45. package/build/zotero-cli.js.map +1 -1
  46. package/build/zotero-lib.d.ts +189 -128
  47. package/build/zotero-lib.js +896 -2234
  48. package/build/zotero-lib.js.map +1 -1
  49. package/package.json +20 -12
package/README.md CHANGED
@@ -1,76 +1,57 @@
1
1
  # zotero-lib
2
2
 
3
- ## Introduction: Tools for working with the APIs of Zotero and Zenodo (zotzen)
3
+ ## Introduction
4
4
 
5
- This repository is part of a set of repositories, see here: https://github.com/orgs/OpenDevEd/teams/zotzen-team/repositories. Currently, this set contains a number of libraries
5
+ Tools for working with the APIs of Zotero and Zenodo (zotzen)
6
6
 
7
- - zenodo-lib https://github.com/opendeved/zenodo-lib, https://www.npmjs.com/package/zenodo-lib
8
- - zotero-lib https://github.com/opendeved/zotero-lib, https://www.npmjs.com/package/zotero-lib
9
- - zotzen-lib https://github.com/opendeved/zotzen-lib, https://www.npmjs.com/package/zotzen-lib
7
+ This repository is part of a set of repositories, [see here](https://github.com/orgs/OpenDevEd/teams/zotzen-team/repositories). Currently, this set contains a number of libraries
8
+
9
+ - zenodo-lib [GitHub](https://github.com/opendeved/zenodo-lib), [npm](https://www.npmjs.com/package/zenodo-lib)
10
+ - zotero-lib [GitHub](https://github.com/opendeved/zotero-lib), [npm](https://www.npmjs.com/package/zotero-lib)
11
+ - zotzen-lib [GitHub](https://github.com/opendeved/zotzen-lib), [npm](https://www.npmjs.com/package/zotzen-lib)
10
12
 
11
13
  (The above tools can also be installed as command-line tools (CLI) with `npm -g`.)
12
14
 
13
15
  And a web application
14
16
 
15
- - zotzen-web https://github.com/opendeved/zotzen-web
17
+ - [zotzen-web](https://github.com/opendeved/zotzen-web)
16
18
 
17
- # zotero-lib
19
+ This code builds on earlier code for [zotero-cli](https://github.com/OpenDevEd/zotero-cli), which was developed by [@bjohas](https://github.com/bjohas), [@retorquere](https://github.com/retorquere) and [@a1diablo](https://github.com/a1diablo).
18
20
 
19
- Install this library with
21
+ ## Installation
20
22
 
21
- ```
23
+ Install this library in a module with
24
+
25
+ ```bash
22
26
  npm install zotero-lib
27
+ yarn add zotero-lib
23
28
  ```
24
29
 
25
- or as CLI
30
+ or as global CLI
26
31
 
32
+ ```bash
33
+ npm install -g zotero-lib
34
+ yarn global add zotero-lib
27
35
  ```
28
- sudo npm install -g zotero-lib
29
- ```
30
-
31
- View entry on https://www.npmjs.com/package/zotero-lib
32
-
33
- # Used by
34
36
 
35
- This library is currently used by
37
+ View entry on [npm](https://www.npmjs.com/package/zotero-lib)
36
38
 
37
- - https://github.com/OpenDevEd/zotero-lib
38
- - https://github.com/OpenDevEd/zotzen-lib
39
- - https://github.com/OpenDevEd/zotzen-web
40
-
41
- This code builds on earlier code for https://github.com/OpenDevEd/zotero-cli, which was developed by [@bjohas](https://github.com/bjohas), [@retorquere](https://github.com/retorquere) and [@a1diablo](https://github.com/a1diablo).
42
-
43
- # Use of the library and the CLI
39
+ ## Use of the library and the CLI
44
40
 
45
41
  The directory tests/ contains a number of tests that illustrate the
46
42
  use of the npm library. The file tests/test_cli.sh has examples for
47
43
  use of the library from the command line.
48
44
 
49
- # Also see:
50
-
51
- https://github.com/tnajdek/zotero-api-client (With hindsight we might have built on zotero-api-client - we might still rebuild our code to use zotero-api-client.)
52
-
53
- # CLI Documentation:
45
+ ## CLI Documentation
54
46
 
55
47
  The zotero-cli allows you to access zoter from cmd line, it allows you to automate redundant taskse easily
56
48
 
57
- ## Installation
58
-
59
- `npm install -g zotero-lib`
60
-
61
- OR
62
-
63
- `yarn global add zotero-lib`
64
-
65
49
  ## Basic usage
66
50
 
67
51
  ### Help
68
52
 
69
- ```
53
+ ```bash
70
54
  zotero-lib -h
71
-
72
- OR
73
-
74
55
  zotero-lib --help
75
56
  ```
76
57
 
@@ -78,70 +59,148 @@ This will print help for all commands and options accepted by zotero-lib
78
59
 
79
60
  ### Version
80
61
 
81
- ```
62
+ ```bash
82
63
  zotero-lib -v
83
-
84
- OR
85
-
86
64
  zotero-lib --version
87
65
  ```
88
66
 
89
67
  This will print the version of cli you have installed
90
68
 
91
- ### Item
92
-
93
- ### Items
69
+ ### create
94
70
 
95
- ### Create
71
+ This allows you to create item(s). You can create items in two different ways either by providing file containg json or json items as string
96
72
 
97
- This allows you to create item(s). You can create items in two different ways by providing following arguments
73
+ Both of these options can be used by providing following arguments
98
74
 
99
75
  - `--files` - this accepts text files containing json
100
76
  - `--items` - this accepts items as json string
101
77
 
102
- for example
78
+ **Note**: You must use only one of these at a time
79
+
80
+ Examples
81
+
82
+ ```bash
83
+ zotero-lib create --files filepath.txt
84
+ zotero-lib create --items '{"title": "zotero item 1", "itemType": "book"}' '{"title": "zotero item 2", "itemType": "book"}'
85
+ ```
86
+
87
+ ### update
88
+
89
+ This sub-command can be used to update existing items
103
90
 
91
+ ```bash
92
+ zotero-lib update --key key-here --json '{"title": "zotero item 1 updat", "itemType": "book"}'
93
+ zotero-lib update --key key-here --file filepath.txt
104
94
  ```
105
- zotero-lib create items --files filepath.txt
106
- zotero-lib create items --items '{"title": "zotero item"}'
95
+
96
+ You can also specify option replace which completely replace existing item and only keep provided information
97
+
98
+ ```bash
99
+ zotero-lib update --replace --key key-here --json '{"title": "zotero item 1 updat", "itemType": "book"}'
100
+ ```
101
+
102
+ ### item
103
+
104
+ This sub-command has various use cases
105
+
106
+ To fetch item
107
+
108
+ ```bash
109
+ zotero-lib item --key key-here
107
110
  ```
108
111
 
109
- ### Update
112
+ To add files
113
+
114
+ ```bash
115
+ zotero-lib item --key key-here --addfiles test.json
116
+ ```
117
+
118
+ ### items
119
+
120
+ This sub-command can be used to fetch items with various filters
121
+
122
+ ```bash
123
+ zotero-lib items --filter '{"limit": 10}'
124
+ ```
125
+
126
+ ### collection
127
+
128
+ ### collections
129
+
130
+ ### publications
131
+
132
+ ### tags
133
+
134
+ ### attachment
135
+
136
+ ### types
137
+
138
+ ### groups
139
+
140
+ ### fields
141
+
142
+ ### searches
143
+
144
+ ### key
145
+
146
+ ### field
147
+
148
+ ### update-url
149
+
150
+ ### get-doi
151
+
152
+ ### update-doi
153
+
154
+ ### enclose-item
155
+
156
+ ### attach-link
110
157
 
111
- ### Collection
158
+ ### attach-note
112
159
 
113
- ### Collections
160
+ ### kciaka
114
161
 
115
- ### Publications
162
+ ### bibliography
116
163
 
117
- ### Tags
164
+ ### Local Database Syncing
118
165
 
119
- ### Attachment
166
+ You can use this cli to locally backup your online zotero library. The `db` cmd allows you to sync online library in local sqlite database. On first run all online records are synced into local database. On subsequent runs only those records are fetched, which were modifed since last sync.
120
167
 
121
- ### Types
168
+ The underlying database is SQLite. You dont need to install any server or anything it will work out of box as SQLite comes bundled with this cli.
122
169
 
123
- ### Groups
170
+ To use this cmd you need to provide your db name along with one or more options. The options which you can specify are detailed below.
124
171
 
125
- ### Fields
172
+ `--sync` make local db synced with online library
173
+ `--lookup` allow you to lookup specific items in the local db
174
+ `--keys` this must be used with `--lookup` to specify specfic keys you want to locate
175
+ `--lockfile` name of lock file to be used, default is "sync.lock"
176
+ `--lock-timeout` if a lock file already exist, how much older it should be to classify it as outdated, if its outdated it will be removed and a new one will be generated
177
+ `--export-json=<file-name.json>` export localdb as json with given `file-name.json`
178
+ `--demon=<valid-cron-pattern` this will make the sync process run in demon mode, where it will peridically sync by itself, see [https://crontab.guru](https://crontab.guru) to learn about crontab pattern
179
+ `--errors` this will list all inconsistent items which have non zero children and non zero references
126
180
 
127
- ### Searches
181
+ These options are optional and can be combined as required. If all options are specified then they will be read/applied in above order.
128
182
 
129
- ### Key
183
+ #### Examples
130
184
 
131
- ### Field
185
+ To sync given db file `backup.db` with online version
132
186
 
133
- ### Update-url
187
+ ````bash
188
+ zotero-cli db backup.db --sync
189
+ ````
134
190
 
135
- ### Get-doi
191
+ To export give db file `backup.db` as json file `./backup.json`
136
192
 
137
- ### Update-doi
193
+ ````bash
194
+ zotero-cli db backup.db --export-json="./backup.json"
195
+ ````
138
196
 
139
- ### Enclose-item
197
+ You can combine previous two steps in one cmd
140
198
 
141
- ### Attach-link
199
+ ````bash
200
+ zotero-cli db backup.db --sync --export-json="./backup.json"
201
+ ````
142
202
 
143
- ### Attach-note
144
203
 
145
- ### Kciaka
204
+ ## Also see
146
205
 
147
- ### Bibliography
206
+ [zotero-api-client](https://github.com/tnajdek/zotero-api-client) (With hindsight we might have built on zotero-api-client - we might still rebuild our code to use zotero-api-client.)
@@ -0,0 +1,35 @@
1
+ declare const decorations: {
2
+ kerko_url: {
3
+ title: string;
4
+ tags: string[];
5
+ };
6
+ kerko_site_url: {
7
+ title: string;
8
+ tags: string[];
9
+ };
10
+ googledoc: {
11
+ title: string;
12
+ tags: string[];
13
+ };
14
+ deposit: {
15
+ title: string;
16
+ tags: string[];
17
+ };
18
+ record: {
19
+ title: string;
20
+ tags: string[];
21
+ };
22
+ doi: {
23
+ title: string;
24
+ tags: string[];
25
+ };
26
+ primarycollection: {
27
+ title: string;
28
+ tags: string[];
29
+ };
30
+ collection: {
31
+ title: string;
32
+ tags: string[];
33
+ };
34
+ };
35
+ export default decorations;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const decorations = {
4
+ kerko_url: {
5
+ title: '👀View item in Evidence Library',
6
+ tags: ['_r:kerko', '_r:zotzen'],
7
+ },
8
+ kerko_site_url: {
9
+ title: '👀View item in Evidence Library',
10
+ tags: ['_r:kerko', '_r:zotzen'],
11
+ },
12
+ googledoc: {
13
+ title: '📝View Google Doc and download alternative formats',
14
+ tags: ['_r:googleDoc', '_r:zotzen'],
15
+ },
16
+ deposit: {
17
+ title: '🔄View entry on Zenodo (deposit)',
18
+ tags: ['_r:zenodoDeposit', '_r:zotzen'],
19
+ },
20
+ record: {
21
+ title: '🔄View entry on Zenodo (record)',
22
+ tags: ['_r:zenodoRecord', '_r:zotzen'],
23
+ },
24
+ doi: {
25
+ title: '🔄Look up this DOI (once activated)',
26
+ tags: ['_r:doi', '_r:zotzen'],
27
+ },
28
+ primarycollection: {
29
+ title: '🆉View primary collection for this item',
30
+ tags: ['_r:primary_collection', '_r:zotzen'],
31
+ },
32
+ collection: {
33
+ title: '🆉View collection for this item',
34
+ tags: ['_r:collection', '_r:zotzen'],
35
+ },
36
+ };
37
+ exports.default = decorations;
38
+ //# sourceMappingURL=decorations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decorations.js","sourceRoot":"","sources":["../src/decorations.ts"],"names":[],"mappings":";;AAAA,MAAM,WAAW,GAAG;IAClB,SAAS,EAAE;QACT,KAAK,EAAE,iCAAiC;QACxC,IAAI,EAAE,CAAC,UAAU,EAAE,WAAW,CAAC;KAChC;IACD,cAAc,EAAE;QACd,KAAK,EAAE,iCAAiC;QACxC,IAAI,EAAE,CAAC,UAAU,EAAE,WAAW,CAAC;KAChC;IACD,SAAS,EAAE;QACT,KAAK,EAAE,oDAAoD;QAC3D,IAAI,EAAE,CAAC,cAAc,EAAE,WAAW,CAAC;KACpC;IACD,OAAO,EAAE;QACP,KAAK,EAAE,kCAAkC;QACzC,IAAI,EAAE,CAAC,kBAAkB,EAAE,WAAW,CAAC;KACxC;IACD,MAAM,EAAE;QACN,KAAK,EAAE,iCAAiC;QACxC,IAAI,EAAE,CAAC,iBAAiB,EAAE,WAAW,CAAC;KACvC;IACD,GAAG,EAAE;QACH,KAAK,EAAE,qCAAqC;QAC5C,IAAI,EAAE,CAAC,QAAQ,EAAE,WAAW,CAAC;KAC9B;IACD,iBAAiB,EAAE;QACjB,KAAK,EAAE,yCAAyC;QAChD,IAAI,EAAE,CAAC,uBAAuB,EAAE,WAAW,CAAC;KAC7C;IACD,UAAU,EAAE;QACV,KAAK,EAAE,iCAAiC;QACxC,IAAI,EAAE,CAAC,eAAe,EAAE,WAAW,CAAC;KACrC;CACF,CAAC;AAEF,kBAAe,WAAW,CAAC"}
@@ -0,0 +1,19 @@
1
+ export declare function createHttpClient(options?: {}): HttpClient;
2
+ export declare class HttpClient {
3
+ private headers;
4
+ constructor({ headers }: {
5
+ headers?: {};
6
+ });
7
+ post(uri: any, data: any, headers?: {}, config?: any): Promise<any>;
8
+ get(uri: any, options?: {
9
+ fulluri?: boolean;
10
+ userOrGroupPrefix?: boolean;
11
+ params?: any;
12
+ resolveWithFullResponse?: boolean;
13
+ json?: boolean;
14
+ arraybuffer?: boolean;
15
+ }, config?: any): Promise<any>;
16
+ put(uri: any, data: any, config: any): Promise<any>;
17
+ patch(uri: any, data: any, version?: number, config?: any): Promise<any>;
18
+ delete(uri: any, version?: number, config?: any): Promise<any>;
19
+ }
@@ -0,0 +1,195 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.HttpClient = exports.createHttpClient = void 0;
7
+ const logger_1 = __importDefault(require("./logger"));
8
+ const utils_1 = require("./utils");
9
+ const axios = require('axios');
10
+ const base = 'https://api.zotero.org';
11
+ function createHttpClient(options = {}) {
12
+ return new HttpClient(options);
13
+ }
14
+ exports.createHttpClient = createHttpClient;
15
+ class HttpClient {
16
+ constructor({ headers = {} }) {
17
+ this.headers = headers;
18
+ }
19
+ async post(uri, data, headers = {}, config = {}) {
20
+ const prefix = config.user_id
21
+ ? `/users/${config.user_id}`
22
+ : `/groups/${config.group_id}`;
23
+ if (!uri.startsWith('http')) {
24
+ uri = `${base}${prefix}${uri}`;
25
+ }
26
+ console.log('POST uri: ' + uri);
27
+ if (config.verbose)
28
+ console.error('POST', uri);
29
+ console.log('POST data: ', data);
30
+ return axios({
31
+ method: 'POST',
32
+ url: uri,
33
+ headers: {
34
+ ...this.headers,
35
+ 'Content-Type': 'application/json',
36
+ ...headers,
37
+ },
38
+ data,
39
+ }).then((res) => res.data);
40
+ }
41
+ async get(uri, options = {}, config = {}) {
42
+ if (typeof options.userOrGroupPrefix === 'undefined')
43
+ options.userOrGroupPrefix = true;
44
+ if (typeof options.params === 'undefined')
45
+ options.params = {};
46
+ if (typeof options.json === 'undefined')
47
+ options.json = true;
48
+ let prefix = '';
49
+ if (options.userOrGroupPrefix) {
50
+ prefix = config.user_id
51
+ ? `/users/${config.user_id}`
52
+ : `/groups/${config.group_id}`;
53
+ }
54
+ const params = Object.keys(options.params)
55
+ .map((param) => {
56
+ let values = options.params[param];
57
+ values = (0, utils_1.as_array)(values);
58
+ return values.map((v) => `${param}=${encodeURI(v)}`).join('&');
59
+ })
60
+ .join('&');
61
+ if (!options.fulluri) {
62
+ uri = `${base}${prefix}${uri}${params ? '?' + params : ''}`;
63
+ }
64
+ if (config.verbose)
65
+ console.error('GET', uri);
66
+ logger_1.default.info('get uri: %s', uri);
67
+ const requestConfig = {
68
+ method: 'get',
69
+ url: uri,
70
+ headers: { ...this.headers },
71
+ encoding: null,
72
+ json: options.json,
73
+ resolveWithFullResponse: options.resolveWithFullResponse,
74
+ };
75
+ if (options.arraybuffer) {
76
+ requestConfig.responseType = 'arraybuffer';
77
+ }
78
+ const res = await axios(requestConfig)
79
+ .then(function (response) {
80
+ return {
81
+ body: response.data,
82
+ status: response.status,
83
+ statusText: response.statusText,
84
+ headers: response.headers,
85
+ config: response.config,
86
+ };
87
+ })
88
+ .catch((error) => {
89
+ if (config.verbose) {
90
+ console.log(`Error in zotero.get = ${JSON.stringify(error, null, 2)}`);
91
+ }
92
+ logger_1.default.error('error in zotero get %O', error);
93
+ // console.log(`Error in zotero.get = ${JSON.stringify(error.error.data, null, 2)}`)
94
+ const message = error.error && error.error.data;
95
+ const shortError = {
96
+ name: error.name,
97
+ statusCode: error.statusCode,
98
+ message,
99
+ url: uri,
100
+ json: options.json,
101
+ };
102
+ console.log('Error in zotero.get = ' + JSON.stringify(shortError, null, 2));
103
+ return error;
104
+ });
105
+ // console.log("all=" + JSON.stringify(res, null, 2))
106
+ if (options.resolveWithFullResponse) {
107
+ return res;
108
+ }
109
+ else {
110
+ return res.body;
111
+ }
112
+ }
113
+ // TODO: Add resolveWithFullResponse: options.resolveWithFullResponse,
114
+ async put(uri, data, config) {
115
+ const prefix = config.user_id
116
+ ? `/users/${config.user_id}`
117
+ : `/groups/${config.group_id}`;
118
+ uri = `${base}${prefix}${uri}`;
119
+ if (config.verbose)
120
+ console.error('PUT', uri);
121
+ return axios({
122
+ method: 'PUT',
123
+ url: uri,
124
+ headers: { ...this.headers, 'Content-Type': 'application/json' },
125
+ data,
126
+ })
127
+ .then((res) => {
128
+ return {
129
+ body: res.data,
130
+ status: res.status,
131
+ statusText: res.statusText,
132
+ headers: res.headers,
133
+ config: res.config,
134
+ };
135
+ })
136
+ .catch((error) => {
137
+ console.log('PUT ERROR=' + JSON.stringify(error, null, 2));
138
+ return error;
139
+ });
140
+ }
141
+ // patch does not return any data.
142
+ // TODO: Errors are not handled - add this to patch (below) but needs adding to others.
143
+ async patch(uri, data, version, config) {
144
+ const prefix = config.user_id
145
+ ? `/users/${config.user_id}`
146
+ : `/groups/${config.group_id}`;
147
+ const headers = { ...this.headers, 'Content-Type': 'application/json' };
148
+ if (typeof version !== 'undefined') {
149
+ headers['If-Unmodified-Since-Version'] = version;
150
+ }
151
+ uri = `${base}${prefix}${uri}`;
152
+ if (config.verbose)
153
+ console.error('PATCH', uri);
154
+ return axios({
155
+ method: 'PATCH',
156
+ url: uri,
157
+ headers,
158
+ data,
159
+ resolveWithFullResponse: true,
160
+ })
161
+ .then((response) => {
162
+ return {
163
+ body: response.data,
164
+ statusCode: response.status,
165
+ statusText: response.statusText,
166
+ headers: response.headers,
167
+ config: response.config,
168
+ };
169
+ })
170
+ .catch((error) => {
171
+ console.log('PAT ERROR=' + JSON.stringify(error, null, 2));
172
+ return error;
173
+ });
174
+ }
175
+ // TODO: Add resolveWithFullResponse: options.resolveWithFullResponse,
176
+ async delete(uri, version, config) {
177
+ const prefix = config.user_id
178
+ ? `/users/${config.user_id}`
179
+ : `/groups/${config.group_id}`;
180
+ const headers = { ...this.headers, 'Content-Type': 'application/json' };
181
+ if (typeof version !== 'undefined') {
182
+ headers['If-Unmodified-Since-Version'] = version;
183
+ }
184
+ uri = `${base}${prefix}${uri}`;
185
+ if (config.verbose)
186
+ console.error('DELETE', uri);
187
+ return axios({
188
+ method: 'DELETE',
189
+ url: uri,
190
+ headers,
191
+ }).then((res) => res.data);
192
+ }
193
+ }
194
+ exports.HttpClient = HttpClient;
195
+ //# sourceMappingURL=http.client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.client.js","sourceRoot":"","sources":["../src/http.client.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA8B;AAC9B,mCAAmC;AAEnC,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAE/B,MAAM,IAAI,GAAG,wBAAwB,CAAC;AAEtC,SAAgB,gBAAgB,CAAC,OAAO,GAAG,EAAE;IAC3C,OAAO,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC;AACjC,CAAC;AAFD,4CAEC;AAED,MAAa,UAAU;IAGrB,YAAY,EAAE,OAAO,GAAG,EAAE,EAAE;QAC1B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,GAAG,EAAE,EAAE,SAAc,EAAE;QAClD,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO;YAC3B,CAAC,CAAC,UAAU,MAAM,CAAC,OAAO,EAAE;YAC5B,CAAC,CAAC,WAAW,MAAM,CAAC,QAAQ,EAAE,CAAC;QACjC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE;YAC3B,GAAG,GAAG,GAAG,IAAI,GAAG,MAAM,GAAG,GAAG,EAAE,CAAC;SAChC;QACD,OAAO,CAAC,GAAG,CAAC,YAAY,GAAG,GAAG,CAAC,CAAC;QAChC,IAAI,MAAM,CAAC,OAAO;YAAE,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAE/C,OAAO,CAAC,GAAG,CAAC,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;IAC7B,CAAC;CACF;AA9MD,gCA8MC"}
@@ -0,0 +1,6 @@
1
+ import { RequestArgs } from './types';
2
+ export declare function fetchCurrentKey(options?: RequestArgs): Promise<any>;
3
+ export declare function fetchGroups(options?: RequestArgs): Promise<any>;
4
+ export declare function fetchGroupData(options?: RequestArgs): Promise<any>;
5
+ export declare function getChangedItemsForGroup(options: any): Promise<any>;
6
+ export declare function fetchItemsByIds(options: any): Promise<any>;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetchItemsByIds = exports.getChangedItemsForGroup = exports.fetchGroupData = exports.fetchGroups = exports.fetchCurrentKey = void 0;
4
+ const axios = require('axios');
5
+ function getZoteroURL(subpath = '') {
6
+ const BASE_URL = 'https://api.zotero.org';
7
+ if (subpath.trim().length) {
8
+ return `${BASE_URL}/${subpath}`;
9
+ }
10
+ return BASE_URL;
11
+ }
12
+ async function fetchCurrentKey(options = { api_key: '' }) {
13
+ const { api_key } = options;
14
+ const headers = { Authorization: `Bearer ${api_key}` };
15
+ return axios
16
+ .get(getZoteroURL('keys/current'), { headers })
17
+ .then((res) => res.data);
18
+ }
19
+ exports.fetchCurrentKey = fetchCurrentKey;
20
+ async function fetchGroups(options = { api_key: '', user_id: '' }) {
21
+ const { api_key, user_id } = options;
22
+ const headers = { Authorization: `Bearer ${api_key}` };
23
+ return axios
24
+ .get(getZoteroURL(`users/${user_id}/groups/?format=versions`), { headers })
25
+ .then((res) => res.data);
26
+ }
27
+ exports.fetchGroups = fetchGroups;
28
+ async function fetchGroupData(options = { api_key: '', user_id: '' }) {
29
+ const { api_key, group_id } = options;
30
+ const headers = { Authorization: `Bearer ${api_key}` };
31
+ const requestURL = getZoteroURL(`groups/${group_id}`);
32
+ return axios.get(requestURL, { headers }).then((res) => {
33
+ return res.data;
34
+ });
35
+ }
36
+ exports.fetchGroupData = fetchGroupData;
37
+ async function getChangedItemsForGroup(options) {
38
+ const { api_key, group, version = 0 } = options;
39
+ const headers = { Authorization: `Bearer ${api_key}` };
40
+ return axios
41
+ .get(getZoteroURL(`groups/${group}/items?since=${version}&format=versions&includeTrashed=1`), { headers })
42
+ .then((res) => res.data);
43
+ }
44
+ exports.getChangedItemsForGroup = getChangedItemsForGroup;
45
+ async function fetchItemsByIds(options) {
46
+ const { api_key, group, itemIds } = options;
47
+ const headers = { Authorization: `Bearer ${api_key}` };
48
+ return axios.get(getZoteroURL(`groups/${group}/items/?itemKey=${itemIds}`), {
49
+ headers,
50
+ });
51
+ }
52
+ exports.fetchItemsByIds = fetchItemsByIds;
53
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/local-db/api.ts"],"names":[],"mappings":";;;AAEA,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAE/B,SAAS,YAAY,CAAC,OAAO,GAAG,EAAE;IAChC,MAAM,QAAQ,GAAG,wBAAwB,CAAC;IAE1C,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE;QACzB,OAAO,GAAG,QAAQ,IAAI,OAAO,EAAE,CAAC;KACjC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC;AAEM,KAAK,UAAU,eAAe,CAAC,UAAuB,EAAE,OAAO,EAAE,EAAE,EAAE;IAC1E,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAE5B,MAAM,OAAO,GAAG,EAAE,aAAa,EAAE,UAAU,OAAO,EAAE,EAAE,CAAC;IAEvD,OAAO,KAAK;SACT,GAAG,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,EAAE,OAAO,EAAE,CAAC;SAC9C,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAC7B,CAAC;AARD,0CAQC;AAEM,KAAK,UAAU,WAAW,CAC/B,UAAuB,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,EAA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