rmapi-js 5.0.0 → 7.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2022 Erik Brinkman
3
+ Copyright (c) 2024 Erik Brinkman
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,135 +1,82 @@
1
- rmapi-js
2
- ========
3
- [![build](https://github.com/erikbrinkman/rmapi-js/actions/workflows/node.js.yml/badge.svg)](https://github.com/erikbrinkman/rmapi-js/actions/workflows/node.js.yml)
1
+ # rmapi-js
2
+
3
+ [![build](https://github.com/erikbrinkman/rmapi-js/actions/workflows/build.yml/badge.svg)](https://github.com/erikbrinkman/rmapi-js/actions/workflows/build.yml)
4
4
  [![docs](https://img.shields.io/badge/docs-docs-blue)](https://erikbrinkman.github.io/rmapi-js/modules.html)
5
5
  [![npm](https://img.shields.io/npm/v/rmapi-js)](https://www.npmjs.com/package/rmapi-js)
6
6
  [![license](https://img.shields.io/github/license/erikbrinkman/rmapi-js)](LICENSE)
7
7
 
8
- JavaScript implementation of the reMarkable 1.5 api. This implementation is
9
- built around web standards for fetch and crypto, but can easily be patched to
10
- work for node. It should also be pretty easy to customize to work with
8
+ JavaScript implementation of the reMarkable api. It should also be pretty easy
9
+ to customize to work with
11
10
  [rmfakecloud](https://github.com/ddvk/rmfakecloud), although that might take a
12
- little bit of extra plumbing. At the current time it's only partially complete,
13
- but has the backbone to be flushed out more.
14
-
15
- This implementation is based off of [`rmapi`](https://github.com/juruen/rmapi),
16
- but aims to be a little simpler. Currently this does no direct handling of the
17
- document tree or syncing efficiently with the cloud, although that support can
18
- be build on top of this library. To make those calls efficient, it will be
19
- helpful to supply a custom cache.
11
+ little bit of extra plumbing.
20
12
 
21
- API
22
- ---
13
+ ## API
23
14
 
24
15
  Before using this API it's necessary to have some rudimentary understanding of
25
16
  how the API works.
26
17
 
27
- All data is stored via its sha256 hash. This includes raw files and
28
- "collections", which have a special format listing all of their `Entry`s by
29
- hash and id. Each document or folder is a collection of it's constituant files,
30
- which inclue metadata about the object. All documents and folders are in the
31
- root collection, and there's a versioned hash which indicates the hash of the
32
- root collection. The root hash version is it's "generation".
18
+ All data is stored via its sha256 hash. This includes raw files ("documents")
19
+ and folders ("collections"). The hash indicates the full current state to manage simultaneous edits. Most entries or edits will take an input hash, and return an output hash. Additionally, every entry has an id, which is a uuid4, and remains constantant over the lifetime of the file or folder. There are two special ids, "" (the empty string) which corresponds to the root collection, e.g. the default location for all files, and "trash", which is the trash.
33
20
 
34
- Usage
35
- -----
21
+ ## Usage
36
22
 
37
23
  To explore files in the cloud, you need to first register your api and persist
38
- the token. Then you can use `getEntries` to explore entries of different file
24
+ the token. Then you can use `listFiles` to explore entries of different file
39
25
  collections.
26
+
40
27
  ```ts
41
28
  import { register, remarkable } from "rmapi-js";
42
29
 
43
- const code = "..." // eight letter code from https://my.remarkable.com/device/desktop/connect
44
- const token = await register(code)
45
- // persist token
30
+ const code = "..."; // eight letter code from https://my.remarkable.com/device/desktop/connect
31
+ const token = await register(code);
32
+ // persist token so you don't have to register again
46
33
  const api = await remarkable(token);
47
- const [root] = await api.getRootHash();
48
- const fileEntries = await api.getEntries(root);
49
- for (const entry of fileEntries) {
50
- const children = await api.getEntries(entry.hash);
51
- for (const { hash, documentId } of children) {
52
- if (documentId.endsWith(".metadata")) {
53
- const meta = api.getMetadata(hash);
54
- // get metadata for entry
55
- console.log(meta);
56
- }
57
- }
58
- }
34
+ const fileEntries = await api.listFiles();
59
35
  ```
60
36
 
61
- To upload an epub, simply call upload with the appropriate name and buffer.
37
+ To upload an epub or pdf, simply call upload with the appropriate name and buffer.
38
+
62
39
  ```ts
63
40
  import { remarkable } from "rmapi-js";
64
41
 
65
42
  const api = await remarkable(...);
66
- await api.putEpub("document name", epubBuffer);
43
+ await api.uploadEpub("name", buffer);
44
+ await api.uploadPdf("name", buffer);
67
45
  ```
68
46
 
69
- Note that to actually update the reMarkable to display it, the root hash will
70
- also need to be updated, see method documentation for more info.
71
-
72
- ### Node
73
-
74
- This uses web standards by default, so using within node takes a little more effort.
75
-
76
- You need import the node crypto library and assign it to globals
77
- ```js
78
- import { webcrypto } from "crypto";
79
- global.crypto = webcrypto;
80
- ```
47
+ There are alos low level apis that more directly manipulate cloud storage.
48
+ Using these apis is a little riskier since they can potentially result in data loss, but it does come with increased flexibility.
81
49
 
82
- or optionally pass it into the constructor
83
- ```js
84
- import { webcrypto } from "crypto";
85
- const api = await remarkable(token, { digest: webcrypto.subtle.digest });
86
- ```
50
+ ```ts
51
+ // ...
87
52
 
88
- You also need to have a globally defined fetch. There are several ways to
89
- accomplish this. In node 17.5 or higher you can enable global fetch with
90
- `node --experimental-fetch`
53
+ // upload with custom line height not avilable through reMarkable
54
+ await api.putEpub("name", buffer, { lineHeight: 180 })
91
55
 
92
- You can also rely on `"node-fetch"` which is compliant enough
93
- ```js
94
- import fetch from "node-fetch";
95
- global.fetch = fetch;
96
- ```
97
- or
98
- ```js
99
- import fetch from "node-fetch";
100
- const api = await remarkable(token, { fetch });
56
+ // fetch an uploaded pdf, using the hash (from listFiles)
57
+ const buffer = await api.getEpub(hash)
101
58
  ```
102
59
 
103
- ### Newer API
60
+ ### Gotchas
104
61
 
105
- Recently I discovered the API the the Read on Remarkable extension uses, which
106
- bypasses the syncing and fetching of the root hash. These APIs are pretty
107
- limited but can be an easy first step.
108
-
109
- ```js
110
- import { remarkable } from "rmapi-js";
62
+ By default, all calls try to do their best to verify that the input and output
63
+ matches what I expect. However, since I reverse-engineered this, some of it
64
+ could be wrong. If you ever run into a `ValidationError` and know you want
65
+ whatever data is returned, You'll have to use the low-level api under `api.raw`
66
+ to access the raw text file and parse the result yourself.
111
67
 
112
- const api = await remarkable(...);
113
- // all the files and folders stored on the reMarkable, no roothash necessary
114
- const entries = await api.getEntriesMetadata();
115
- // upload epubs and pdfs without root hash
116
- // NOTE pdfs aren't currently working as expected
117
- // NOTE epub options aren't supported
118
- await api.uploadEpub("name", buffer);
119
- await api.uploadPdf("name", buffer);
120
- ```
68
+ It seems that exporting happens within the apps themselves, which will require
69
+ layout of the remarkable file structure. That's currently outside the scope of
70
+ this project.
121
71
 
72
+ ## Users
122
73
 
123
- Design
124
- ------
74
+ - [✉️ Send Via](https://sendvia.me/) [[github](https://github.com/PaulKinlan/send-to-remarkable)] - upload to reMarkable via email
75
+ - [ⓡ rePub](https://chromewebstore.google.com/detail/repub/blkjpagbjaekkpojgcgdapmikoaolpbl) [[github](https://github.com/hafaio/repub)] - web clipper for reMarkable that supports images and customization
125
76
 
126
- Building a full syncing version of the remarkable filesystem from the cloud API
127
- is a project in and of itself, so I opted to only implement the primative calls
128
- which should still be possible to compose into advanced functionality.
77
+ ## Contributing
129
78
 
130
- In order to make this as easily cross platform as possible, web standards were
131
- chosen as the basis since they enjoy relative adoption in node. However, node
132
- has middling support of webstreams and since none of the reading or writing is
133
- that intensive or doesn't already require the whole file in memory, we opted to
134
- process strings or ArrayBuffers ignoring Readable and WriteableStreams for the
135
- time being.
79
+ Since this has all been reverse engineered, any help expanding the api would be
80
+ helpful. For example, There's currently a function to download the entire state
81
+ of a document, but I ran into trouble trying to reupload that exact same file as
82
+ a clone.