rmapi-js 11.2.0 → 12.0.1

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 CHANGED
@@ -62,8 +62,9 @@ Using these apis is a little riskier since they can potentially result in data l
62
62
  // upload with custom line height not avilable through reMarkable
63
63
  await api.putEpub("name", buffer, { lineHeight: 180 })
64
64
 
65
- // fetch an uploaded epub, using the id and hash (from listItems)
66
- const buffer = await api.getEpub(id, hash)
65
+ // fetch an uploaded epub, passing an item reference (from listItems)
66
+ const [entry] = await api.listItems()
67
+ const buffer = await api.getEpub(entry)
67
68
  ```
68
69
 
69
70
  ### Gotchas
package/dist/index.d.ts CHANGED
@@ -1,21 +1,17 @@
1
- import { type BackgroundFilter, type CollectionContent, type Content, type DocumentContent, type Metadata, type Orientation, type RawRemarkableApi, type RmPage, type SimpleEntry, type Tag, type TemplateContent, type TextAlignment, type ZoomMode } from "./raw.js";
1
+ import { type BackgroundFilter, type CollectionContent, type Content, type DocumentContent, type ItemRef, type Metadata, type Orientation, RawRemarkable, type RmPage, type Tag, type TemplateContent, type TextAlignment, type ZoomMode } from "./raw.js";
2
2
  export { type DeviceModel, type DeviceScreen, deviceScreens, } from "./devices.js";
3
3
  export { HashNotFoundError, ValidationError } from "./error.js";
4
- export type { BackgroundFilter, CollectionContent, Content, CPageNumberValue, CPagePage, CPageStringValue, CPages, CPageUUID, DocumentContent, DocumentMetadata, Entries, FileType, KeyboardMetadata, LegacyCollectionContent, LegacyDocumentContent, Metadata, Orientation, PageTag, RawEntry, RawRemarkableApi, RmPage, SchemaVersion, SimpleEntry, Tag, TemplateContent, TextAlignment, UploadMimeType, ZoomMode, } from "./raw.js";
4
+ export type { BackgroundFilter, CollectionContent, Content, CPageNumberValue, CPagePage, CPageStringValue, CPages, CPageUUID, DocumentContent, DocumentMetadata, Entries, FileType, ItemRef, KeyboardMetadata, LegacyCollectionContent, LegacyDocumentContent, Metadata, Orientation, PageTag, RawEntry, RawRemarkableApi, RmPage, SchemaVersion, Tag, TemplateContent, TextAlignment, UploadMimeType, ZoomMode, } from "./raw.js";
5
5
  export type { RmBrush, RmLayer, RmLine, RmPageV5, RmPoint, RmVersion, } from "./rm5.js";
6
6
  export { decodeBrush, rmColors } from "./rm5.js";
7
7
  export type { AuthorIdsBlock, CrdtId, GlyphRange, LwwValue, MigrationInfoBlock, PageInfoBlock, Rectangle, RmBlock, RmScene, RmSceneItem, RmSceneLayer, RmV6Line, RmV6Point, RmV6Text, RmV6TextValue, RootTextBlock, SceneGlyphItemBlock, SceneGroupItemBlock, SceneInfoBlock, SceneItem, SceneLineItemBlock, SceneTextItemBlock, SceneTombstoneItemBlock, SceneTreeBlock, TreeNodeBlock, UnknownBlock, } from "./rm6.js";
8
8
  export { crdtKey, END_MARKER, parseRmScene, ROOT_ID } from "./rm6.js";
9
9
  /** common properties shared by collections and documents */
10
- export interface EntryCommon {
11
- /** the document id, a uuid4 */
12
- id: string;
13
- /** the current hash of the state of this entry */
14
- hash: string;
10
+ export interface EntryCommon extends ItemRef {
15
11
  /** the visible display name of this entry */
16
12
  visibleName: string;
17
13
  /** the last modified timestamp */
18
- lastModified: string;
14
+ lastModified?: string;
19
15
  /** true if the entry is starred in most ui elements */
20
16
  pinned: boolean;
21
17
  /**
@@ -55,16 +51,6 @@ export interface TemplateType extends EntryCommon {
55
51
  }
56
52
  /** a remarkable entry for cloud items */
57
53
  export type Entry = CollectionEntry | DocumentType | TemplateType;
58
- /** the new hash of a modified entry */
59
- export interface HashEntry {
60
- /** the actual hash */
61
- hash: string;
62
- }
63
- /** the mapping from old hashes to new hashes after a bulk modify */
64
- export interface HashesEntry {
65
- /** the mapping from old to new hashes */
66
- hashes: Record<string, string>;
67
- }
68
54
  /** options for creating a folder */
69
55
  export interface FolderOptions {
70
56
  /** the id of the folder's parent directory, "" or omitted for root */
@@ -221,9 +207,11 @@ export interface PutOptions {
221
207
  * you should be able to use the low level api to work around any restrictive
222
208
  * validation.
223
209
  */
224
- export interface RemarkableApi {
210
+ declare class Remarkable {
211
+ #private;
225
212
  /** scoped access to the raw low-level api */
226
- raw: RawRemarkableApi;
213
+ readonly raw: RawRemarkable;
214
+ constructor(sessionToken: string, rawHost: string, uploadHost: string, cache: Map<string, string | null>, maxGenerationRetries: number, maxTransientRetries: number);
227
215
  /**
228
216
  * list all items
229
217
  *
@@ -249,73 +237,60 @@ export interface RemarkableApi {
249
237
  *
250
238
  * @param refresh - if true, refresh the root hash before listing
251
239
  */
252
- listIds(refresh?: boolean): Promise<SimpleEntry[]>;
240
+ listIds(refresh?: boolean): Promise<ItemRef[]>;
253
241
  /**
254
- * get the content metadata from an item hash
255
- *
256
- * This takes the high level item hash, e.g. the hashes you get from
257
- * {@link listItems | `listItems`} or {@link listIds | `listIds`}.
242
+ * get the content metadata for an item
258
243
  *
259
244
  * @remarks
260
245
  * If this fails validation and you still want to get the content, you can use
261
246
  * the low-level api to get the raw text of the `.content` file in the
262
247
  * `RawEntry` for this hash.
263
248
  *
264
- * @param id - the id of the item (as returned by `listIds`)
265
- * @param hash - the hash of the item to get content for
249
+ * @param ref - a reference to the item (e.g. from `listItems` or `listIds`)
266
250
  * @returns the content
267
251
  */
268
- getContent(id: string, hash: string): Promise<Content>;
252
+ getContent({ id, hash }: ItemRef): Promise<Content>;
269
253
  /**
270
- * get the metadata from an item hash
271
- *
272
- * This takes the high level item hash, e.g. the hashes you get from
273
- * {@link listItems | `listItems`} or {@link listIds | `listIds`}.
254
+ * get the metadata for an item
274
255
  *
275
256
  * @remarks
276
257
  * If this fails validation and you still want to get the content, you can use
277
258
  * the low-level api to get the raw text of the `.metadata` file in the
278
259
  * `RawEntry` for this hash.
279
260
  *
280
- * @param id - the id of the item (as returned by `listIds`)
281
- * @param hash - the hash of the item to get metadata for
261
+ * @param ref - a reference to the item (e.g. from `listItems` or `listIds`)
282
262
  * @returns the metadata
283
263
  */
284
- getMetadata(id: string, hash: string): Promise<Metadata>;
264
+ getMetadata({ id, hash }: ItemRef): Promise<Metadata>;
285
265
  /**
286
- * get the pdf associated with a document hash
266
+ * get the pdf associated with a document
287
267
  *
288
268
  * This returns the raw input pdf, not the rendered pdf with any markup.
289
269
  *
290
- * @param id - the id of the document (as returned by `listIds`)
291
- * @param hash - the hash of the document to get the pdf for (e.g. the hash
292
- * received from `listItems`)
270
+ * @param ref - a reference to the document (e.g. from `listItems`)
293
271
  * @returns the pdf bytes
294
272
  */
295
- getPdf(id: string, hash: string): Promise<Uint8Array>;
273
+ getPdf({ id, hash }: ItemRef): Promise<Uint8Array>;
296
274
  /**
297
- * get the epub associated with a document hash
275
+ * get the epub associated with a document
298
276
  *
299
277
  * This returns the raw input epub if a document was created from an epub.
300
278
  *
301
- * @param id - the id of the document (as returned by `listIds`)
302
- * @param hash - the hash of the document to get the epub for (e.g. the hash
303
- * received from `listItems`)
279
+ * @param ref - a reference to the document (e.g. from `listItems`)
304
280
  * @returns the epub bytes
305
281
  */
306
- getEpub(id: string, hash: string): Promise<Uint8Array>;
282
+ getEpub({ id, hash }: ItemRef): Promise<Uint8Array>;
307
283
  /**
308
284
  * get a single page's parsed reMarkable lines (`.rm`) drawing
309
285
  *
310
- * @param id - the id of the document (as returned by `listIds`)
311
- * @param hash - the hash of the document (e.g. from `listItems`)
286
+ * @param ref - a reference to the document (e.g. from `listItems`)
312
287
  * @param pageId - the id of the page, from the document's `.content` page
313
288
  * list (see {@link getRmPages | `getRmPages`} for every page)
314
289
  * @returns the parsed page, or `undefined` if the page exists but has no
315
290
  * `.rm` drawing (a page you haven't drawn on has no `.rm` file)
316
291
  * @throws if `pageId` is not a page of the document
317
292
  */
318
- getRmPage(id: string, hash: string, pageId: string): Promise<RmPage | undefined>;
293
+ getRmPage(ref: ItemRef, pageId: string): Promise<RmPage | undefined>;
319
294
  /**
320
295
  * get every drawn page of a document, parsed, keyed by page id
321
296
  *
@@ -324,11 +299,10 @@ export interface RemarkableApi {
324
299
  * no drawing (and soft-deleted pages) are omitted. Version 3, 5, and 6 pages
325
300
  * are all supported.
326
301
  *
327
- * @param id - the id of the document (as returned by `listIds`)
328
- * @param hash - the hash of the document (e.g. from `listItems`)
302
+ * @param ref - a reference to the document (e.g. from `listItems`)
329
303
  * @returns the drawn pages, keyed by page id, in document order
330
304
  */
331
- getRmPages(id: string, hash: string): Promise<Map<string, RmPage>>;
305
+ getRmPages(ref: ItemRef): Promise<Map<string, RmPage>>;
332
306
  /**
333
307
  * get a document's entire contents as a zip archive
334
308
  *
@@ -339,11 +313,9 @@ export interface RemarkableApi {
339
313
  * This is an experimental feature. The resulting archive round-trips back
340
314
  * through {@link putDocumentArchive | `putDocumentArchive`}.
341
315
  *
342
- * @param id - the id of the document (as returned by `listIds`)
343
- * @param hash - the hash of the document to get contents for (e.g. the
344
- * hash received from `listItems`)
316
+ * @param ref - a reference to the document (e.g. from `listItems`)
345
317
  */
346
- getDocumentArchive(id: string, hash: string): Promise<Uint8Array>;
318
+ getDocumentArchive({ id, hash }: ItemRef): Promise<Uint8Array>;
347
319
  /**
348
320
  * upload a document archive produced by {@link getDocumentArchive | `getDocumentArchive`}
349
321
  *
@@ -360,11 +332,7 @@ export interface RemarkableApi {
360
332
  * @param buffer - the archive bytes, as returned by `getDocumentArchive`
361
333
  * @param options - overrides for parent, visible name, and id
362
334
  */
363
- putDocumentArchive(buffer: Uint8Array, options?: PutDocumentOptions): Promise<SimpleEntry>;
364
- /** @deprecated renamed; use {@link getDocumentArchive | `getDocumentArchive`} */
365
- getDocument(id: string, hash: string): Promise<Uint8Array>;
366
- /** @deprecated renamed; use {@link putDocumentArchive | `putDocumentArchive`} */
367
- putDocument(buffer: Uint8Array, options?: PutDocumentOptions): Promise<SimpleEntry>;
335
+ putDocumentArchive(buffer: Uint8Array, { refresh, parent, visibleName, id: keepId, }?: PutDocumentOptions): Promise<ItemRef>;
368
336
  /**
369
337
  * use the low-level api to add a pdf document
370
338
  *
@@ -405,7 +373,7 @@ export interface RemarkableApi {
405
373
  * @throws GenerationError if the generation doesn't match the current server generation
406
374
  * @returns the entry for the newly inserted document
407
375
  */
408
- putPdf(visibleName: string, buffer: Uint8Array, opts?: PutOptions): Promise<SimpleEntry>;
376
+ putPdf(visibleName: string, buffer: Uint8Array, opts?: PutOptions): Promise<ItemRef>;
409
377
  /**
410
378
  * use the low-level api to add an epub document
411
379
  *
@@ -421,9 +389,9 @@ export interface RemarkableApi {
421
389
  * @throws GenerationError if the generation doesn't match the current server generation
422
390
  * @returns the entry for the newly inserted document
423
391
  */
424
- putEpub(visibleName: string, buffer: Uint8Array, opts?: PutOptions): Promise<SimpleEntry>;
392
+ putEpub(visibleName: string, buffer: Uint8Array, opts?: PutOptions): Promise<ItemRef>;
425
393
  /** create a folder */
426
- putFolder(visibleName: string, opts?: FolderOptions, refresh?: boolean): Promise<SimpleEntry>;
394
+ putFolder(visibleName: string, { parent }?: FolderOptions, refresh?: boolean): Promise<ItemRef>;
427
395
  /**
428
396
  * upload an epub
429
397
  *
@@ -438,7 +406,7 @@ export interface RemarkableApi {
438
406
  * @param visibleName - the name to show for the uploaded epub
439
407
  * @param buffer - the epub contents
440
408
  */
441
- uploadEpub(visibleName: string, buffer: Uint8Array): Promise<SimpleEntry>;
409
+ uploadEpub(visibleName: string, buffer: Uint8Array): Promise<ItemRef>;
442
410
  /**
443
411
  * upload a pdf
444
412
  *
@@ -453,118 +421,121 @@ export interface RemarkableApi {
453
421
  * @param visibleName - the name to show for the uploaded epub
454
422
  * @param buffer - the epub contents
455
423
  */
456
- uploadPdf(visibleName: string, buffer: Uint8Array): Promise<SimpleEntry>;
424
+ uploadPdf(visibleName: string, buffer: Uint8Array): Promise<ItemRef>;
457
425
  /** create a folder using the simple api */
458
- uploadFolder(visibleName: string): Promise<SimpleEntry>;
426
+ uploadFolder(visibleName: string): Promise<ItemRef>;
459
427
  /**
460
428
  * update content metadata for a document
461
429
  *
462
430
  * @example
463
431
  * ```ts
