rmapi-js 1.1.0 → 2.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/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,21 +70,28 @@ 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
85
  /** parent uuid or "" for root or "trash" */
79
- parent: string;
86
+ parent?: string;
80
87
  /** last modified time */
81
88
  lastModified: string;
82
89
  /** unsure */
83
- version: number;
90
+ version?: number;
84
91
  /** unsure */
85
92
  pinned?: boolean;
86
93
  /** unsure */
87
- synced: boolean;
94
+ synced?: boolean;
88
95
  /** unsure */
89
96
  modified?: boolean;
90
97
  /** if file is deleted */
@@ -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
  */
@@ -347,19 +382,98 @@ export interface RemarkableApi {
347
382
  * more information.
348
383
  *
349
384
  * ```ts
350
- * const entry = await putEpub(...);
385
+ * const entry = await api.putEpub(...);
351
386
  * const [root, gen] = await api.getRootHash();
352
387
  * const rootEntries = await api.getEntries(root);
353
388
  * rootEntries.push(entry);
354
389
  * const { hash } = await api.putEntries("", rootEntries);
355
- * await api.putRootHash(hash, gen);
390
+ * const nextGen = await api.putRootHash(hash, gen);
391
+ * await api.syncComplete(nextGen);
356
392
  * ```
357
393
  *
358
394
  * @param visibleName - the name to show for the uploaded epub
359
395
  * @param buffer - the epub contents
360
396
  * @param opts - extra options you can specify at upload
361
397
  */
362
- putEpub(visibleName: string, buffer: Uint8Array, opts?: PutEpubOptions): Promise<Entry>;
398
+ putEpub(visibleName: string, buffer: Uint8Array, opts?: PutEpubOptions): Promise<CollectionEntry>;
399
+ /**
400
+ * upload a pdf
401
+ *
402
+ * @remarks this only uploads the raw data and returns an entry that could be
403
+ * uploaded as part of a larger collection. To make sure devices know about
404
+ * it, you'll still need to update the root hash, and potentially notify
405
+ * other devices.
406
+ *
407
+ * @example
408
+ * This example shows a full process upload. Note that it may fail if other
409
+ * devices are simultaneously syncing content. See {@link putRootHash} for
410
+ * more information.
411
+ *
412
+ * ```ts
413
+ * const entry = await api.putPdf(...);
414
+ * const [root, gen] = await api.getRootHash();
415
+ * const rootEntries = await api.getEntries(root);
416
+ * rootEntries.push(entry);
417
+ * const { hash } = await api.putEntries("", rootEntries);
418
+ * const nextGen = await api.putRootHash(hash, gen);
419
+ * await api.syncComplete(nextGen);
420
+ * ```
421
+ *
422
+ * @param visibleName - the name to show for the uploaded pdf
423
+ * @param buffer - the pdf contents
424
+ * @param opts - extra options you can specify at upload
425
+ */
426
+ putPdf(visibleName: string, buffer: Uint8Array, opts?: PutPdfOptions): Promise<CollectionEntry>;
427
+ /**
428
+ * indicate that a sync is complete and push updates to other devices
429
+ *
430
+ * @remarks after successfully putting a new root hash, use this to indicate
431
+ * that other devices should pick up the change.
432
+ */
433
+ syncComplete(generation: bigint): Promise<void>;
434
+ /**
435
+ * get metadata on all entries
436
+ *
437
+ * @remarks this uses a newer api, that returns metadata associated with all
438
+ * entries and their hash and documentId.
439
+ */
440
+ getEntriesMetadata(): Promise<MetadataEntry[]>;
441
+ /**
442
+ * upload an epub
443
+ *
444
+ * @remarks this uses a newer api that performs a full upload and sync, but
445
+ * doesn't allow adding the same level of extra content data. Useful if you
446
+ * just want to upload a document with no fuss.
447
+ *
448
+ * @example
449
+ * ```ts
450
+ * await api.uploadEpub("My EPub", ...);
451
+ * ```
452
+ *
453
+ * @param visibleName - the name to show for the uploaded epub
454
+ * @param buffer - the epub contents
455
+ */
456
+ uploadEpub(visibleName: string, buffer: Uint8Array): Promise<UploadEntry>;
457
+ /**
458
+ * upload a pdf
459
+ *
460
+ * this currently uploads invalid pdfs, but it's not clear why, which is why
461
+ * this is marked as experimental. Potentially some tweak in the formatting
462
+ * of buffer will fix it.
463
+ *
464
+ * @remarks this uses a newer api that performs a full upload and sync, but
465
+ * doesn't allow adding the same level of extra information.
466
+ *
467
+ * @example
468
+ * ```ts
469
+ * await api.uploadPdf("My PDF", ...);
470
+ * ```
471
+ *
472
+ * @param visibleName - the name to show for the uploaded epub
473
+ * @param buffer - the epub contents
474
+ * @experimental
475
+ */
476
+ uploadPdf(visibleName: string, buffer: Uint8Array): Promise<UploadEntry>;
363
477
  }
364
478
  /** format an entry */
365
479
  export declare function formatEntry({ hash, type, documentId, subfiles, size, }: Entry): string;
@@ -400,9 +514,11 @@ export interface RemarkableOptions {
400
514
  */
401
515
  subtle?: SubtleCryptoLike;
402
516
  /** the url for making authorization requests */
403
- authUrl?: string;
404
- /** the window for making blob requests */
405
- blobUrl?: string;
517
+ authHost?: string;
518
+ /** the url for making raw document requests */
519
+ docHost?: string;
520
+ /** the url for making synchronization requests */
521
+ syncHost?: string;
406
522
  }
407
523
  /**
408
524
  * create an instance of the api
@@ -410,7 +526,8 @@ export interface RemarkableOptions {
410
526
  * This gets a temporary authentication token with the device token. If
411
527
  * requests start failing, simply recreate the api instance.
412
528
  *
413
- * @param deviceToken - the device token proving this api instance is registered. Create one with {@link register}.
529
+ * @param deviceToken - the device token proving this api instance is
530
+ * registered. Create one with {@link register}.
414
531
  * @returns an api instance
415
532
  */
416
- export declare function remarkable(deviceToken: string, { fetch, cache, subtle, authUrl, blobUrl, }?: RemarkableOptions): Promise<RemarkableApi>;
533
+ export declare function remarkable(deviceToken: string, { fetch, cache, subtle, authHost, syncHost, }?: RemarkableOptions): Promise<RemarkableApi>;