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 +1 -1
- package/README.md +45 -98
- package/dist/index.d.ts +731 -491
- package/dist/index.js +774 -686
- package/dist/lru.d.ts +8 -0
- package/dist/lru.js +64 -0
- package/dist/rmapi-js.esm.min.js +21 -1
- package/package.json +18 -17
- package/dist/index.spec.d.ts +0 -1
- package/dist/index.spec.js +0 -800
- package/dist/test-utils.d.ts +0 -22
- package/dist/test-utils.js +0 -71
- package/dist/utils.d.ts +0 -6
- package/dist/utils.js +0 -22
- package/dist/utils.spec.d.ts +0 -1
- package/dist/utils.spec.js +0 -21
- package/dist/validate.d.ts +0 -3
- package/dist/validate.js +0 -8
- package/dist/validate.spec.d.ts +0 -1
- package/dist/validate.spec.js +0 -15
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,135 +1,82 @@
|
|
|
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
|
-
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.
|
|
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
|
|
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".
|
|
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 `
|
|
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 = "..."
|
|
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
|
|
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.
|
|
43
|
+
await api.uploadEpub("name", buffer);
|
|
44
|
+
await api.uploadPdf("name", buffer);
|
|
67
45
|
```
|
|
68
46
|
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
import { webcrypto } from "crypto";
|
|
85
|
-
const api = await remarkable(token, { digest: webcrypto.subtle.digest });
|
|
86
|
-
```
|
|
50
|
+
```ts
|
|
51
|
+
// ...
|
|
87
52
|
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
93
|
-
|
|
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
|
-
###
|
|
60
|
+
### Gotchas
|
|
104
61
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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.
|