1.0.27 • Published 4 months ago

@retorquere/zotero-sync v1.0.27

Weekly downloads
-
License
AGPL
Repository
-
Last release
4 months ago

Zotero one-way sync

  • Get a Zotero API key here -- the key only needs read only access to what you want to have synced
import { Sync } from '@retorquere/zotero-sync'
import { Store } from '@retorquere/zotero-sync/json-store'

(async () => {
  const zotero = new Sync

  // will emit the following so you can track progress:
  // emit(Sync.event.library, <library object>, n, total number of libraries). Called at the start of a library sync. Library name is empty for the main library, if there's a name, it's a group library
  // emit(Sync.event.error, err)
  // emit(Sync.event.item, <item object>, n, total number of items within library). Called when an item is added/updated
  // emit(Sync.event.collection, <collection object>, n, number of collections within library). Called when a collection is added/updated

  for (const event of [ Sync.event.library, Sync.event.collection, Sync.event.item, Sync.event.error ]) {
    zotero.on(event, (e => function() { console.log(e, [...arguments]) })(event))
  }
  await zotero.login(process.env.ZOTERO_API_KEY)
  await zotero.sync(await (new Store).load('data'))
})().catch(err => {
  console.log(err)
  process.exit(1)
})

or

const Sync = require('@retorquere/zotero-sync').Sync
const Store = require('@retorquere/zotero-sync/json-store').Store

(async () => {
  const zotero = new Sync;
  for (const event of [Sync.event.library, Sync.event.collection, Sync.event.item, Sync.event.error]) {
    zotero.on(event, (e => function () { console.log(e, [...arguments]); })(event));
  }
  await zotero.login(process.env.ZOTERO_API_KEY);
  await zotero.sync(await (new Store).load('data'));
})().catch(err => {
    console.log(err);
    process.exit(1);
});

make your own store by implementing

interface Library {
  version: number
  name: string
  save: (name: string, version: number) => Promise<void>
  remove_collections: (keys: string[]) => Promise<void>
  add_collection: (collection: Collection) => Promise<void>
  add: (item: Item.Any) => Promise<void>
  remove: (keys: string[]) => Promise<void>
}

interface Store {
  libraries: string[] // user_or_group_prefix
  remove: (user_or_group_prefix: string) => Promise<void>
  get: (user_or_group_prefix: string) => Promise<Library> // must return a library -- create one if it doesn't exist yet
}
1.0.27

4 months ago

1.0.19

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.22

3 years ago

1.0.21

3 years ago

1.0.20

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.23

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago