#!/usr/bin/env node import { ZoteroTypes } from './zotero-interface'; import { HttpClient } from './http.client'; import { ZoteroConfig, ZoteroConfigOptions } from './types/config'; import { Ids } from './types/ids'; import { ItemArgs, Item, FullItemResponse, ItemTemplate, CreateItemResponse, UpdateItemResponse, ItemType, Fields } from './types/item'; import { TagObject } from './types/tag'; import { PublicationsArgs } from './types/publications'; import { Collection, UpdateCollectionResponse } from './types/collection'; import { GroupResponse } from './types/group'; import { CreateSearch, Search } from './types/search'; import { MessageData, MessageStatus } from './types/message'; import { KeyReturn } from './types/key'; declare class Zotero { config_keys: string[]; config: ZoteroConfigOptions; output: string; http: HttpClient; /** * Constructor for Zotero class * @param args - arguments passed to the constructor * @param args.config - path to the config file * @param args.config_json - config in json format * @param args.verbose - verbose output */ constructor(args?: ZoteroConfig); /** * Configure the zotero class * @param args - arguments passed to the constructor * @param args.config - path to the config file * @param args.config_json - config in json format * @param args.verbose - verbose output * @param shouldReadConfigFile - if the config file should be read * @returns the config */ configure(args: ZoteroConfig, shouldReadConfigFile?: boolean): ZoteroConfigOptions; /** * Convert array of string tags to array of object tags * @param tags - Array of string tags * @returns Array of Object tags * @example - ['title'] to [{tag: 'title', type: 0}] */ objectifyTags(tags: string[]): TagObject[]; /** * Takes config and args defined in various supported formats * and return standardized configs i.e. it will convert api-key, * api_key, zotero-api-key or zotero_api_key to api_key * @param _config - current configs * @param _args - configs provided in args * @returns standardized configs */ private canonicalConfig; showConfig(): ZoteroConfigOptions; changeConfig(args: ZoteroConfigOptions): void; private message; private finalActions; print(...args: any[]): void; all(uri: string, params?: {}): Promise; /** * Expose 'get' * Make a direct query to the API using 'GET uri'. */ __get(args: ZoteroTypes.__getArgs): Promise; /** * Expose 'post'. Make a direct query to the API using * 'POST uri [--data data]'. */ __post(args: ZoteroTypes.__postArgs): Promise; /** * Make a direct query to the API using * 'PUT uri [--data data]'. */ __put(args: ZoteroTypes.__putArgs): Promise; /** * Make a direct query to the API using * 'PATCH uri [--data data]'. */ __patch(args: ZoteroTypes.__patchArgs): Promise; /** * Make a direct delete query to the API using * 'DELETE uri'. */ __delete(args: ZoteroTypes.__deleteArgs): Promise; /** * Show details about this API key. * (API: /keys ) * @param args.api_key - the API key to show details for * @param args.groups - show groups for this user, only 100 are shown * @param args.terse - show output in a terse format, `id name owner type` * @returns details about the API key */ key(args: ZoteroTypes.IKeyArgs): Promise; /** * Extract the key, type and group from a zotero select link. * @param args.key - zotero select link format, or just the key * @returns object with key, type and group (if applicable) or key */ getIds(args: ZoteroTypes.IGetIdsArgs): Ids; /** * Return the total results from a query. * @param uri - the uri to query * @param params - the parameters to pass to the query * @returns the total results from a query */ count(uri: string, params?: {}): Promise; /** * Show a message. If the message is an object, it is stringified. * @param v - the message to show */ private show; /** * Extract the key, type (items or collections) and group from a zotero select link. * @param key - array of (or simple variable) zotero select link format, or just the key * @param n - the input key type (1=group or 3=key) ir the key not match zotero select link */ private extractKeyGroupVariable; private extractKeyAndSetGroup; /** * Attach a note to an item. * @param PARENT - the parent item to attach the note to * @param options - options for the note * @param options.content - the content of the note * @param options.tags - the tags for the note * @returns the note attached to the item */ attachNoteToItem(PARENT: string, options?: { content?: string; tags?: any; }): Promise; /** * Attach a link to an item * @param PARENT - the parent item to attach the link to * @param URL - the URL to attach * @param options - options for the link * @param options.title - the title of the link * @param options.tags - the tags for the link */ attachLinkToItem(PARENT: string, URL: string, options?: { title?: string; tags?: any; }): Promise; /** * Retrieve a list of collections or create a collection. * (API: /collections, /collections/top, /collections//collections). * Use 'collections --help' for details. * * @param args - arguments passed to the function * @param args.json - the json file to save the collections results to * @param args.key - the key of the collection to retrieve, if not provided, all collections are retrieved * @param args.recursive - whether to retrieve subcollections * @param args.create_child - create a child collection, it takes an array of collection names * @param args.top - whether to retrieve top level collections * @param args.terse - whether to return the results in forma of object with key and name * @returns the list of collections * * https://www.zotero.org/support/dev/web_api/v3/basics * Collections * /collections Collections in the library * /collections/top Top-level collections in the library * /collections/ A specific collection in the library * /collections//collections Subcollections within a specific collection in the library * TODO: --create-child should go into 'collection'. */ collections(args: ZoteroTypes.ICollectionsArgs): Promise; /** * Update a collection. * (API: /collections/KEY). * Use 'collection --help' for details. * * @param args - arguments passed to the function * @param args.key - the key of the collection to update * @param args.json - the json string to update the collection with * @param args.version - the version of the collection to update, if not provided, it is retrieved * @returns the updated collection * */ update_collection(args: ZoteroTypes.IUpdateCollectionArgs): Promise; /** * Delete a collection * (API: /collections/KEY). * Use 'collection --help' for details. * * @param args - arguments passed to the function * @param args.key - the key of the collection to delete * @param args.version - the version of the collection to delete, if not provided, it use the latest version * @returns a string confirming the deletion of the collection */ delete_collection(args: ZoteroTypes.IDeleteCollectionArgs): Promise; /** * Delete multiple collections * * @param args - arguments passed to the function * @param args.keys - the keys of the collections to delete * @returns an array of strings confirming the deletion of the collections */ delete_collections(args: ZoteroTypes.IDeleteCollectionsArgs): Promise; /** * Retrieve information about a specific collection * --key KEY (API: /collections/KEY or /collections/KEY/tags). * Use 'collection --help' for details. * (Note: Retrieve items is a collection via 'items --collection KEY'.) * * @param args - arguments passed to the function * @param args.key - the key of the collection to retrieve, in zotero select link format * @param args.tags - whether to retrieve the tags of the collection * @param args.add - add an item to the collection, takes an array of item keys * @param args.remove - remove an item from the collection, takes an array of item keys * @returns the collection * * Operate on a specific collection. * /collections//items Items within a specific collection in the library * /collections//items/top Top-level items within a specific collection in the library * TODO: --create-child should go into 'collection'. * DONE: Why is does the setup for --add and --remove differ? Should 'add' not be "nargs: '*'"? Remove 'itemkeys'? * TODO: Add option "--output file.json" to pipe output to file. */ collection(args: ZoteroTypes.ICollectionArgs): Promise; /** * Retrieve list of items from API. * (API: /items, /items/top, /collections/COLLECTION/items/top). * Use 'items --help' for details. * By default, all items are retrieved. With --top or limit (via --filter) the default number of items are retrieved. * * @param args - arguments passed to the function * @param args.filter - the filter to apply to the items, this is the parameters to pass to the query * @param args.json - the json file to save the items results to * @param args.count - whether to count the number of items * @param args.collection - the collection to retrieve items from * @param args.top - whether to retrieve top level items * @param args.tags - whether to retrieve the tags of the items * @param args.validate - whether to validate the items, with a pre-defined schema * @param args.validate_with - the schema to validate the items with * @param args.show - whether to show the items * @returns the list of items * * URI Description * https://www.zotero.org/support/dev/web_api/v3/basics * /items All items in the library, excluding trashed items * /items/top Top-level items in the library, excluding trashed items */ items(args: ItemArgs): Promise; /** * Downloads an attachment file from a Zotero item. * * This method downloads a file attachment associated with a Zotero item and saves it to the local filesystem. * It uses the Zotero API to retrieve the file and streams it to the specified location. * * @param args - The arguments for downloading the attachment * @param args.key - The key of the Zotero item attachment to download * @param args.filename - The local filename/path where the attachment should be saved * @param args.group_id - (Optional) The Zotero group ID. If not provided, uses the configured group_id * * @returns A Promise that resolves to: * - null if the download was successful * - MessageData with status 1 and error message if there was a failure * * @example * ```typescript * // Download an attachment * const result = await zotero.download_attachment({ * key: "ABCD1234", * filename: "document.pdf", * group_id: "123456" * }); * ``` */ download_attachment(args: ZoteroTypes.IDownloadAttachmentsArgs): Promise; /** * Validates the items using a specified schema or the default Zotero schema. * @param args - The arguments passed to the method. * @param args.validate_with - The schema to validate the items with. * @param args.items - The items to be validated. * @param items - The items to be validated. * @throws Error if the specified schema does not exist or if validation is requested but the default Zotero schema does not exist. */ private validate_items; /** * Retrieve an item (item --key KEY), save/add file attachments, * retrieve children. Manage collections and tags. * (API: /items/KEY/ or /items/KEY/children). * * @param args - arguments passed to the function * @param args.key - the key of the item to retrieve * @param args.tags - whether to retrieve the tags of the item * @param args.filter - the filter to apply to the item, this is the parameters to pass to the query * @param args.savefiles - whether to save the attachments of the item * @param args.addfiles - the files to add to the item, array of file paths * @param args.addtocollection - the collections to add the item to, array of collection keys * @param args.removefromcollection - the collections to remove the item from, array of collection keys * @param args.switchNames - whether to switch the first and last names of the creators * @param args.crossref - whether to format the item as a crossref XML * @param args.verbose - whether to show verbose output * @param args.debug - whether to show debug output * @param args.organise_extra - to organize the extra field * @param args.addtags - the tags to add to the item, array of tags * @param args.removetags - the tags to remove from the item, array of tags * @param args.children - retrieve the list of children items * @returns the item * * Also see 'attachment', 'create' and 'update'. * https://www.zotero.org/support/dev/web_api/v3/basics * /items/ A specific item in the library * /items//children Child items under a specific item */ item(args: ZoteroTypes.IItemArgs): Promise; /** * Retrieve/save file attachments for the item specified with --key KEY * @param args.key - the key of the item to retrieve the attachment for, in zotero select link format * @param args.save - the file to save the attachment to * @returns an object with the message 'File saved' and the filename, md5, and mtime of the file * (API: /items/KEY/file). * Also see 'item', which has options for adding/saving file attachments. */ attachment(args: { key: string; save: string; }): Promise<{ status: number; message: string; data: any; }>; /** * Create a new item or items. (API: /items/new) You can retrieve * a template with the --template option.Use this option to create * both top-level items, as well as child items (including notes and links). * * @param args.items - the items to create, an array of items * @param args.files - the files to create items from, an array of file paths * @param args.template - get the template for the item to create instead of creating an item * @param args.newcollection - create a new collection, takes an array of collection names, for now only the first one is used * @param args.collections - the collections to add the items to, an array of collection keys * @param args.fullresponse - whether to return the full response * @returns the created item or items * * see api docs for creating * [single item](https://www.zotero.org/support/dev/web_api/v3/write_requests#_an_item) OR * [multiple items](https://www.zotero.org/support/dev/web_api/v3/write_requests#creating_multiple_items) */ create_item(args: ZoteroTypes.ICreateItemArgs): Promise; pruneData(res: any, fullresponse?: boolean): any; /** * Update/replace an item with given key (--key KEY), * either update the item (API: patch /items/KEY) * or replace (using --replace, API: put /items/KEY). * * @param args - arguments passed to the function * @param args.key - The key of the item. You can provide the key as zotero-select link (zotero://...) to also set the group-id * @param args.json - The JSON object of the new item to update the item with * @param args.file - Path of the file in JSON format to update the item with * @param args.version - Specify the version of the item to update or else the latest version will be used * @param args.replace - Whether to replace the item or update it, if true you should provide the full item * @returns the updated item * * [see api docs](https://www.zotero.org/support/dev/web_api/v3/write_requests#updating_an_existing_item) */ update_item(args: ZoteroTypes.IUpdateItemArgs): Promise; /** * Delete an item with given key (--key KEY). * (API: delete /items/KEY) * * @param args - arguments passed to the function * @param args.key - the key of the item to delete, in zotero select link format * @param args.version - the version of the item to delete * @returns a message indicating the item was deleted * * [see api docs](https://www.zotero.org/support/dev/web_api/v3/write_requests#deleting_an_item) */ delete_item(args: ZoteroTypes.IDeleteItemArgs): Promise; /** * Delete multiple items with given keys (--keys KEYS). * (API: delete /items/KEY) * * @param args - arguments passed to the function * @param args.keys - the keys of the items to delete, in zotero select link format * @returns a message indicating the items were deleted * * [see api docs](https://www.zotero.org/support/dev/web_api/v3/write_requests#deleting_multiple_items) */ delete_items(args: ZoteroTypes.IDeleteItemsArgs): Promise; /** * Retrieves the items in the trash. * @param args - Additional arguments for the request. * @param args.tags - Whether to retrieve the tags of the items. * @returns A Promise that resolves to the items in the trash. */ trash(args: ZoteroTypes.ITrashArgs): Promise; /** * Return a list of items in publications (user library only). * (API: /publications/items) * @param args - Additional arguments for the request. * @param args.tags - Whether to retrieve the tags of the publications. * @returns A Promise that resolves to the items in the publications. * * https://www.zotero.org/support/dev/web_api/v3/basics * /publications/items Items in My Publications */ publications(args: PublicationsArgs): Promise; /** * Retrieve a list of items types available in Zotero. * (API: /itemTypes) */ types(): Promise; /** * Retrieve the Zotero groups data to which the current * library_id and api_key has access to. * (API: /users//groups) */ groups(): Promise; /** * Retrieve a template with the fields for --type TYPE * (API: /itemTypeFields, /itemTypeCreatorTypes) or all item fields * (API: /itemFields). * Note that to retrieve a template, use 'create-item --template TYPE' * rather than this command. * * @param args.type - Display fields types for TYPE. * @returns A Promise that resolves to the template fields. */ fields(args: { type?: string; }): Promise; /** * Return a list of the saved searches of the library. or create a new saved search. or delete saved searches. * Create new saved searches. (API: /searches) * @param args - Additional arguments for the request. * @param args.key - The key of the saved search to retrieve. or else will retrieve all saved searches. * @param args.create - Create a new saved search. it gets an array of search definitions. * @param args.delete - Delete saved searches, it gets an array of search keys. * @returns * * https://www.zotero.org/support/dev/web_api/v3/basics */ searches(args: ZoteroTypes.ISearchesArgs): Promise; /** * Return a list of tags in the library. Options to filter * and count tags. (API: /tags) * * @param args.filter - Filter tags by a specific tag. * @param args.count - Count the number of items with each tag. * @returns A Promise that resolves to the tags. */ tags(args: ZoteroTypes.ITagsArgs): Promise>; /** * Utility functions. * Enlose the item in a collection and create further subcollections. * * @param args.key - The Zotero item key for the item to be enclosed. * @param args.collection - The Zotero collection key in which the new collection is created. * @param args.title - The title for the new collection. */ enclose_item_in_collection(args: ZoteroTypes.IEncloseItemInCollectionArgs): Promise<{ status: number; message: string; data: any; }>; /** * Get the DOI of the item provided. * @param args * @param args.key - the key of the item to get the DOI for * @param args.fullresponse - whether to return the full response * @see item for more information on the args * @returns the DOI of the item */ get_doi(args: ZoteroTypes.IGetDoiArgs): Promise; /** * Get the DOI of the item provided. * @param item - the item to get the DOI for * @returns the DOI of the item */ get_doi_from_item(item: Item): string; /** * Manages the local synced version of the Zotero library. * * @param args.lookup - Whether to lookup the elements in the local database. * @param group_id - The group ID of the library to get backup from. * @param args.keys - The keys of the items to lookup in the local database. * @param args.sync - Whether to sync the local database with the online library. * @param args.export_json - The name of the file to export records from the local database. * @param args.demon - The cron pattern to run the sync as a demon. * @param args.lockfile - The lockfile for the sync. * @param args.lock_timeout - The number of seconds to wait for the lock before resetting it. * @param args.websocket - Whether to use the websocket for sync if not provided the process will exit after 1 second. * @param args.verbose - Whether to show verbose output. * @returns A promise that resolves to the result of the database management operation. */ manageLocalDB(args: ZoteroTypes.IManageLocalDBArgs): Promise; /** * Deduplicate items in a collection. * It writes the duplicates to a file named `duplicates.json`. * @param args - The deduplication function arguments. * @param args.group_id - The ID of the group to deduplicate. * @param args.api_key - The API key of the group. * @param args.collection - The collection to deduplicate. */ deduplicate_func(args: ZoteroTypes.IDeduplicateFuncArgs): Promise; /** * Move items from deduplicate json file to provided collection. * * @param args.file - The json file to read items from , this file is generated by deduplicate_func function. * @returns A Promise that resolves when the items have been moved and deduplicated. */ Move_deduplicate_to_collection(args: ZoteroTypes.IMoveDeduplicateToCollectionArgs): Promise; /** * Merges items from a specified data file into a Zotero group. * * @param args - The arguments for the merge function. * @param args.data - The path to the data file containing the items to be merged. JSON file. * @param args.options - The options for merging the items. * @param args.group_id - The ID of the Zotero group to merge the items into. */ merge_func(args: ZoteroTypes.IMergeFuncArgs): Promise; /** * Retrieves the count of items from the database based on the provided item IDs. * @param items - An array of item IDs. * @returns A Promise that resolves to the count of items. */ private getItems; /** * Resolve a Zotero Select link (zotero://...) to a key. * * @param args - The arguments to resolve. * @param args.keys - The keys of the items to resolve. * @param args.groupid - The ID of the group to resolve the items from. * @returns The resolved result, null if keys not provided. */ resolvefunc(args: ZoteroTypes.IResolveFuncArgs): Promise>; /** * Update the DOI of the item provided. * * @param args - The arguments for updating the DOI. * @param args.key - The key of the item to update the DOI for. * @param args.doi - The new DOI to update the item with. * @param args.zenodoRecordID - The Zenodo record number for the item. * @param args.verbose - Whether to show verbose output. * @returns A Promise that resolves to the updated item. */ update_doi(args: ZoteroTypes.IUpdateDoiArgs): Promise; TEMPLATE(args: any): Promise; /** * Attaches a link to an item in Zotero. * @param args - The arguments for attaching the link. * @param args.key - The key of the item to attach the link to. * @param args.url - The URL to attach to the item. * @param args.title - The title of the link. * @param args.zenodo - Determine Zenodo id from Zotero item and then add links for Zenodo record, deposit and doi. * @param args.id - The Zenodo ID to attach the link to. * @param args.tags - The tags to attach to the link. * @param args.kerko_site_url - The Kerko site URL to attach to the link. * @param args.update_url_field - Update/overwrite the url field of the item. The url used is `url` (if set) or `kerko-link-key`. * @returns A Promise that resolves to the result of attaching the link. */ attach_link(args: ZoteroTypes.IAttachLinkArgs): Promise; /** * Retrieves the value of a specific field from a Zotero item. * If the `value` argument is provided, it updates the field with the new value. * @param args - The arguments for retrieving or updating the field. * @param args.key - The key of the item to retrieve or update the field for. * @param args.field - The field to retrieve or update. * @param args.value - The new value to update the field with, if not provided, the field value is returned. * @param args.version - The version of the item to update. * @returns The value of the field or the updated Zotero item. */ field(args: ZoteroTypes.IFieldArgs): Promise; extra_append(): Promise<{ status: number; message: string; data: any; }>; /** * Updates the URL of an item in the Zotero library. * @param args - The arguments for updating the URL. * @param args.key - The key of the item to update the URL for. * @param args.value - The new URL to update the item with, if not provided, the field value is returned. * @param args.version - The version of the item to update, or else the latest version will be used * @returns A promise that resolves with the updated item. */ update_url(args: ZoteroTypes.IUpdateUrlArgs): Promise; /** * View/merge - extra>Kerko.CiteItemAlsoKnownAs. * * @param args.key - The key of the item to view or update. * @param args.add - The value to update if not provided the field value is returned. */ KerkoCiteItemAlsoKnownAs(args: ZoteroTypes.IKerkoCiteItemAlsoKnownAsArgs): Promise<{ status: number; message: string; data: any; }>; /** * Get the bibliography * * @param args.key - The key of the item to get the bibliography for. Can be provided as zotero select link * @param args.keys - The array of keys of the items to get the bibliography for. Can be provided as list of Item keys * @param args.group - If you pass `keys` pass `group` as well to specify the group of the keys * @param args.groupkeys - The Zotero items keys for the items for which the bib is obtained. This is a string of the format `1234567:ABCDEFGH,1234567:ABCDEFGH,...` * @param args.xml - The default is for this function to return xml/html (wrapped in json). Use this switch to only return the xml. * @param args.json - The default is for this function to return xml/html (wrapped in json). Use this switch to convert the xml to json. * @param args.zgroup - The source group. Added to the xml. * @param args.zkey - The source key. Added to the xml. * @param args.openinzotero - Target zotero app. Added to the xml. * */ getbib(args: ZoteroTypes.IGetbibArgs): Promise; /** * The get bib function utility * * @param args.key - The key of the item to get the bibliography for. Can be provided as zotero select link * @param args.keys - The array of keys of the items to get the bibliography for. Can be provided as list of Item keys * @param args.group - If you pass `keys` pass `group` as well to specify the group of the keys * @param args.groupkeys - The Zotero items keys for the items for which the bib is obtained. This is a string of the format `1234567:ABCDEFGH,1234567:ABCDEFGH,...` * @param args.xml - The default is for this function to return xml/html (wrapped in json). Use this switch to only return the xml. * @param args.json - The default is for this function to return xml/html (wrapped in json). Use this switch to convert the xml to json. * @param args.zgroup - The source group. Added to the xml. * @param args.zkey - The source key. Added to the xml. * @param args.openinzotero - Target zotero app. Added to the xml. */ getZoteroDataX(args: ZoteroTypes.IGetZoteroDataXargs): Promise; /** * Helper function for getZoteroDataX to get simple item */ makeZoteroQuery(arg: ZoteroTypes.IMakeZoteroQueryArgs): Promise<{ status: number; message: string; data: any[]; }>; /** * Helper function for getZoteroDataX to get multiple items */ makeMultiQuery(args: ZoteroTypes.IMakeMultiQueryArgs): Promise<{ status: number; message: string; data: any[]; errors: any[]; }>; /** * Attach note to item * * @param args.key - The key of the item to attach the note to. * @param args.notetext - The text of the note to attach. * @param args.notefile - The path to the file that contains the note to attach. * @param args.tags - The tags to attach to the note. */ attach_note(args: ZoteroTypes.IAttachNoteArgs): Promise; getValue(args: any): Promise; collectionName(args: any): Promise; amendCollection(args: any): Promise; /** * Finds and handles empty items in the database. * * @param args - The arguments for finding and handling empty items. * @param args.output - The path to store the empty items result in a JSON file. Default is './empty_items.json'. * @param args.delete - Whether to delete the empty items from the database. * @param args.onlykeys - Whether to store only the keys of the empty items. This argument is required when using the 'output' option. */ findEmptyItems(args: ZoteroTypes.IFindEmptyItemsArgs): Promise; formatMessage(m: any): string; } export = Zotero;