rmapi-js 8.2.0 → 8.3.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/raw.d.ts CHANGED
@@ -167,7 +167,7 @@ export interface DocumentContent {
167
167
  */
168
168
  fontName: string;
169
169
  /** the format version, this should always be 1 */
170
- formatVersion: number;
170
+ formatVersion?: number;
171
171
  /** the last opened page, starts at zero */
172
172
  lastOpenedPage?: number;
173
173
  /**
@@ -210,17 +210,37 @@ export interface DocumentContent {
210
210
  * values outside of this range are valid.
211
211
  */
212
212
  textScale: number;
213
- /** [speculative] the center of the zoom for zoomed in documents */
213
+ /**
214
+ * the center of the zoom for customFit zoom
215
+ *
216
+ * This is an absolute offset from the center of the page. Negative numbers
217
+ * indicate shifted left and positive numbers indicate shifted right. The
218
+ * units are relative to the document pixels, but it's not sure how the
219
+ * document size is calculated.
220
+ */
214
221
  customZoomCenterX?: number;
215
- /** [speculative] the center of the zoom for zoomed in documents */
222
+ /**
223
+ * the center of the zoom for customFit documents
224
+ *
225
+ * This is an absolute number relative to the top of the page. Negative
226
+ * numbers indicate shifted up, while positive numbers indicate shifted down.
227
+ * The units are relative to the document pixels, but it's not sure how the
228
+ * document size is calculated.
229
+ */
216
230
  customZoomCenterY?: number;
217
- /** [speculative] the orientation */
231
+ /** this seems unused */
218
232
  customZoomOrientation?: Orientation;
219
- /** [speculative] the zoom height for zoomed in pages */
233
+ /** this seems unused */
220
234
  customZoomPageHeight?: number;
221
- /** [speculative] the zoom width for zoomed in pages */
235
+ /** this seems unused */
222
236
  customZoomPageWidth?: number;
223
- /** [speculative] the scale for zoomed in pages */
237
+ /**
238
+ * the scale for customFit documents
239
+ *
240
+ * 1 indicates no zoom, smaller numbers indicate zoomed out, larger numbers
241
+ * indicate zoomed in. reMarkable generally allows setting this from 0.5 to 5,
242
+ * but values outside that bound are still supported.
243
+ */
224
244
  customZoomScale?: number;
225
245
  /** what zoom mode is set for the page */
226
246
  zoomMode?: ZoomMode;
@@ -261,7 +281,7 @@ export interface TemplateContent {
261
281
  /** semantic version for this template */
262
282
  templateVersion: string;
263
283
  /** template configuration format version (currently just `1`) */
264
- formatVersion: number;
284
+ formatVersion?: number;
265
285
  /**
266
286
  * which screens the template supports:
267
287
  *
package/dist/raw.js CHANGED
@@ -70,7 +70,6 @@ const documentContent = properties({
70
70
  extraMetadata: values(string()),
71
71
  fileType: enumeration("epub", "notebook", "pdf"),
72
72
  fontName: string(),
73
- formatVersion: uint8(),
74
73
  lineHeight: int32(),
75
74
  orientation: enumeration("portrait", "landscape"),
76
75
  pageCount: uint32(),
@@ -86,6 +85,7 @@ const documentContent = properties({
86
85
  customZoomPageWidth: float64(),
87
86
  customZoomScale: float64(),
88
87
  dummyDocument: boolean(),
88
+ formatVersion: uint8(),
89
89
  keyboardMetadata: properties({
90
90
  count: uint32(),
91
91
  timestamp: float64(),
@@ -120,10 +120,11 @@ const templateContent = properties({
120
120
  labels: elements(string()),
121
121
  orientation: enumeration("portrait", "landscape"),
122
122
  templateVersion: string(),
123
- formatVersion: uint8(),
124
123
  supportedScreens: elements(enumeration("rm2", "rmPP")),
125
124
  constants: elements(values(int32())),
126
125
  items: elements(empty()),
126
+ }, {
127
+ formatVersion: uint8(),
127
128
  });
128
129
  const metadata = properties({
129
130
  lastModified: string(),
@@ -13,7 +13,7 @@ While trying to validate:
13
13
  ${Q}
14
14
 
15
15
  Against schema:
16
- ${q}`)}else return!0}}class B9 extends k0{#$;definitions;nullable=!0;constructor($){super();this.#$=$,this.definitions=$.definitions}*pathErrors($){if($!==null)for(let[V,Q]of this.#$.pathErrors($))yield[V,`${Q} or ${o0($)} is not null`]}fuzz(){return u1(0.1)?null:this.#$.fuzz()}schema(){return{...this.#$.schema(),nullable:!0}}}function C9($){return new B9($)}class DY extends k0{#$;#Q;definitions;nullable;constructor($,V){super();this.#$=$,this.#Q=V,this.definitions=$.definitions,this.nullable=$.nullable}*pathErrors($){yield*this.#$.pathErrors($)}fuzz(){return this.#$.fuzz()}schema(){return{...this.#$.schema(),metadata:this.#Q}}}class I9 extends k0{*pathErrors($){if($===void 0)yield[[],"value is undefined"]}fuzz(){return m2([()=>null,u1,O$,()=>F1(r0()),()=>Array(r0()).fill(null).map(()=>this.fuzz()),()=>Object.fromEntries(Array(r0()).fill(null).map(()=>[F1(r0(3)),this.fuzz()]))])()}schema(){return{}}}function D9(){return new I9}class w9 extends k0{*pathErrors($){if(typeof $!=="boolean")yield[[],`${o0($)} is not a boolean`]}fuzz(){return u1()}schema(){return{type:"boolean"}}}function i6(){return new w9}class p2 extends k0{#$;#Q;#V;constructor($){super();this.#$=$,[this.#Q,this.#V]=BY[$]}*pathErrors($){if(typeof $!=="number")yield[[],`${o0($)} is not a number`];else if($%1!==0)yield[[],`${$.toPrecision()} is not an integer`];else if($<this.#Q)yield[[],`${$.toFixed()} is less than ${this.#Q.toFixed()}`];else if($>=this.#V)yield[[],`${$.toFixed()} is greater than ${(this.#V-1).toFixed()}`]}fuzz(){return L9(this.#Q,this.#V)}schema(){return{type:this.#$}}}function d1(){return new p2("uint8")}function M6(){return new p2("int32")}function n6(){return new p2("uint32")}class N9 extends k0{#$;constructor($){super();this.#$=$}*pathErrors($){if(typeof $!=="number")yield[[],`${o0($)} is not number, expected a float`]}fuzz(){return O$()}schema(){return{type:this.#$}}}function v0(){return new N9("float64")}class v9 extends k0{*pathErrors($){if(typeof $!=="string")yield[[],`${o0($)} is not a string`]}fuzz(){return F1(r0(3))}schema(){return{type:"string"}}}function X0(){return new v9}class A9 extends k0{*pathErrors($){if(typeof $!=="string")yield[[],`${o0($)} is not a string`];else if(!HY($))yield[[],`${$} is not a valid timestamp`]}fuzz(){return new Date(Math.random()*3153600000000).toISOString()}schema(){return{type:"timestamp"}}}function R9(){return new A9}class x9 extends k0{#$;#Q;constructor($,V){super();this.#$=$,this.#Q=V}*pathErrors($){if(typeof $!=="string")yield[[],`${o0($)} is not a string`];else if(!this.#Q.has($))yield[[],`${$} is not one of ${this.#$.join(", ")}`]}fuzz(){return m2(this.#$)}schema(){return{enum:[...this.#$]}}}function X6(...$){let V=new Set($);if(V.size!==$.length)throw new Error("enum can't contain duplicates");else return new x9($,V)}class T9 extends k0{#$;constructor($){super();this.#$=$}*pathErrors($){if(!Array.isArray($))yield[[],`${o0($)} is not an array`];else for(let[V,Q]of $.entries())for(let[q,K]of this.#$.pathErrors(Q))q.push(`[${V.toFixed()}]`),yield[q,K]}fuzz(){return Array(r0()).fill(null).map(()=>this.#$.fuzz())}schema(){return{elements:this.#$.schema()}}}function _0($){if($.definitions)throw new Error("definitions can only exist on a root schema");else return new T9($)}class S9 extends k0{#$;constructor($){super();this.#$=$}*pathErrors($){if(!_2($))yield[[],`${o0($)} is not a record`];else for(let[V,Q]of Object.entries($))for(let[q,K]of this.#$.pathErrors(Q))q.push(Z1(V)),yield[q,K]}fuzz(){return Object.fromEntries(Array(r0()).fill(null).map(()=>[F1(r0(3)),this.#$.fuzz()]))}schema(){return{values:this.#$.schema()}}}function l1($){if($.definitions)throw new Error("definitions can only exist on a root schema");else return new S9($)}class k9 extends k0{#$;#Q;#V;keys;constructor($,V,Q,q){super();this.#$=$,this.#Q=V,this.#V=Q,this.keys=q}*pathErrors($){if(!_2($))yield[[],`${o0($)} is not a record`];else{if(this.#$)for(let[V,Q]of this.#$){let q=$[V];if(q===void 0)yield[[],`required key '${V}' is missing`];else for(let[K,G]of Q.pathErrors(q))K.push(Z1(V)),yield[K,G]}if(this.#Q){for(let[V,Q]of this.#Q)if($[V]!==void 0)for(let[q,K]of Q.pathErrors($[V]))q.push(Z1(V)),yield[q,K]}if(!this.#V){for(let V of Object.keys($))if(!this.keys.has(V))yield[[Z1(V)],`'${V}' is not a valid property and additional properties are not allowed`]}}}fuzz(){let $=h2(this.#$??[],([q,K])=>[q,K.fuzz()]),V=h2(CY(this.#Q??[],()=>u1()),([q,K])=>[q,K.fuzz()]),Q=this.#V?h2(IY(r0()),()=>[F1(r0(3)),m2([()=>null,u1,O$,()=>F1(r0()),()=>[],()=>({})])()]):[];return Object.fromEntries(O9($,V,Q))}schema(){let $={};if(this.#$)$.properties=Object.fromEntries(this.#$.map(([V,Q])=>[V,Q.schema()]));if(this.#Q)$.optionalProperties=Object.fromEntries(this.#Q.map(([V,Q])=>[V,Q.schema()]));if(this.#V)$.additionalProperties=!0;return $}}function wY($,V,Q){let q=new Set(h2(O9($??[],V??[]),([K])=>K));if($?.some(([,K])=>K.definitions))throw new Error("definitions can only exist on a root schema");else if(V?.some(([,K])=>K.definitions))throw new Error("definitions can only exist on a root schema");else if(q.size!==($?.length??0)+(V?.length??0))throw new Error("properties and optionalProperties keys must be unique");else return new k9($,V,Q??!1,q)}function N0($,V,Q){return wY($?Object.entries($):void 0,V?Object.entries(V):void 0,Q)}class NY extends k0{#$;#Q;#V;constructor($,V,Q){super();this.#$=$,this.#Q=V,this.#V=Q}guard($){if(!_2($))return!1;let{[this.#$]:V,...Q}=$;if(typeof V!=="string")return!1;return this.#Q[V]?.guard(Q)??!1}*pathErrors($){if(!_2($))yield[[],`${o0($)} is not an object`];else{let{[this.#$]:V,...Q}=$;if(V===void 0)yield[[],`discriminator key '${this.#$}' is missing`];else if(typeof V!=="string")yield[[Z1(this.#$)],`${o0(V)} is not a string`];else{let q=this.#Q[V];if(q===void 0)yield[[Z1(this.#$)],`'${V}' is not a valid discriminator value (${Object.keys(this.#Q).join(", ")})`];else yield*q.pathErrors(Q)}}}fuzz(){let[$,V]=m2(this.#V);return{...V.fuzz(),[this.#$]:$}}schema(){let $=Object.fromEntries(this.#V.map(([V,Q])=>[V,Q.schema()]));return{discriminator:this.#$,mapping:$}}}class g9 extends k0{#$;#Q;definitions=!0;constructor($,V){super();this.#$=$,this.#Q=V}*pathErrors($){yield*this.#Q.pathErrors($)}fuzz(){return this.#Q.fuzz()}schema(){let $=Object.fromEntries(Object.entries(this.#$).map(([V,Q])=>[V,Q.schema()]));return{...this.#Q.schema(),definitions:$}}}class E9 extends k0{#$;#Q;constructor($,V){super();this.#$=$,this.#Q=V}*pathErrors($){yield*this.#Q.pathErrors($)}fuzz(){return this.#Q.fuzz()}schema(){return{ref:this.#$}}}class y9{#$;#Q;constructor($,V){this.#$=$,this.#Q=V}def($,V){let Q=V(this.#Q);return new y9({...this.#$,[$]:Q},{...this.#Q,[$]:new E9($,Q)})}build($){return new g9(this.#$,$(this.#Q))}}class vY extends k0{#$;#Q;constructor($,V){super();this.#Q=$,this.#$=V}#V(){let $=this.#Q[this.#$];if($===void 0)throw new Error(`ref ${this.#$} was not in definitions after ref builder was finished`);else return $}*pathErrors($){yield*this.#V().pathErrors($)}fuzz(){return this.#V().fuzz()}schema(){return{ref:this.#$}}}var g0=[];for(let $=0;$<256;++$)g0.push(($+256).toString(16).slice(1));function b9($,V=0){return(g0[$[V+0]]+g0[$[V+1]]+g0[$[V+2]]+g0[$[V+3]]+"-"+g0[$[V+4]]+g0[$[V+5]]+"-"+g0[$[V+6]]+g0[$[V+7]]+"-"+g0[$[V+8]]+g0[$[V+9]]+"-"+g0[$[V+10]]+g0[$[V+11]]+g0[$[V+12]]+g0[$[V+13]]+g0[$[V+14]]+g0[$[V+15]]).toLowerCase()}var B$,AY=new Uint8Array(16);function C$(){if(!B$){if(typeof crypto==="undefined"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");B$=crypto.getRandomValues.bind(crypto)}return B$(AY)}var RY=typeof crypto!=="undefined"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),I$={randomUUID:RY};function xY($,V,Q){if(I$.randomUUID&&!V&&!$)return I$.randomUUID();$=$||{};let q=$.random??$.rng?.()??C$();if(q.length<16)throw new Error("Random bytes length must be >= 16");if(q[6]=q[6]&15|64,q[8]=q[8]&63|128,V){if(Q=Q||0,Q<0||Q+16>V.length)throw new RangeError(`UUID byte range ${Q}:${Q+15} is out of buffer bounds`);for(let K=0;K<16;++K)V[Q+K]=q[K];return V}return b9(q)}var H1=xY;class Y6 extends Error{field;regex;constructor($,V,Q){super(Q);this.field=$,this.regex=V}}class o1 extends Error{hash;constructor($){super(`'${$}' not found in the root hash`);this.hash=$}}class D$ extends Map{#$;#Q=0;constructor($,V=[]){super();this.#$=$;for(let[Q,q]of V)this.set(Q,q)}get($){let V=super.get($);if(V!==void 0)super.delete($),super.set($,V);return V}set($,V){let Q=super.get($);if(Q===void 0)this.#Q+=$.length;else if(Q!==null)this.#Q-=Q.length;if(V!==null)this.#Q+=V.length;super.delete($);let q;while(this.#Q>this.#$&&(q=this.entries().next().value)){let[K,G]=q;if(super.delete(K),this.#Q-=K.length,G!==null)this.#Q-=G.length}return super.set($,V),this}delete($){let V=super.get($);if(V===void 0)return!1;if(super.delete($),V!==null)this.#Q-=V.length;return this.#Q-=$.length,!0}clear(){super.clear(),this.#Q=0}}var A$=kY;var K6=[],v$=[];var w$="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(x6=0,N$=w$.length;x6<N$;++x6)K6[x6]=w$[x6],v$[w$.charCodeAt(x6)]=x6;var x6,N$;v$[45]=62;v$[95]=63;function TY($){return K6[$>>18&63]+K6[$>>12&63]+K6[$>>6&63]+K6[$&63]}function SY($,V,Q){var q,K=[];for(var G=V;G<Q;G+=3)q=($[G]<<16&16711680)+($[G+1]<<8&65280)+($[G+2]&255),K.push(TY(q));return K.join("")}function kY($){var V,Q=$.length,q=Q%3,K=[],G=16383;for(var W=0,J=Q-q;W<J;W+=G)K.push(SY($,W,W+G>J?J:W+G));if(q===1)V=$[Q-1],K.push(K6[V>>2]+K6[V<<4&63]+"==");else if(q===2)V=($[Q-2]<<8)+$[Q-1],K.push(K6[V>>10]+K6[V>>4&63]+K6[V<<2&63]+"=");return K.join("")}var m9=y$(h9(),1);var c2=/^[0-9a-f]{64}$/,p9=N0({name:X0(),timestamp:v0()},void 0,!0),gY=N0({name:X0(),pageId:X0(),timestamp:v0()},void 0,!0),EY=N0(void 0,{authors:_0(X0()),title:X0(),publicationDate:X0(),publisher:X0()},!0),yY=N0({id:X0(),idx:N0({timestamp:X0(),value:X0()},void 0,!0)},{template:N0({timestamp:X0(),value:X0()},void 0,!0),redir:N0({timestamp:X0(),value:M6()},void 0,!0),scrollTime:N0({timestamp:X0(),value:R9()},void 0,!0),verticalScroll:N0({timestamp:X0(),value:v0()},void 0,!0),deleted:N0({timestamp:X0(),value:M6()},void 0,!0)},!0),bY=N0({lastOpened:N0({timestamp:X0(),value:X0()},void 0,!0),original:N0({timestamp:X0(),value:M6()},void 0,!0),pages:_0(yY),uuids:_0(N0({first:X0(),second:n6()},void 0,!0))},void 0,!0),fY=N0(void 0,{tags:_0(p9)}),hY=N0({coverPageNumber:M6(),documentMetadata:EY,extraMetadata:l1(X0()),fileType:X6("epub","notebook","pdf"),fontName:X0(),formatVersion:d1(),lineHeight:M6(),orientation:X6("portrait","landscape"),pageCount:n6(),sizeInBytes:X0(),textAlignment:X6("justify","left"),textScale:v0()},{cPages:bY,customZoomCenterX:v0(),customZoomCenterY:v0(),customZoomOrientation:X6("portrait","landscape"),customZoomPageHeight:v0(),customZoomPageWidth:v0(),customZoomScale:v0(),dummyDocument:i6(),keyboardMetadata:N0({count:n6(),timestamp:v0()},void 0,!0),lastOpenedPage:n6(),margins:n6(),originalPageCount:M6(),pages:_0(X0()),pageTags:_0(gY),redirectionPageMap:_0(M6()),tags:_0(p9),transform:N0({m11:v0(),m12:v0(),m13:v0(),m21:v0(),m22:v0(),m23:v0(),m31:v0(),m32:v0(),m33:v0()},void 0,!0),viewBackgroundFilter:X6("off","fullpage"),zoomMode:X6("bestFit","customFit","fitToHeight","fitToWidth")},!0),_Y=N0({name:X0(),author:X0(),iconData:X0(),categories:_0(X0()),labels:_0(X0()),orientation:X6("portrait","landscape"),templateVersion:X0(),formatVersion:d1(),supportedScreens:_0(X6("rm2","rmPP")),constants:_0(l1(M6())),items:_0(D9())}),mY=N0({lastModified:X0(),parent:X0(),pinned:i6(),type:X6("DocumentType","CollectionType","TemplateType"),visibleName:X0()},{lastOpened:X0(),lastOpenedPage:n6(),createdTime:X0(),deleted:i6(),metadatamodified:i6(),modified:i6(),synced:i6(),version:d1()},!0),pY=N0({hash:X0(),generation:v0()},void 0,!0),cY=N0({hash:X0(),generation:v0(),schemaVersion:d1()},void 0,!0);async function _9($){let V=await crypto.subtle.digest("SHA-256",$);return[...new Uint8Array(V)].map((Q)=>Q.toString(16).padStart(2,"0")).join("")}class x${#$;#Q;#V;constructor($,V,Q){this.#$=$,this.#V=V,this.#Q=Q}async getRootHash(){let V=await(await this.#$("GET",`${this.#Q}/sync/v4/root`)).text(),Q=JSON.parse(V);if(!cY.guardAssert(Q))throw Error("invalid root hash");let{hash:q,generation:K,schemaVersion:G}=Q;if(G!==3)throw new Error(`schema version ${G} not supported`);else if(!Number.isSafeInteger(K))throw new Error(`generation ${K} was not a safe integer; please file a bug report`);else return[q,K]}async#q($){if(!c2.test($))throw new Y6($,c2,"hash was not a valid hash");let Q=await(await this.#$("GET",`${this.#Q}/sync/v3/files/${$}`)).arrayBuffer();return new Uint8Array(Q)}async getHash($){let V=this.#V.get($);if(V!=null)return new TextEncoder().encode(V);else{let Q=await this.#q($);if(this.#V.get($)===void 0)this.#V.set($,null);return Q}}async getText($){let V=this.#V.get($);if(V!=null)return V;else{let Q=await this.#q($),K=new TextDecoder().decode(Q);return this.#V.set($,K),K}}async getEntries($){let V=await this.getText($),[Q,...q]=V.slice(0,-1).split(`
16
+ ${q}`)}else return!0}}class B9 extends k0{#$;definitions;nullable=!0;constructor($){super();this.#$=$,this.definitions=$.definitions}*pathErrors($){if($!==null)for(let[V,Q]of this.#$.pathErrors($))yield[V,`${Q} or ${o0($)} is not null`]}fuzz(){return u1(0.1)?null:this.#$.fuzz()}schema(){return{...this.#$.schema(),nullable:!0}}}function C9($){return new B9($)}class DY extends k0{#$;#Q;definitions;nullable;constructor($,V){super();this.#$=$,this.#Q=V,this.definitions=$.definitions,this.nullable=$.nullable}*pathErrors($){yield*this.#$.pathErrors($)}fuzz(){return this.#$.fuzz()}schema(){return{...this.#$.schema(),metadata:this.#Q}}}class I9 extends k0{*pathErrors($){if($===void 0)yield[[],"value is undefined"]}fuzz(){return m2([()=>null,u1,O$,()=>F1(r0()),()=>Array(r0()).fill(null).map(()=>this.fuzz()),()=>Object.fromEntries(Array(r0()).fill(null).map(()=>[F1(r0(3)),this.fuzz()]))])()}schema(){return{}}}function D9(){return new I9}class w9 extends k0{*pathErrors($){if(typeof $!=="boolean")yield[[],`${o0($)} is not a boolean`]}fuzz(){return u1()}schema(){return{type:"boolean"}}}function i6(){return new w9}class p2 extends k0{#$;#Q;#V;constructor($){super();this.#$=$,[this.#Q,this.#V]=BY[$]}*pathErrors($){if(typeof $!=="number")yield[[],`${o0($)} is not a number`];else if($%1!==0)yield[[],`${$.toPrecision()} is not an integer`];else if($<this.#Q)yield[[],`${$.toFixed()} is less than ${this.#Q.toFixed()}`];else if($>=this.#V)yield[[],`${$.toFixed()} is greater than ${(this.#V-1).toFixed()}`]}fuzz(){return L9(this.#Q,this.#V)}schema(){return{type:this.#$}}}function d1(){return new p2("uint8")}function M6(){return new p2("int32")}function n6(){return new p2("uint32")}class N9 extends k0{#$;constructor($){super();this.#$=$}*pathErrors($){if(typeof $!=="number")yield[[],`${o0($)} is not number, expected a float`]}fuzz(){return O$()}schema(){return{type:this.#$}}}function v0(){return new N9("float64")}class v9 extends k0{*pathErrors($){if(typeof $!=="string")yield[[],`${o0($)} is not a string`]}fuzz(){return F1(r0(3))}schema(){return{type:"string"}}}function X0(){return new v9}class A9 extends k0{*pathErrors($){if(typeof $!=="string")yield[[],`${o0($)} is not a string`];else if(!HY($))yield[[],`${$} is not a valid timestamp`]}fuzz(){return new Date(Math.random()*3153600000000).toISOString()}schema(){return{type:"timestamp"}}}function R9(){return new A9}class x9 extends k0{#$;#Q;constructor($,V){super();this.#$=$,this.#Q=V}*pathErrors($){if(typeof $!=="string")yield[[],`${o0($)} is not a string`];else if(!this.#Q.has($))yield[[],`${$} is not one of ${this.#$.join(", ")}`]}fuzz(){return m2(this.#$)}schema(){return{enum:[...this.#$]}}}function X6(...$){let V=new Set($);if(V.size!==$.length)throw new Error("enum can't contain duplicates");else return new x9($,V)}class T9 extends k0{#$;constructor($){super();this.#$=$}*pathErrors($){if(!Array.isArray($))yield[[],`${o0($)} is not an array`];else for(let[V,Q]of $.entries())for(let[q,K]of this.#$.pathErrors(Q))q.push(`[${V.toFixed()}]`),yield[q,K]}fuzz(){return Array(r0()).fill(null).map(()=>this.#$.fuzz())}schema(){return{elements:this.#$.schema()}}}function _0($){if($.definitions)throw new Error("definitions can only exist on a root schema");else return new T9($)}class S9 extends k0{#$;constructor($){super();this.#$=$}*pathErrors($){if(!_2($))yield[[],`${o0($)} is not a record`];else for(let[V,Q]of Object.entries($))for(let[q,K]of this.#$.pathErrors(Q))q.push(Z1(V)),yield[q,K]}fuzz(){return Object.fromEntries(Array(r0()).fill(null).map(()=>[F1(r0(3)),this.#$.fuzz()]))}schema(){return{values:this.#$.schema()}}}function l1($){if($.definitions)throw new Error("definitions can only exist on a root schema");else return new S9($)}class k9 extends k0{#$;#Q;#V;keys;constructor($,V,Q,q){super();this.#$=$,this.#Q=V,this.#V=Q,this.keys=q}*pathErrors($){if(!_2($))yield[[],`${o0($)} is not a record`];else{if(this.#$)for(let[V,Q]of this.#$){let q=$[V];if(q===void 0)yield[[],`required key '${V}' is missing`];else for(let[K,G]of Q.pathErrors(q))K.push(Z1(V)),yield[K,G]}if(this.#Q){for(let[V,Q]of this.#Q)if($[V]!==void 0)for(let[q,K]of Q.pathErrors($[V]))q.push(Z1(V)),yield[q,K]}if(!this.#V){for(let V of Object.keys($))if(!this.keys.has(V))yield[[Z1(V)],`'${V}' is not a valid property and additional properties are not allowed`]}}}fuzz(){let $=h2(this.#$??[],([q,K])=>[q,K.fuzz()]),V=h2(CY(this.#Q??[],()=>u1()),([q,K])=>[q,K.fuzz()]),Q=this.#V?h2(IY(r0()),()=>[F1(r0(3)),m2([()=>null,u1,O$,()=>F1(r0()),()=>[],()=>({})])()]):[];return Object.fromEntries(O9($,V,Q))}schema(){let $={};if(this.#$)$.properties=Object.fromEntries(this.#$.map(([V,Q])=>[V,Q.schema()]));if(this.#Q)$.optionalProperties=Object.fromEntries(this.#Q.map(([V,Q])=>[V,Q.schema()]));if(this.#V)$.additionalProperties=!0;return $}}function wY($,V,Q){let q=new Set(h2(O9($??[],V??[]),([K])=>K));if($?.some(([,K])=>K.definitions))throw new Error("definitions can only exist on a root schema");else if(V?.some(([,K])=>K.definitions))throw new Error("definitions can only exist on a root schema");else if(q.size!==($?.length??0)+(V?.length??0))throw new Error("properties and optionalProperties keys must be unique");else return new k9($,V,Q??!1,q)}function N0($,V,Q){return wY($?Object.entries($):void 0,V?Object.entries(V):void 0,Q)}class NY extends k0{#$;#Q;#V;constructor($,V,Q){super();this.#$=$,this.#Q=V,this.#V=Q}guard($){if(!_2($))return!1;let{[this.#$]:V,...Q}=$;if(typeof V!=="string")return!1;return this.#Q[V]?.guard(Q)??!1}*pathErrors($){if(!_2($))yield[[],`${o0($)} is not an object`];else{let{[this.#$]:V,...Q}=$;if(V===void 0)yield[[],`discriminator key '${this.#$}' is missing`];else if(typeof V!=="string")yield[[Z1(this.#$)],`${o0(V)} is not a string`];else{let q=this.#Q[V];if(q===void 0)yield[[Z1(this.#$)],`'${V}' is not a valid discriminator value (${Object.keys(this.#Q).join(", ")})`];else yield*q.pathErrors(Q)}}}fuzz(){let[$,V]=m2(this.#V);return{...V.fuzz(),[this.#$]:$}}schema(){let $=Object.fromEntries(this.#V.map(([V,Q])=>[V,Q.schema()]));return{discriminator:this.#$,mapping:$}}}class g9 extends k0{#$;#Q;definitions=!0;constructor($,V){super();this.#$=$,this.#Q=V}*pathErrors($){yield*this.#Q.pathErrors($)}fuzz(){return this.#Q.fuzz()}schema(){let $=Object.fromEntries(Object.entries(this.#$).map(([V,Q])=>[V,Q.schema()]));return{...this.#Q.schema(),definitions:$}}}class E9 extends k0{#$;#Q;constructor($,V){super();this.#$=$,this.#Q=V}*pathErrors($){yield*this.#Q.pathErrors($)}fuzz(){return this.#Q.fuzz()}schema(){return{ref:this.#$}}}class y9{#$;#Q;constructor($,V){this.#$=$,this.#Q=V}def($,V){let Q=V(this.#Q);return new y9({...this.#$,[$]:Q},{...this.#Q,[$]:new E9($,Q)})}build($){return new g9(this.#$,$(this.#Q))}}class vY extends k0{#$;#Q;constructor($,V){super();this.#Q=$,this.#$=V}#V(){let $=this.#Q[this.#$];if($===void 0)throw new Error(`ref ${this.#$} was not in definitions after ref builder was finished`);else return $}*pathErrors($){yield*this.#V().pathErrors($)}fuzz(){return this.#V().fuzz()}schema(){return{ref:this.#$}}}var g0=[];for(let $=0;$<256;++$)g0.push(($+256).toString(16).slice(1));function b9($,V=0){return(g0[$[V+0]]+g0[$[V+1]]+g0[$[V+2]]+g0[$[V+3]]+"-"+g0[$[V+4]]+g0[$[V+5]]+"-"+g0[$[V+6]]+g0[$[V+7]]+"-"+g0[$[V+8]]+g0[$[V+9]]+"-"+g0[$[V+10]]+g0[$[V+11]]+g0[$[V+12]]+g0[$[V+13]]+g0[$[V+14]]+g0[$[V+15]]).toLowerCase()}var B$,AY=new Uint8Array(16);function C$(){if(!B$){if(typeof crypto==="undefined"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");B$=crypto.getRandomValues.bind(crypto)}return B$(AY)}var RY=typeof crypto!=="undefined"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),I$={randomUUID:RY};function xY($,V,Q){if(I$.randomUUID&&!V&&!$)return I$.randomUUID();$=$||{};let q=$.random??$.rng?.()??C$();if(q.length<16)throw new Error("Random bytes length must be >= 16");if(q[6]=q[6]&15|64,q[8]=q[8]&63|128,V){if(Q=Q||0,Q<0||Q+16>V.length)throw new RangeError(`UUID byte range ${Q}:${Q+15} is out of buffer bounds`);for(let K=0;K<16;++K)V[Q+K]=q[K];return V}return b9(q)}var H1=xY;class Y6 extends Error{field;regex;constructor($,V,Q){super(Q);this.field=$,this.regex=V}}class o1 extends Error{hash;constructor($){super(`'${$}' not found in the root hash`);this.hash=$}}class D$ extends Map{#$;#Q=0;constructor($,V=[]){super();this.#$=$;for(let[Q,q]of V)this.set(Q,q)}get($){let V=super.get($);if(V!==void 0)super.delete($),super.set($,V);return V}set($,V){let Q=super.get($);if(Q===void 0)this.#Q+=$.length;else if(Q!==null)this.#Q-=Q.length;if(V!==null)this.#Q+=V.length;super.delete($);let q;while(this.#Q>this.#$&&(q=this.entries().next().value)){let[K,G]=q;if(super.delete(K),this.#Q-=K.length,G!==null)this.#Q-=G.length}return super.set($,V),this}delete($){let V=super.get($);if(V===void 0)return!1;if(super.delete($),V!==null)this.#Q-=V.length;return this.#Q-=$.length,!0}clear(){super.clear(),this.#Q=0}}var A$=kY;var K6=[],v$=[];var w$="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(x6=0,N$=w$.length;x6<N$;++x6)K6[x6]=w$[x6],v$[w$.charCodeAt(x6)]=x6;var x6,N$;v$[45]=62;v$[95]=63;function TY($){return K6[$>>18&63]+K6[$>>12&63]+K6[$>>6&63]+K6[$&63]}function SY($,V,Q){var q,K=[];for(var G=V;G<Q;G+=3)q=($[G]<<16&16711680)+($[G+1]<<8&65280)+($[G+2]&255),K.push(TY(q));return K.join("")}function kY($){var V,Q=$.length,q=Q%3,K=[],G=16383;for(var W=0,J=Q-q;W<J;W+=G)K.push(SY($,W,W+G>J?J:W+G));if(q===1)V=$[Q-1],K.push(K6[V>>2]+K6[V<<4&63]+"==");else if(q===2)V=($[Q-2]<<8)+$[Q-1],K.push(K6[V>>10]+K6[V>>4&63]+K6[V<<2&63]+"=");return K.join("")}var m9=y$(h9(),1);var c2=/^[0-9a-f]{64}$/,p9=N0({name:X0(),timestamp:v0()},void 0,!0),gY=N0({name:X0(),pageId:X0(),timestamp:v0()},void 0,!0),EY=N0(void 0,{authors:_0(X0()),title:X0(),publicationDate:X0(),publisher:X0()},!0),yY=N0({id:X0(),idx:N0({timestamp:X0(),value:X0()},void 0,!0)},{template:N0({timestamp:X0(),value:X0()},void 0,!0),redir:N0({timestamp:X0(),value:M6()},void 0,!0),scrollTime:N0({timestamp:X0(),value:R9()},void 0,!0),verticalScroll:N0({timestamp:X0(),value:v0()},void 0,!0),deleted:N0({timestamp:X0(),value:M6()},void 0,!0)},!0),bY=N0({lastOpened:N0({timestamp:X0(),value:X0()},void 0,!0),original:N0({timestamp:X0(),value:M6()},void 0,!0),pages:_0(yY),uuids:_0(N0({first:X0(),second:n6()},void 0,!0))},void 0,!0),fY=N0(void 0,{tags:_0(p9)}),hY=N0({coverPageNumber:M6(),documentMetadata:EY,extraMetadata:l1(X0()),fileType:X6("epub","notebook","pdf"),fontName:X0(),lineHeight:M6(),orientation:X6("portrait","landscape"),pageCount:n6(),sizeInBytes:X0(),textAlignment:X6("justify","left"),textScale:v0()},{cPages:bY,customZoomCenterX:v0(),customZoomCenterY:v0(),customZoomOrientation:X6("portrait","landscape"),customZoomPageHeight:v0(),customZoomPageWidth:v0(),customZoomScale:v0(),dummyDocument:i6(),formatVersion:d1(),keyboardMetadata:N0({count:n6(),timestamp:v0()},void 0,!0),lastOpenedPage:n6(),margins:n6(),originalPageCount:M6(),pages:_0(X0()),pageTags:_0(gY),redirectionPageMap:_0(M6()),tags:_0(p9),transform:N0({m11:v0(),m12:v0(),m13:v0(),m21:v0(),m22:v0(),m23:v0(),m31:v0(),m32:v0(),m33:v0()},void 0,!0),viewBackgroundFilter:X6("off","fullpage"),zoomMode:X6("bestFit","customFit","fitToHeight","fitToWidth")},!0),_Y=N0({name:X0(),author:X0(),iconData:X0(),categories:_0(X0()),labels:_0(X0()),orientation:X6("portrait","landscape"),templateVersion:X0(),supportedScreens:_0(X6("rm2","rmPP")),constants:_0(l1(M6())),items:_0(D9())},{formatVersion:d1()}),mY=N0({lastModified:X0(),parent:X0(),pinned:i6(),type:X6("DocumentType","CollectionType","TemplateType"),visibleName:X0()},{lastOpened:X0(),lastOpenedPage:n6(),createdTime:X0(),deleted:i6(),metadatamodified:i6(),modified:i6(),synced:i6(),version:d1()},!0),pY=N0({hash:X0(),generation:v0()},void 0,!0),cY=N0({hash:X0(),generation:v0(),schemaVersion:d1()},void 0,!0);async function _9($){let V=await crypto.subtle.digest("SHA-256",$);return[...new Uint8Array(V)].map((Q)=>Q.toString(16).padStart(2,"0")).join("")}class x${#$;#Q;#V;constructor($,V,Q){this.#$=$,this.#V=V,this.#Q=Q}async getRootHash(){let V=await(await this.#$("GET",`${this.#Q}/sync/v4/root`)).text(),Q=JSON.parse(V);if(!cY.guardAssert(Q))throw Error("invalid root hash");let{hash:q,generation:K,schemaVersion:G}=Q;if(G!==3)throw new Error(`schema version ${G} not supported`);else if(!Number.isSafeInteger(K))throw new Error(`generation ${K} was not a safe integer; please file a bug report`);else return[q,K]}async#q($){if(!c2.test($))throw new Y6($,c2,"hash was not a valid hash");let Q=await(await this.#$("GET",`${this.#Q}/sync/v3/files/${$}`)).arrayBuffer();return new Uint8Array(Q)}async getHash($){let V=this.#V.get($);if(V!=null)return new TextEncoder().encode(V);else{let Q=await this.#q($);if(this.#V.get($)===void 0)this.#V.set($,null);return Q}}async getText($){let V=this.#V.get($);if(V!=null)return V;else{let Q=await this.#q($),K=new TextDecoder().decode(Q);return this.#V.set($,K),K}}async getEntries($){let V=await this.getText($),[Q,...q]=V.slice(0,-1).split(`
17
17
  `);if(Q!="3")throw new Error(`schema version ${Q} not supported`);else return q.map((K)=>{let[G,W,J,j,P]=K.split(":");if(G===void 0||W===void 0||J===void 0||j===void 0||P===void 0)throw new Error(`line '${K}' was not formatted correctly`);else if(W==="80000000")return{hash:G,type:80000000,id:J,subfiles:parseInt(j),size:parseInt(P)};else if(W==="0"&&j==="0")return{hash:G,type:0,id:J,subfiles:0,size:parseInt(P)};else throw new Error(`line '${K}' was not formatted correctly`)})}async getContent($){let V=await this.getText($),Q=JSON.parse(V),q=[];for(let[G,W]of[["collection",fY],["template",_Y],["document",hY]])try{if(W.guardAssert(Q))return Q}catch(J){let j=J instanceof Error?J.message:"unknown error type";q.push(`Couldn't validate as ${G} because:
18
18
  ${j}`)}let K=q.join(`
19
19
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rmapi-js",
3
- "version": "8.2.0",
3
+ "version": "8.3.0",
4
4
  "description": "JavaScript implementation of the reMarkable 1.5 api",
5
5
  "repository": "git@github.com:erikbrinkman/rmapi-js.git",
6
6
  "author": "Erik Brinkman <erik.brinkman@gmail.com>",