rmapi-js 11.1.2 → 12.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 +3 -2
- package/dist/index.d.ts +154 -91
- package/dist/index.js +756 -178
- package/dist/raw.d.ts +97 -65
- package/dist/raw.js +276 -23
- package/dist/rm5.d.ts +111 -0
- package/dist/rm5.js +181 -0
- package/dist/rm6.d.ts +334 -0
- package/dist/rm6.js +728 -0
- package/dist/rmapi-js.esm.min.js +8 -8
- package/package.json +1 -1
package/dist/raw.d.ts
CHANGED
|
@@ -1,14 +1,43 @@
|
|
|
1
|
+
import { type RmPageV5 } from "./rm5.js";
|
|
2
|
+
import { type RmScene } from "./rm6.js";
|
|
3
|
+
/**
|
|
4
|
+
* a parsed reMarkable `.rm` page
|
|
5
|
+
*
|
|
6
|
+
* A discriminated union on `version`: versions 3/5 parse to the flat, renderable
|
|
7
|
+
* {@link RmPageV5 | `RmPageV5`}; version 6 parses to the richer
|
|
8
|
+
* {@link RmScene | `RmScene`} CRDT scene (`version: 6`).
|
|
9
|
+
*/
|
|
10
|
+
export type RmPage = RmPageV5 | RmScene;
|
|
11
|
+
/**
|
|
12
|
+
* parse the bytes of a reMarkable `.rm` page file
|
|
13
|
+
*
|
|
14
|
+
* Dispatches on the header version: versions 3/5 parse to a flat
|
|
15
|
+
* {@link RmPageV5 | `RmPageV5`}; version 6 parses to an
|
|
16
|
+
* {@link RmScene | `RmScene`}. Throws for an unknown version or malformed data.
|
|
17
|
+
*
|
|
18
|
+
* @param data - the raw `.rm` file bytes
|
|
19
|
+
* @returns the parsed page
|
|
20
|
+
*/
|
|
21
|
+
export declare function parseRm(data: Uint8Array): RmPage;
|
|
1
22
|
/** request types */
|
|
2
23
|
export type RequestMethod = "POST" | "GET" | "PUT" | "DELETE" | "PATCH" | "OPTIONS";
|
|
3
24
|
/** the supported upload mime types */
|
|
4
25
|
export type UploadMimeType = "application/pdf" | "application/epub+zip" | "folder";
|
|
5
26
|
/** the schema version */
|
|
6
27
|
export type SchemaVersion = 3 | 4;
|
|
7
|
-
/**
|
|
8
|
-
|
|
9
|
-
|
|
28
|
+
/**
|
|
29
|
+
* a reference to stored cloud data: an id paired with the hash of its state
|
|
30
|
+
*
|
|
31
|
+
* This is the canonical way to point at something in the cloud. The `id` names
|
|
32
|
+
* *what*: a document's uuid at the high level, or a stored file name (like
|
|
33
|
+
* `<id>.content`) at the low level. The `hash` names *which version*, and
|
|
34
|
+
* changes every time that data mutates. Reads take one of these, and mutations
|
|
35
|
+
* return a fresh one with the new hash.
|
|
36
|
+
*/
|
|
37
|
+
export interface ItemRef {
|
|
38
|
+
/** the id of the referenced data: a document uuid, or a stored file name */
|
|
10
39
|
id: string;
|
|
11
|
-
/** the
|
|
40
|
+
/** the hash of the referenced state */
|
|
12
41
|
hash: string;
|
|
13
42
|
}
|
|
14
43
|
/**
|
|
@@ -19,13 +48,9 @@ export interface SimpleEntry {
|
|
|
19
48
|
* files, the high level entry will have the same hash and id as the low-level
|
|
20
49
|
* entry for that collection.
|
|
21
50
|
*/
|
|
22
|
-
export interface RawEntry {
|
|
51
|
+
export interface RawEntry extends ItemRef {
|
|
23
52
|
/** 80000000 for schema 3 collection type or 0 for schema 4 or schema 3 files or */
|
|
24
53
|
type: 80000000 | 0;
|
|
25
|
-
/** the hash of the collection this points to */
|
|
26
|
-
hash: string;
|
|
27
|
-
/** the unique id of the collection */
|
|
28
|
-
id: string;
|
|
29
54
|
/** the number of subfiles */
|
|
30
55
|
subfiles: number;
|
|
31
56
|
/** the total size of everything in the collection */
|
|
@@ -120,6 +145,14 @@ export interface CPagePage {
|
|
|
120
145
|
verticalScroll?: CPageNumberValue;
|
|
121
146
|
/** [unknown] */
|
|
122
147
|
deleted?: CPageNumberValue;
|
|
148
|
+
/**
|
|
149
|
+
* a per-page last-modified epoch-milliseconds timestamp
|
|
150
|
+
*
|
|
151
|
+
* The misspelling is reMarkable's own: the firmware writes this key as
|
|
152
|
+
* `modifed`. Unlike the sibling fields it is a bare string, not a
|
|
153
|
+
* timestamped value.
|
|
154
|
+
*/
|
|
155
|
+
modifed?: string;
|
|
123
156
|
}
|
|
124
157
|
/** [unknown] */
|
|
125
158
|
export interface CPageUUID {
|
|
@@ -379,6 +412,12 @@ export interface Metadata {
|
|
|
379
412
|
/** the visible name of the item, what it's called on the reMarkable */
|
|
380
413
|
visibleName: string;
|
|
381
414
|
}
|
|
415
|
+
/** parse and validate the json text of a `.metadata` file */
|
|
416
|
+
export declare function parseMetadata(text: string): Metadata;
|
|
417
|
+
type AuthedFetch = (method: RequestMethod, url: string, init?: {
|
|
418
|
+
body?: string | Uint8Array;
|
|
419
|
+
headers?: Record<string, string>;
|
|
420
|
+
}) => Promise<Response>;
|
|
382
421
|
/**
|
|
383
422
|
* access to the low-level reMarkable api
|
|
384
423
|
*
|
|
@@ -438,7 +477,10 @@ export interface Metadata {
|
|
|
438
477
|
*
|
|
439
478
|
* Generally all hashes are 64 character hex strings, and all ids are uuid4.
|
|
440
479
|
*/
|
|
441
|
-
export
|
|
480
|
+
export declare class RawRemarkable {
|
|
481
|
+
#private;
|
|
482
|
+
constructor(authedFetch: AuthedFetch, cache: Map<string, string | null>, rawHost: string, uploadHost: string);
|
|
483
|
+
/** make an authorized request to remarkable */
|
|
442
484
|
/**
|
|
443
485
|
* gets the root hash and the current generation
|
|
444
486
|
*
|
|
@@ -451,58 +493,69 @@ export interface RawRemarkableApi {
|
|
|
451
493
|
/**
|
|
452
494
|
* get the raw binary data associated with a hash
|
|
453
495
|
*
|
|
454
|
-
* @param
|
|
455
|
-
* `<id>.docSchema` / `"root.docSchema"`
|
|
456
|
-
* validates
|
|
457
|
-
*
|
|
496
|
+
* @param ref - a reference to the stored file. Its `id` is the logical file
|
|
497
|
+
* name (`<id>.<ext>` for files, or `<id>.docSchema` / `"root.docSchema"`
|
|
498
|
+
* for entry indexes), which reMarkable validates against the rm-filename
|
|
499
|
+
* header. Sub-entries from {@link getEntries | `getEntries`} can be passed
|
|
500
|
+
* directly.
|
|
458
501
|
* @returns the data
|
|
459
502
|
*/
|
|
460
|
-
getHash(
|
|
503
|
+
getHash({ id: fileName, hash }: ItemRef): Promise<Uint8Array>;
|
|
461
504
|
/**
|
|
462
505
|
* get raw text data associated with a hash
|
|
463
506
|
*
|
|
464
507
|
* We assume text data are small, and so cache the entire text. If you want to
|
|
465
508
|
* avoid this, use {@link getHash | `getHash`} combined with a TextDecoder.
|
|
466
|
-
|
|
467
|
-
* @param
|
|
468
|
-
* @param hash - the hash to get text for
|
|
509
|
+
*
|
|
510
|
+
* @param ref - a reference to the stored file (see {@link getHash})
|
|
469
511
|
* @returns the text
|
|
470
512
|
*/
|
|
471
|
-
getText(
|
|
513
|
+
getText({ id: fileName, hash }: ItemRef): Promise<string>;
|
|
472
514
|
/**
|
|
473
515
|
* get the entries associated with a list hash
|
|
474
516
|
*
|
|
475
517
|
* A list hash is the root hash, or any hash with the type 80000000. NOTE
|
|
476
518
|
* these are hashed differently than files.
|
|
477
|
-
|
|
478
|
-
* @param
|
|
479
|
-
* for a sub-document's entry index
|
|
480
|
-
* @param hash - the hash to get entries for
|
|
519
|
+
*
|
|
520
|
+
* @param ref - a reference whose `id` is `"root.docSchema"` for the root, or
|
|
521
|
+
* `"<id>.docSchema"` for a sub-document's entry index
|
|
481
522
|
* @returns the entries
|
|
482
523
|
*/
|
|
483
|
-
getEntries(
|
|
524
|
+
getEntries(ref: ItemRef): Promise<Entries>;
|
|
484
525
|
/**
|
|
485
526
|
* get the parsed and validated `Content` of a content hash
|
|
486
527
|
*
|
|
487
528
|
* Use {@link getText | `getText`} combined with `JSON.parse` to bypass
|
|
488
529
|
* validation
|
|
489
|
-
|
|
490
|
-
* @param
|
|
491
|
-
* @param hash - the hash to get Content for
|
|
530
|
+
*
|
|
531
|
+
* @param ref - a reference to the stored file, typically `"<id>.content"`
|
|
492
532
|
* @returns the content
|
|
493
533
|
*/
|
|
494
|
-
getContent(
|
|
534
|
+
getContent(ref: ItemRef): Promise<Content>;
|
|
495
535
|
/**
|
|
496
536
|
* get the parsed and validated `Metadata` of a metadata hash
|
|
497
537
|
*
|
|
498
538
|
* Use {@link getText | `getText`} combined with `JSON.parse` to bypass
|
|
499
539
|
* validation
|
|
500
|
-
|
|
501
|
-
* @param
|
|
502
|
-
* @param hash - the hash to get Metadata for
|
|
540
|
+
*
|
|
541
|
+
* @param ref - a reference to the stored file, typically `"<id>.metadata"`
|
|
503
542
|
* @returns the metadata
|
|
504
543
|
*/
|
|
505
|
-
getMetadata(
|
|
544
|
+
getMetadata(ref: ItemRef): Promise<Metadata>;
|
|
545
|
+
/**
|
|
546
|
+
* get the parsed reMarkable lines (`.rm`) drawing of a page hash
|
|
547
|
+
*
|
|
548
|
+
* @param ref - a reference to the stored file, typically `"<id>/<pageid>.rm"`
|
|
549
|
+
* @returns the parsed page
|
|
550
|
+
*/
|
|
551
|
+
getRm(ref: ItemRef): Promise<RmPage>;
|
|
552
|
+
/**
|
|
553
|
+
* the same as {@link putFile | `putFile`} but rendering an `RmPage` to `.rm`
|
|
554
|
+
* bytes
|
|
555
|
+
*
|
|
556
|
+
* Only version 3 and 5 pages can be rendered; version 6 pages are read-only.
|
|
557
|
+
*/
|
|
558
|
+
putRm(fileName: string, page: RmPageV5): Promise<[RawEntry, Promise<void>]>;
|
|
506
559
|
/**
|
|
507
560
|
* update the current root hash
|
|
508
561
|
*
|
|
@@ -533,17 +586,17 @@ export interface RawRemarkableApi {
|
|
|
533
586
|
* NOTE: This won't update the state of the reMarkable until this entry is
|
|
534
587
|
* incorporated into the root hash.
|
|
535
588
|
*
|
|
536
|
-
* @param
|
|
589
|
+
* @param fileName - the file name to upload (e.g. `<id>.pdf`)
|
|
537
590
|
* @param bytes - the bytes to upload
|
|
538
591
|
* @returns the new entry and a promise to finish the upload
|
|
539
592
|
*/
|
|
540
|
-
putFile(
|
|
593
|
+
putFile(fileName: string, bytes: Uint8Array): Promise<[RawEntry, Promise<void>]>;
|
|
541
594
|
/** the same as {@link putFile | `putFile`} but with caching for text */
|
|
542
|
-
putText(
|
|
595
|
+
putText(fileName: string, text: string): Promise<[RawEntry, Promise<void>]>;
|
|
543
596
|
/** the same as {@link putText | `putText`} but with extra validation for Content */
|
|
544
|
-
putContent(
|
|
597
|
+
putContent(fileName: string, content: Content): Promise<[RawEntry, Promise<void>]>;
|
|
545
598
|
/** the same as {@link putText | `putText`} but with extra validation for Metadata */
|
|
546
|
-
putMetadata(
|
|
599
|
+
putMetadata(fileName: string, metadata: Metadata): Promise<[RawEntry, Promise<void>]>;
|
|
547
600
|
/**
|
|
548
601
|
* put a set of entries to make an entry list file
|
|
549
602
|
*
|
|
@@ -559,7 +612,10 @@ export interface RawRemarkableApi {
|
|
|
559
612
|
* warning is logged if a schema 3 root index is written.
|
|
560
613
|
*
|
|
561
614
|
* @param id - the id of the list to upload - this should be the item id if
|
|
562
|
-
* uploading an item list, or "root" if uploading a new root list.
|
|
615
|
+
* uploading an item list, or "root" if uploading a new root list. Note the
|
|
616
|
+
* asymmetry with {@link getEntries | `getEntries`}: `getEntries` takes the
|
|
617
|
+
* full `"<id>.docSchema"` file name, whereas `putEntries` takes the bare id
|
|
618
|
+
* and appends `.docSchema` (and special-cases `"root"`) itself.
|
|
563
619
|
* @param entries - the entries to upload
|
|
564
620
|
*
|
|
565
621
|
* @returns the new list entry and a promise to finish the upload
|
|
@@ -575,10 +631,10 @@ export interface RawRemarkableApi {
|
|
|
575
631
|
* @param visibleName - the name of the file as it should appear on the reMarkable
|
|
576
632
|
* @param bytes - the bytes of the file to upload
|
|
577
633
|
* @param mime - the mime type of the file to upload
|
|
578
|
-
|
|
634
|
+
|
|
579
635
|
* @returns a simple entry with the id and hash of the uploaded file
|
|
580
636
|
*/
|
|
581
|
-
uploadFile(visibleName: string, bytes: Uint8Array, mime: UploadMimeType): Promise<
|
|
637
|
+
uploadFile(visibleName: string, bytes: Uint8Array, mime: UploadMimeType): Promise<ItemRef>;
|
|
582
638
|
/**
|
|
583
639
|
* dump the current cache to a string to preserve between session
|
|
584
640
|
*
|
|
@@ -588,28 +644,4 @@ export interface RawRemarkableApi {
|
|
|
588
644
|
/** completely clear the cache */
|
|
589
645
|
clearCache(): void;
|
|
590
646
|
}
|
|
591
|
-
type
|
|
592
|
-
body?: string | Uint8Array;
|
|
593
|
-
headers?: Record<string, string>;
|
|
594
|
-
}) => Promise<Response>;
|
|
595
|
-
export declare class RawRemarkable implements RawRemarkableApi {
|
|
596
|
-
#private;
|
|
597
|
-
constructor(authedFetch: AuthedFetch, cache: Map<string, string | null>, rawHost: string, uploadHost: string);
|
|
598
|
-
/** make an authorized request to remarkable */
|
|
599
|
-
getRootHash(): Promise<[string, number, SchemaVersion]>;
|
|
600
|
-
getHash(fileName: string, hash: string): Promise<Uint8Array>;
|
|
601
|
-
getText(fileName: string, hash: string): Promise<string>;
|
|
602
|
-
getEntries(fileName: string, hash: string): Promise<Entries>;
|
|
603
|
-
getContent(fileName: string, hash: string): Promise<Content>;
|
|
604
|
-
getMetadata(fileName: string, hash: string): Promise<Metadata>;
|
|
605
|
-
putRootHash(hash: string, generation: number, broadcast?: boolean): Promise<[string, number]>;
|
|
606
|
-
putFile(id: string, bytes: Uint8Array): Promise<[RawEntry, Promise<void>]>;
|
|
607
|
-
putText(id: string, text: string): Promise<[RawEntry, Promise<void>]>;
|
|
608
|
-
putContent(id: string, content: Content): Promise<[RawEntry, Promise<void>]>;
|
|
609
|
-
putMetadata(id: string, metadata: Metadata): Promise<[RawEntry, Promise<void>]>;
|
|
610
|
-
putEntries(id: string, entries: readonly RawEntry[], schemaVersion: SchemaVersion): Promise<[RawEntry, Promise<void>]>;
|
|
611
|
-
uploadFile(visibleName: string, bytes: Uint8Array, mime: UploadMimeType): Promise<SimpleEntry>;
|
|
612
|
-
dumpCache(): string;
|
|
613
|
-
clearCache(): void;
|
|
614
|
-
}
|
|
615
|
-
export {};
|
|
647
|
+
export type { RawRemarkable as RawRemarkableApi };
|