464
- * await api.updateDocument(doc.hash, { textAlignment: "left" });
432
+ * const next = await api.updateDocument(doc, { textAlignment: "left" });
465
433
  * ```
466
434
  *
467
- * @param hash - the hash of the file to update
435
+ * @param ref - a reference to the file to update
468
436
  * @param content - the fields of content to update
437
+ * @returns a reference to the updated entry, with its new hash
469
438
  */
470
- updateDocument(hash: string, content: Partial<DocumentContent>, refresh?: boolean): Promise<HashEntry>;
439
+ updateDocument(ref: ItemRef, content: Partial<DocumentContent>, refresh?: boolean): Promise<ItemRef>;
471
440
  /**
472
441
  * update content metadata for a collection
473
442
  *
474
443
  * @example
475
444
  * ```ts
476
- * await api.updateCollection(doc.hash, { textAlignment: "left" });
445
+ * const next = await api.updateCollection(dir, { textAlignment: "left" });
477
446
  * ```
478
447
  *
479
- * @param hash - the hash of the file to update
448
+ * @param ref - a reference to the collection to update
480
449
  * @param content - the fields of content to update
450
+ * @returns a reference to the updated entry, with its new hash
481
451
  */
482
- updateCollection(hash: string, content: Partial<CollectionContent>, refresh?: boolean): Promise<HashEntry>;
452
+ updateCollection(ref: ItemRef, content: Partial<CollectionContent>, refresh?: boolean): Promise<ItemRef>;
483
453
  /**
484
454
  * update content metadata for a template
485
455
  *
486
456
  * @example
487
457
  * ```ts
