rmapi-js 1.1.0 → 2.1.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/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /** request types */
2
- export declare type RequestMethod = "POST" | "GET" | "PUT" | "DELETE";
2
+ export type RequestMethod = "POST" | "GET" | "PUT" | "DELETE";
3
3
  /** text alignment types */
4
- export declare type TextAlignment = "justify" | "left";
4
+ export type TextAlignment = "justify" | "left";
5
5
  /** tool options */
6
6
  export declare const builtinTools: readonly ["Ballpoint", "Ballpointv2", "Brush", "Calligraphy", "ClearPage", "EraseSection", "Eraser", "Fineliner", "Finelinerv2", "Highlighter", "Highlighterv2", "Marker", "Markerv2", "Paintbrush", "Paintbrushv2", "Pencilv2", "SharpPencil", "SharpPencilv2", "SolidPen", "ZoomTool"];
7
7
  /** font name options */
@@ -47,7 +47,7 @@ export declare const builtinLineHeights: {
47
47
  export interface CollectionEntry {
48
48
  /** collection type */
49
49
  type: "80000000";
50
- /** the hash of the file this points to */
50
+ /** the hash of the collection this points to */
51
51
  hash: string;
52
52
  /** the unique id of the collection */
53
53
  documentId: string;
@@ -70,26 +70,33 @@ export interface FileEntry {
70
70
  size: bigint;
71
71
  }
72
72
  /** a remarkable entry for cloud items */
73
- export declare type Entry = CollectionEntry | FileEntry;
73
+ export type Entry = CollectionEntry | FileEntry;
74
+ /** an simple entry produced by the upload api */
75
+ export interface UploadEntry {
76
+ /** the document id */
77
+ docID: string;
78
+ /** the document hash */
79
+ hash: string;
80
+ }
74
81
  /** common metadata for documents and collections */
75
82
  export interface CommonMetadata {
76
83
  /** name of content */
77
84
  visibleName: string;
78
- /** parent uuid or "" for root or "trash" */
79
- parent: string;
85
+ /** parent uuid (documentId) or "" for root or "trash" */
86
+ parent?: string;
80
87
  /** last modified time */
81
88
  lastModified: string;
82
- /** unsure */
83
- version: number;
84
- /** unsure */
89
+ /** unknown significance */
90
+ version?: number;
91
+ /** unknown significance */
85
92
  pinned?: boolean;
86
- /** unsure */
87
- synced: boolean;
88
- /** unsure */
93
+ /** unknown significance */
94
+ synced?: boolean;
95
+ /** unknown significance */
89
96
  modified?: boolean;
90
97
  /** if file is deleted */
91
98
  deleted?: boolean;
92
- /** unsure */
99
+ /** unknown significance */
93
100
  metadatamodified?: boolean;
94
101
  }
95
102
  /** metadata for collection types */
@@ -111,13 +118,30 @@ export interface DocumentTypeMetadata extends CommonMetadata {
111
118
  *
112
119
  * This is found in the the `.metadata` file.
113
120
  */
114
- export declare type Metadata = CollectionTypeMetadata | DocumentTypeMetadata;
121
+ export type Metadata = CollectionTypeMetadata | DocumentTypeMetadata;
122
+ /** fields common to all {@link MetadataEntry | MetadataEntries} */
123
+ export interface BaseMetadataEntry {
124
+ /** the document id of the entry */
125
+ id: string;
126
+ /** the hash of the entry */
127
+ hash: string;
128
+ }
129
+ /** the metadata entry for a collection */
130
+ export interface CollectionMetadataEntry extends BaseMetadataEntry, CollectionTypeMetadata {
131
+ }
132
+ /** the metadata entry for a document */
133
+ export interface DocumentMetadataEntry extends BaseMetadataEntry, DocumentTypeMetadata {
134
+ /** the type of the document */
135
+ fileType: FileType;
136
+ }
137
+ /** a full metadata entry returned by {@link RemarkableApi.getEntriesMetadata} */
138
+ export type MetadataEntry = CollectionMetadataEntry | DocumentMetadataEntry;
115
139
  /** extra content metadata */
116
- export declare type ExtraMetadata = Record<string, string | undefined>;
140
+ export type ExtraMetadata = Record<string, string | undefined>;
117
141
  /** remarkable file type; empty for notebook */
118
- export declare type FileType = "pdf" | "epub" | "";
142
+ export type FileType = "notebook" | "pdf" | "epub" | "";
119
143
  /** document matrix transform */
120
- export declare type Transform = Record<`m${1 | 2 | 3}${1 | 2 | 3}`, number>;
144
+ export type Transform = Record<`m${1 | 2 | 3}${1 | 2 | 3}`, number>;
121
145
  /** content document metadata */
122
146
  export interface DocumentMetadata {
123
147
  /** document title */
@@ -165,7 +189,7 @@ export interface Content {
165
189
  textAlignment?: TextAlignment;
166
190
  }
167
191
  /** anything that can be awaited */
168
- export declare type Awaitable<T> = T | PromiseLike<T>;
192
+ export type Awaitable<T> = T | PromiseLike<T>;
169
193
  /** stripped down version of RequestInit */
170
194
  export interface RequestInitLike {
171
195
  /** request method */
@@ -235,28 +259,28 @@ export interface RegisterOptions {
235
259
  *
236
260
  * Using an improper one will results in the registration being rejected.
237
261
  */
238
- deviceDesc?: string;
262
+ deviceDesc?: "desktop-windows" | "desktop-macos" | "desktop-linux" | "mobile-android" | "mobile-ios" | "browser-chrome" | "remarkable";
239
263
  /**
240
264
  * the unique id of this device
241
265
  *
242
266
  * If omitted it will be randomly generated */
243
267
  uuid?: string;
244
- /** The url to user for authorization requests */
245
- authUrl?: string;
268
+ /** The host to use for authorization requests */
269
+ authHost?: string;
246
270
  /** a function for making fetch requests, see {@link RemarkableOptions.fetch} for more info */
247
271
  fetch?: FetchLike;
248
272
  }
249
273
  /**
250
274
  * register a device and get the token needed to access the api
251
275
  *
252
- * Have users go to `https://my.remarkable.com/device/desktop/connect` and pass
276
+ * Have users go to `https://my.remarkable.com/device/browser/connect` and pass
253
277
  * the resulting code into this function to get a device token. Persist that
254
278
  * token to use the api.
255
279
  *
256
- * @param code - the eight letter code a user got from `https://my.remarkable.com/device/desktop/connect`.
280
+ * @param code - the eight letter code a user got from `https://my.remarkable.com/device/browser/connect`.
257
281
  * @returns the device token necessary for creating an api instace. These never expire so persist as long as necessary.
258
282
  */
259
- export declare function register(code: string, { deviceDesc, uuid, authUrl, fetch, }?: RegisterOptions): Promise<string>;
283
+ export declare function register(code: string, { deviceDesc, uuid, authHost, fetch, }?: RegisterOptions): Promise<string>;
260
284
  /** options for uploading an epub document */
261
285
  export interface PutEpubOptions {
262
286
  /** the parent id, default to root */
@@ -278,6 +302,17 @@ export interface PutEpubOptions {
278
302
  /** the tool to have enabled by default */
279
303
  lastTool?: string;
280
304
  }
305
+ /** options for uploading a pdf */
306
+ export interface PutPdfOptions {
307
+ /** the parent id, default to root */
308
+ parent?: string | undefined;
309
+ /** the page orientation */
310
+ orientation?: "portrait" | "landscape" | undefined;
311
+ /** which page should be shone as the cover */
312
+ cover?: "first" | "visited" | undefined;
313
+ /** the tool to have enabled by default */
314
+ lastTool?: string;
315
+ }
281
316
  /**
282
317
  * the api for accessing remarkable functions
283
318
  */
@@ -333,6 +368,23 @@ export interface RemarkableApi {
333
368
  * This is similar to `putBuffer` but will also cache the upload.
334
369
  */
335
370
  putText(documentId: string, contents: string): Promise<FileEntry>;
371
+ /**
372
+ * put metadata into the cloud
373
+ *
374
+ * This is a small wrapper around {@link RemarkableApi.putText | `putText`}.
375
+ *
376
+ * @param documentId - this should be the documentId of the item that this is
377
+ * metadata for; it should not end in `.metadata`
378
+ * @param metadata - the metadata to upload
379
+ */
380
+ putMetadata(documentId: string, metadata: Metadata): Promise<FileEntry>;
381
+ /**
382
+ * create a new collection (folder)
383
+ *
384
+ * @param documentId - the name of the new folder
385
+ * @param parent - the documentId of the parent collection (folder)
386
+ */
387
+ putCollection(visibleName: string, parent?: string): Promise<CollectionEntry>;
336
388
  /**
337
389
  * upload an epub
338
390
  *
@@ -347,19 +399,98 @@ export interface RemarkableApi {
347
399
  * more information.
348
400
  *
349
401
  * ```ts
350
- * const entry = await putEpub(...);
402
+ * const entry = await api.putEpub(...);
351
403
  * const [root, gen] = await api.getRootHash();
352
404
  * const rootEntries = await api.getEntries(root);
353
405
  * rootEntries.push(entry);
354
406
  * const { hash } = await api.putEntries("", rootEntries);
355
- * await api.putRootHash(hash, gen);
407
+ * const nextGen = await api.putRootHash(hash, gen);
408
+ * await api.syncComplete(nextGen);
356
409
  * ```
357
410
  *
358
411
  * @param visibleName - the name to show for the uploaded epub
359
412
  * @param buffer - the epub contents
360
413
  * @param opts - extra options you can specify at upload
361
414
  */
362
- putEpub(visibleName: string, buffer: Uint8Array, opts?: PutEpubOptions): Promise<Entry>;
415
+ putEpub(visibleName: string, buffer: Uint8Array, opts?: PutEpubOptions): Promise<CollectionEntry>;
416
+ /**
417
+ * upload a pdf
418
+ *
419
+ * @remarks this only uploads the raw data and returns an entry that could be
420
+ * uploaded as part of a larger collection. To make sure devices know about
421
+ * it, you'll still need to update the root hash, and potentially notify
422
+ * other devices.
423
+ *
424
+ * @example
425
+ * This example shows a full process upload. Note that it may fail if other
426
+ * devices are simultaneously syncing content. See {@link putRootHash} for
427
+ * more information.
428
+ *
429
+ * ```ts
430
+ * const entry = await api.putPdf(...);
431
+ * const [root, gen] = await api.getRootHash();
432
+ * const rootEntries = await api.getEntries(root);
433
+ * rootEntries.push(entry);
434
+ * const { hash } = await api.putEntries("", rootEntries);
435
+ * const nextGen = await api.putRootHash(hash, gen);
436
+ * await api.syncComplete(nextGen);
437
+ * ```
438
+ *
439
+ * @param visibleName - the name to show for the uploaded pdf
440
+ * @param buffer - the pdf contents
441
+ * @param opts - extra options you can specify at upload
442
+ */
443
+ putPdf(visibleName: string, buffer: Uint8Array, opts?: PutPdfOptions): Promise<CollectionEntry>;
444
+ /**
445
+ * indicate that a sync is complete and push updates to other devices
446
+ *
447
+ * @remarks after successfully putting a new root hash, use this to indicate
448
+ * that other devices should pick up the change.
449
+ */
450
+ syncComplete(generation: bigint): Promise<void>;
451
+ /**
452
+ * get metadata on all entries
453
+ *
454
+ * @remarks this uses a newer api, that returns metadata associated with all
455
+ * entries and their hash and documentId.
456
+ */
457
+ getEntriesMetadata(): Promise<MetadataEntry[]>;
458
+ /**
459
+ * upload an epub
460
+ *
461
+ * @remarks this uses a newer api that performs a full upload and sync, but
462
+ * doesn't allow adding the same level of extra content data. Useful if you
463
+ * just want to upload a document with no fuss.
464
+ *
465
+ * @example
466
+ * ```ts
467
+ * await api.uploadEpub("My EPub", ...);
468
+ * ```
469
+ *
470
+ * @param visibleName - the name to show for the uploaded epub
471
+ * @param buffer - the epub contents
472
+ */
473
+ uploadEpub(visibleName: string, buffer: Uint8Array): Promise<UploadEntry>;
474
+ /**
475
+ * upload a pdf
476
+ *
477
+ * this currently uploads invalid pdfs, but it's not clear why, which is why
478
+ * this is marked as experimental. Potentially some tweak in the formatting
479
+ * of buffer will fix it.
480
+ *
481
+ * @remarks this uses a newer api that performs a full upload and sync, but
482
+ * doesn't allow adding the same level of extra information.
483
+ *
484
+ * @example
485
+ * ```ts
486
+ * await api.uploadPdf("My PDF", ...);
487
+ * ```
488
+ *
489
+ * @param visibleName - the name to show for the uploaded epub
490
+ * @param buffer - the epub contents
491
+ * @experimental
492
+ */
493
+ uploadPdf(visibleName: string, buffer: Uint8Array): Promise<UploadEntry>;
363
494
  }
364
495
  /** format an entry */
365
496
  export declare function formatEntry({ hash, type, documentId, subfiles, size, }: Entry): string;
@@ -400,9 +531,11 @@ export interface RemarkableOptions {
400
531
  */
401
532
  subtle?: SubtleCryptoLike;
402
533
  /** the url for making authorization requests */
403
- authUrl?: string;
404
- /** the window for making blob requests */
405
- blobUrl?: string;
534
+ authHost?: string;
535
+ /** the url for making raw document requests */
536
+ docHost?: string;
537
+ /** the url for making synchronization requests */
538
+ syncHost?: string;
406
539
  }
407
540
  /**
408
541
  * create an instance of the api
@@ -410,7 +543,8 @@ export interface RemarkableOptions {
410
543
  * This gets a temporary authentication token with the device token. If
411
544
  * requests start failing, simply recreate the api instance.
412
545
  *
413
- * @param deviceToken - the device token proving this api instance is registered. Create one with {@link register}.
546
+ * @param deviceToken - the device token proving this api instance is
547
+ * registered. Create one with {@link register}.
414
548
  * @returns an api instance
415
549
  */
416
- export declare function remarkable(deviceToken: string, { fetch, cache, subtle, authUrl, blobUrl, }?: RemarkableOptions): Promise<RemarkableApi>;
550
+ export declare function remarkable(deviceToken: string, { fetch, cache, subtle, authHost, syncHost, }?: RemarkableOptions): Promise<RemarkableApi>;