rmapi-js 4.0.1 → 6.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/README.md +32 -90
- package/dist/index.d.ts +101 -514
- package/dist/index.js +159 -701
- package/dist/rmapi-js.esm.min.js +1 -0
- package/package.json +23 -136
- package/CHANGELOG.md +0 -93
- package/bundle/rmapi-js.cjs.min.js +0 -12
- package/bundle/rmapi-js.esm.min.js +0 -12
- package/bundle/rmapi-js.iife.min.js +0 -12
- package/dist/utils.d.ts +0 -6
- package/dist/utils.js +0 -24
- package/dist/validate.d.ts +0 -3
- package/dist/validate.js +0 -8
package/README.md
CHANGED
|
@@ -1,135 +1,77 @@
|
|
|
1
|
-
rmapi-js
|
|
2
|
-
|
|
3
|
-
[](https://github.com/erikbrinkman/rmapi-js/actions/workflows/build.yml)
|
|
4
4
|
[](https://erikbrinkman.github.io/rmapi-js/modules.html)
|
|
5
5
|
[](https://www.npmjs.com/package/rmapi-js)
|
|
6
6
|
[](LICENSE)
|
|
7
7
|
|
|
8
|
-
JavaScript implementation of the reMarkable
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
JavaScript implementation of the reMarkable api. This implementation is built
|
|
9
|
+
around web standards for fetch, but can easily be patched to work for node. It
|
|
10
|
+
should also be pretty easy to customize to work with
|
|
11
11
|
[rmfakecloud](https://github.com/ddvk/rmfakecloud), although that might take a
|
|
12
|
-
little bit of extra plumbing.
|
|
13
|
-
but has the backbone to be flushed out more.
|
|
12
|
+
little bit of extra plumbing.
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
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.
|
|
14
|
+
reMarkable keep updating their API, makig it hard to keep all features
|
|
15
|
+
functioning. The current version is based on the api used by reMarkables web uploader and file viewer. While this api works for moving and uploading, it doesn't support more fine-grained access to document configuration, or downloading.
|
|
20
16
|
|
|
21
|
-
API
|
|
22
|
-
---
|
|
17
|
+
## API
|
|
23
18
|
|
|
24
19
|
Before using this API it's necessary to have some rudimentary understanding of
|
|
25
20
|
how the API works.
|
|
26
21
|
|
|
27
|
-
All data is stored via its sha256 hash. This includes raw files
|
|
28
|
-
"collections", which
|
|
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".
|
|
22
|
+
All data is stored via its sha256 hash. This includes raw files ("documents")
|
|
23
|
+
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. 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
24
|
|
|
34
|
-
Usage
|
|
35
|
-
-----
|
|
25
|
+
## Usage
|
|
36
26
|
|
|
37
27
|
To explore files in the cloud, you need to first register your api and persist
|
|
38
|
-
the token. Then you can use `
|
|
28
|
+
the token. Then you can use `listFiles` to explore entries of different file
|
|
39
29
|
collections.
|
|
30
|
+
|
|
40
31
|
```ts
|
|
41
32
|
import { register, remarkable } from "rmapi-js";
|
|
42
33
|
|
|
43
|
-
const code = "..."
|
|
44
|
-
const token = await register(code)
|
|
45
|
-
// persist token
|
|
34
|
+
const code = "..."; // eight letter code from https://my.remarkable.com/device/desktop/connect
|
|
35
|
+
const token = await register(code);
|
|
36
|
+
// persist token so you don't have to register again
|
|
46
37
|
const api = await remarkable(token);
|
|
47
|
-
const
|
|
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
|
-
}
|
|
38
|
+
const fileEntries = await api.listFiles();
|
|
59
39
|
```
|
|
60
40
|
|
|
61
|
-
To upload an epub, simply call upload with the appropriate name and buffer.
|
|
41
|
+
To upload an epub or pdf, simply call upload with the appropriate name and buffer.
|
|
42
|
+
|
|
62
43
|
```ts
|
|
63
44
|
import { remarkable } from "rmapi-js";
|
|
64
45
|
|
|
65
46
|
const api = await remarkable(...);
|
|
66
|
-
await api.
|
|
47
|
+
await api.uploadEpub("name", buffer);
|
|
48
|
+
await api.uploadPdf("name", buffer);
|
|
67
49
|
```
|
|
68
50
|
|
|
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
51
|
### Node
|
|
73
52
|
|
|
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
|
-
```
|
|
81
|
-
|
|
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
|
-
```
|
|
87
|
-
|
|
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
|
|
53
|
+
This uses web standards by default, so using within node takes a little more effort. You also need to have a globally defined fetch. There are several ways to
|
|
54
|
+
accomplish this. In node 17.5 or higher you can enable global fetch with
|
|
90
55
|
`node --experimental-fetch`
|
|
91
56
|
|
|
92
57
|
You can also rely on `"node-fetch"` which is compliant enough
|
|
58
|
+
|
|
93
59
|
```js
|
|
94
60
|
import fetch from "node-fetch";
|
|
95
61
|
global.fetch = fetch;
|
|
96
62
|
```
|
|
63
|
+
|
|
97
64
|
or
|
|
65
|
+
|
|
98
66
|
```js
|
|
99
67
|
import fetch from "node-fetch";
|
|
100
68
|
const api = await remarkable(token, { fetch });
|
|
101
69
|
```
|
|
102
70
|
|
|
103
|
-
###
|
|
104
|
-
|
|
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";
|
|
111
|
-
|
|
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
|
-
```
|
|
121
|
-
|
|
71
|
+
### Gotchas
|
|
122
72
|
|
|
123
|
-
|
|
124
|
-
------
|
|
73
|
+
By default, all calls try to do their best to verify that the input and output matches what I expect. However, since I reverse-engineered this, some of it could be wrong. If you ever run into a `ValidationError` and know you want whatever data is returned, simply pass `{ verify: false }` in the options to that API, and that should temporarily remove the blocker. However note that in instances like this, the typescript types will be wrong.
|
|
125
74
|
|
|
126
|
-
|
|
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.
|
|
75
|
+
## Contributing
|
|
129
76
|
|
|
130
|
-
|
|
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.
|
|
77
|
+
Thie current API provides high level limited access. I'd love to reverse engineer what the apps use so this can one again tweak document settings as well as download files. Any help doing this or suggesting approaches would be grealy appreciated!
|