488
- * await api.updateTemplate(doc.hash, { textAlignment: "left" });
458
+ * const next = await api.updateTemplate(tmpl, { textAlignment: "left" });
489
459
  * ```
490
460
  *
491
- * @param hash - the hash of the file to update
461
+ * @param ref - a reference to the template to update
492
462
  * @param content - the fields of content to update
463
+ * @returns a reference to the updated entry, with its new hash
493
464
  */
494
- updateTemplate(hash: string, content: Partial<TemplateContent>, refresh?: boolean): Promise<HashEntry>;
465
+ updateTemplate(ref: ItemRef, content: Partial<TemplateContent>, refresh?: boolean): Promise<ItemRef>;
495
466
  /**
496
467
  * move an entry
497
468
  *
498
469
  * @example
499
470
  * ```ts
500
- * await api.move(doc.hash, dir.id);
471
+ * const next = await api.move(doc, dir.id);
501
472
  * ```
502
473
  *
503
- * @param hash - the hash of the file to move
474
+ * @param ref - a reference to the entry to move
504
475
  * @param parent - the id of the directory to move the entry to, "" (root) and "trash" are special parents
476
+ * @returns a reference to the moved entry, with its new hash
505
477
  */
506
- move(hash: string, parent: string, refresh?: boolean): Promise<HashEntry>;
478
+ move(ref: ItemRef, parent: string, refresh?: boolean): Promise<ItemRef>;
507
479
  /**
508
480
  * delete an entry
509
481
  *
510
482
  * @example
511
483
  * ```ts
512
- * await api.delete(file.hash);
484
+ * await api.delete(file);
513
485
  * ```
514
- * @param hash - the hash of the entry to delete
486
+ * @param ref - a reference to the entry to delete
487
+ * @returns a reference to the deleted entry, with its new hash
515
488
  */
516
- delete(hash: string, refresh?: boolean): Promise<HashEntry>;
489
+ delete(ref: ItemRef, refresh?: boolean): Promise<ItemRef>;
517
490
  /**
518
491
  * rename an entry
519
492
  *
520
493
  * @example
521
494
  * ```ts
522
- * await api.rename(file.hash, "new name");
495
+ * const next = await api.rename(file, "new name");
523
496
  * ```
524
- * @param hash - the hash of the entry to rename
497
+ * @param ref - a reference to the entry to rename
525
498
  * @param visibleName - the new name to assign
499
+ * @returns a reference to the renamed entry, with its new hash
526
500
  */
527
- rename(hash: string, visibleName: string, refresh?: boolean): Promise<HashEntry>;
501
+ rename(ref: ItemRef, visibleName: string, refresh?: boolean): Promise<ItemRef>;
528
502
  /**
529
503
  * star or unstar an entry
530
504
  *
531
505
  * @example
532
506
  * ```ts
533
- * await api.star(file.hash, true);
507
+ * const next = await api.star(file, true);
534
508
  * ```
535
- * @param hash - the hash of the entry to star
509
+ * @param ref - a reference to the entry to star
536
510
  * @param starred - whether the entry should be starred or not
511
+ * @returns a reference to the updated entry, with its new hash
537
512
  */
538
- star(hash: string, starred: boolean, refresh?: boolean): Promise<HashEntry>;
539
- /**
540
- * set if an entry is starred
541
- *
542
- * @deprecated misspelling; use {@link star | `star`} instead
543
- */
544
- stared(hash: string, stared: boolean, refresh?: boolean): Promise<HashEntry>;
513
+ star(ref: ItemRef, starred: boolean, refresh?: boolean): Promise<ItemRef>;
545
514
  /**
546
515
  * move many entries
547
516
  *
548
517
  * @example
549
518
  * ```ts
550
- * await api.bulkMove([file.hash], dir.id);
519
+ * const next = await api.bulkMove([file], dir.id);
551
520
  * ```
552
521
  *
553
- * @param hashes - an array of entry hashes to move
522
+ * @param refs - references to the entries to move
554
523
  * @param parent - the directory id to move the entries to, "" (root) and "trash" are special ids
524
+ * @returns references to the moved entries, each with its new hash
555
525
  */
556
- bulkMove(hashes: readonly string[], parent: string, refresh?: boolean): Promise<HashesEntry>;
526
+ bulkMove(refs: readonly ItemRef[], parent: string, refresh?: boolean): Promise<ItemRef[]>;
557
527
  /**
558
528
  * delete many entries
559
529
  *
560
530
  * @example
561
531
  * ```ts
562
- * await api.bulkDelete([file.hash]);
532
+ * await api.bulkDelete([file]);
563
533
  * ```
564
534
  *
565
- * @param hashes - the hashes of the entries to delete
535
+ * @param refs - references to the entries to delete
536
+ * @returns references to the deleted entries, each with its new hash
566
537
  */
567
- bulkDelete(hashes: readonly string[], refresh?: boolean): Promise<HashesEntry>;
538
+ bulkDelete(refs: readonly ItemRef[], refresh?: boolean): Promise<ItemRef[]>;
568
539
  /**
569
540
  * get the current cache value as a string
570
541
  *
@@ -596,6 +567,7 @@ export interface RemarkableApi {
596
567
  */
597
568
  clearCache(): void;
598
569
  }
570
+ export type { Remarkable as RemarkableApi };
599
571
  /** configuration for exchanging a device token */
600
572
  export interface AuthOptions {
601
573
  /**
@@ -677,7 +649,7 @@ export declare function auth(deviceToken: string, { authHost }?: AuthOptions): P
677
649
  * @param sessionToken - the session token used for authorization
678
650
  * @returns an api instance
679
651
  */
680
- export declare function session(sessionToken: string, { rawHost, uploadHost, cache, maxCacheSize, maxGenerationRetries, maxTransientRetries, }?: RemarkableSessionOptions): RemarkableApi;
652
+ export declare function session(sessionToken: string, { rawHost, uploadHost, cache, maxCacheSize, maxGenerationRetries, maxTransientRetries, }?: RemarkableSessionOptions): Remarkable;
681
653
  /**
682
654
  * create an instance of the api
683
655
  *
@@ -688,4 +660,4 @@ export declare function session(sessionToken: string, { rawHost, uploadHost, cac
688
660
  * registered. Create one with {@link register}.
689
661
  * @returns an api instance
690
662
  */
691
- export declare function remarkable(deviceToken: string, options?: RemarkableOptions): Promise<RemarkableApi>;
663
+ export declare function remarkable(deviceToken: string, options?: RemarkableOptions): Promise<Remarkable>;