rmapi-js 2.3.0 → 3.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/CHANGELOG.md +20 -0
- package/bundle/rmapi-js.cjs.min.js +12 -4
- package/bundle/rmapi-js.esm.min.js +12 -4
- package/bundle/rmapi-js.iife.min.js +12 -4
- package/dist/index.d.ts +83 -53
- package/dist/index.js +118 -40
- package/package.json +36 -27
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
8
8
|
|
|
9
9
|
## [Unreleased]
|
|
10
10
|
|
|
11
|
+
## [3.0.0] - 2023-01-03
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- The ability to call `getEntries` without a hash to implicitely fetch the root
|
|
16
|
+
hash.
|
|
17
|
+
- `getJson` and `putJson` methods that use stable hashing.
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
|
|
21
|
+
- Caching behavior: You can no longer customize the caching behavior with a
|
|
22
|
+
custom `CacheLike` object, but instead specify the maximum size of objects to
|
|
23
|
+
cache. This both cleans up the caching code, and makes it easier to remove
|
|
24
|
+
most redundant calls from higher level interfaces.
|
|
25
|
+
- Changed `FetchLike` interfaces to be promises instead of awaitable.
|
|
26
|
+
|
|
27
|
+
### Removed
|
|
28
|
+
|
|
29
|
+
- Removed deprecated versions of `create` and `move`.
|
|
30
|
+
|
|
11
31
|
## [2.3.0] - 2022-12-31
|
|
12
32
|
|
|
13
33
|
### Added
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
var Pt=Object.create;var z=Object.defineProperty;var Et=Object.getOwnPropertyDescriptor;var Tt=Object.getOwnPropertyNames;var Ot=Object.getPrototypeOf,At=Object.prototype.hasOwnProperty;var p=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Mt=(e,t)=>{for(var r in t)z(e,r,{get:t[r],enumerable:!0})},Ce=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Tt(t))!At.call(e,i)&&i!==r&&z(e,i,{get:()=>t[i],enumerable:!(n=Et(t,i))||n.enumerable});return e};var ge=(e,t,r)=>(r=e!=null?Pt(Ot(e)):{},Ce(t||!e||!e.__esModule?z(r,"default",{value:e,enumerable:!0}):r,e)),St=e=>Ce(z({},"__esModule",{value:!0}),e);var Ie=p(G=>{"use strict";G.byteLength=Ct;G.toByteArray=Rt;G.fromByteArray=Ut;var P=[],x=[],kt=typeof Uint8Array<"u"?Uint8Array:Array,he="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(S=0,Fe=he.length;S<Fe;++S)P[S]=he[S],x[he.charCodeAt(S)]=S;var S,Fe;x["-".charCodeAt(0)]=62;x["_".charCodeAt(0)]=63;function Re(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");r===-1&&(r=t);var n=r===t?0:4-r%4;return[r,n]}function Ct(e){var t=Re(e),r=t[0],n=t[1];return(r+n)*3/4-n}function Ft(e,t,r){return(t+r)*3/4-r}function Rt(e){var t,r=Re(e),n=r[0],i=r[1],a=new kt(Ft(e,n,i)),o=0,s=i>0?n-4:n,f;for(f=0;f<s;f+=4)t=x[e.charCodeAt(f)]<<18|x[e.charCodeAt(f+1)]<<12|x[e.charCodeAt(f+2)]<<6|x[e.charCodeAt(f+3)],a[o++]=t>>16&255,a[o++]=t>>8&255,a[o++]=t&255;return i===2&&(t=x[e.charCodeAt(f)]<<2|x[e.charCodeAt(f+1)]>>4,a[o++]=t&255),i===1&&(t=x[e.charCodeAt(f)]<<10|x[e.charCodeAt(f+1)]<<4|x[e.charCodeAt(f+2)]>>2,a[o++]=t>>8&255,a[o++]=t&255),a}function It(e){return P[e>>18&63]+P[e>>12&63]+P[e>>6&63]+P[e&63]}function Dt(e,t,r){for(var n,i=[],a=t;a<r;a+=3)n=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(e[a+2]&255),i.push(It(n));return i.join("")}function Ut(e){for(var t,r=e.length,n=r%3,i=[],a=16383,o=0,s=r-n;o<s;o+=a)i.push(Dt(e,o,o+a>s?s:o+a));return n===1?(t=e[r-1],i.push(P[t>>2]+P[t<<4&63]+"==")):n===2&&(t=(e[r-2]<<8)+e[r-1],i.push(P[t>>10]+P[t>>4&63]+P[t<<2&63]+"=")),i.join("")}});var be=p(ve=>{"use strict";Object.defineProperty(ve,"__esModule",{value:!0});ve.default=$t;var qt=Lt(require("crypto"));function Lt(e){return e&&e.__esModule?e:{default:e}}var Y=new Uint8Array(256),V=Y.length;function $t(){return V>Y.length-16&&(qt.default.randomFillSync(Y),V=0),Y.slice(V,V+=16)}});var De=p(Z=>{"use strict";Object.defineProperty(Z,"__esModule",{value:!0});Z.default=void 0;var Nt=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;Z.default=Nt});var N=p(W=>{"use strict";Object.defineProperty(W,"__esModule",{value:!0});W.default=void 0;var Bt=Ht(De());function Ht(e){return e&&e.__esModule?e:{default:e}}function jt(e){return typeof e=="string"&&Bt.default.test(e)}var Jt=jt;W.default=Jt});var H=p(B=>{"use strict";Object.defineProperty(B,"__esModule",{value:!0});B.default=void 0;B.unsafeStringify=Ue;var zt=Gt(N());function Gt(e){return e&&e.__esModule?e:{default:e}}var m=[];for(let e=0;e<256;++e)m.push((e+256).toString(16).slice(1));function Ue(e,t=0){return(m[e[t+0]]+m[e[t+1]]+m[e[t+2]]+m[e[t+3]]+"-"+m[e[t+4]]+m[e[t+5]]+"-"+m[e[t+6]]+m[e[t+7]]+"-"+m[e[t+8]]+m[e[t+9]]+"-"+m[e[t+10]]+m[e[t+11]]+m[e[t+12]]+m[e[t+13]]+m[e[t+14]]+m[e[t+15]]).toLowerCase()}function Vt(e,t=0){let r=Ue(e,t);if(!(0,zt.default)(r))throw TypeError("Stringified UUID is invalid");return r}var Yt=Vt;B.default=Yt});var Le=p(K=>{"use strict";Object.defineProperty(K,"__esModule",{value:!0});K.default=void 0;var Zt=Kt(be()),Wt=H();function Kt(e){return e&&e.__esModule?e:{default:e}}var qe,xe,we=0,_e=0;function Qt(e,t,r){let n=t&&r||0,i=t||new Array(16);e=e||{};let a=e.node||qe,o=e.clockseq!==void 0?e.clockseq:xe;if(a==null||o==null){let c=e.random||(e.rng||Zt.default)();a==null&&(a=qe=[c[0]|1,c[1],c[2],c[3],c[4],c[5]]),o==null&&(o=xe=(c[6]<<8|c[7])&16383)}let s=e.msecs!==void 0?e.msecs:Date.now(),f=e.nsecs!==void 0?e.nsecs:_e+1,u=s-we+(f-_e)/1e4;if(u<0&&e.clockseq===void 0&&(o=o+1&16383),(u<0||s>we)&&e.nsecs===void 0&&(f=0),f>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");we=s,_e=f,xe=o,s+=122192928e5;let l=((s&268435455)*1e4+f)%4294967296;i[n++]=l>>>24&255,i[n++]=l>>>16&255,i[n++]=l>>>8&255,i[n++]=l&255;let y=s/4294967296*1e4&268435455;i[n++]=y>>>8&255,i[n++]=y&255,i[n++]=y>>>24&15|16,i[n++]=y>>>16&255,i[n++]=o>>>8|128,i[n++]=o&255;for(let c=0;c<6;++c)i[n+c]=a[c];return t||(0,Wt.unsafeStringify)(i)}var Xt=Qt;K.default=Xt});var Pe=p(Q=>{"use strict";Object.defineProperty(Q,"__esModule",{value:!0});Q.default=void 0;var er=tr(N());function tr(e){return e&&e.__esModule?e:{default:e}}function rr(e){if(!(0,er.default)(e))throw TypeError("Invalid UUID");let t,r=new Uint8Array(16);return r[0]=(t=parseInt(e.slice(0,8),16))>>>24,r[1]=t>>>16&255,r[2]=t>>>8&255,r[3]=t&255,r[4]=(t=parseInt(e.slice(9,13),16))>>>8,r[5]=t&255,r[6]=(t=parseInt(e.slice(14,18),16))>>>8,r[7]=t&255,r[8]=(t=parseInt(e.slice(19,23),16))>>>8,r[9]=t&255,r[10]=(t=parseInt(e.slice(24,36),16))/1099511627776&255,r[11]=t/4294967296&255,r[12]=t>>>24&255,r[13]=t>>>16&255,r[14]=t>>>8&255,r[15]=t&255,r}var nr=rr;Q.default=nr});var Ee=p(k=>{"use strict";Object.defineProperty(k,"__esModule",{value:!0});k.URL=k.DNS=void 0;k.default=fr;var ir=H(),ar=or(Pe());function or(e){return e&&e.__esModule?e:{default:e}}function sr(e){e=unescape(encodeURIComponent(e));let t=[];for(let r=0;r<e.length;++r)t.push(e.charCodeAt(r));return t}var $e="6ba7b810-9dad-11d1-80b4-00c04fd430c8";k.DNS=$e;var Ne="6ba7b811-9dad-11d1-80b4-00c04fd430c8";k.URL=Ne;function fr(e,t,r){function n(i,a,o,s){var f;if(typeof i=="string"&&(i=sr(i)),typeof a=="string"&&(a=(0,ar.default)(a)),((f=a)===null||f===void 0?void 0:f.length)!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let u=new Uint8Array(16+i.length);if(u.set(a),u.set(i,a.length),u=r(u),u[6]=u[6]&15|t,u[8]=u[8]&63|128,o){s=s||0;for(let l=0;l<16;++l)o[s+l]=u[l];return o}return(0,ir.unsafeStringify)(u)}try{n.name=e}catch{}return n.DNS=$e,n.URL=Ne,n}});var Be=p(X=>{"use strict";Object.defineProperty(X,"__esModule",{value:!0});X.default=void 0;var ur=lr(require("crypto"));function lr(e){return e&&e.__esModule?e:{default:e}}function dr(e){return Array.isArray(e)?e=Buffer.from(e):typeof e=="string"&&(e=Buffer.from(e,"utf8")),ur.default.createHash("md5").update(e).digest()}var cr=dr;X.default=cr});var je=p(ee=>{"use strict";Object.defineProperty(ee,"__esModule",{value:!0});ee.default=void 0;var pr=He(Ee()),yr=He(Be());function He(e){return e&&e.__esModule?e:{default:e}}var mr=(0,pr.default)("v3",48,yr.default),gr=mr;ee.default=gr});var Je=p(te=>{"use strict";Object.defineProperty(te,"__esModule",{value:!0});te.default=void 0;var hr=vr(require("crypto"));function vr(e){return e&&e.__esModule?e:{default:e}}var br={randomUUID:hr.default.randomUUID};te.default=br});var Ve=p(re=>{"use strict";Object.defineProperty(re,"__esModule",{value:!0});re.default=void 0;var ze=Ge(Je()),xr=Ge(be()),wr=H();function Ge(e){return e&&e.__esModule?e:{default:e}}function _r(e,t,r){if(ze.default.randomUUID&&!t&&!e)return ze.default.randomUUID();e=e||{};let n=e.random||(e.rng||xr.default)();if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,t){r=r||0;for(let i=0;i<16;++i)t[r+i]=n[i];return t}return(0,wr.unsafeStringify)(n)}var Pr=_r;re.default=Pr});var Ye=p(ne=>{"use strict";Object.defineProperty(ne,"__esModule",{value:!0});ne.default=void 0;var Er=Tr(require("crypto"));function Tr(e){return e&&e.__esModule?e:{default:e}}function Or(e){return Array.isArray(e)?e=Buffer.from(e):typeof e=="string"&&(e=Buffer.from(e,"utf8")),Er.default.createHash("sha1").update(e).digest()}var Ar=Or;ne.default=Ar});var We=p(ie=>{"use strict";Object.defineProperty(ie,"__esModule",{value:!0});ie.default=void 0;var Mr=Ze(Ee()),Sr=Ze(Ye());function Ze(e){return e&&e.__esModule?e:{default:e}}var kr=(0,Mr.default)("v5",80,Sr.default),Cr=kr;ie.default=Cr});var Ke=p(ae=>{"use strict";Object.defineProperty(ae,"__esModule",{value:!0});ae.default=void 0;var Fr="00000000-0000-0000-0000-000000000000";ae.default=Fr});var Qe=p(oe=>{"use strict";Object.defineProperty(oe,"__esModule",{value:!0});oe.default=void 0;var Rr=Ir(N());function Ir(e){return e&&e.__esModule?e:{default:e}}function Dr(e){if(!(0,Rr.default)(e))throw TypeError("Invalid UUID");return parseInt(e.slice(14,15),16)}var Ur=Dr;oe.default=Ur});var Xe=p(_=>{"use strict";Object.defineProperty(_,"__esModule",{value:!0});Object.defineProperty(_,"NIL",{enumerable:!0,get:function(){return Br.default}});Object.defineProperty(_,"parse",{enumerable:!0,get:function(){return zr.default}});Object.defineProperty(_,"stringify",{enumerable:!0,get:function(){return Jr.default}});Object.defineProperty(_,"v1",{enumerable:!0,get:function(){return qr.default}});Object.defineProperty(_,"v3",{enumerable:!0,get:function(){return Lr.default}});Object.defineProperty(_,"v4",{enumerable:!0,get:function(){return $r.default}});Object.defineProperty(_,"v5",{enumerable:!0,get:function(){return Nr.default}});Object.defineProperty(_,"validate",{enumerable:!0,get:function(){return jr.default}});Object.defineProperty(_,"version",{enumerable:!0,get:function(){return Hr.default}});var qr=O(Le()),Lr=O(je()),$r=O(Ve()),Nr=O(We()),Br=O(Ke()),Hr=O(Qe()),jr=O(N()),Jr=O(H()),zr=O(Pe());function O(e){return e&&e.__esModule?e:{default:e}}});var Ae=p(d=>{"use strict";var rt=d&&d.__rest||function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]]);return r};Object.defineProperty(d,"__esModule",{value:!0});d.isSchema=d.isValidSchema=d.isDiscriminatorForm=d.isValuesForm=d.isPropertiesForm=d.isElementsForm=d.isEnumForm=d.isTypeForm=d.isRefForm=d.isEmptyForm=void 0;function Gr(e){let{definitions:t,nullable:r,metadata:n}=e,i=rt(e,["definitions","nullable","metadata"]);return Object.keys(i).length===0}d.isEmptyForm=Gr;function nt(e){return"ref"in e}d.isRefForm=nt;function Vr(e){return"type"in e}d.isTypeForm=Vr;function it(e){return"enum"in e}d.isEnumForm=it;function at(e){return"elements"in e}d.isElementsForm=at;function Oe(e){return"properties"in e||"optionalProperties"in e}d.isPropertiesForm=Oe;function ot(e){return"values"in e}d.isValuesForm=ot;function st(e){return"discriminator"in e}d.isDiscriminatorForm=st;function C(e,t){if(t===void 0&&(t=e),e.definitions!==void 0){if(t!==e)return!1;for(let r of Object.values(e.definitions))if(!C(r,t))return!1}if(nt(e)&&!(e.ref in(t.definitions||{}))||it(e)&&(e.enum.length===0||e.enum.length!==new Set(e.enum).size))return!1;if(at(e))return C(e.elements,t);if(Oe(e)){for(let r of Object.values(e.properties||{}))if(!C(r,t))return!1;for(let r of Object.values(e.optionalProperties||{}))if(!C(r,t))return!1;for(let r of Object.keys(e.properties||{}))if(r in(e.optionalProperties||{}))return!1}if(ot(e))return C(e.values,t);if(st(e)){for(let r of Object.values(e.mapping))if(!C(r,t)||!Oe(r)||r.nullable||e.discriminator in(r.properties||{})||e.discriminator in(r.optionalProperties||{}))return!1}return!0}d.isValidSchema=C;var Yr=[[!1,!1,!1,!1,!1,!1,!1,!1,!1,!1],[!0,!1,!1,!1,!1,!1,!1,!1,!1,!1],[!1,!0,!1,!1,!1,!1,!1,!1,!1,!1],[!1,!1,!0,!1,!1,!1,!1,!1,!1,!1],[!1,!1,!1,!0,!1,!1,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!1,!1,!1,!1,!1],[!1,!1,!1,!1,!1,!0,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!0,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!1,!0,!1,!1,!1],[!1,!1,!1,!1,!1,!0,!0,!1,!1,!1],[!1,!1,!1,!1,!0,!0,!0,!1,!1,!1],[!1,!1,!1,!1,!1,!1,!1,!0,!1,!1],[!1,!1,!1,!1,!1,!1,!1,!1,!0,!0]],Zr=["boolean","float32","float64","int8","uint8","int16","uint16","int32","uint32","string","timestamp"];function F(e){if(typeof e!="object"||Array.isArray(e)||e===null)return!1;let t=e,{definitions:r=void 0,nullable:n=void 0,metadata:i=void 0,ref:a=void 0,type:o=void 0,enum:s=void 0,elements:f=void 0,properties:u=void 0,optionalProperties:l=void 0,additionalProperties:y=void 0,values:c=void 0,discriminator:$=void 0,mapping:T=void 0}=t,pe=rt(t,["definitions","nullable","metadata","ref","type","enum","elements","properties","optionalProperties","additionalProperties","values","discriminator","mapping"]),ye=[a!==void 0,o!==void 0,s!==void 0,f!==void 0,u!==void 0,l!==void 0,y!==void 0,c!==void 0,$!==void 0,T!==void 0],w=!1;for(let b of Yr)w=w||b.every((J,ke)=>J===ye[ke]);if(!w)return!1;if(r!==void 0){if(typeof r!="object"||Array.isArray(r)||r===null)return!1;for(let b of Object.values(r))if(!F(b))return!1}if(n!==void 0&&typeof n!="boolean"||i!==void 0&&(typeof i!="object"||Array.isArray(i)||i===null)||a!==void 0&&typeof a!="string"||o!==void 0&&(typeof o!="string"||!Zr.includes(o))||s!==void 0&&(!Array.isArray(s)||!s.every(b=>typeof b=="string"))||f!==void 0&&!F(f))return!1;if(u!==void 0){if(typeof u!="object"||Array.isArray(u)||u===null)return!1;for(let b of Object.values(u))if(!F(b))return!1}if(l!==void 0){if(typeof l!="object"||Array.isArray(l)||l===null)return!1;for(let b of Object.values(l))if(!F(b))return!1}if(y!==void 0&&typeof y!="boolean"||c!==void 0&&!F(c)||$!==void 0&&typeof $!="string")return!1;if(T!==void 0){if(typeof T!="object"||Array.isArray(T)||T===null)return!1;for(let b of Object.values(T))if(!F(b))return!1}return Object.keys(pe).length===0}d.isSchema=F});var ft=p(Me=>{"use strict";Object.defineProperty(Me,"__esModule",{value:!0});var Wr=/^(\d{4})-(\d{2})-(\d{2})[tT](\d{2}):(\d{2}):(\d{2})(\.\d+)?([zZ]|((\+|-)(\d{2}):(\d{2})))$/;function Kr(e){let t=e.match(Wr);if(t===null)return!1;let r=parseInt(t[1],10),n=parseInt(t[2],10),i=parseInt(t[3],10),a=parseInt(t[4],10),o=parseInt(t[5],10),s=parseInt(t[6],10);return!(n>12||i>Qr(r,n)||a>23||o>59||s>60)}Me.default=Kr;function Qr(e,t){return t===2?Xr(e)?29:28:en[t]}function Xr(e){return e%4===0&&(e%100!==0||e%400===0)}var en=[0,31,0,31,30,31,30,31,31,30,31,30,31]});var ut=p(A=>{"use strict";var tn=A&&A.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(A,"__esModule",{value:!0});A.validate=A.MaxDepthExceededError=void 0;var rn=tn(ft()),R=Ae(),fe=class extends Error{};A.MaxDepthExceededError=fe;var ue=class extends Error{};function nn(e,t,r){let n={errors:[],instanceTokens:[],schemaTokens:[[]],root:e,config:r||{maxDepth:0,maxErrors:0}};try{U(n,e,t)}catch(i){if(!(i instanceof ue))throw i}return n.errors}A.validate=nn;function U(e,t,r,n){if(!(t.nullable&&r===null)){if(R.isRefForm(t)){if(e.schemaTokens.length===e.config.maxDepth)throw new fe;e.schemaTokens.push(["definitions",t.ref]),U(e,e.root.definitions[t.ref],r),e.schemaTokens.pop()}else if(R.isTypeForm(t)){switch(g(e,"type"),t.type){case"boolean":typeof r!="boolean"&&h(e);break;case"float32":case"float64":typeof r!="number"&&h(e);break;case"int8":L(e,r,-128,127);break;case"uint8":L(e,r,0,255);break;case"int16":L(e,r,-32768,32767);break;case"uint16":L(e,r,0,65535);break;case"int32":L(e,r,-2147483648,2147483647);break;case"uint32":L(e,r,0,4294967295);break;case"string":typeof r!="string"&&h(e);break;case"timestamp":typeof r!="string"?h(e):rn.default(r)||h(e);break}v(e)}else if(R.isEnumForm(t))g(e,"enum"),(typeof r!="string"||!t.enum.includes(r))&&h(e),v(e);else if(R.isElementsForm(t)){if(g(e,"elements"),Array.isArray(r))for(let[i,a]of r.entries())I(e,i.toString()),U(e,t.elements,a),D(e);else h(e);v(e)}else if(R.isPropertiesForm(t))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){if(t.properties!==void 0){g(e,"properties");for(let[i,a]of Object.entries(t.properties))g(e,i),r.hasOwnProperty(i)?(I(e,i),U(e,a,r[i]),D(e)):h(e),v(e);v(e)}if(t.optionalProperties!==void 0){g(e,"optionalProperties");for(let[i,a]of Object.entries(t.optionalProperties))g(e,i),r.hasOwnProperty(i)&&(I(e,i),U(e,a,r[i]),D(e)),v(e);v(e)}if(t.additionalProperties!==!0)for(let i of Object.keys(r)){let a=t.properties&&i in t.properties,o=t.optionalProperties&&i in t.optionalProperties;!a&&!o&&i!==n&&(I(e,i),h(e),D(e))}}else t.properties!==void 0?g(e,"properties"):g(e,"optionalProperties"),h(e),v(e);else if(R.isValuesForm(t)){if(g(e,"values"),typeof r=="object"&&r!==null&&!Array.isArray(r))for(let[i,a]of Object.entries(r))I(e,i),U(e,t.values,a),D(e);else h(e);v(e)}else if(R.isDiscriminatorForm(t))if(typeof r=="object"&&r!==null&&!Array.isArray(r))if(r.hasOwnProperty(t.discriminator)){let i=r[t.discriminator];typeof i=="string"?i in t.mapping?(g(e,"mapping"),g(e,i),U(e,t.mapping[i],r,t.discriminator),v(e),v(e)):(g(e,"mapping"),I(e,t.discriminator),h(e),D(e),v(e)):(g(e,"discriminator"),I(e,t.discriminator),h(e),D(e),v(e))}else g(e,"discriminator"),h(e),v(e);else g(e,"discriminator"),h(e),v(e)}}function L(e,t,r,n){(typeof t!="number"||!Number.isInteger(t)||t<r||t>n)&&h(e)}function I(e,t){e.instanceTokens.push(t)}function D(e){e.instanceTokens.pop()}function g(e,t){e.schemaTokens[e.schemaTokens.length-1].push(t)}function v(e){e.schemaTokens[e.schemaTokens.length-1].pop()}function h(e){if(e.errors.push({instancePath:[...e.instanceTokens],schemaPath:[...e.schemaTokens[e.schemaTokens.length-1]]}),e.errors.length===e.config.maxErrors)throw new ue}});var dt=p(M=>{"use strict";var an=M&&M.__createBinding||(Object.create?function(e,t,r,n){n===void 0&&(n=r),Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,n){n===void 0&&(n=r),e[n]=t[r]}),lt=M&&M.__exportStar||function(e,t){for(var r in e)r!=="default"&&!t.hasOwnProperty(r)&&an(t,e,r)};Object.defineProperty(M,"__esModule",{value:!0});lt(Ae(),M);lt(ut(),M)});var hn={};Mt(hn,{GenerationError:()=>ce,ResponseError:()=>q,builtinFontNames:()=>ln,builtinLineHeights:()=>xt,builtinMargins:()=>bt,builtinTextScales:()=>vt,builtinTools:()=>un,formatEntry:()=>wt,parseEntry:()=>_t,register:()=>mn,remarkable:()=>gn});module.exports=St(hn);var gt=ge(Ie());var E=ge(Xe(),1),Un=E.default.v1,qn=E.default.v3,se=E.default.v4,Ln=E.default.v5,$n=E.default.NIL,Nn=E.default.version,Bn=E.default.validate,Hn=E.default.stringify,jn=E.default.parse;function Te(e){return[...new Uint8Array(e)].map(t=>t.toString(16).padStart(2,"0")).join("")}function et(e){return new Uint8Array((e.match(/../g)??[]).map(t=>parseInt(t,16)))}function tt(e){let t=0;for(let i of e)t+=i.length;let r=new Uint8Array(t),n=0;for(let i of e)r.set(i,n),n+=i.length;return r}var ct=ge(dt());function j(e,t){if((0,ct.validate)(e,t).length)throw new Error(`couldn't validate schema: ${JSON.stringify(t)} didn't match schema ${JSON.stringify(e)}`)}var pt="3",ht="https://webapp-prod.cloud.remarkable.engineering",on="https://internal.cloud.remarkable.com",yt="x-goog-generation",sn="x-goog-if-generation-match",fn="x-goog-content-length-range",un=["Ballpoint","Ballpointv2","Brush","Calligraphy","ClearPage","EraseSection","Eraser","Fineliner","Finelinerv2","Highlighter","Highlighterv2","Marker","Markerv2","Paintbrush","Paintbrushv2","Pencilv2","SharpPencil","SharpPencilv2","SolidPen","ZoomTool"],ln=["Maison Neue","EB Garamond","Noto Sans","Noto Serif","Noto Mono","Noto Sans UI"],vt={xs:.7,sm:.8,md:1,lg:1.2,xl:1.5,xx:2},bt={sm:50,md:125,rr:180,lg:200},xt={df:-1,md:100,lg:150,xl:200},dn={properties:{docID:{type:"string"},hash:{type:"string"}}},cn={properties:{relative_path:{type:"string"},url:{type:"string"},expires:{type:"timestamp"},method:{enum:["POST","GET","PUT","DELETE"]}},optionalProperties:{maxuploadsize_bytes:{type:"float64"}}},le={visibleName:{type:"string"},lastModified:{type:"string"}},de={version:{type:"int32"},pinned:{type:"boolean"},synced:{type:"boolean"},modified:{type:"boolean"},deleted:{type:"boolean"},metadatamodified:{type:"boolean"},parent:{type:"string"}},pn={discriminator:"type",mapping:{CollectionType:{properties:le,optionalProperties:de},DocumentType:{properties:le,optionalProperties:{...de,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},mt={id:{type:"string"},hash:{type:"string"}},yn={discriminator:"type",mapping:{CollectionType:{properties:{...le,...mt},optionalProperties:de},DocumentType:{properties:{...le,...mt,fileType:{enum:["notebook","epub","pdf",""]}},optionalProperties:{...de,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},q=class extends Error{constructor(r,n,i){super(i);this.status=r,this.statusText=n}},ce=class extends Error{constructor(){super("Generation preconditions failed. This means the current state is out of date with the cloud and needs to be re-synced.")}};async function mn(e,{deviceDesc:t="browser-chrome",uuid:r=se(),authHost:n=ht,fetch:i=globalThis.fetch}={}){if(e.length!==8)throw new Error(`code should be length 8, but was ${e.length}`);let a=await i(`${n}/token/json/2/device/new`,{method:"POST",headers:{Authorization:"Bearer"},body:JSON.stringify({code:e,deviceDesc:t,deviceID:r})});if(a.ok)return await a.text();throw new q(a.status,a.statusText,"couldn't register api")}function wt({hash:e,type:t,documentId:r,subfiles:n,size:i}){return`${e}:${t}:${r}:${n}:${i}
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";var ft=Object.create;var Z=Object.defineProperty;var ut=Object.getOwnPropertyDescriptor;var lt=Object.getOwnPropertyNames;var ct=Object.getPrototypeOf,pt=Object.prototype.hasOwnProperty;var S=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),dt=(e,t)=>{for(var r in t)Z(e,r,{get:t[r],enumerable:!0})},xe=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of lt(t))!pt.call(e,i)&&i!==r&&Z(e,i,{get:()=>t[i],enumerable:!(n=ut(t,i))||n.enumerable});return e};var z=(e,t,r)=>(r=e!=null?ft(ct(e)):{},xe(t||!e||!e.__esModule?Z(r,"default",{value:e,enumerable:!0}):r,e)),yt=e=>xe(Z({},"__esModule",{value:!0}),e);var Te=S(K=>{"use strict";K.byteLength=ht;K.toByteArray=bt;K.fromByteArray=xt;var O=[],T=[],mt=typeof Uint8Array<"u"?Uint8Array:Array,ue="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(B=0,Ee=ue.length;B<Ee;++B)O[B]=ue[B],T[ue.charCodeAt(B)]=B;var B,Ee;T["-".charCodeAt(0)]=62;T["_".charCodeAt(0)]=63;function Pe(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");r===-1&&(r=t);var n=r===t?0:4-r%4;return[r,n]}function ht(e){var t=Pe(e),r=t[0],n=t[1];return(r+n)*3/4-n}function gt(e,t,r){return(t+r)*3/4-r}function bt(e){var t,r=Pe(e),n=r[0],i=r[1],o=new mt(gt(e,n,i)),a=0,f=i>0?n-4:n,s;for(s=0;s<f;s+=4)t=T[e.charCodeAt(s)]<<18|T[e.charCodeAt(s+1)]<<12|T[e.charCodeAt(s+2)]<<6|T[e.charCodeAt(s+3)],o[a++]=t>>16&255,o[a++]=t>>8&255,o[a++]=t&255;return i===2&&(t=T[e.charCodeAt(s)]<<2|T[e.charCodeAt(s+1)]>>4,o[a++]=t&255),i===1&&(t=T[e.charCodeAt(s)]<<10|T[e.charCodeAt(s+1)]<<4|T[e.charCodeAt(s+2)]>>2,o[a++]=t>>8&255,o[a++]=t&255),o}function vt(e){return O[e>>18&63]+O[e>>12&63]+O[e>>6&63]+O[e&63]}function wt(e,t,r){for(var n,i=[],o=t;o<r;o+=3)n=(e[o]<<16&16711680)+(e[o+1]<<8&65280)+(e[o+2]&255),i.push(vt(n));return i.join("")}function xt(e){for(var t,r=e.length,n=r%3,i=[],o=16383,a=0,f=r-n;a<f;a+=o)i.push(wt(e,a,a+o>f?f:a+o));return n===1?(t=e[r-1],i.push(O[t>>2]+O[t<<4&63]+"==")):n===2&&(t=(e[r-2]<<8)+e[r-1],i.push(O[t>>10]+O[t>>4&63]+O[t<<2&63]+"=")),i.join("")}});var Fe=S((rr,ke)=>{"use strict";var W,l,Ae={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:`
|
|
2
|
+
`,r:"\r",t:" "},le;function M(e){throw{name:"SyntaxError",message:e,at:W,text:le}}function c(e){return e&&e!==l&&M("Expected '"+e+"' instead of '"+l+"'"),l=le.charAt(W),W+=1,l}function Oe(){var e,t="";for(l==="-"&&(t="-",c("-"));l>="0"&&l<="9";)t+=l,c();if(l===".")for(t+=".";c()&&l>="0"&&l<="9";)t+=l;if(l==="e"||l==="E")for(t+=l,c(),(l==="-"||l==="+")&&(t+=l,c());l>="0"&&l<="9";)t+=l,c();return e=Number(t),isFinite(e)||M("Bad number"),e}function Se(){var e,t,r="",n;if(l==='"')for(;c();){if(l==='"')return c(),r;if(l==="\\")if(c(),l==="u"){for(n=0,t=0;t<4&&(e=parseInt(c(),16),!!isFinite(e));t+=1)n=n*16+e;r+=String.fromCharCode(n)}else if(typeof Ae[l]=="string")r+=Ae[l];else break;else r+=l}M("Bad string")}function k(){for(;l&&l<=" ";)c()}function Et(){switch(l){case"t":return c("t"),c("r"),c("u"),c("e"),!0;case"f":return c("f"),c("a"),c("l"),c("s"),c("e"),!1;case"n":return c("n"),c("u"),c("l"),c("l"),null;default:M("Unexpected '"+l+"'")}}function Pt(){var e=[];if(l==="["){if(c("["),k(),l==="]")return c("]"),e;for(;l;){if(e.push(Q()),k(),l==="]")return c("]"),e;c(","),k()}}M("Bad array")}function Tt(){var e,t={};if(l==="{"){if(c("{"),k(),l==="}")return c("}"),t;for(;l;){if(e=Se(),k(),c(":"),Object.prototype.hasOwnProperty.call(t,e)&&M('Duplicate key "'+e+'"'),t[e]=Q(),k(),l==="}")return c("}"),t;c(","),k()}}M("Bad object")}function Q(){switch(k(),l){case"{":return Tt();case"[":return Pt();case'"':return Se();case"-":return Oe();default:return l>="0"&&l<="9"?Oe():Et()}}ke.exports=function(e,t){var r;return le=e,W=0,l=" ",r=Q(),k(),l&&M("Syntax error"),typeof t=="function"?function n(i,o){var a,f,s=i[o];if(s&&typeof s=="object")for(a in Q)Object.prototype.hasOwnProperty.call(s,a)&&(f=n(s,a),typeof f>"u"?delete s[a]:s[a]=f);return t.call(i,o,s)}({"":r},""):r}});var Ce=S((nr,Me)=>{"use strict";var ce=/[\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,E,X,At={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},I;function pe(e){return ce.lastIndex=0,ce.test(e)?'"'+e.replace(ce,function(t){var r=At[t];return typeof r=="string"?r:"\\u"+("0000"+t.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+e+'"'}function ee(e,t){var r,n,i,o,a=E,f,s=t[e];switch(s&&typeof s=="object"&&typeof s.toJSON=="function"&&(s=s.toJSON(e)),typeof I=="function"&&(s=I.call(t,e,s)),typeof s){case"string":return pe(s);case"number":return isFinite(s)?String(s):"null";case"boolean":case"null":return String(s);case"object":if(!s)return"null";if(E+=X,f=[],Object.prototype.toString.apply(s)==="[object Array]"){for(o=s.length,r=0;r<o;r+=1)f[r]=ee(r,s)||"null";return i=f.length===0?"[]":E?`[
|
|
3
|
+
`+E+f.join(`,
|
|
4
|
+
`+E)+`
|
|
5
|
+
`+a+"]":"["+f.join(",")+"]",E=a,i}if(I&&typeof I=="object")for(o=I.length,r=0;r<o;r+=1)n=I[r],typeof n=="string"&&(i=ee(n,s),i&&f.push(pe(n)+(E?": ":":")+i));else for(n in s)Object.prototype.hasOwnProperty.call(s,n)&&(i=ee(n,s),i&&f.push(pe(n)+(E?": ":":")+i));return i=f.length===0?"{}":E?`{
|
|
6
|
+
`+E+f.join(`,
|
|
7
|
+
`+E)+`
|
|
8
|
+
`+a+"}":"{"+f.join(",")+"}",E=a,i;default:}}Me.exports=function(e,t,r){var n;if(E="",X="",typeof r=="number")for(n=0;n<r;n+=1)X+=" ";else typeof r=="string"&&(X=r);if(I=t,t&&typeof t!="function"&&(typeof t!="object"||typeof t.length!="number"))throw new Error("JSON.stringify");return ee("",{"":e})}});var je=S(de=>{"use strict";de.parse=Fe();de.stringify=Ce()});var Ie=S((or,Be)=>{"use strict";var te=typeof JSON<"u"?JSON:je(),Ot=Array.isArray||function(e){return{}.toString.call(e)==="[object Array]"},St=Object.keys||function(e){var t=Object.prototype.hasOwnProperty||function(){return!0},r=[];for(var n in e)t.call(e,n)&&r.push(n);return r};Be.exports=function(e,t){t||(t={}),typeof t=="function"&&(t={cmp:t});var r=t.space||"";typeof r=="number"&&(r=Array(r+1).join(" "));var n=typeof t.cycles=="boolean"?t.cycles:!1,i=t.replacer||function(f,s){return s},o=t.cmp&&function(f){return function(s){return function(p,u){var g={key:p,value:s[p]},x={key:u,value:s[u]};return f(g,x)}}}(t.cmp),a=[];return function f(s,p,u,g){var x=r?`
|
|
9
|
+
`+new Array(g+1).join(r):"",F=r?": ":":";if(u&&u.toJSON&&typeof u.toJSON=="function"&&(u=u.toJSON()),u=i.call(s,p,u),u!==void 0){if(typeof u!="object"||u===null)return te.stringify(u);if(Ot(u)){for(var A=[],y=0;y<u.length;y++){var J=f(u,y,u[y],g+1)||te.stringify(null);A.push(x+r+J)}return"["+A.join(",")+x+"]"}if(a.indexOf(u)!==-1){if(n)return te.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}else a.push(u);for(var P=St(u).sort(o&&o(u)),A=[],y=0;y<P.length;y++){var p=P[y],m=f(u,p,u[p],g+1);if(m){var Y=te.stringify(p)+F+m;A.push(x+r+Y)}}return a.splice(a.indexOf(u),1),"{"+A.join(",")+x+"}"}}({"":e},"",e,0)}});var be=S(d=>{"use strict";var De=d&&d.__rest||function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]]);return r};Object.defineProperty(d,"__esModule",{value:!0});d.isSchema=d.isValidSchema=d.isDiscriminatorForm=d.isValuesForm=d.isPropertiesForm=d.isElementsForm=d.isEnumForm=d.isTypeForm=d.isRefForm=d.isEmptyForm=void 0;function Ft(e){let{definitions:t,nullable:r,metadata:n}=e,i=De(e,["definitions","nullable","metadata"]);return Object.keys(i).length===0}d.isEmptyForm=Ft;function He(e){return"ref"in e}d.isRefForm=He;function Mt(e){return"type"in e}d.isTypeForm=Mt;function Ue(e){return"enum"in e}d.isEnumForm=Ue;function Je(e){return"elements"in e}d.isElementsForm=Je;function ge(e){return"properties"in e||"optionalProperties"in e}d.isPropertiesForm=ge;function qe(e){return"values"in e}d.isValuesForm=qe;function ze(e){return"discriminator"in e}d.isDiscriminatorForm=ze;function R(e,t){if(t===void 0&&(t=e),e.definitions!==void 0){if(t!==e)return!1;for(let r of Object.values(e.definitions))if(!R(r,t))return!1}if(He(e)&&!(e.ref in(t.definitions||{}))||Ue(e)&&(e.enum.length===0||e.enum.length!==new Set(e.enum).size))return!1;if(Je(e))return R(e.elements,t);if(ge(e)){for(let r of Object.values(e.properties||{}))if(!R(r,t))return!1;for(let r of Object.values(e.optionalProperties||{}))if(!R(r,t))return!1;for(let r of Object.keys(e.properties||{}))if(r in(e.optionalProperties||{}))return!1}if(qe(e))return R(e.values,t);if(ze(e)){for(let r of Object.values(e.mapping))if(!R(r,t)||!ge(r)||r.nullable||e.discriminator in(r.properties||{})||e.discriminator in(r.optionalProperties||{}))return!1}return!0}d.isValidSchema=R;var Ct=[[!1,!1,!1,!1,!1,!1,!1,!1,!1,!1],[!0,!1,!1,!1,!1,!1,!1,!1,!1,!1],[!1,!0,!1,!1,!1,!1,!1,!1,!1,!1],[!1,!1,!0,!1,!1,!1,!1,!1,!1,!1],[!1,!1,!1,!0,!1,!1,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!1,!1,!1,!1,!1],[!1,!1,!1,!1,!1,!0,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!0,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!1,!0,!1,!1,!1],[!1,!1,!1,!1,!1,!0,!0,!1,!1,!1],[!1,!1,!1,!1,!0,!0,!0,!1,!1,!1],[!1,!1,!1,!1,!1,!1,!1,!0,!1,!1],[!1,!1,!1,!1,!1,!1,!1,!1,!0,!0]],jt=["boolean","float32","float64","int8","uint8","int16","uint16","int32","uint32","string","timestamp"];function _(e){if(typeof e!="object"||Array.isArray(e)||e===null)return!1;let t=e,{definitions:r=void 0,nullable:n=void 0,metadata:i=void 0,ref:o=void 0,type:a=void 0,enum:f=void 0,elements:s=void 0,properties:p=void 0,optionalProperties:u=void 0,additionalProperties:g=void 0,values:x=void 0,discriminator:F=void 0,mapping:y=void 0}=t,J=De(t,["definitions","nullable","metadata","ref","type","enum","elements","properties","optionalProperties","additionalProperties","values","discriminator","mapping"]),P=[o!==void 0,a!==void 0,f!==void 0,s!==void 0,p!==void 0,u!==void 0,g!==void 0,x!==void 0,F!==void 0,y!==void 0],A=!1;for(let m of Ct)A=A||m.every((Y,q)=>Y===P[q]);if(!A)return!1;if(r!==void 0){if(typeof r!="object"||Array.isArray(r)||r===null)return!1;for(let m of Object.values(r))if(!_(m))return!1}if(n!==void 0&&typeof n!="boolean"||i!==void 0&&(typeof i!="object"||Array.isArray(i)||i===null)||o!==void 0&&typeof o!="string"||a!==void 0&&(typeof a!="string"||!jt.includes(a))||f!==void 0&&(!Array.isArray(f)||!f.every(m=>typeof m=="string"))||s!==void 0&&!_(s))return!1;if(p!==void 0){if(typeof p!="object"||Array.isArray(p)||p===null)return!1;for(let m of Object.values(p))if(!_(m))return!1}if(u!==void 0){if(typeof u!="object"||Array.isArray(u)||u===null)return!1;for(let m of Object.values(u))if(!_(m))return!1}if(g!==void 0&&typeof g!="boolean"||x!==void 0&&!_(x)||F!==void 0&&typeof F!="string")return!1;if(y!==void 0){if(typeof y!="object"||Array.isArray(y)||y===null)return!1;for(let m of Object.values(y))if(!_(m))return!1}return Object.keys(J).length===0}d.isSchema=_});var Ge=S(ve=>{"use strict";Object.defineProperty(ve,"__esModule",{value:!0});var Bt=/^(\d{4})-(\d{2})-(\d{2})[tT](\d{2}):(\d{2}):(\d{2})(\.\d+)?([zZ]|((\+|-)(\d{2}):(\d{2})))$/;function It(e){let t=e.match(Bt);if(t===null)return!1;let r=parseInt(t[1],10),n=parseInt(t[2],10),i=parseInt(t[3],10),o=parseInt(t[4],10),a=parseInt(t[5],10),f=parseInt(t[6],10);return!(n>12||i>Rt(r,n)||o>23||a>59||f>60)}ve.default=It;function Rt(e,t){return t===2?_t(e)?29:28:Nt[t]}function _t(e){return e%4===0&&(e%100!==0||e%400===0)}var Nt=[0,31,0,31,30,31,30,31,31,30,31,30,31]});var Ve=S(C=>{"use strict";var $t=C&&C.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(C,"__esModule",{value:!0});C.validate=C.MaxDepthExceededError=void 0;var Lt=$t(Ge()),N=be(),ie=class extends Error{};C.MaxDepthExceededError=ie;var oe=class extends Error{};function Dt(e,t,r){let n={errors:[],instanceTokens:[],schemaTokens:[[]],root:e,config:r||{maxDepth:0,maxErrors:0}};try{D(n,e,t)}catch(i){if(!(i instanceof oe))throw i}return n.errors}C.validate=Dt;function D(e,t,r,n){if(!(t.nullable&&r===null)){if(N.isRefForm(t)){if(e.schemaTokens.length===e.config.maxDepth)throw new ie;e.schemaTokens.push(["definitions",t.ref]),D(e,e.root.definitions[t.ref],r),e.schemaTokens.pop()}else if(N.isTypeForm(t)){switch(b(e,"type"),t.type){case"boolean":typeof r!="boolean"&&v(e);break;case"float32":case"float64":typeof r!="number"&&v(e);break;case"int8":U(e,r,-128,127);break;case"uint8":U(e,r,0,255);break;case"int16":U(e,r,-32768,32767);break;case"uint16":U(e,r,0,65535);break;case"int32":U(e,r,-2147483648,2147483647);break;case"uint32":U(e,r,0,4294967295);break;case"string":typeof r!="string"&&v(e);break;case"timestamp":typeof r!="string"?v(e):Lt.default(r)||v(e);break}w(e)}else if(N.isEnumForm(t))b(e,"enum"),(typeof r!="string"||!t.enum.includes(r))&&v(e),w(e);else if(N.isElementsForm(t)){if(b(e,"elements"),Array.isArray(r))for(let[i,o]of r.entries())$(e,i.toString()),D(e,t.elements,o),L(e);else v(e);w(e)}else if(N.isPropertiesForm(t))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){if(t.properties!==void 0){b(e,"properties");for(let[i,o]of Object.entries(t.properties))b(e,i),r.hasOwnProperty(i)?($(e,i),D(e,o,r[i]),L(e)):v(e),w(e);w(e)}if(t.optionalProperties!==void 0){b(e,"optionalProperties");for(let[i,o]of Object.entries(t.optionalProperties))b(e,i),r.hasOwnProperty(i)&&($(e,i),D(e,o,r[i]),L(e)),w(e);w(e)}if(t.additionalProperties!==!0)for(let i of Object.keys(r)){let o=t.properties&&i in t.properties,a=t.optionalProperties&&i in t.optionalProperties;!o&&!a&&i!==n&&($(e,i),v(e),L(e))}}else t.properties!==void 0?b(e,"properties"):b(e,"optionalProperties"),v(e),w(e);else if(N.isValuesForm(t)){if(b(e,"values"),typeof r=="object"&&r!==null&&!Array.isArray(r))for(let[i,o]of Object.entries(r))$(e,i),D(e,t.values,o),L(e);else v(e);w(e)}else if(N.isDiscriminatorForm(t))if(typeof r=="object"&&r!==null&&!Array.isArray(r))if(r.hasOwnProperty(t.discriminator)){let i=r[t.discriminator];typeof i=="string"?i in t.mapping?(b(e,"mapping"),b(e,i),D(e,t.mapping[i],r,t.discriminator),w(e),w(e)):(b(e,"mapping"),$(e,t.discriminator),v(e),L(e),w(e)):(b(e,"discriminator"),$(e,t.discriminator),v(e),L(e),w(e))}else b(e,"discriminator"),v(e),w(e);else b(e,"discriminator"),v(e),w(e)}}function U(e,t,r,n){(typeof t!="number"||!Number.isInteger(t)||t<r||t>n)&&v(e)}function $(e,t){e.instanceTokens.push(t)}function L(e){e.instanceTokens.pop()}function b(e,t){e.schemaTokens[e.schemaTokens.length-1].push(t)}function w(e){e.schemaTokens[e.schemaTokens.length-1].pop()}function v(e){if(e.errors.push({instancePath:[...e.instanceTokens],schemaPath:[...e.schemaTokens[e.schemaTokens.length-1]]}),e.errors.length===e.config.maxErrors)throw new oe}});var Ze=S(j=>{"use strict";var Ht=j&&j.__createBinding||(Object.create?function(e,t,r,n){n===void 0&&(n=r),Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,n){n===void 0&&(n=r),e[n]=t[r]}),Ye=j&&j.__exportStar||function(e,t){for(var r in e)r!=="default"&&!t.hasOwnProperty(r)&&Ht(t,e,r)};Object.defineProperty(j,"__esModule",{value:!0});Ye(be(),j);Ye(Ve(),j)});var Xt={};dt(Xt,{GenerationError:()=>fe,ResponseError:()=>H,builtinFontNames:()=>Gt,builtinLineHeights:()=>ot,builtinMargins:()=>it,builtinTextScales:()=>nt,builtinTools:()=>zt,formatEntry:()=>st,parseEntry:()=>at,register:()=>Wt,remarkable:()=>Qt});module.exports=yt(Xt);var et=z(Te()),tt=z(Ie());var Re=z(require("crypto")),ne=new Uint8Array(256),re=ne.length;function ye(){return re>ne.length-16&&(Re.default.randomFillSync(ne),re=0),ne.slice(re,re+=16)}var h=[];for(let e=0;e<256;++e)h.push((e+256).toString(16).slice(1));function _e(e,t=0){return(h[e[t+0]]+h[e[t+1]]+h[e[t+2]]+h[e[t+3]]+"-"+h[e[t+4]]+h[e[t+5]]+"-"+h[e[t+6]]+h[e[t+7]]+"-"+h[e[t+8]]+h[e[t+9]]+"-"+h[e[t+10]]+h[e[t+11]]+h[e[t+12]]+h[e[t+13]]+h[e[t+14]]+h[e[t+15]]).toLowerCase()}var Ne=z(require("crypto")),me={randomUUID:Ne.default.randomUUID};function kt(e,t,r){if(me.randomUUID&&!t&&!e)return me.randomUUID();e=e||{};let n=e.random||(e.rng||ye)();if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,t){r=r||0;for(let i=0;i<16;++i)t[r+i]=n[i];return t}return _e(n)}var G=kt;function he(e){return[...new Uint8Array(e)].map(t=>t.toString(16).padStart(2,"0")).join("")}function $e(e){return new Uint8Array((e.match(/../g)??[]).map(t=>parseInt(t,16)))}function Le(e){let t=0;for(let i of e)t+=i.length;let r=new Uint8Array(t),n=0;for(let i of e)r.set(i,n),n+=i.length;return r}var Ke=z(Ze());function V(e,t){if((0,Ke.validate)(e,t).length)throw new Error(`couldn't validate schema: ${JSON.stringify(t)} didn't match schema ${JSON.stringify(e)}`)}var We="3",rt="https://webapp-prod.cloud.remarkable.engineering",Ut="https://internal.cloud.remarkable.com",Qe="x-goog-generation",Jt="x-goog-if-generation-match",qt="x-goog-content-length-range",zt=["Ballpoint","Ballpointv2","Brush","Calligraphy","ClearPage","EraseSection","Eraser","Fineliner","Finelinerv2","Highlighter","Highlighterv2","Marker","Markerv2","Paintbrush","Paintbrushv2","Pencilv2","SharpPencil","SharpPencilv2","SolidPen","ZoomTool"],Gt=["Maison Neue","EB Garamond","Noto Sans","Noto Serif","Noto Mono","Noto Sans UI"],nt={xs:.7,sm:.8,md:1,lg:1.2,xl:1.5,xx:2},it={sm:50,md:125,rr:180,lg:200},ot={df:-1,md:100,lg:150,xl:200},Vt={properties:{docID:{type:"string"},hash:{type:"string"}}},Yt={properties:{relative_path:{type:"string"},url:{type:"string"},expires:{type:"timestamp"},method:{enum:["POST","GET","PUT","DELETE"]}},optionalProperties:{maxuploadsize_bytes:{type:"float64"}}},se={visibleName:{type:"string"},lastModified:{type:"string"}},ae={version:{type:"int32"},pinned:{type:"boolean"},synced:{type:"boolean"},modified:{type:"boolean"},deleted:{type:"boolean"},metadatamodified:{type:"boolean"},parent:{type:"string"}},Zt={discriminator:"type",mapping:{CollectionType:{properties:se,optionalProperties:ae},DocumentType:{properties:se,optionalProperties:{...ae,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},Xe={id:{type:"string"},hash:{type:"string"}},Kt={discriminator:"type",mapping:{CollectionType:{properties:{...se,...Xe},optionalProperties:ae},DocumentType:{properties:{...se,...Xe,fileType:{enum:["notebook","epub","pdf",""]}},optionalProperties:{...ae,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},H=class extends Error{status;statusText;constructor(t,r,n){super(n),this.status=t,this.statusText=r}},fe=class extends Error{constructor(){super("Generation preconditions failed. This means the current state is out of date with the cloud and needs to be re-synced.")}};async function Wt(e,{deviceDesc:t="browser-chrome",uuid:r=G(),authHost:n=rt,fetch:i=globalThis.fetch}={}){if(e.length!==8)throw new Error(`code should be length 8, but was ${e.length}`);let o=await i(`${n}/token/json/2/device/new`,{method:"POST",headers:{Authorization:"Bearer"},body:JSON.stringify({code:e,deviceDesc:t,deviceID:r})});if(o.ok)return await o.text();throw new H(o.status,o.statusText,"couldn't register api")}function st({hash:e,type:t,documentId:r,subfiles:n,size:i}){return`${e}:${t}:${r}:${n}:${i}
|
|
10
|
+
`}function at(e){let[t,r,n,i,o]=e.split(":");if(t===void 0||r===void 0||n===void 0||i===void 0||o===void 0)throw new Error(`entries line didn't contain five fields: '${e}'`);if(r==="80000000")return{hash:t,type:r,documentId:n,subfiles:parseInt(i),size:BigInt(o)};if(r==="0"){if(i!=="0")throw new Error(`file type entry had nonzero number of subfiles: ${i}`);return{hash:t,type:r,documentId:n,subfiles:0,size:BigInt(o)}}else throw new Error(`entries line contained invalid type: ${r}`)}var we=class{#u;#a;#f;#r;#n;#e=new Map;#t=null;constructor(t,r,n,i,o,a){this.#u=t,this.#a=r,this.#f=n,this.#r=i,this.#n=o;for(let[f,s]of a)this.#e.set(f,Promise.resolve(s))}async#i(t,{body:r,method:n="POST",headers:i={}}){let o=await this.#a(t,{method:n,headers:{Authorization:`Bearer ${this.#u}`,...i},body:r});if(o.ok)return o;{let a=await o.text();throw new H(o.status,o.statusText,`failed reMarkable request: ${a}`)}}async#o({url:t,method:r,maxuploadsize_bytes:n},i,o={}){let a=n?{...o,[qt]:`0,${n}`}:o,f=await this.#a(t,{method:r,body:i,headers:a});if(f.ok)return f;{let s=await f.text();throw new H(f.status,f.statusText,s)}}async#s(t,r,n){let i=r===void 0?"downloads":"uploads",o=n&&r!==null&&r!==void 0?`{ "http_method": "PUT", "relative_path": "${t}", "root_schema": "${n}", "generation": ${r} }`:JSON.stringify({http_method:"GET",relative_path:t}),f=await(await this.#i(`${this.#r}/sync/v2/signed-urls/${i}`,{body:o})).text(),s=JSON.parse(f);return V(Yt,s),s}async getRootHash({cache:t=!0}={}){if(t)for(;this.#t;)try{let[o,a]=await this.#t;return[o,a]}catch{}let r=(async()=>{try{let o=await this.#s("root"),a=await this.#o(o),f=a.headers.get(Qe);if(f)return[await a.text(),BigInt(f)];throw new Error("no generation header in root hash")}catch(o){throw this.#t=null,o}})();this.#t=r;let[n,i]=await r;return[n,i]}async putRootHash(t,r){let n=await this.#s("root",r,t),i;try{i=await this.#o(n,t,{[Jt]:`${r}`})}catch(f){throw f instanceof H&&f.status===412?(this.#t=null,new fe):f}let o=i.headers.get(Qe);if(!o)throw new Error("no generation header in root hash");let a=BigInt(o);return this.#t=Promise.resolve([t,a]),a}async#l(t){let r=this.#e.get(t);for(;r;)try{let i=await r;if(i)return i;r=void 0}catch{r=this.#e.get(t)}let n=(async()=>{let i=await this.#s(t);return await(await this.#o(i)).arrayBuffer()})();return this.#e.set(t,n.then(i=>i.byteLength<this.#n?i:null,i=>{throw this.#e.delete(t),i})),await n}async getBuffer(t){let r=await this.#l(t);return r.byteLength<this.#n?r.slice(0):r}async getText(t){let r=await this.#l(t);return new TextDecoder().decode(r)}async getJson(t){let r=await this.getText(t);return JSON.parse(r)}async getMetadata(t){let r=await this.getJson(t);return V(Zt,r),r}async getEntries(t){if(t===void 0){let[o]=await this.getRootHash({cache:!0});t=o}let r=await this.getText(t),[n,...i]=r.slice(0,-1).split(`
|
|
11
|
+
`);if(n!==We)throw new Error(`got unexpected schema version: ${n}`);return i.map(at)}async#c(t,r){let n=this.#e.get(t);if(n)try{await n;return}catch{}let i=(async()=>{try{let o=await this.#s(t,null);return await this.#o(o,r),r.byteLength<this.#n?r:null}catch(o){throw this.#e.delete(t),o}})();this.#e.set(t,i),await i}async putEntries(t,r){let n=new TextEncoder;r.sort((u,g)=>u.documentId.localeCompare(g.documentId));let i=Le(r.map(u=>$e(u.hash))),o=await this.#f.digest("SHA-256",i),a=he(o),f=r.map(st).join(""),s=`${We}
|
|
12
|
+
${f}`,p=n.encode(s);return await this.#c(a,p),{hash:a,type:"80000000",documentId:t,subfiles:r.length,size:0n}}async putBuffer(t,r){let n=await this.#f.digest("SHA-256",r),i=he(n);return await this.#c(i,r),{hash:i,type:"0",documentId:t,subfiles:0,size:BigInt(r.byteLength)}}async putText(t,r){let n=new TextEncoder;return await this.putBuffer(t,n.encode(r))}async putJson(t,r){return await this.putText(t,(0,tt.default)(r))}async putMetadata(t,r){return await this.putJson(`${t}.metadata`,r)}async putCollection(t,r=""){let n=G(),i=`${new Date().valueOf()}`,o=[],a={type:"CollectionType",visibleName:t,version:0,parent:r,synced:!0,lastModified:i};o.push(this.putMetadata(n,a)),o.push(this.putText(`${n}.content`,"{}"));let f=await Promise.all(o);return await this.putEntries(n,f)}async#p(t,r,n,i,o){if(o.fileType!==n)throw new Error(`internal error: fileTypes don't match: ${n}, ${o.fileType}`);let a=G(),f=`${new Date().valueOf()}`,s=[];s.push(this.putBuffer(`${a}.${n}`,r));let p={type:"DocumentType",visibleName:t,version:0,parent:i,synced:!0,lastModified:f};s.push(this.putMetadata(a,p)),s.push(this.putText(`${a}.content`,JSON.stringify(o)));let u=await Promise.all(s);return await this.putEntries(a,u)}async putEpub(t,r,{parent:n="",margins:i=125,orientation:o,textAlignment:a,textScale:f=1,lineHeight:s=-1,fontName:p="",cover:u="visited",lastTool:g}={}){let x={dummyDocument:!1,extraMetadata:{LastTool:g},fileType:"epub",pageCount:0,lastOpenedPage:0,lineHeight:typeof s=="string"?ot[s]:s,margins:typeof i=="string"?it[i]:i,textScale:typeof f=="string"?nt[f]:f,pages:[],coverPageNumber:u==="first"?0:-1,formatVersion:1,orientation:o,textAlignment:a,fontName:p};return await this.#p(t,r,"epub",n,x)}async putPdf(t,r,{parent:n="",orientation:i,cover:o="first",lastTool:a}={}){let f={dummyDocument:!1,extraMetadata:{LastTool:a},fileType:"pdf",pageCount:0,lastOpenedPage:0,lineHeight:-1,margins:125,textScale:1,pages:[],coverPageNumber:o==="first"?0:-1,formatVersion:1,orientation:i};return await this.#p(t,r,"pdf",n,f)}async syncComplete(t){let r=`{ "generation": ${t} }`;await this.#i(`${this.#r}/sync/v2/sync-complete`,{body:r})}async#d(t,r,n){let{hash:i}=await this.putEntries("",r),o=await this.putRootHash(i,t);if(n)try{return await this.syncComplete(o),!0}catch{return!1}else return!1}async create(t,{cache:r=!0,sync:n=!0}={}){let[i,o]=await this.getRootHash({cache:r}),a=await this.getEntries(i);return a.push(t),await this.#d(o,a,n)}async move(t,r,{cache:n=!0,sync:i=!0}={}){let[o,a]=await this.getRootHash({cache:n}),f=await this.getEntries(o);if(!(!r||r==="trash")){let P=f.find(q=>q.documentId===r);if(P){if(P.type!=="80000000")throw new Error(`destination id was a raw file: ${r}`)}else throw new Error(`destination id not found: ${r}`);let A=await this.getEntries(P.hash),[m]=A.filter(q=>q.documentId===`${r}.metadata`);if(!m)throw new Error(`destination id didn't have metadata: ${r}`);if((await this.getMetadata(m.hash)).type!=="CollectionType")throw new Error(`destination id wasn't a collection: ${r}`)}let s=f.findIndex(P=>P.documentId===t);if(s===-1)throw new Error(`document not found: ${t}`);let[p]=f.splice(s,1);if(p.type!=="80000000")throw new Error(`document was a raw file: ${t}`);let u=await this.getEntries(p.hash),g=u.findIndex(P=>P.documentId===`${t}.metadata`);if(g===-1)throw new Error(`document didn't have metadata: ${t}`);let[x]=u.splice(g,1),F=await this.getMetadata(x.hash);F.parent=r;let y=await this.putMetadata(t,F);u.push(y);let J=await this.putEntries(t,u);return f.push(J),await this.#d(a,f,i)}async getEntriesMetadata(){let r=await(await this.#i(`${this.#r}/doc/v2/files`,{method:"GET",headers:{"rm-source":"RoR-Browser"}})).text(),n=JSON.parse(r);return V({elements:Kt},n),n}async#y(t,r,n){let o=new TextEncoder().encode(JSON.stringify({file_name:t})),f=await(await this.#i(`${this.#r}/doc/v2/files`,{body:r,headers:{"content-type":n,"rm-meta":(0,et.fromByteArray)(o),"rm-source":"RoR-Browser"}})).text(),s=JSON.parse(f);return V(Vt,s),s}async uploadEpub(t,r){return await this.#y(t,r,"application/epub+zip")}async uploadPdf(t,r){return await this.#y(t,r,"application/pdf")}async getCache(){let t=[];for(let[i,o]of this.#e)t.push(o.then(a=>[i,a],()=>[i,null]));let r=await Promise.all(t),n=new Map;for(let[i,o]of r)o&&n.set(i,o);return n}};async function Qt(e,{fetch:t=globalThis.fetch,subtle:r=globalThis.crypto?.subtle,authHost:n=rt,syncHost:i=Ut,cacheLimitBytes:o=1048576,initCache:a=[]}={}){if(!r)throw new Error("subtle was missing, try specifying it manually");let f=await t(`${n}/token/json/2/user/new`,{method:"POST",headers:{Authorization:`Bearer ${e}`}});if(!f.ok)throw new Error(`couldn't fetch auth token: ${f.statusText}`);let s=await f.text();return new we(s,t,r,i,o,a)}0&&(module.exports={GenerationError,ResponseError,builtinFontNames,builtinLineHeights,builtinMargins,builtinTextScales,builtinTools,formatEntry,parseEntry,register,remarkable});
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
var He=Object.create;var ye=Object.defineProperty;var Je=Object.getOwnPropertyDescriptor;var Ve=Object.getOwnPropertyNames;var qe=Object.getPrototypeOf,Ge=Object.prototype.hasOwnProperty;var j=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports);var ze=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of Ve(r))!Ge.call(e,i)&&i!==t&&ye(e,i,{get:()=>r[i],enumerable:!(n=Je(r,i))||n.enumerable});return e};var he=(e,r,t)=>(t=e!=null?He(qe(e)):{},ze(r||!e||!e.__esModule?ye(t,"default",{value:e,enumerable:!0}):t,e));var we=j(W=>{"use strict";W.byteLength=Ye;W.toByteArray=Ke;W.fromByteArray=et;var O=[],A=[],We=typeof Uint8Array<"u"?Uint8Array:Array,ie="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(F=0,ge=ie.length;F<ge;++F)O[F]=ie[F],A[ie.charCodeAt(F)]=F;var F,ge;A["-".charCodeAt(0)]=62;A["_".charCodeAt(0)]=63;function be(e){var r=e.length;if(r%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var t=e.indexOf("=");t===-1&&(t=r);var n=t===r?0:4-t%4;return[t,n]}function Ye(e){var r=be(e),t=r[0],n=r[1];return(t+n)*3/4-n}function Ze(e,r,t){return(r+t)*3/4-t}function Ke(e){var r,t=be(e),n=t[0],i=t[1],o=new We(Ze(e,n,i)),s=0,a=i>0?n-4:n,f;for(f=0;f<a;f+=4)r=A[e.charCodeAt(f)]<<18|A[e.charCodeAt(f+1)]<<12|A[e.charCodeAt(f+2)]<<6|A[e.charCodeAt(f+3)],o[s++]=r>>16&255,o[s++]=r>>8&255,o[s++]=r&255;return i===2&&(r=A[e.charCodeAt(f)]<<2|A[e.charCodeAt(f+1)]>>4,o[s++]=r&255),i===1&&(r=A[e.charCodeAt(f)]<<10|A[e.charCodeAt(f+1)]<<4|A[e.charCodeAt(f+2)]>>2,o[s++]=r>>8&255,o[s++]=r&255),o}function Xe(e){return O[e>>18&63]+O[e>>12&63]+O[e>>6&63]+O[e&63]}function Qe(e,r,t){for(var n,i=[],o=r;o<t;o+=3)n=(e[o]<<16&16711680)+(e[o+1]<<8&65280)+(e[o+2]&255),i.push(Xe(n));return i.join("")}function et(e){for(var r,t=e.length,n=t%3,i=[],o=16383,s=0,a=t-n;s<a;s+=o)i.push(Qe(e,s,s+o>a?a:s+o));return n===1?(r=e[t-1],i.push(O[r>>2]+O[r<<4&63]+"==")):n===2&&(r=(e[t-2]<<8)+e[t-1],i.push(O[r>>10]+O[r>>4&63]+O[r<<2&63]+"=")),i.join("")}});var ue=j(d=>{"use strict";var ke=d&&d.__rest||function(e,r){var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&r.indexOf(n)<0&&(t[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(e);i<n.length;i++)r.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(t[n[i]]=e[n[i]]);return t};Object.defineProperty(d,"__esModule",{value:!0});d.isSchema=d.isValidSchema=d.isDiscriminatorForm=d.isValuesForm=d.isPropertiesForm=d.isElementsForm=d.isEnumForm=d.isTypeForm=d.isRefForm=d.isEmptyForm=void 0;function ht(e){let{definitions:r,nullable:t,metadata:n}=e,i=ke(e,["definitions","nullable","metadata"]);return Object.keys(i).length===0}d.isEmptyForm=ht;function Oe(e){return"ref"in e}d.isRefForm=Oe;function gt(e){return"type"in e}d.isTypeForm=gt;function Se(e){return"enum"in e}d.isEnumForm=Se;function Ce(e){return"elements"in e}d.isElementsForm=Ce;function le(e){return"properties"in e||"optionalProperties"in e}d.isPropertiesForm=le;function Me(e){return"values"in e}d.isValuesForm=Me;function Fe(e){return"discriminator"in e}d.isDiscriminatorForm=Fe;function U(e,r){if(r===void 0&&(r=e),e.definitions!==void 0){if(r!==e)return!1;for(let t of Object.values(e.definitions))if(!U(t,r))return!1}if(Oe(e)&&!(e.ref in(r.definitions||{}))||Se(e)&&(e.enum.length===0||e.enum.length!==new Set(e.enum).size))return!1;if(Ce(e))return U(e.elements,r);if(le(e)){for(let t of Object.values(e.properties||{}))if(!U(t,r))return!1;for(let t of Object.values(e.optionalProperties||{}))if(!U(t,r))return!1;for(let t of Object.keys(e.properties||{}))if(t in(e.optionalProperties||{}))return!1}if(Me(e))return U(e.values,r);if(Fe(e)){for(let t of Object.values(e.mapping))if(!U(t,r)||!le(t)||t.nullable||e.discriminator in(t.properties||{})||e.discriminator in(t.optionalProperties||{}))return!1}return!0}d.isValidSchema=U;var bt=[[!1,!1,!1,!1,!1,!1,!1,!1,!1,!1],[!0,!1,!1,!1,!1,!1,!1,!1,!1,!1],[!1,!0,!1,!1,!1,!1,!1,!1,!1,!1],[!1,!1,!0,!1,!1,!1,!1,!1,!1,!1],[!1,!1,!1,!0,!1,!1,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!1,!1,!1,!1,!1],[!1,!1,!1,!1,!1,!0,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!0,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!1,!0,!1,!1,!1],[!1,!1,!1,!1,!1,!0,!0,!1,!1,!1],[!1,!1,!1,!1,!0,!0,!0,!1,!1,!1],[!1,!1,!1,!1,!1,!1,!1,!0,!1,!1],[!1,!1,!1,!1,!1,!1,!1,!1,!0,!0]],wt=["boolean","float32","float64","int8","uint8","int16","uint16","int32","uint32","string","timestamp"];function I(e){if(typeof e!="object"||Array.isArray(e)||e===null)return!1;let r=e,{definitions:t=void 0,nullable:n=void 0,metadata:i=void 0,ref:o=void 0,type:s=void 0,enum:a=void 0,elements:f=void 0,properties:l=void 0,optionalProperties:u=void 0,additionalProperties:p=void 0,values:P=void 0,discriminator:c=void 0,mapping:T=void 0}=r,B=ke(r,["definitions","nullable","metadata","ref","type","enum","elements","properties","optionalProperties","additionalProperties","values","discriminator","mapping"]),re=[o!==void 0,s!==void 0,a!==void 0,f!==void 0,l!==void 0,u!==void 0,p!==void 0,P!==void 0,c!==void 0,T!==void 0],k=!1;for(let v of bt)k=k||v.every((z,me)=>z===re[me]);if(!k)return!1;if(t!==void 0){if(typeof t!="object"||Array.isArray(t)||t===null)return!1;for(let v of Object.values(t))if(!I(v))return!1}if(n!==void 0&&typeof n!="boolean"||i!==void 0&&(typeof i!="object"||Array.isArray(i)||i===null)||o!==void 0&&typeof o!="string"||s!==void 0&&(typeof s!="string"||!wt.includes(s))||a!==void 0&&(!Array.isArray(a)||!a.every(v=>typeof v=="string"))||f!==void 0&&!I(f))return!1;if(l!==void 0){if(typeof l!="object"||Array.isArray(l)||l===null)return!1;for(let v of Object.values(l))if(!I(v))return!1}if(u!==void 0){if(typeof u!="object"||Array.isArray(u)||u===null)return!1;for(let v of Object.values(u))if(!I(v))return!1}if(p!==void 0&&typeof p!="boolean"||P!==void 0&&!I(P)||c!==void 0&&typeof c!="string")return!1;if(T!==void 0){if(typeof T!="object"||Array.isArray(T)||T===null)return!1;for(let v of Object.values(T))if(!I(v))return!1}return Object.keys(B).length===0}d.isSchema=I});var Ue=j(de=>{"use strict";Object.defineProperty(de,"__esModule",{value:!0});var xt=/^(\d{4})-(\d{2})-(\d{2})[tT](\d{2}):(\d{2}):(\d{2})(\.\d+)?([zZ]|((\+|-)(\d{2}):(\d{2})))$/;function Et(e){let r=e.match(xt);if(r===null)return!1;let t=parseInt(r[1],10),n=parseInt(r[2],10),i=parseInt(r[3],10),o=parseInt(r[4],10),s=parseInt(r[5],10),a=parseInt(r[6],10);return!(n>12||i>vt(t,n)||o>23||s>59||a>60)}de.default=Et;function vt(e,r){return r===2?Pt(e)?29:28:Tt[r]}function Pt(e){return e%4===0&&(e%100!==0||e%400===0)}var Tt=[0,31,0,31,30,31,30,31,31,30,31,30,31]});var Ie=j(C=>{"use strict";var At=C&&C.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(C,"__esModule",{value:!0});C.validate=C.MaxDepthExceededError=void 0;var kt=At(Ue()),R=ue(),X=class extends Error{};C.MaxDepthExceededError=X;var Q=class extends Error{};function Ot(e,r,t){let n={errors:[],instanceTokens:[],schemaTokens:[[]],root:e,config:t||{maxDepth:0,maxErrors:0}};try{L(n,e,r)}catch(i){if(!(i instanceof Q))throw i}return n.errors}C.validate=Ot;function L(e,r,t,n){if(!(r.nullable&&t===null)){if(R.isRefForm(r)){if(e.schemaTokens.length===e.config.maxDepth)throw new X;e.schemaTokens.push(["definitions",r.ref]),L(e,e.root.definitions[r.ref],t),e.schemaTokens.pop()}else if(R.isTypeForm(r)){switch(w(e,"type"),r.type){case"boolean":typeof t!="boolean"&&x(e);break;case"float32":case"float64":typeof t!="number"&&x(e);break;case"int8":D(e,t,-128,127);break;case"uint8":D(e,t,0,255);break;case"int16":D(e,t,-32768,32767);break;case"uint16":D(e,t,0,65535);break;case"int32":D(e,t,-2147483648,2147483647);break;case"uint32":D(e,t,0,4294967295);break;case"string":typeof t!="string"&&x(e);break;case"timestamp":typeof t!="string"?x(e):kt.default(t)||x(e);break}E(e)}else if(R.isEnumForm(r))w(e,"enum"),(typeof t!="string"||!r.enum.includes(t))&&x(e),E(e);else if(R.isElementsForm(r)){if(w(e,"elements"),Array.isArray(t))for(let[i,o]of t.entries())_(e,i.toString()),L(e,r.elements,o),$(e);else x(e);E(e)}else if(R.isPropertiesForm(r))if(typeof t=="object"&&t!==null&&!Array.isArray(t)){if(r.properties!==void 0){w(e,"properties");for(let[i,o]of Object.entries(r.properties))w(e,i),t.hasOwnProperty(i)?(_(e,i),L(e,o,t[i]),$(e)):x(e),E(e);E(e)}if(r.optionalProperties!==void 0){w(e,"optionalProperties");for(let[i,o]of Object.entries(r.optionalProperties))w(e,i),t.hasOwnProperty(i)&&(_(e,i),L(e,o,t[i]),$(e)),E(e);E(e)}if(r.additionalProperties!==!0)for(let i of Object.keys(t)){let o=r.properties&&i in r.properties,s=r.optionalProperties&&i in r.optionalProperties;!o&&!s&&i!==n&&(_(e,i),x(e),$(e))}}else r.properties!==void 0?w(e,"properties"):w(e,"optionalProperties"),x(e),E(e);else if(R.isValuesForm(r)){if(w(e,"values"),typeof t=="object"&&t!==null&&!Array.isArray(t))for(let[i,o]of Object.entries(t))_(e,i),L(e,r.values,o),$(e);else x(e);E(e)}else if(R.isDiscriminatorForm(r))if(typeof t=="object"&&t!==null&&!Array.isArray(t))if(t.hasOwnProperty(r.discriminator)){let i=t[r.discriminator];typeof i=="string"?i in r.mapping?(w(e,"mapping"),w(e,i),L(e,r.mapping[i],t,r.discriminator),E(e),E(e)):(w(e,"mapping"),_(e,r.discriminator),x(e),$(e),E(e)):(w(e,"discriminator"),_(e,r.discriminator),x(e),$(e),E(e))}else w(e,"discriminator"),x(e),E(e);else w(e,"discriminator"),x(e),E(e)}}function D(e,r,t,n){(typeof r!="number"||!Number.isInteger(r)||r<t||r>n)&&x(e)}function _(e,r){e.instanceTokens.push(r)}function $(e){e.instanceTokens.pop()}function w(e,r){e.schemaTokens[e.schemaTokens.length-1].push(r)}function E(e){e.schemaTokens[e.schemaTokens.length-1].pop()}function x(e){if(e.errors.push({instancePath:[...e.instanceTokens],schemaPath:[...e.schemaTokens[e.schemaTokens.length-1]]}),e.errors.length===e.config.maxErrors)throw new Q}});var _e=j(M=>{"use strict";var St=M&&M.__createBinding||(Object.create?function(e,r,t,n){n===void 0&&(n=t),Object.defineProperty(e,n,{enumerable:!0,get:function(){return r[t]}})}:function(e,r,t,n){n===void 0&&(n=t),e[n]=r[t]}),Re=M&&M.__exportStar||function(e,r){for(var t in e)t!=="default"&&!r.hasOwnProperty(t)&&St(r,e,t)};Object.defineProperty(M,"__esModule",{value:!0});Re(ue(),M);Re(Ie(),M)});var Be=he(we());var Y,tt=new Uint8Array(16);function Z(){if(!Y&&(Y=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Y))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Y(tt)}var xe=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function rt(e){return typeof e=="string"&&xe.test(e)}var H=rt;var m=[];for(let e=0;e<256;++e)m.push((e+256).toString(16).slice(1));function J(e,r=0){return(m[e[r+0]]+m[e[r+1]]+m[e[r+2]]+m[e[r+3]]+"-"+m[e[r+4]]+m[e[r+5]]+"-"+m[e[r+6]]+m[e[r+7]]+"-"+m[e[r+8]]+m[e[r+9]]+"-"+m[e[r+10]]+m[e[r+11]]+m[e[r+12]]+m[e[r+13]]+m[e[r+14]]+m[e[r+15]]).toLowerCase()}function nt(e){if(!H(e))throw TypeError("Invalid UUID");let r,t=new Uint8Array(16);return t[0]=(r=parseInt(e.slice(0,8),16))>>>24,t[1]=r>>>16&255,t[2]=r>>>8&255,t[3]=r&255,t[4]=(r=parseInt(e.slice(9,13),16))>>>8,t[5]=r&255,t[6]=(r=parseInt(e.slice(14,18),16))>>>8,t[7]=r&255,t[8]=(r=parseInt(e.slice(19,23),16))>>>8,t[9]=r&255,t[10]=(r=parseInt(e.slice(24,36),16))/1099511627776&255,t[11]=r/4294967296&255,t[12]=r>>>24&255,t[13]=r>>>16&255,t[14]=r>>>8&255,t[15]=r&255,t}var oe=nt;function it(e){e=unescape(encodeURIComponent(e));let r=[];for(let t=0;t<e.length;++t)r.push(e.charCodeAt(t));return r}var ot="6ba7b810-9dad-11d1-80b4-00c04fd430c8",st="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function V(e,r,t){function n(i,o,s,a){var f;if(typeof i=="string"&&(i=it(i)),typeof o=="string"&&(o=oe(o)),((f=o)===null||f===void 0?void 0:f.length)!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let l=new Uint8Array(16+i.length);if(l.set(o),l.set(i,o.length),l=t(l),l[6]=l[6]&15|r,l[8]=l[8]&63|128,s){a=a||0;for(let u=0;u<16;++u)s[a+u]=l[u];return s}return J(l)}try{n.name=e}catch{}return n.DNS=ot,n.URL=st,n}function at(e){if(typeof e=="string"){let r=unescape(encodeURIComponent(e));e=new Uint8Array(r.length);for(let t=0;t<r.length;++t)e[t]=r.charCodeAt(t)}return ft(lt(ut(e),e.length*8))}function ft(e){let r=[],t=e.length*32,n="0123456789abcdef";for(let i=0;i<t;i+=8){let o=e[i>>5]>>>i%32&255,s=parseInt(n.charAt(o>>>4&15)+n.charAt(o&15),16);r.push(s)}return r}function Ee(e){return(e+64>>>9<<4)+14+1}function lt(e,r){e[r>>5]|=128<<r%32,e[Ee(r)-1]=r;let t=1732584193,n=-271733879,i=-1732584194,o=271733878;for(let s=0;s<e.length;s+=16){let a=t,f=n,l=i,u=o;t=y(t,n,i,o,e[s],7,-680876936),o=y(o,t,n,i,e[s+1],12,-389564586),i=y(i,o,t,n,e[s+2],17,606105819),n=y(n,i,o,t,e[s+3],22,-1044525330),t=y(t,n,i,o,e[s+4],7,-176418897),o=y(o,t,n,i,e[s+5],12,1200080426),i=y(i,o,t,n,e[s+6],17,-1473231341),n=y(n,i,o,t,e[s+7],22,-45705983),t=y(t,n,i,o,e[s+8],7,1770035416),o=y(o,t,n,i,e[s+9],12,-1958414417),i=y(i,o,t,n,e[s+10],17,-42063),n=y(n,i,o,t,e[s+11],22,-1990404162),t=y(t,n,i,o,e[s+12],7,1804603682),o=y(o,t,n,i,e[s+13],12,-40341101),i=y(i,o,t,n,e[s+14],17,-1502002290),n=y(n,i,o,t,e[s+15],22,1236535329),t=h(t,n,i,o,e[s+1],5,-165796510),o=h(o,t,n,i,e[s+6],9,-1069501632),i=h(i,o,t,n,e[s+11],14,643717713),n=h(n,i,o,t,e[s],20,-373897302),t=h(t,n,i,o,e[s+5],5,-701558691),o=h(o,t,n,i,e[s+10],9,38016083),i=h(i,o,t,n,e[s+15],14,-660478335),n=h(n,i,o,t,e[s+4],20,-405537848),t=h(t,n,i,o,e[s+9],5,568446438),o=h(o,t,n,i,e[s+14],9,-1019803690),i=h(i,o,t,n,e[s+3],14,-187363961),n=h(n,i,o,t,e[s+8],20,1163531501),t=h(t,n,i,o,e[s+13],5,-1444681467),o=h(o,t,n,i,e[s+2],9,-51403784),i=h(i,o,t,n,e[s+7],14,1735328473),n=h(n,i,o,t,e[s+12],20,-1926607734),t=g(t,n,i,o,e[s+5],4,-378558),o=g(o,t,n,i,e[s+8],11,-2022574463),i=g(i,o,t,n,e[s+11],16,1839030562),n=g(n,i,o,t,e[s+14],23,-35309556),t=g(t,n,i,o,e[s+1],4,-1530992060),o=g(o,t,n,i,e[s+4],11,1272893353),i=g(i,o,t,n,e[s+7],16,-155497632),n=g(n,i,o,t,e[s+10],23,-1094730640),t=g(t,n,i,o,e[s+13],4,681279174),o=g(o,t,n,i,e[s],11,-358537222),i=g(i,o,t,n,e[s+3],16,-722521979),n=g(n,i,o,t,e[s+6],23,76029189),t=g(t,n,i,o,e[s+9],4,-640364487),o=g(o,t,n,i,e[s+12],11,-421815835),i=g(i,o,t,n,e[s+15],16,530742520),n=g(n,i,o,t,e[s+2],23,-995338651),t=b(t,n,i,o,e[s],6,-198630844),o=b(o,t,n,i,e[s+7],10,1126891415),i=b(i,o,t,n,e[s+14],15,-1416354905),n=b(n,i,o,t,e[s+5],21,-57434055),t=b(t,n,i,o,e[s+12],6,1700485571),o=b(o,t,n,i,e[s+3],10,-1894986606),i=b(i,o,t,n,e[s+10],15,-1051523),n=b(n,i,o,t,e[s+1],21,-2054922799),t=b(t,n,i,o,e[s+8],6,1873313359),o=b(o,t,n,i,e[s+15],10,-30611744),i=b(i,o,t,n,e[s+6],15,-1560198380),n=b(n,i,o,t,e[s+13],21,1309151649),t=b(t,n,i,o,e[s+4],6,-145523070),o=b(o,t,n,i,e[s+11],10,-1120210379),i=b(i,o,t,n,e[s+2],15,718787259),n=b(n,i,o,t,e[s+9],21,-343485551),t=S(t,a),n=S(n,f),i=S(i,l),o=S(o,u)}return[t,n,i,o]}function ut(e){if(e.length===0)return[];let r=e.length*8,t=new Uint32Array(Ee(r));for(let n=0;n<r;n+=8)t[n>>5]|=(e[n/8]&255)<<n%32;return t}function S(e,r){let t=(e&65535)+(r&65535);return(e>>16)+(r>>16)+(t>>16)<<16|t&65535}function dt(e,r){return e<<r|e>>>32-r}function K(e,r,t,n,i,o){return S(dt(S(S(r,e),S(n,o)),i),t)}function y(e,r,t,n,i,o,s){return K(r&t|~r&n,e,r,i,o,s)}function h(e,r,t,n,i,o,s){return K(r&n|t&~n,e,r,i,o,s)}function g(e,r,t,n,i,o,s){return K(r^t^n,e,r,i,o,s)}function b(e,r,t,n,i,o,s){return K(t^(r|~n),e,r,i,o,s)}var ve=at;var sr=V("v3",48,ve);var ct=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),se={randomUUID:ct};function pt(e,r,t){if(se.randomUUID&&!r&&!e)return se.randomUUID();e=e||{};let n=e.random||(e.rng||Z)();if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,r){t=t||0;for(let i=0;i<16;++i)r[t+i]=n[i];return r}return J(n)}var q=pt;function mt(e,r,t,n){switch(e){case 0:return r&t^~r&n;case 1:return r^t^n;case 2:return r&t^r&n^t&n;case 3:return r^t^n}}function ae(e,r){return e<<r|e>>>32-r}function yt(e){let r=[1518500249,1859775393,2400959708,3395469782],t=[1732584193,4023233417,2562383102,271733878,3285377520];if(typeof e=="string"){let s=unescape(encodeURIComponent(e));e=[];for(let a=0;a<s.length;++a)e.push(s.charCodeAt(a))}else Array.isArray(e)||(e=Array.prototype.slice.call(e));e.push(128);let n=e.length/4+2,i=Math.ceil(n/16),o=new Array(i);for(let s=0;s<i;++s){let a=new Uint32Array(16);for(let f=0;f<16;++f)a[f]=e[s*64+f*4]<<24|e[s*64+f*4+1]<<16|e[s*64+f*4+2]<<8|e[s*64+f*4+3];o[s]=a}o[i-1][14]=(e.length-1)*8/Math.pow(2,32),o[i-1][14]=Math.floor(o[i-1][14]),o[i-1][15]=(e.length-1)*8&4294967295;for(let s=0;s<i;++s){let a=new Uint32Array(80);for(let c=0;c<16;++c)a[c]=o[s][c];for(let c=16;c<80;++c)a[c]=ae(a[c-3]^a[c-8]^a[c-14]^a[c-16],1);let f=t[0],l=t[1],u=t[2],p=t[3],P=t[4];for(let c=0;c<80;++c){let T=Math.floor(c/20),B=ae(f,5)+mt(T,l,u,p)+P+r[T]+a[c]>>>0;P=p,p=u,u=ae(l,30)>>>0,l=f,f=B}t[0]=t[0]+f>>>0,t[1]=t[1]+l>>>0,t[2]=t[2]+u>>>0,t[3]=t[3]+p>>>0,t[4]=t[4]+P>>>0}return[t[0]>>24&255,t[0]>>16&255,t[0]>>8&255,t[0]&255,t[1]>>24&255,t[1]>>16&255,t[1]>>8&255,t[1]&255,t[2]>>24&255,t[2]>>16&255,t[2]>>8&255,t[2]&255,t[3]>>24&255,t[3]>>16&255,t[3]>>8&255,t[3]&255,t[4]>>24&255,t[4]>>16&255,t[4]>>8&255,t[4]&255]}var Pe=yt;var hr=V("v5",80,Pe);function fe(e){return[...new Uint8Array(e)].map(r=>r.toString(16).padStart(2,"0")).join("")}function Te(e){return new Uint8Array((e.match(/../g)??[]).map(r=>parseInt(r,16)))}function Ae(e){let r=0;for(let i of e)r+=i.length;let t=new Uint8Array(r),n=0;for(let i of e)t.set(i,n),n+=i.length;return t}var $e=he(_e());function G(e,r){if((0,$e.validate)(e,r).length)throw new Error(`couldn't validate schema: ${JSON.stringify(r)} didn't match schema ${JSON.stringify(e)}`)}var Le="3",je="https://webapp-prod.cloud.remarkable.engineering",Ct="https://internal.cloud.remarkable.com",De="x-goog-generation",Mt="x-goog-if-generation-match",Ft="x-goog-content-length-range",zr=["Ballpoint","Ballpointv2","Brush","Calligraphy","ClearPage","EraseSection","Eraser","Fineliner","Finelinerv2","Highlighter","Highlighterv2","Marker","Markerv2","Paintbrush","Paintbrushv2","Pencilv2","SharpPencil","SharpPencilv2","SolidPen","ZoomTool"],Wr=["Maison Neue","EB Garamond","Noto Sans","Noto Serif","Noto Mono","Noto Sans UI"],Ut={xs:.7,sm:.8,md:1,lg:1.2,xl:1.5,xx:2},It={sm:50,md:125,rr:180,lg:200},Rt={df:-1,md:100,lg:150,xl:200},_t={properties:{docID:{type:"string"},hash:{type:"string"}}},$t={properties:{relative_path:{type:"string"},url:{type:"string"},expires:{type:"timestamp"},method:{enum:["POST","GET","PUT","DELETE"]}},optionalProperties:{maxuploadsize_bytes:{type:"float64"}}},ee={visibleName:{type:"string"},lastModified:{type:"string"}},te={version:{type:"int32"},pinned:{type:"boolean"},synced:{type:"boolean"},modified:{type:"boolean"},deleted:{type:"boolean"},metadatamodified:{type:"boolean"},parent:{type:"string"}},Lt={discriminator:"type",mapping:{CollectionType:{properties:ee,optionalProperties:te},DocumentType:{properties:ee,optionalProperties:{...te,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},Ne={id:{type:"string"},hash:{type:"string"}},Dt={discriminator:"type",mapping:{CollectionType:{properties:{...ee,...Ne},optionalProperties:te},DocumentType:{properties:{...ee,...Ne,fileType:{enum:["notebook","epub","pdf",""]}},optionalProperties:{...te,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},N=class extends Error{constructor(t,n,i){super(i);this.status=t,this.statusText=n}},ce=class extends Error{constructor(){super("Generation preconditions failed. This means the current state is out of date with the cloud and needs to be re-synced.")}};async function Yr(e,{deviceDesc:r="browser-chrome",uuid:t=q(),authHost:n=je,fetch:i=globalThis.fetch}={}){if(e.length!==8)throw new Error(`code should be length 8, but was ${e.length}`);let o=await i(`${n}/token/json/2/device/new`,{method:"POST",headers:{Authorization:"Bearer"},body:JSON.stringify({code:e,deviceDesc:r,deviceID:t})});if(o.ok)return await o.text();throw new N(o.status,o.statusText,"couldn't register api")}function Nt({hash:e,type:r,documentId:t,subfiles:n,size:i}){return`${e}:${r}:${t}:${n}:${i}
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
var Xe=Object.create;var we=Object.defineProperty;var et=Object.getOwnPropertyDescriptor;var tt=Object.getOwnPropertyNames;var rt=Object.getPrototypeOf,nt=Object.prototype.hasOwnProperty;var S=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var it=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of tt(t))!nt.call(e,i)&&i!==r&&we(e,i,{get:()=>t[i],enumerable:!(n=et(t,i))||n.enumerable});return e};var oe=(e,t,r)=>(r=e!=null?Xe(rt(e)):{},it(t||!e||!e.__esModule?we(r,"default",{value:e,enumerable:!0}):r,e));var Ee=S(Y=>{"use strict";Y.byteLength=st;Y.toByteArray=ft;Y.fromByteArray=ct;var O=[],T=[],ot=typeof Uint8Array<"u"?Uint8Array:Array,se="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(B=0,ve=se.length;B<ve;++B)O[B]=se[B],T[se.charCodeAt(B)]=B;var B,ve;T["-".charCodeAt(0)]=62;T["_".charCodeAt(0)]=63;function xe(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");r===-1&&(r=t);var n=r===t?0:4-r%4;return[r,n]}function st(e){var t=xe(e),r=t[0],n=t[1];return(r+n)*3/4-n}function at(e,t,r){return(t+r)*3/4-r}function ft(e){var t,r=xe(e),n=r[0],i=r[1],o=new ot(at(e,n,i)),a=0,f=i>0?n-4:n,s;for(s=0;s<f;s+=4)t=T[e.charCodeAt(s)]<<18|T[e.charCodeAt(s+1)]<<12|T[e.charCodeAt(s+2)]<<6|T[e.charCodeAt(s+3)],o[a++]=t>>16&255,o[a++]=t>>8&255,o[a++]=t&255;return i===2&&(t=T[e.charCodeAt(s)]<<2|T[e.charCodeAt(s+1)]>>4,o[a++]=t&255),i===1&&(t=T[e.charCodeAt(s)]<<10|T[e.charCodeAt(s+1)]<<4|T[e.charCodeAt(s+2)]>>2,o[a++]=t>>8&255,o[a++]=t&255),o}function ut(e){return O[e>>18&63]+O[e>>12&63]+O[e>>6&63]+O[e&63]}function lt(e,t,r){for(var n,i=[],o=t;o<r;o+=3)n=(e[o]<<16&16711680)+(e[o+1]<<8&65280)+(e[o+2]&255),i.push(ut(n));return i.join("")}function ct(e){for(var t,r=e.length,n=r%3,i=[],o=16383,a=0,f=r-n;a<f;a+=o)i.push(lt(e,a,a+o>f?f:a+o));return n===1?(t=e[r-1],i.push(O[t>>2]+O[t<<4&63]+"==")):n===2&&(t=(e[r-2]<<8)+e[r-1],i.push(O[t>>10]+O[t>>4&63]+O[t<<2&63]+"=")),i.join("")}});var Se=S((Yt,Oe)=>{"use strict";var Z,l,Pe={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:`
|
|
2
|
+
`,r:"\r",t:" "},ae;function M(e){throw{name:"SyntaxError",message:e,at:Z,text:ae}}function c(e){return e&&e!==l&&M("Expected '"+e+"' instead of '"+l+"'"),l=ae.charAt(Z),Z+=1,l}function Te(){var e,t="";for(l==="-"&&(t="-",c("-"));l>="0"&&l<="9";)t+=l,c();if(l===".")for(t+=".";c()&&l>="0"&&l<="9";)t+=l;if(l==="e"||l==="E")for(t+=l,c(),(l==="-"||l==="+")&&(t+=l,c());l>="0"&&l<="9";)t+=l,c();return e=Number(t),isFinite(e)||M("Bad number"),e}function Ae(){var e,t,r="",n;if(l==='"')for(;c();){if(l==='"')return c(),r;if(l==="\\")if(c(),l==="u"){for(n=0,t=0;t<4&&(e=parseInt(c(),16),!!isFinite(e));t+=1)n=n*16+e;r+=String.fromCharCode(n)}else if(typeof Pe[l]=="string")r+=Pe[l];else break;else r+=l}M("Bad string")}function k(){for(;l&&l<=" ";)c()}function pt(){switch(l){case"t":return c("t"),c("r"),c("u"),c("e"),!0;case"f":return c("f"),c("a"),c("l"),c("s"),c("e"),!1;case"n":return c("n"),c("u"),c("l"),c("l"),null;default:M("Unexpected '"+l+"'")}}function dt(){var e=[];if(l==="["){if(c("["),k(),l==="]")return c("]"),e;for(;l;){if(e.push(K()),k(),l==="]")return c("]"),e;c(","),k()}}M("Bad array")}function yt(){var e,t={};if(l==="{"){if(c("{"),k(),l==="}")return c("}"),t;for(;l;){if(e=Ae(),k(),c(":"),Object.prototype.hasOwnProperty.call(t,e)&&M('Duplicate key "'+e+'"'),t[e]=K(),k(),l==="}")return c("}"),t;c(","),k()}}M("Bad object")}function K(){switch(k(),l){case"{":return yt();case"[":return dt();case'"':return Ae();case"-":return Te();default:return l>="0"&&l<="9"?Te():pt()}}Oe.exports=function(e,t){var r;return ae=e,Z=0,l=" ",r=K(),k(),l&&M("Syntax error"),typeof t=="function"?function n(i,o){var a,f,s=i[o];if(s&&typeof s=="object")for(a in K)Object.prototype.hasOwnProperty.call(s,a)&&(f=n(s,a),typeof f>"u"?delete s[a]:s[a]=f);return t.call(i,o,s)}({"":r},""):r}});var Fe=S((Zt,ke)=>{"use strict";var fe=/[\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,E,W,mt={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},R;function ue(e){return fe.lastIndex=0,fe.test(e)?'"'+e.replace(fe,function(t){var r=mt[t];return typeof r=="string"?r:"\\u"+("0000"+t.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+e+'"'}function Q(e,t){var r,n,i,o,a=E,f,s=t[e];switch(s&&typeof s=="object"&&typeof s.toJSON=="function"&&(s=s.toJSON(e)),typeof R=="function"&&(s=R.call(t,e,s)),typeof s){case"string":return ue(s);case"number":return isFinite(s)?String(s):"null";case"boolean":case"null":return String(s);case"object":if(!s)return"null";if(E+=W,f=[],Object.prototype.toString.apply(s)==="[object Array]"){for(o=s.length,r=0;r<o;r+=1)f[r]=Q(r,s)||"null";return i=f.length===0?"[]":E?`[
|
|
3
|
+
`+E+f.join(`,
|
|
4
|
+
`+E)+`
|
|
5
|
+
`+a+"]":"["+f.join(",")+"]",E=a,i}if(R&&typeof R=="object")for(o=R.length,r=0;r<o;r+=1)n=R[r],typeof n=="string"&&(i=Q(n,s),i&&f.push(ue(n)+(E?": ":":")+i));else for(n in s)Object.prototype.hasOwnProperty.call(s,n)&&(i=Q(n,s),i&&f.push(ue(n)+(E?": ":":")+i));return i=f.length===0?"{}":E?`{
|
|
6
|
+
`+E+f.join(`,
|
|
7
|
+
`+E)+`
|
|
8
|
+
`+a+"}":"{"+f.join(",")+"}",E=a,i;default:}}ke.exports=function(e,t,r){var n;if(E="",W="",typeof r=="number")for(n=0;n<r;n+=1)W+=" ";else typeof r=="string"&&(W=r);if(R=t,t&&typeof t!="function"&&(typeof t!="object"||typeof t.length!="number"))throw new Error("JSON.stringify");return Q("",{"":e})}});var Me=S(le=>{"use strict";le.parse=Se();le.stringify=Fe()});var je=S((Wt,Ce)=>{"use strict";var X=typeof JSON<"u"?JSON:Me(),ht=Array.isArray||function(e){return{}.toString.call(e)==="[object Array]"},gt=Object.keys||function(e){var t=Object.prototype.hasOwnProperty||function(){return!0},r=[];for(var n in e)t.call(e,n)&&r.push(n);return r};Ce.exports=function(e,t){t||(t={}),typeof t=="function"&&(t={cmp:t});var r=t.space||"";typeof r=="number"&&(r=Array(r+1).join(" "));var n=typeof t.cycles=="boolean"?t.cycles:!1,i=t.replacer||function(f,s){return s},o=t.cmp&&function(f){return function(s){return function(p,u){var g={key:p,value:s[p]},x={key:u,value:s[u]};return f(g,x)}}}(t.cmp),a=[];return function f(s,p,u,g){var x=r?`
|
|
9
|
+
`+new Array(g+1).join(r):"",F=r?": ":":";if(u&&u.toJSON&&typeof u.toJSON=="function"&&(u=u.toJSON()),u=i.call(s,p,u),u!==void 0){if(typeof u!="object"||u===null)return X.stringify(u);if(ht(u)){for(var A=[],y=0;y<u.length;y++){var J=f(u,y,u[y],g+1)||X.stringify(null);A.push(x+r+J)}return"["+A.join(",")+x+"]"}if(a.indexOf(u)!==-1){if(n)return X.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}else a.push(u);for(var P=gt(u).sort(o&&o(u)),A=[],y=0;y<P.length;y++){var p=P[y],m=f(u,p,u[p],g+1);if(m){var G=X.stringify(p)+F+m;A.push(x+r+G)}}return a.splice(a.indexOf(u),1),"{"+A.join(",")+x+"}"}}({"":e},"",e,0)}});var me=S(d=>{"use strict";var _e=d&&d.__rest||function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]]);return r};Object.defineProperty(d,"__esModule",{value:!0});d.isSchema=d.isValidSchema=d.isDiscriminatorForm=d.isValuesForm=d.isPropertiesForm=d.isElementsForm=d.isEnumForm=d.isTypeForm=d.isRefForm=d.isEmptyForm=void 0;function xt(e){let{definitions:t,nullable:r,metadata:n}=e,i=_e(e,["definitions","nullable","metadata"]);return Object.keys(i).length===0}d.isEmptyForm=xt;function Ne(e){return"ref"in e}d.isRefForm=Ne;function Et(e){return"type"in e}d.isTypeForm=Et;function $e(e){return"enum"in e}d.isEnumForm=$e;function Le(e){return"elements"in e}d.isElementsForm=Le;function ye(e){return"properties"in e||"optionalProperties"in e}d.isPropertiesForm=ye;function De(e){return"values"in e}d.isValuesForm=De;function He(e){return"discriminator"in e}d.isDiscriminatorForm=He;function I(e,t){if(t===void 0&&(t=e),e.definitions!==void 0){if(t!==e)return!1;for(let r of Object.values(e.definitions))if(!I(r,t))return!1}if(Ne(e)&&!(e.ref in(t.definitions||{}))||$e(e)&&(e.enum.length===0||e.enum.length!==new Set(e.enum).size))return!1;if(Le(e))return I(e.elements,t);if(ye(e)){for(let r of Object.values(e.properties||{}))if(!I(r,t))return!1;for(let r of Object.values(e.optionalProperties||{}))if(!I(r,t))return!1;for(let r of Object.keys(e.properties||{}))if(r in(e.optionalProperties||{}))return!1}if(De(e))return I(e.values,t);if(He(e)){for(let r of Object.values(e.mapping))if(!I(r,t)||!ye(r)||r.nullable||e.discriminator in(r.properties||{})||e.discriminator in(r.optionalProperties||{}))return!1}return!0}d.isValidSchema=I;var Pt=[[!1,!1,!1,!1,!1,!1,!1,!1,!1,!1],[!0,!1,!1,!1,!1,!1,!1,!1,!1,!1],[!1,!0,!1,!1,!1,!1,!1,!1,!1,!1],[!1,!1,!0,!1,!1,!1,!1,!1,!1,!1],[!1,!1,!1,!0,!1,!1,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!1,!1,!1,!1,!1],[!1,!1,!1,!1,!1,!0,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!0,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!1,!0,!1,!1,!1],[!1,!1,!1,!1,!1,!0,!0,!1,!1,!1],[!1,!1,!1,!1,!0,!0,!0,!1,!1,!1],[!1,!1,!1,!1,!1,!1,!1,!0,!1,!1],[!1,!1,!1,!1,!1,!1,!1,!1,!0,!0]],Tt=["boolean","float32","float64","int8","uint8","int16","uint16","int32","uint32","string","timestamp"];function _(e){if(typeof e!="object"||Array.isArray(e)||e===null)return!1;let t=e,{definitions:r=void 0,nullable:n=void 0,metadata:i=void 0,ref:o=void 0,type:a=void 0,enum:f=void 0,elements:s=void 0,properties:p=void 0,optionalProperties:u=void 0,additionalProperties:g=void 0,values:x=void 0,discriminator:F=void 0,mapping:y=void 0}=t,J=_e(t,["definitions","nullable","metadata","ref","type","enum","elements","properties","optionalProperties","additionalProperties","values","discriminator","mapping"]),P=[o!==void 0,a!==void 0,f!==void 0,s!==void 0,p!==void 0,u!==void 0,g!==void 0,x!==void 0,F!==void 0,y!==void 0],A=!1;for(let m of Pt)A=A||m.every((G,V)=>G===P[V]);if(!A)return!1;if(r!==void 0){if(typeof r!="object"||Array.isArray(r)||r===null)return!1;for(let m of Object.values(r))if(!_(m))return!1}if(n!==void 0&&typeof n!="boolean"||i!==void 0&&(typeof i!="object"||Array.isArray(i)||i===null)||o!==void 0&&typeof o!="string"||a!==void 0&&(typeof a!="string"||!Tt.includes(a))||f!==void 0&&(!Array.isArray(f)||!f.every(m=>typeof m=="string"))||s!==void 0&&!_(s))return!1;if(p!==void 0){if(typeof p!="object"||Array.isArray(p)||p===null)return!1;for(let m of Object.values(p))if(!_(m))return!1}if(u!==void 0){if(typeof u!="object"||Array.isArray(u)||u===null)return!1;for(let m of Object.values(u))if(!_(m))return!1}if(g!==void 0&&typeof g!="boolean"||x!==void 0&&!_(x)||F!==void 0&&typeof F!="string")return!1;if(y!==void 0){if(typeof y!="object"||Array.isArray(y)||y===null)return!1;for(let m of Object.values(y))if(!_(m))return!1}return Object.keys(J).length===0}d.isSchema=_});var Ue=S(he=>{"use strict";Object.defineProperty(he,"__esModule",{value:!0});var At=/^(\d{4})-(\d{2})-(\d{2})[tT](\d{2}):(\d{2}):(\d{2})(\.\d+)?([zZ]|((\+|-)(\d{2}):(\d{2})))$/;function Ot(e){let t=e.match(At);if(t===null)return!1;let r=parseInt(t[1],10),n=parseInt(t[2],10),i=parseInt(t[3],10),o=parseInt(t[4],10),a=parseInt(t[5],10),f=parseInt(t[6],10);return!(n>12||i>St(r,n)||o>23||a>59||f>60)}he.default=Ot;function St(e,t){return t===2?kt(e)?29:28:Ft[t]}function kt(e){return e%4===0&&(e%100!==0||e%400===0)}var Ft=[0,31,0,31,30,31,30,31,31,30,31,30,31]});var Je=S(C=>{"use strict";var Mt=C&&C.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(C,"__esModule",{value:!0});C.validate=C.MaxDepthExceededError=void 0;var Ct=Mt(Ue()),N=me(),te=class extends Error{};C.MaxDepthExceededError=te;var re=class extends Error{};function jt(e,t,r){let n={errors:[],instanceTokens:[],schemaTokens:[[]],root:e,config:r||{maxDepth:0,maxErrors:0}};try{D(n,e,t)}catch(i){if(!(i instanceof re))throw i}return n.errors}C.validate=jt;function D(e,t,r,n){if(!(t.nullable&&r===null)){if(N.isRefForm(t)){if(e.schemaTokens.length===e.config.maxDepth)throw new te;e.schemaTokens.push(["definitions",t.ref]),D(e,e.root.definitions[t.ref],r),e.schemaTokens.pop()}else if(N.isTypeForm(t)){switch(b(e,"type"),t.type){case"boolean":typeof r!="boolean"&&w(e);break;case"float32":case"float64":typeof r!="number"&&w(e);break;case"int8":H(e,r,-128,127);break;case"uint8":H(e,r,0,255);break;case"int16":H(e,r,-32768,32767);break;case"uint16":H(e,r,0,65535);break;case"int32":H(e,r,-2147483648,2147483647);break;case"uint32":H(e,r,0,4294967295);break;case"string":typeof r!="string"&&w(e);break;case"timestamp":typeof r!="string"?w(e):Ct.default(r)||w(e);break}v(e)}else if(N.isEnumForm(t))b(e,"enum"),(typeof r!="string"||!t.enum.includes(r))&&w(e),v(e);else if(N.isElementsForm(t)){if(b(e,"elements"),Array.isArray(r))for(let[i,o]of r.entries())$(e,i.toString()),D(e,t.elements,o),L(e);else w(e);v(e)}else if(N.isPropertiesForm(t))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){if(t.properties!==void 0){b(e,"properties");for(let[i,o]of Object.entries(t.properties))b(e,i),r.hasOwnProperty(i)?($(e,i),D(e,o,r[i]),L(e)):w(e),v(e);v(e)}if(t.optionalProperties!==void 0){b(e,"optionalProperties");for(let[i,o]of Object.entries(t.optionalProperties))b(e,i),r.hasOwnProperty(i)&&($(e,i),D(e,o,r[i]),L(e)),v(e);v(e)}if(t.additionalProperties!==!0)for(let i of Object.keys(r)){let o=t.properties&&i in t.properties,a=t.optionalProperties&&i in t.optionalProperties;!o&&!a&&i!==n&&($(e,i),w(e),L(e))}}else t.properties!==void 0?b(e,"properties"):b(e,"optionalProperties"),w(e),v(e);else if(N.isValuesForm(t)){if(b(e,"values"),typeof r=="object"&&r!==null&&!Array.isArray(r))for(let[i,o]of Object.entries(r))$(e,i),D(e,t.values,o),L(e);else w(e);v(e)}else if(N.isDiscriminatorForm(t))if(typeof r=="object"&&r!==null&&!Array.isArray(r))if(r.hasOwnProperty(t.discriminator)){let i=r[t.discriminator];typeof i=="string"?i in t.mapping?(b(e,"mapping"),b(e,i),D(e,t.mapping[i],r,t.discriminator),v(e),v(e)):(b(e,"mapping"),$(e,t.discriminator),w(e),L(e),v(e)):(b(e,"discriminator"),$(e,t.discriminator),w(e),L(e),v(e))}else b(e,"discriminator"),w(e),v(e);else b(e,"discriminator"),w(e),v(e)}}function H(e,t,r,n){(typeof t!="number"||!Number.isInteger(t)||t<r||t>n)&&w(e)}function $(e,t){e.instanceTokens.push(t)}function L(e){e.instanceTokens.pop()}function b(e,t){e.schemaTokens[e.schemaTokens.length-1].push(t)}function v(e){e.schemaTokens[e.schemaTokens.length-1].pop()}function w(e){if(e.errors.push({instancePath:[...e.instanceTokens],schemaPath:[...e.schemaTokens[e.schemaTokens.length-1]]}),e.errors.length===e.config.maxErrors)throw new re}});var qe=S(j=>{"use strict";var Bt=j&&j.__createBinding||(Object.create?function(e,t,r,n){n===void 0&&(n=r),Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,n){n===void 0&&(n=r),e[n]=t[r]}),Ve=j&&j.__exportStar||function(e,t){for(var r in e)r!=="default"&&!t.hasOwnProperty(r)&&Bt(t,e,r)};Object.defineProperty(j,"__esModule",{value:!0});Ve(me(),j);Ve(Je(),j)});var Ke=oe(Ee()),We=oe(je());var ee,bt=new Uint8Array(16);function ce(){if(!ee&&(ee=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!ee))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return ee(bt)}var h=[];for(let e=0;e<256;++e)h.push((e+256).toString(16).slice(1));function Be(e,t=0){return(h[e[t+0]]+h[e[t+1]]+h[e[t+2]]+h[e[t+3]]+"-"+h[e[t+4]]+h[e[t+5]]+"-"+h[e[t+6]]+h[e[t+7]]+"-"+h[e[t+8]]+h[e[t+9]]+"-"+h[e[t+10]]+h[e[t+11]]+h[e[t+12]]+h[e[t+13]]+h[e[t+14]]+h[e[t+15]]).toLowerCase()}var wt=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),pe={randomUUID:wt};function vt(e,t,r){if(pe.randomUUID&&!t&&!e)return pe.randomUUID();e=e||{};let n=e.random||(e.rng||ce)();if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,t){r=r||0;for(let i=0;i<16;++i)t[r+i]=n[i];return t}return Be(n)}var q=vt;function de(e){return[...new Uint8Array(e)].map(t=>t.toString(16).padStart(2,"0")).join("")}function Re(e){return new Uint8Array((e.match(/../g)??[]).map(t=>parseInt(t,16)))}function Ie(e){let t=0;for(let i of e)t+=i.length;let r=new Uint8Array(t),n=0;for(let i of e)r.set(i,n),n+=i.length;return r}var ze=oe(qe());function z(e,t){if((0,ze.validate)(e,t).length)throw new Error(`couldn't validate schema: ${JSON.stringify(t)} didn't match schema ${JSON.stringify(e)}`)}var Ge="3",Qe="https://webapp-prod.cloud.remarkable.engineering",Rt="https://internal.cloud.remarkable.com",Ye="x-goog-generation",It="x-goog-if-generation-match",_t="x-goog-content-length-range",gr=["Ballpoint","Ballpointv2","Brush","Calligraphy","ClearPage","EraseSection","Eraser","Fineliner","Finelinerv2","Highlighter","Highlighterv2","Marker","Markerv2","Paintbrush","Paintbrushv2","Pencilv2","SharpPencil","SharpPencilv2","SolidPen","ZoomTool"],br=["Maison Neue","EB Garamond","Noto Sans","Noto Serif","Noto Mono","Noto Sans UI"],Nt={xs:.7,sm:.8,md:1,lg:1.2,xl:1.5,xx:2},$t={sm:50,md:125,rr:180,lg:200},Lt={df:-1,md:100,lg:150,xl:200},Dt={properties:{docID:{type:"string"},hash:{type:"string"}}},Ht={properties:{relative_path:{type:"string"},url:{type:"string"},expires:{type:"timestamp"},method:{enum:["POST","GET","PUT","DELETE"]}},optionalProperties:{maxuploadsize_bytes:{type:"float64"}}},ne={visibleName:{type:"string"},lastModified:{type:"string"}},ie={version:{type:"int32"},pinned:{type:"boolean"},synced:{type:"boolean"},modified:{type:"boolean"},deleted:{type:"boolean"},metadatamodified:{type:"boolean"},parent:{type:"string"}},Ut={discriminator:"type",mapping:{CollectionType:{properties:ne,optionalProperties:ie},DocumentType:{properties:ne,optionalProperties:{...ie,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},Ze={id:{type:"string"},hash:{type:"string"}},Jt={discriminator:"type",mapping:{CollectionType:{properties:{...ne,...Ze},optionalProperties:ie},DocumentType:{properties:{...ne,...Ze,fileType:{enum:["notebook","epub","pdf",""]}},optionalProperties:{...ie,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},U=class extends Error{status;statusText;constructor(t,r,n){super(n),this.status=t,this.statusText=r}},ge=class extends Error{constructor(){super("Generation preconditions failed. This means the current state is out of date with the cloud and needs to be re-synced.")}};async function wr(e,{deviceDesc:t="browser-chrome",uuid:r=q(),authHost:n=Qe,fetch:i=globalThis.fetch}={}){if(e.length!==8)throw new Error(`code should be length 8, but was ${e.length}`);let o=await i(`${n}/token/json/2/device/new`,{method:"POST",headers:{Authorization:"Bearer"},body:JSON.stringify({code:e,deviceDesc:t,deviceID:r})});if(o.ok)return await o.text();throw new U(o.status,o.statusText,"couldn't register api")}function Vt({hash:e,type:t,documentId:r,subfiles:n,size:i}){return`${e}:${t}:${r}:${n}:${i}
|
|
10
|
+
`}function qt(e){let[t,r,n,i,o]=e.split(":");if(t===void 0||r===void 0||n===void 0||i===void 0||o===void 0)throw new Error(`entries line didn't contain five fields: '${e}'`);if(r==="80000000")return{hash:t,type:r,documentId:n,subfiles:parseInt(i),size:BigInt(o)};if(r==="0"){if(i!=="0")throw new Error(`file type entry had nonzero number of subfiles: ${i}`);return{hash:t,type:r,documentId:n,subfiles:0,size:BigInt(o)}}else throw new Error(`entries line contained invalid type: ${r}`)}var be=class{#u;#a;#f;#r;#n;#e=new Map;#t=null;constructor(t,r,n,i,o,a){this.#u=t,this.#a=r,this.#f=n,this.#r=i,this.#n=o;for(let[f,s]of a)this.#e.set(f,Promise.resolve(s))}async#i(t,{body:r,method:n="POST",headers:i={}}){let o=await this.#a(t,{method:n,headers:{Authorization:`Bearer ${this.#u}`,...i},body:r});if(o.ok)return o;{let a=await o.text();throw new U(o.status,o.statusText,`failed reMarkable request: ${a}`)}}async#o({url:t,method:r,maxuploadsize_bytes:n},i,o={}){let a=n?{...o,[_t]:`0,${n}`}:o,f=await this.#a(t,{method:r,body:i,headers:a});if(f.ok)return f;{let s=await f.text();throw new U(f.status,f.statusText,s)}}async#s(t,r,n){let i=r===void 0?"downloads":"uploads",o=n&&r!==null&&r!==void 0?`{ "http_method": "PUT", "relative_path": "${t}", "root_schema": "${n}", "generation": ${r} }`:JSON.stringify({http_method:"GET",relative_path:t}),f=await(await this.#i(`${this.#r}/sync/v2/signed-urls/${i}`,{body:o})).text(),s=JSON.parse(f);return z(Ht,s),s}async getRootHash({cache:t=!0}={}){if(t)for(;this.#t;)try{let[o,a]=await this.#t;return[o,a]}catch{}let r=(async()=>{try{let o=await this.#s("root"),a=await this.#o(o),f=a.headers.get(Ye);if(f)return[await a.text(),BigInt(f)];throw new Error("no generation header in root hash")}catch(o){throw this.#t=null,o}})();this.#t=r;let[n,i]=await r;return[n,i]}async putRootHash(t,r){let n=await this.#s("root",r,t),i;try{i=await this.#o(n,t,{[It]:`${r}`})}catch(f){throw f instanceof U&&f.status===412?(this.#t=null,new ge):f}let o=i.headers.get(Ye);if(!o)throw new Error("no generation header in root hash");let a=BigInt(o);return this.#t=Promise.resolve([t,a]),a}async#l(t){let r=this.#e.get(t);for(;r;)try{let i=await r;if(i)return i;r=void 0}catch{r=this.#e.get(t)}let n=(async()=>{let i=await this.#s(t);return await(await this.#o(i)).arrayBuffer()})();return this.#e.set(t,n.then(i=>i.byteLength<this.#n?i:null,i=>{throw this.#e.delete(t),i})),await n}async getBuffer(t){let r=await this.#l(t);return r.byteLength<this.#n?r.slice(0):r}async getText(t){let r=await this.#l(t);return new TextDecoder().decode(r)}async getJson(t){let r=await this.getText(t);return JSON.parse(r)}async getMetadata(t){let r=await this.getJson(t);return z(Ut,r),r}async getEntries(t){if(t===void 0){let[o]=await this.getRootHash({cache:!0});t=o}let r=await this.getText(t),[n,...i]=r.slice(0,-1).split(`
|
|
11
|
+
`);if(n!==Ge)throw new Error(`got unexpected schema version: ${n}`);return i.map(qt)}async#c(t,r){let n=this.#e.get(t);if(n)try{await n;return}catch{}let i=(async()=>{try{let o=await this.#s(t,null);return await this.#o(o,r),r.byteLength<this.#n?r:null}catch(o){throw this.#e.delete(t),o}})();this.#e.set(t,i),await i}async putEntries(t,r){let n=new TextEncoder;r.sort((u,g)=>u.documentId.localeCompare(g.documentId));let i=Ie(r.map(u=>Re(u.hash))),o=await this.#f.digest("SHA-256",i),a=de(o),f=r.map(Vt).join(""),s=`${Ge}
|
|
12
|
+
${f}`,p=n.encode(s);return await this.#c(a,p),{hash:a,type:"80000000",documentId:t,subfiles:r.length,size:0n}}async putBuffer(t,r){let n=await this.#f.digest("SHA-256",r),i=de(n);return await this.#c(i,r),{hash:i,type:"0",documentId:t,subfiles:0,size:BigInt(r.byteLength)}}async putText(t,r){let n=new TextEncoder;return await this.putBuffer(t,n.encode(r))}async putJson(t,r){return await this.putText(t,(0,We.default)(r))}async putMetadata(t,r){return await this.putJson(`${t}.metadata`,r)}async putCollection(t,r=""){let n=q(),i=`${new Date().valueOf()}`,o=[],a={type:"CollectionType",visibleName:t,version:0,parent:r,synced:!0,lastModified:i};o.push(this.putMetadata(n,a)),o.push(this.putText(`${n}.content`,"{}"));let f=await Promise.all(o);return await this.putEntries(n,f)}async#p(t,r,n,i,o){if(o.fileType!==n)throw new Error(`internal error: fileTypes don't match: ${n}, ${o.fileType}`);let a=q(),f=`${new Date().valueOf()}`,s=[];s.push(this.putBuffer(`${a}.${n}`,r));let p={type:"DocumentType",visibleName:t,version:0,parent:i,synced:!0,lastModified:f};s.push(this.putMetadata(a,p)),s.push(this.putText(`${a}.content`,JSON.stringify(o)));let u=await Promise.all(s);return await this.putEntries(a,u)}async putEpub(t,r,{parent:n="",margins:i=125,orientation:o,textAlignment:a,textScale:f=1,lineHeight:s=-1,fontName:p="",cover:u="visited",lastTool:g}={}){let x={dummyDocument:!1,extraMetadata:{LastTool:g},fileType:"epub",pageCount:0,lastOpenedPage:0,lineHeight:typeof s=="string"?Lt[s]:s,margins:typeof i=="string"?$t[i]:i,textScale:typeof f=="string"?Nt[f]:f,pages:[],coverPageNumber:u==="first"?0:-1,formatVersion:1,orientation:o,textAlignment:a,fontName:p};return await this.#p(t,r,"epub",n,x)}async putPdf(t,r,{parent:n="",orientation:i,cover:o="first",lastTool:a}={}){let f={dummyDocument:!1,extraMetadata:{LastTool:a},fileType:"pdf",pageCount:0,lastOpenedPage:0,lineHeight:-1,margins:125,textScale:1,pages:[],coverPageNumber:o==="first"?0:-1,formatVersion:1,orientation:i};return await this.#p(t,r,"pdf",n,f)}async syncComplete(t){let r=`{ "generation": ${t} }`;await this.#i(`${this.#r}/sync/v2/sync-complete`,{body:r})}async#d(t,r,n){let{hash:i}=await this.putEntries("",r),o=await this.putRootHash(i,t);if(n)try{return await this.syncComplete(o),!0}catch{return!1}else return!1}async create(t,{cache:r=!0,sync:n=!0}={}){let[i,o]=await this.getRootHash({cache:r}),a=await this.getEntries(i);return a.push(t),await this.#d(o,a,n)}async move(t,r,{cache:n=!0,sync:i=!0}={}){let[o,a]=await this.getRootHash({cache:n}),f=await this.getEntries(o);if(!(!r||r==="trash")){let P=f.find(V=>V.documentId===r);if(P){if(P.type!=="80000000")throw new Error(`destination id was a raw file: ${r}`)}else throw new Error(`destination id not found: ${r}`);let A=await this.getEntries(P.hash),[m]=A.filter(V=>V.documentId===`${r}.metadata`);if(!m)throw new Error(`destination id didn't have metadata: ${r}`);if((await this.getMetadata(m.hash)).type!=="CollectionType")throw new Error(`destination id wasn't a collection: ${r}`)}let s=f.findIndex(P=>P.documentId===t);if(s===-1)throw new Error(`document not found: ${t}`);let[p]=f.splice(s,1);if(p.type!=="80000000")throw new Error(`document was a raw file: ${t}`);let u=await this.getEntries(p.hash),g=u.findIndex(P=>P.documentId===`${t}.metadata`);if(g===-1)throw new Error(`document didn't have metadata: ${t}`);let[x]=u.splice(g,1),F=await this.getMetadata(x.hash);F.parent=r;let y=await this.putMetadata(t,F);u.push(y);let J=await this.putEntries(t,u);return f.push(J),await this.#d(a,f,i)}async getEntriesMetadata(){let r=await(await this.#i(`${this.#r}/doc/v2/files`,{method:"GET",headers:{"rm-source":"RoR-Browser"}})).text(),n=JSON.parse(r);return z({elements:Jt},n),n}async#y(t,r,n){let o=new TextEncoder().encode(JSON.stringify({file_name:t})),f=await(await this.#i(`${this.#r}/doc/v2/files`,{body:r,headers:{"content-type":n,"rm-meta":(0,Ke.fromByteArray)(o),"rm-source":"RoR-Browser"}})).text(),s=JSON.parse(f);return z(Dt,s),s}async uploadEpub(t,r){return await this.#y(t,r,"application/epub+zip")}async uploadPdf(t,r){return await this.#y(t,r,"application/pdf")}async getCache(){let t=[];for(let[i,o]of this.#e)t.push(o.then(a=>[i,a],()=>[i,null]));let r=await Promise.all(t),n=new Map;for(let[i,o]of r)o&&n.set(i,o);return n}};async function vr(e,{fetch:t=globalThis.fetch,subtle:r=globalThis.crypto?.subtle,authHost:n=Qe,syncHost:i=Rt,cacheLimitBytes:o=1048576,initCache:a=[]}={}){if(!r)throw new Error("subtle was missing, try specifying it manually");let f=await t(`${n}/token/json/2/user/new`,{method:"POST",headers:{Authorization:`Bearer ${e}`}});if(!f.ok)throw new Error(`couldn't fetch auth token: ${f.statusText}`);let s=await f.text();return new be(s,t,r,i,o,a)}export{ge as GenerationError,U as ResponseError,br as builtinFontNames,Lt as builtinLineHeights,$t as builtinMargins,Nt as builtinTextScales,gr as builtinTools,Vt as formatEntry,qt as parseEntry,wr as register,vr as remarkable};
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
var rmapi=(()=>{var We=Object.create;var W=Object.defineProperty;var Ye=Object.getOwnPropertyDescriptor;var Ze=Object.getOwnPropertyNames;var Ke=Object.getPrototypeOf,Xe=Object.prototype.hasOwnProperty;var j=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),Qe=(e,r)=>{for(var t in r)W(e,t,{get:r[t],enumerable:!0})},he=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of Ze(r))!Xe.call(e,i)&&i!==t&&W(e,i,{get:()=>r[i],enumerable:!(n=Ye(r,i))||n.enumerable});return e};var ge=(e,r,t)=>(t=e!=null?We(Ke(e)):{},he(r||!e||!e.__esModule?W(t,"default",{value:e,enumerable:!0}):t,e)),et=e=>he(W({},"__esModule",{value:!0}),e);var xe=j(Y=>{"use strict";Y.byteLength=rt;Y.toByteArray=it;Y.fromByteArray=at;var O=[],A=[],tt=typeof Uint8Array<"u"?Uint8Array:Array,se="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(F=0,be=se.length;F<be;++F)O[F]=se[F],A[se.charCodeAt(F)]=F;var F,be;A["-".charCodeAt(0)]=62;A["_".charCodeAt(0)]=63;function we(e){var r=e.length;if(r%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var t=e.indexOf("=");t===-1&&(t=r);var n=t===r?0:4-t%4;return[t,n]}function rt(e){var r=we(e),t=r[0],n=r[1];return(t+n)*3/4-n}function nt(e,r,t){return(r+t)*3/4-t}function it(e){var r,t=we(e),n=t[0],i=t[1],o=new tt(nt(e,n,i)),s=0,a=i>0?n-4:n,f;for(f=0;f<a;f+=4)r=A[e.charCodeAt(f)]<<18|A[e.charCodeAt(f+1)]<<12|A[e.charCodeAt(f+2)]<<6|A[e.charCodeAt(f+3)],o[s++]=r>>16&255,o[s++]=r>>8&255,o[s++]=r&255;return i===2&&(r=A[e.charCodeAt(f)]<<2|A[e.charCodeAt(f+1)]>>4,o[s++]=r&255),i===1&&(r=A[e.charCodeAt(f)]<<10|A[e.charCodeAt(f+1)]<<4|A[e.charCodeAt(f+2)]>>2,o[s++]=r>>8&255,o[s++]=r&255),o}function ot(e){return O[e>>18&63]+O[e>>12&63]+O[e>>6&63]+O[e&63]}function st(e,r,t){for(var n,i=[],o=r;o<t;o+=3)n=(e[o]<<16&16711680)+(e[o+1]<<8&65280)+(e[o+2]&255),i.push(ot(n));return i.join("")}function at(e){for(var r,t=e.length,n=t%3,i=[],o=16383,s=0,a=t-n;s<a;s+=o)i.push(st(e,s,s+o>a?a:s+o));return n===1?(r=e[t-1],i.push(O[r>>2]+O[r<<4&63]+"==")):n===2&&(r=(e[t-2]<<8)+e[t-1],i.push(O[r>>10]+O[r>>4&63]+O[r<<2&63]+"=")),i.join("")}});var ce=j(d=>{"use strict";var Oe=d&&d.__rest||function(e,r){var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&r.indexOf(n)<0&&(t[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(e);i<n.length;i++)r.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(t[n[i]]=e[n[i]]);return t};Object.defineProperty(d,"__esModule",{value:!0});d.isSchema=d.isValidSchema=d.isDiscriminatorForm=d.isValuesForm=d.isPropertiesForm=d.isElementsForm=d.isEnumForm=d.isTypeForm=d.isRefForm=d.isEmptyForm=void 0;function Pt(e){let{definitions:r,nullable:t,metadata:n}=e,i=Oe(e,["definitions","nullable","metadata"]);return Object.keys(i).length===0}d.isEmptyForm=Pt;function Se(e){return"ref"in e}d.isRefForm=Se;function Tt(e){return"type"in e}d.isTypeForm=Tt;function Ce(e){return"enum"in e}d.isEnumForm=Ce;function Me(e){return"elements"in e}d.isElementsForm=Me;function de(e){return"properties"in e||"optionalProperties"in e}d.isPropertiesForm=de;function Fe(e){return"values"in e}d.isValuesForm=Fe;function Ue(e){return"discriminator"in e}d.isDiscriminatorForm=Ue;function U(e,r){if(r===void 0&&(r=e),e.definitions!==void 0){if(r!==e)return!1;for(let t of Object.values(e.definitions))if(!U(t,r))return!1}if(Se(e)&&!(e.ref in(r.definitions||{}))||Ce(e)&&(e.enum.length===0||e.enum.length!==new Set(e.enum).size))return!1;if(Me(e))return U(e.elements,r);if(de(e)){for(let t of Object.values(e.properties||{}))if(!U(t,r))return!1;for(let t of Object.values(e.optionalProperties||{}))if(!U(t,r))return!1;for(let t of Object.keys(e.properties||{}))if(t in(e.optionalProperties||{}))return!1}if(Fe(e))return U(e.values,r);if(Ue(e)){for(let t of Object.values(e.mapping))if(!U(t,r)||!de(t)||t.nullable||e.discriminator in(t.properties||{})||e.discriminator in(t.optionalProperties||{}))return!1}return!0}d.isValidSchema=U;var At=[[!1,!1,!1,!1,!1,!1,!1,!1,!1,!1],[!0,!1,!1,!1,!1,!1,!1,!1,!1,!1],[!1,!0,!1,!1,!1,!1,!1,!1,!1,!1],[!1,!1,!0,!1,!1,!1,!1,!1,!1,!1],[!1,!1,!1,!0,!1,!1,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!1,!1,!1,!1,!1],[!1,!1,!1,!1,!1,!0,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!0,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!1,!0,!1,!1,!1],[!1,!1,!1,!1,!1,!0,!0,!1,!1,!1],[!1,!1,!1,!1,!0,!0,!0,!1,!1,!1],[!1,!1,!1,!1,!1,!1,!1,!0,!1,!1],[!1,!1,!1,!1,!1,!1,!1,!1,!0,!0]],kt=["boolean","float32","float64","int8","uint8","int16","uint16","int32","uint32","string","timestamp"];function I(e){if(typeof e!="object"||Array.isArray(e)||e===null)return!1;let r=e,{definitions:t=void 0,nullable:n=void 0,metadata:i=void 0,ref:o=void 0,type:s=void 0,enum:a=void 0,elements:f=void 0,properties:l=void 0,optionalProperties:u=void 0,additionalProperties:p=void 0,values:P=void 0,discriminator:c=void 0,mapping:T=void 0}=r,B=Oe(r,["definitions","nullable","metadata","ref","type","enum","elements","properties","optionalProperties","additionalProperties","values","discriminator","mapping"]),ie=[o!==void 0,s!==void 0,a!==void 0,f!==void 0,l!==void 0,u!==void 0,p!==void 0,P!==void 0,c!==void 0,T!==void 0],k=!1;for(let v of At)k=k||v.every((z,ye)=>z===ie[ye]);if(!k)return!1;if(t!==void 0){if(typeof t!="object"||Array.isArray(t)||t===null)return!1;for(let v of Object.values(t))if(!I(v))return!1}if(n!==void 0&&typeof n!="boolean"||i!==void 0&&(typeof i!="object"||Array.isArray(i)||i===null)||o!==void 0&&typeof o!="string"||s!==void 0&&(typeof s!="string"||!kt.includes(s))||a!==void 0&&(!Array.isArray(a)||!a.every(v=>typeof v=="string"))||f!==void 0&&!I(f))return!1;if(l!==void 0){if(typeof l!="object"||Array.isArray(l)||l===null)return!1;for(let v of Object.values(l))if(!I(v))return!1}if(u!==void 0){if(typeof u!="object"||Array.isArray(u)||u===null)return!1;for(let v of Object.values(u))if(!I(v))return!1}if(p!==void 0&&typeof p!="boolean"||P!==void 0&&!I(P)||c!==void 0&&typeof c!="string")return!1;if(T!==void 0){if(typeof T!="object"||Array.isArray(T)||T===null)return!1;for(let v of Object.values(T))if(!I(v))return!1}return Object.keys(B).length===0}d.isSchema=I});var Ie=j(pe=>{"use strict";Object.defineProperty(pe,"__esModule",{value:!0});var Ot=/^(\d{4})-(\d{2})-(\d{2})[tT](\d{2}):(\d{2}):(\d{2})(\.\d+)?([zZ]|((\+|-)(\d{2}):(\d{2})))$/;function St(e){let r=e.match(Ot);if(r===null)return!1;let t=parseInt(r[1],10),n=parseInt(r[2],10),i=parseInt(r[3],10),o=parseInt(r[4],10),s=parseInt(r[5],10),a=parseInt(r[6],10);return!(n>12||i>Ct(t,n)||o>23||s>59||a>60)}pe.default=St;function Ct(e,r){return r===2?Mt(e)?29:28:Ft[r]}function Mt(e){return e%4===0&&(e%100!==0||e%400===0)}var Ft=[0,31,0,31,30,31,30,31,31,30,31,30,31]});var Re=j(C=>{"use strict";var Ut=C&&C.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(C,"__esModule",{value:!0});C.validate=C.MaxDepthExceededError=void 0;var It=Ut(Ie()),R=ce(),Q=class extends Error{};C.MaxDepthExceededError=Q;var ee=class extends Error{};function Rt(e,r,t){let n={errors:[],instanceTokens:[],schemaTokens:[[]],root:e,config:t||{maxDepth:0,maxErrors:0}};try{L(n,e,r)}catch(i){if(!(i instanceof ee))throw i}return n.errors}C.validate=Rt;function L(e,r,t,n){if(!(r.nullable&&t===null)){if(R.isRefForm(r)){if(e.schemaTokens.length===e.config.maxDepth)throw new Q;e.schemaTokens.push(["definitions",r.ref]),L(e,e.root.definitions[r.ref],t),e.schemaTokens.pop()}else if(R.isTypeForm(r)){switch(w(e,"type"),r.type){case"boolean":typeof t!="boolean"&&x(e);break;case"float32":case"float64":typeof t!="number"&&x(e);break;case"int8":N(e,t,-128,127);break;case"uint8":N(e,t,0,255);break;case"int16":N(e,t,-32768,32767);break;case"uint16":N(e,t,0,65535);break;case"int32":N(e,t,-2147483648,2147483647);break;case"uint32":N(e,t,0,4294967295);break;case"string":typeof t!="string"&&x(e);break;case"timestamp":typeof t!="string"?x(e):It.default(t)||x(e);break}E(e)}else if(R.isEnumForm(r))w(e,"enum"),(typeof t!="string"||!r.enum.includes(t))&&x(e),E(e);else if(R.isElementsForm(r)){if(w(e,"elements"),Array.isArray(t))for(let[i,o]of t.entries())_(e,i.toString()),L(e,r.elements,o),$(e);else x(e);E(e)}else if(R.isPropertiesForm(r))if(typeof t=="object"&&t!==null&&!Array.isArray(t)){if(r.properties!==void 0){w(e,"properties");for(let[i,o]of Object.entries(r.properties))w(e,i),t.hasOwnProperty(i)?(_(e,i),L(e,o,t[i]),$(e)):x(e),E(e);E(e)}if(r.optionalProperties!==void 0){w(e,"optionalProperties");for(let[i,o]of Object.entries(r.optionalProperties))w(e,i),t.hasOwnProperty(i)&&(_(e,i),L(e,o,t[i]),$(e)),E(e);E(e)}if(r.additionalProperties!==!0)for(let i of Object.keys(t)){let o=r.properties&&i in r.properties,s=r.optionalProperties&&i in r.optionalProperties;!o&&!s&&i!==n&&(_(e,i),x(e),$(e))}}else r.properties!==void 0?w(e,"properties"):w(e,"optionalProperties"),x(e),E(e);else if(R.isValuesForm(r)){if(w(e,"values"),typeof t=="object"&&t!==null&&!Array.isArray(t))for(let[i,o]of Object.entries(t))_(e,i),L(e,r.values,o),$(e);else x(e);E(e)}else if(R.isDiscriminatorForm(r))if(typeof t=="object"&&t!==null&&!Array.isArray(t))if(t.hasOwnProperty(r.discriminator)){let i=t[r.discriminator];typeof i=="string"?i in r.mapping?(w(e,"mapping"),w(e,i),L(e,r.mapping[i],t,r.discriminator),E(e),E(e)):(w(e,"mapping"),_(e,r.discriminator),x(e),$(e),E(e)):(w(e,"discriminator"),_(e,r.discriminator),x(e),$(e),E(e))}else w(e,"discriminator"),x(e),E(e);else w(e,"discriminator"),x(e),E(e)}}function N(e,r,t,n){(typeof r!="number"||!Number.isInteger(r)||r<t||r>n)&&x(e)}function _(e,r){e.instanceTokens.push(r)}function $(e){e.instanceTokens.pop()}function w(e,r){e.schemaTokens[e.schemaTokens.length-1].push(r)}function E(e){e.schemaTokens[e.schemaTokens.length-1].pop()}function x(e){if(e.errors.push({instancePath:[...e.instanceTokens],schemaPath:[...e.schemaTokens[e.schemaTokens.length-1]]}),e.errors.length===e.config.maxErrors)throw new ee}});var $e=j(M=>{"use strict";var _t=M&&M.__createBinding||(Object.create?function(e,r,t,n){n===void 0&&(n=t),Object.defineProperty(e,n,{enumerable:!0,get:function(){return r[t]}})}:function(e,r,t,n){n===void 0&&(n=t),e[n]=r[t]}),_e=M&&M.__exportStar||function(e,r){for(var t in e)t!=="default"&&!r.hasOwnProperty(t)&&_t(r,e,t)};Object.defineProperty(M,"__esModule",{value:!0});_e(ce(),M);_e(Re(),M)});var zt={};Qe(zt,{GenerationError:()=>ne,ResponseError:()=>D,builtinFontNames:()=>Bt,builtinLineHeights:()=>qe,builtinMargins:()=>Ve,builtinTextScales:()=>Je,builtinTools:()=>Nt,formatEntry:()=>Ge,parseEntry:()=>ze,register:()=>qt,remarkable:()=>Gt});var je=ge(xe());var Z,ft=new Uint8Array(16);function K(){if(!Z&&(Z=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Z))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Z(ft)}var Ee=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function lt(e){return typeof e=="string"&&Ee.test(e)}var H=lt;var m=[];for(let e=0;e<256;++e)m.push((e+256).toString(16).slice(1));function J(e,r=0){return(m[e[r+0]]+m[e[r+1]]+m[e[r+2]]+m[e[r+3]]+"-"+m[e[r+4]]+m[e[r+5]]+"-"+m[e[r+6]]+m[e[r+7]]+"-"+m[e[r+8]]+m[e[r+9]]+"-"+m[e[r+10]]+m[e[r+11]]+m[e[r+12]]+m[e[r+13]]+m[e[r+14]]+m[e[r+15]]).toLowerCase()}function ut(e){if(!H(e))throw TypeError("Invalid UUID");let r,t=new Uint8Array(16);return t[0]=(r=parseInt(e.slice(0,8),16))>>>24,t[1]=r>>>16&255,t[2]=r>>>8&255,t[3]=r&255,t[4]=(r=parseInt(e.slice(9,13),16))>>>8,t[5]=r&255,t[6]=(r=parseInt(e.slice(14,18),16))>>>8,t[7]=r&255,t[8]=(r=parseInt(e.slice(19,23),16))>>>8,t[9]=r&255,t[10]=(r=parseInt(e.slice(24,36),16))/1099511627776&255,t[11]=r/4294967296&255,t[12]=r>>>24&255,t[13]=r>>>16&255,t[14]=r>>>8&255,t[15]=r&255,t}var ae=ut;function dt(e){e=unescape(encodeURIComponent(e));let r=[];for(let t=0;t<e.length;++t)r.push(e.charCodeAt(t));return r}var ct="6ba7b810-9dad-11d1-80b4-00c04fd430c8",pt="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function V(e,r,t){function n(i,o,s,a){var f;if(typeof i=="string"&&(i=dt(i)),typeof o=="string"&&(o=ae(o)),((f=o)===null||f===void 0?void 0:f.length)!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let l=new Uint8Array(16+i.length);if(l.set(o),l.set(i,o.length),l=t(l),l[6]=l[6]&15|r,l[8]=l[8]&63|128,s){a=a||0;for(let u=0;u<16;++u)s[a+u]=l[u];return s}return J(l)}try{n.name=e}catch{}return n.DNS=ct,n.URL=pt,n}function mt(e){if(typeof e=="string"){let r=unescape(encodeURIComponent(e));e=new Uint8Array(r.length);for(let t=0;t<r.length;++t)e[t]=r.charCodeAt(t)}return yt(ht(gt(e),e.length*8))}function yt(e){let r=[],t=e.length*32,n="0123456789abcdef";for(let i=0;i<t;i+=8){let o=e[i>>5]>>>i%32&255,s=parseInt(n.charAt(o>>>4&15)+n.charAt(o&15),16);r.push(s)}return r}function ve(e){return(e+64>>>9<<4)+14+1}function ht(e,r){e[r>>5]|=128<<r%32,e[ve(r)-1]=r;let t=1732584193,n=-271733879,i=-1732584194,o=271733878;for(let s=0;s<e.length;s+=16){let a=t,f=n,l=i,u=o;t=y(t,n,i,o,e[s],7,-680876936),o=y(o,t,n,i,e[s+1],12,-389564586),i=y(i,o,t,n,e[s+2],17,606105819),n=y(n,i,o,t,e[s+3],22,-1044525330),t=y(t,n,i,o,e[s+4],7,-176418897),o=y(o,t,n,i,e[s+5],12,1200080426),i=y(i,o,t,n,e[s+6],17,-1473231341),n=y(n,i,o,t,e[s+7],22,-45705983),t=y(t,n,i,o,e[s+8],7,1770035416),o=y(o,t,n,i,e[s+9],12,-1958414417),i=y(i,o,t,n,e[s+10],17,-42063),n=y(n,i,o,t,e[s+11],22,-1990404162),t=y(t,n,i,o,e[s+12],7,1804603682),o=y(o,t,n,i,e[s+13],12,-40341101),i=y(i,o,t,n,e[s+14],17,-1502002290),n=y(n,i,o,t,e[s+15],22,1236535329),t=h(t,n,i,o,e[s+1],5,-165796510),o=h(o,t,n,i,e[s+6],9,-1069501632),i=h(i,o,t,n,e[s+11],14,643717713),n=h(n,i,o,t,e[s],20,-373897302),t=h(t,n,i,o,e[s+5],5,-701558691),o=h(o,t,n,i,e[s+10],9,38016083),i=h(i,o,t,n,e[s+15],14,-660478335),n=h(n,i,o,t,e[s+4],20,-405537848),t=h(t,n,i,o,e[s+9],5,568446438),o=h(o,t,n,i,e[s+14],9,-1019803690),i=h(i,o,t,n,e[s+3],14,-187363961),n=h(n,i,o,t,e[s+8],20,1163531501),t=h(t,n,i,o,e[s+13],5,-1444681467),o=h(o,t,n,i,e[s+2],9,-51403784),i=h(i,o,t,n,e[s+7],14,1735328473),n=h(n,i,o,t,e[s+12],20,-1926607734),t=g(t,n,i,o,e[s+5],4,-378558),o=g(o,t,n,i,e[s+8],11,-2022574463),i=g(i,o,t,n,e[s+11],16,1839030562),n=g(n,i,o,t,e[s+14],23,-35309556),t=g(t,n,i,o,e[s+1],4,-1530992060),o=g(o,t,n,i,e[s+4],11,1272893353),i=g(i,o,t,n,e[s+7],16,-155497632),n=g(n,i,o,t,e[s+10],23,-1094730640),t=g(t,n,i,o,e[s+13],4,681279174),o=g(o,t,n,i,e[s],11,-358537222),i=g(i,o,t,n,e[s+3],16,-722521979),n=g(n,i,o,t,e[s+6],23,76029189),t=g(t,n,i,o,e[s+9],4,-640364487),o=g(o,t,n,i,e[s+12],11,-421815835),i=g(i,o,t,n,e[s+15],16,530742520),n=g(n,i,o,t,e[s+2],23,-995338651),t=b(t,n,i,o,e[s],6,-198630844),o=b(o,t,n,i,e[s+7],10,1126891415),i=b(i,o,t,n,e[s+14],15,-1416354905),n=b(n,i,o,t,e[s+5],21,-57434055),t=b(t,n,i,o,e[s+12],6,1700485571),o=b(o,t,n,i,e[s+3],10,-1894986606),i=b(i,o,t,n,e[s+10],15,-1051523),n=b(n,i,o,t,e[s+1],21,-2054922799),t=b(t,n,i,o,e[s+8],6,1873313359),o=b(o,t,n,i,e[s+15],10,-30611744),i=b(i,o,t,n,e[s+6],15,-1560198380),n=b(n,i,o,t,e[s+13],21,1309151649),t=b(t,n,i,o,e[s+4],6,-145523070),o=b(o,t,n,i,e[s+11],10,-1120210379),i=b(i,o,t,n,e[s+2],15,718787259),n=b(n,i,o,t,e[s+9],21,-343485551),t=S(t,a),n=S(n,f),i=S(i,l),o=S(o,u)}return[t,n,i,o]}function gt(e){if(e.length===0)return[];let r=e.length*8,t=new Uint32Array(ve(r));for(let n=0;n<r;n+=8)t[n>>5]|=(e[n/8]&255)<<n%32;return t}function S(e,r){let t=(e&65535)+(r&65535);return(e>>16)+(r>>16)+(t>>16)<<16|t&65535}function bt(e,r){return e<<r|e>>>32-r}function X(e,r,t,n,i,o){return S(bt(S(S(r,e),S(n,o)),i),t)}function y(e,r,t,n,i,o,s){return X(r&t|~r&n,e,r,i,o,s)}function h(e,r,t,n,i,o,s){return X(r&n|t&~n,e,r,i,o,s)}function g(e,r,t,n,i,o,s){return X(r^t^n,e,r,i,o,s)}function b(e,r,t,n,i,o,s){return X(t^(r|~n),e,r,i,o,s)}var Pe=mt;var pr=V("v3",48,Pe);var wt=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),fe={randomUUID:wt};function xt(e,r,t){if(fe.randomUUID&&!r&&!e)return fe.randomUUID();e=e||{};let n=e.random||(e.rng||K)();if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,r){t=t||0;for(let i=0;i<16;++i)r[t+i]=n[i];return r}return J(n)}var q=xt;function Et(e,r,t,n){switch(e){case 0:return r&t^~r&n;case 1:return r^t^n;case 2:return r&t^r&n^t&n;case 3:return r^t^n}}function le(e,r){return e<<r|e>>>32-r}function vt(e){let r=[1518500249,1859775393,2400959708,3395469782],t=[1732584193,4023233417,2562383102,271733878,3285377520];if(typeof e=="string"){let s=unescape(encodeURIComponent(e));e=[];for(let a=0;a<s.length;++a)e.push(s.charCodeAt(a))}else Array.isArray(e)||(e=Array.prototype.slice.call(e));e.push(128);let n=e.length/4+2,i=Math.ceil(n/16),o=new Array(i);for(let s=0;s<i;++s){let a=new Uint32Array(16);for(let f=0;f<16;++f)a[f]=e[s*64+f*4]<<24|e[s*64+f*4+1]<<16|e[s*64+f*4+2]<<8|e[s*64+f*4+3];o[s]=a}o[i-1][14]=(e.length-1)*8/Math.pow(2,32),o[i-1][14]=Math.floor(o[i-1][14]),o[i-1][15]=(e.length-1)*8&4294967295;for(let s=0;s<i;++s){let a=new Uint32Array(80);for(let c=0;c<16;++c)a[c]=o[s][c];for(let c=16;c<80;++c)a[c]=le(a[c-3]^a[c-8]^a[c-14]^a[c-16],1);let f=t[0],l=t[1],u=t[2],p=t[3],P=t[4];for(let c=0;c<80;++c){let T=Math.floor(c/20),B=le(f,5)+Et(T,l,u,p)+P+r[T]+a[c]>>>0;P=p,p=u,u=le(l,30)>>>0,l=f,f=B}t[0]=t[0]+f>>>0,t[1]=t[1]+l>>>0,t[2]=t[2]+u>>>0,t[3]=t[3]+p>>>0,t[4]=t[4]+P>>>0}return[t[0]>>24&255,t[0]>>16&255,t[0]>>8&255,t[0]&255,t[1]>>24&255,t[1]>>16&255,t[1]>>8&255,t[1]&255,t[2]>>24&255,t[2]>>16&255,t[2]>>8&255,t[2]&255,t[3]>>24&255,t[3]>>16&255,t[3]>>8&255,t[3]&255,t[4]>>24&255,t[4]>>16&255,t[4]>>8&255,t[4]&255]}var Te=vt;var Pr=V("v5",80,Te);function ue(e){return[...new Uint8Array(e)].map(r=>r.toString(16).padStart(2,"0")).join("")}function Ae(e){return new Uint8Array((e.match(/../g)??[]).map(r=>parseInt(r,16)))}function ke(e){let r=0;for(let i of e)r+=i.length;let t=new Uint8Array(r),n=0;for(let i of e)t.set(i,n),n+=i.length;return t}var Le=ge($e());function G(e,r){if((0,Le.validate)(e,r).length)throw new Error(`couldn't validate schema: ${JSON.stringify(r)} didn't match schema ${JSON.stringify(e)}`)}var De="3",He="https://webapp-prod.cloud.remarkable.engineering",$t="https://internal.cloud.remarkable.com",Ne="x-goog-generation",Lt="x-goog-if-generation-match",Dt="x-goog-content-length-range",Nt=["Ballpoint","Ballpointv2","Brush","Calligraphy","ClearPage","EraseSection","Eraser","Fineliner","Finelinerv2","Highlighter","Highlighterv2","Marker","Markerv2","Paintbrush","Paintbrushv2","Pencilv2","SharpPencil","SharpPencilv2","SolidPen","ZoomTool"],Bt=["Maison Neue","EB Garamond","Noto Sans","Noto Serif","Noto Mono","Noto Sans UI"],Je={xs:.7,sm:.8,md:1,lg:1.2,xl:1.5,xx:2},Ve={sm:50,md:125,rr:180,lg:200},qe={df:-1,md:100,lg:150,xl:200},jt={properties:{docID:{type:"string"},hash:{type:"string"}}},Ht={properties:{relative_path:{type:"string"},url:{type:"string"},expires:{type:"timestamp"},method:{enum:["POST","GET","PUT","DELETE"]}},optionalProperties:{maxuploadsize_bytes:{type:"float64"}}},te={visibleName:{type:"string"},lastModified:{type:"string"}},re={version:{type:"int32"},pinned:{type:"boolean"},synced:{type:"boolean"},modified:{type:"boolean"},deleted:{type:"boolean"},metadatamodified:{type:"boolean"},parent:{type:"string"}},Jt={discriminator:"type",mapping:{CollectionType:{properties:te,optionalProperties:re},DocumentType:{properties:te,optionalProperties:{...re,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},Be={id:{type:"string"},hash:{type:"string"}},Vt={discriminator:"type",mapping:{CollectionType:{properties:{...te,...Be},optionalProperties:re},DocumentType:{properties:{...te,...Be,fileType:{enum:["notebook","epub","pdf",""]}},optionalProperties:{...re,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},D=class extends Error{constructor(t,n,i){super(i);this.status=t,this.statusText=n}},ne=class extends Error{constructor(){super("Generation preconditions failed. This means the current state is out of date with the cloud and needs to be re-synced.")}};async function qt(e,{deviceDesc:r="browser-chrome",uuid:t=q(),authHost:n=He,fetch:i=globalThis.fetch}={}){if(e.length!==8)throw new Error(`code should be length 8, but was ${e.length}`);let o=await i(`${n}/token/json/2/device/new`,{method:"POST",headers:{Authorization:"Bearer"},body:JSON.stringify({code:e,deviceDesc:r,deviceID:t})});if(o.ok)return await o.text();throw new D(o.status,o.statusText,"couldn't register api")}function Ge({hash:e,type:r,documentId:t,subfiles:n,size:i}){return`${e}:${r}:${t}:${n}:${i}
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";(()=>{var Xe=Object.create;var we=Object.defineProperty;var et=Object.getOwnPropertyDescriptor;var tt=Object.getOwnPropertyNames;var rt=Object.getPrototypeOf,nt=Object.prototype.hasOwnProperty;var S=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var it=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of tt(t))!nt.call(e,i)&&i!==r&&we(e,i,{get:()=>t[i],enumerable:!(n=et(t,i))||n.enumerable});return e};var oe=(e,t,r)=>(r=e!=null?Xe(rt(e)):{},it(t||!e||!e.__esModule?we(r,"default",{value:e,enumerable:!0}):r,e));var Ee=S(Y=>{"use strict";Y.byteLength=st;Y.toByteArray=ft;Y.fromByteArray=ct;var O=[],T=[],ot=typeof Uint8Array<"u"?Uint8Array:Array,se="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(B=0,ve=se.length;B<ve;++B)O[B]=se[B],T[se.charCodeAt(B)]=B;var B,ve;T["-".charCodeAt(0)]=62;T["_".charCodeAt(0)]=63;function xe(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");r===-1&&(r=t);var n=r===t?0:4-r%4;return[r,n]}function st(e){var t=xe(e),r=t[0],n=t[1];return(r+n)*3/4-n}function at(e,t,r){return(t+r)*3/4-r}function ft(e){var t,r=xe(e),n=r[0],i=r[1],o=new ot(at(e,n,i)),a=0,f=i>0?n-4:n,s;for(s=0;s<f;s+=4)t=T[e.charCodeAt(s)]<<18|T[e.charCodeAt(s+1)]<<12|T[e.charCodeAt(s+2)]<<6|T[e.charCodeAt(s+3)],o[a++]=t>>16&255,o[a++]=t>>8&255,o[a++]=t&255;return i===2&&(t=T[e.charCodeAt(s)]<<2|T[e.charCodeAt(s+1)]>>4,o[a++]=t&255),i===1&&(t=T[e.charCodeAt(s)]<<10|T[e.charCodeAt(s+1)]<<4|T[e.charCodeAt(s+2)]>>2,o[a++]=t>>8&255,o[a++]=t&255),o}function ut(e){return O[e>>18&63]+O[e>>12&63]+O[e>>6&63]+O[e&63]}function lt(e,t,r){for(var n,i=[],o=t;o<r;o+=3)n=(e[o]<<16&16711680)+(e[o+1]<<8&65280)+(e[o+2]&255),i.push(ut(n));return i.join("")}function ct(e){for(var t,r=e.length,n=r%3,i=[],o=16383,a=0,f=r-n;a<f;a+=o)i.push(lt(e,a,a+o>f?f:a+o));return n===1?(t=e[r-1],i.push(O[t>>2]+O[t<<4&63]+"==")):n===2&&(t=(e[r-2]<<8)+e[r-1],i.push(O[t>>10]+O[t>>4&63]+O[t<<2&63]+"=")),i.join("")}});var Se=S((Yt,Oe)=>{"use strict";var Z,l,Pe={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:`
|
|
2
|
+
`,r:"\r",t:" "},ae;function M(e){throw{name:"SyntaxError",message:e,at:Z,text:ae}}function c(e){return e&&e!==l&&M("Expected '"+e+"' instead of '"+l+"'"),l=ae.charAt(Z),Z+=1,l}function Te(){var e,t="";for(l==="-"&&(t="-",c("-"));l>="0"&&l<="9";)t+=l,c();if(l===".")for(t+=".";c()&&l>="0"&&l<="9";)t+=l;if(l==="e"||l==="E")for(t+=l,c(),(l==="-"||l==="+")&&(t+=l,c());l>="0"&&l<="9";)t+=l,c();return e=Number(t),isFinite(e)||M("Bad number"),e}function Ae(){var e,t,r="",n;if(l==='"')for(;c();){if(l==='"')return c(),r;if(l==="\\")if(c(),l==="u"){for(n=0,t=0;t<4&&(e=parseInt(c(),16),!!isFinite(e));t+=1)n=n*16+e;r+=String.fromCharCode(n)}else if(typeof Pe[l]=="string")r+=Pe[l];else break;else r+=l}M("Bad string")}function k(){for(;l&&l<=" ";)c()}function pt(){switch(l){case"t":return c("t"),c("r"),c("u"),c("e"),!0;case"f":return c("f"),c("a"),c("l"),c("s"),c("e"),!1;case"n":return c("n"),c("u"),c("l"),c("l"),null;default:M("Unexpected '"+l+"'")}}function dt(){var e=[];if(l==="["){if(c("["),k(),l==="]")return c("]"),e;for(;l;){if(e.push(K()),k(),l==="]")return c("]"),e;c(","),k()}}M("Bad array")}function yt(){var e,t={};if(l==="{"){if(c("{"),k(),l==="}")return c("}"),t;for(;l;){if(e=Ae(),k(),c(":"),Object.prototype.hasOwnProperty.call(t,e)&&M('Duplicate key "'+e+'"'),t[e]=K(),k(),l==="}")return c("}"),t;c(","),k()}}M("Bad object")}function K(){switch(k(),l){case"{":return yt();case"[":return dt();case'"':return Ae();case"-":return Te();default:return l>="0"&&l<="9"?Te():pt()}}Oe.exports=function(e,t){var r;return ae=e,Z=0,l=" ",r=K(),k(),l&&M("Syntax error"),typeof t=="function"?function n(i,o){var a,f,s=i[o];if(s&&typeof s=="object")for(a in K)Object.prototype.hasOwnProperty.call(s,a)&&(f=n(s,a),typeof f>"u"?delete s[a]:s[a]=f);return t.call(i,o,s)}({"":r},""):r}});var Fe=S((Zt,ke)=>{"use strict";var fe=/[\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,E,W,mt={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},R;function ue(e){return fe.lastIndex=0,fe.test(e)?'"'+e.replace(fe,function(t){var r=mt[t];return typeof r=="string"?r:"\\u"+("0000"+t.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+e+'"'}function Q(e,t){var r,n,i,o,a=E,f,s=t[e];switch(s&&typeof s=="object"&&typeof s.toJSON=="function"&&(s=s.toJSON(e)),typeof R=="function"&&(s=R.call(t,e,s)),typeof s){case"string":return ue(s);case"number":return isFinite(s)?String(s):"null";case"boolean":case"null":return String(s);case"object":if(!s)return"null";if(E+=W,f=[],Object.prototype.toString.apply(s)==="[object Array]"){for(o=s.length,r=0;r<o;r+=1)f[r]=Q(r,s)||"null";return i=f.length===0?"[]":E?`[
|
|
3
|
+
`+E+f.join(`,
|
|
4
|
+
`+E)+`
|
|
5
|
+
`+a+"]":"["+f.join(",")+"]",E=a,i}if(R&&typeof R=="object")for(o=R.length,r=0;r<o;r+=1)n=R[r],typeof n=="string"&&(i=Q(n,s),i&&f.push(ue(n)+(E?": ":":")+i));else for(n in s)Object.prototype.hasOwnProperty.call(s,n)&&(i=Q(n,s),i&&f.push(ue(n)+(E?": ":":")+i));return i=f.length===0?"{}":E?`{
|
|
6
|
+
`+E+f.join(`,
|
|
7
|
+
`+E)+`
|
|
8
|
+
`+a+"}":"{"+f.join(",")+"}",E=a,i;default:}}ke.exports=function(e,t,r){var n;if(E="",W="",typeof r=="number")for(n=0;n<r;n+=1)W+=" ";else typeof r=="string"&&(W=r);if(R=t,t&&typeof t!="function"&&(typeof t!="object"||typeof t.length!="number"))throw new Error("JSON.stringify");return Q("",{"":e})}});var Me=S(le=>{"use strict";le.parse=Se();le.stringify=Fe()});var je=S((Wt,Ce)=>{"use strict";var X=typeof JSON<"u"?JSON:Me(),ht=Array.isArray||function(e){return{}.toString.call(e)==="[object Array]"},gt=Object.keys||function(e){var t=Object.prototype.hasOwnProperty||function(){return!0},r=[];for(var n in e)t.call(e,n)&&r.push(n);return r};Ce.exports=function(e,t){t||(t={}),typeof t=="function"&&(t={cmp:t});var r=t.space||"";typeof r=="number"&&(r=Array(r+1).join(" "));var n=typeof t.cycles=="boolean"?t.cycles:!1,i=t.replacer||function(f,s){return s},o=t.cmp&&function(f){return function(s){return function(p,u){var g={key:p,value:s[p]},x={key:u,value:s[u]};return f(g,x)}}}(t.cmp),a=[];return function f(s,p,u,g){var x=r?`
|
|
9
|
+
`+new Array(g+1).join(r):"",F=r?": ":":";if(u&&u.toJSON&&typeof u.toJSON=="function"&&(u=u.toJSON()),u=i.call(s,p,u),u!==void 0){if(typeof u!="object"||u===null)return X.stringify(u);if(ht(u)){for(var A=[],y=0;y<u.length;y++){var J=f(u,y,u[y],g+1)||X.stringify(null);A.push(x+r+J)}return"["+A.join(",")+x+"]"}if(a.indexOf(u)!==-1){if(n)return X.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}else a.push(u);for(var P=gt(u).sort(o&&o(u)),A=[],y=0;y<P.length;y++){var p=P[y],m=f(u,p,u[p],g+1);if(m){var G=X.stringify(p)+F+m;A.push(x+r+G)}}return a.splice(a.indexOf(u),1),"{"+A.join(",")+x+"}"}}({"":e},"",e,0)}});var me=S(d=>{"use strict";var _e=d&&d.__rest||function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]]);return r};Object.defineProperty(d,"__esModule",{value:!0});d.isSchema=d.isValidSchema=d.isDiscriminatorForm=d.isValuesForm=d.isPropertiesForm=d.isElementsForm=d.isEnumForm=d.isTypeForm=d.isRefForm=d.isEmptyForm=void 0;function xt(e){let{definitions:t,nullable:r,metadata:n}=e,i=_e(e,["definitions","nullable","metadata"]);return Object.keys(i).length===0}d.isEmptyForm=xt;function Ne(e){return"ref"in e}d.isRefForm=Ne;function Et(e){return"type"in e}d.isTypeForm=Et;function $e(e){return"enum"in e}d.isEnumForm=$e;function Le(e){return"elements"in e}d.isElementsForm=Le;function ye(e){return"properties"in e||"optionalProperties"in e}d.isPropertiesForm=ye;function De(e){return"values"in e}d.isValuesForm=De;function He(e){return"discriminator"in e}d.isDiscriminatorForm=He;function I(e,t){if(t===void 0&&(t=e),e.definitions!==void 0){if(t!==e)return!1;for(let r of Object.values(e.definitions))if(!I(r,t))return!1}if(Ne(e)&&!(e.ref in(t.definitions||{}))||$e(e)&&(e.enum.length===0||e.enum.length!==new Set(e.enum).size))return!1;if(Le(e))return I(e.elements,t);if(ye(e)){for(let r of Object.values(e.properties||{}))if(!I(r,t))return!1;for(let r of Object.values(e.optionalProperties||{}))if(!I(r,t))return!1;for(let r of Object.keys(e.properties||{}))if(r in(e.optionalProperties||{}))return!1}if(De(e))return I(e.values,t);if(He(e)){for(let r of Object.values(e.mapping))if(!I(r,t)||!ye(r)||r.nullable||e.discriminator in(r.properties||{})||e.discriminator in(r.optionalProperties||{}))return!1}return!0}d.isValidSchema=I;var Pt=[[!1,!1,!1,!1,!1,!1,!1,!1,!1,!1],[!0,!1,!1,!1,!1,!1,!1,!1,!1,!1],[!1,!0,!1,!1,!1,!1,!1,!1,!1,!1],[!1,!1,!0,!1,!1,!1,!1,!1,!1,!1],[!1,!1,!1,!0,!1,!1,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!1,!1,!1,!1,!1],[!1,!1,!1,!1,!1,!0,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!0,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!1,!0,!1,!1,!1],[!1,!1,!1,!1,!1,!0,!0,!1,!1,!1],[!1,!1,!1,!1,!0,!0,!0,!1,!1,!1],[!1,!1,!1,!1,!1,!1,!1,!0,!1,!1],[!1,!1,!1,!1,!1,!1,!1,!1,!0,!0]],Tt=["boolean","float32","float64","int8","uint8","int16","uint16","int32","uint32","string","timestamp"];function _(e){if(typeof e!="object"||Array.isArray(e)||e===null)return!1;let t=e,{definitions:r=void 0,nullable:n=void 0,metadata:i=void 0,ref:o=void 0,type:a=void 0,enum:f=void 0,elements:s=void 0,properties:p=void 0,optionalProperties:u=void 0,additionalProperties:g=void 0,values:x=void 0,discriminator:F=void 0,mapping:y=void 0}=t,J=_e(t,["definitions","nullable","metadata","ref","type","enum","elements","properties","optionalProperties","additionalProperties","values","discriminator","mapping"]),P=[o!==void 0,a!==void 0,f!==void 0,s!==void 0,p!==void 0,u!==void 0,g!==void 0,x!==void 0,F!==void 0,y!==void 0],A=!1;for(let m of Pt)A=A||m.every((G,V)=>G===P[V]);if(!A)return!1;if(r!==void 0){if(typeof r!="object"||Array.isArray(r)||r===null)return!1;for(let m of Object.values(r))if(!_(m))return!1}if(n!==void 0&&typeof n!="boolean"||i!==void 0&&(typeof i!="object"||Array.isArray(i)||i===null)||o!==void 0&&typeof o!="string"||a!==void 0&&(typeof a!="string"||!Tt.includes(a))||f!==void 0&&(!Array.isArray(f)||!f.every(m=>typeof m=="string"))||s!==void 0&&!_(s))return!1;if(p!==void 0){if(typeof p!="object"||Array.isArray(p)||p===null)return!1;for(let m of Object.values(p))if(!_(m))return!1}if(u!==void 0){if(typeof u!="object"||Array.isArray(u)||u===null)return!1;for(let m of Object.values(u))if(!_(m))return!1}if(g!==void 0&&typeof g!="boolean"||x!==void 0&&!_(x)||F!==void 0&&typeof F!="string")return!1;if(y!==void 0){if(typeof y!="object"||Array.isArray(y)||y===null)return!1;for(let m of Object.values(y))if(!_(m))return!1}return Object.keys(J).length===0}d.isSchema=_});var Ue=S(he=>{"use strict";Object.defineProperty(he,"__esModule",{value:!0});var At=/^(\d{4})-(\d{2})-(\d{2})[tT](\d{2}):(\d{2}):(\d{2})(\.\d+)?([zZ]|((\+|-)(\d{2}):(\d{2})))$/;function Ot(e){let t=e.match(At);if(t===null)return!1;let r=parseInt(t[1],10),n=parseInt(t[2],10),i=parseInt(t[3],10),o=parseInt(t[4],10),a=parseInt(t[5],10),f=parseInt(t[6],10);return!(n>12||i>St(r,n)||o>23||a>59||f>60)}he.default=Ot;function St(e,t){return t===2?kt(e)?29:28:Ft[t]}function kt(e){return e%4===0&&(e%100!==0||e%400===0)}var Ft=[0,31,0,31,30,31,30,31,31,30,31,30,31]});var Je=S(C=>{"use strict";var Mt=C&&C.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(C,"__esModule",{value:!0});C.validate=C.MaxDepthExceededError=void 0;var Ct=Mt(Ue()),N=me(),te=class extends Error{};C.MaxDepthExceededError=te;var re=class extends Error{};function jt(e,t,r){let n={errors:[],instanceTokens:[],schemaTokens:[[]],root:e,config:r||{maxDepth:0,maxErrors:0}};try{D(n,e,t)}catch(i){if(!(i instanceof re))throw i}return n.errors}C.validate=jt;function D(e,t,r,n){if(!(t.nullable&&r===null)){if(N.isRefForm(t)){if(e.schemaTokens.length===e.config.maxDepth)throw new te;e.schemaTokens.push(["definitions",t.ref]),D(e,e.root.definitions[t.ref],r),e.schemaTokens.pop()}else if(N.isTypeForm(t)){switch(b(e,"type"),t.type){case"boolean":typeof r!="boolean"&&w(e);break;case"float32":case"float64":typeof r!="number"&&w(e);break;case"int8":H(e,r,-128,127);break;case"uint8":H(e,r,0,255);break;case"int16":H(e,r,-32768,32767);break;case"uint16":H(e,r,0,65535);break;case"int32":H(e,r,-2147483648,2147483647);break;case"uint32":H(e,r,0,4294967295);break;case"string":typeof r!="string"&&w(e);break;case"timestamp":typeof r!="string"?w(e):Ct.default(r)||w(e);break}v(e)}else if(N.isEnumForm(t))b(e,"enum"),(typeof r!="string"||!t.enum.includes(r))&&w(e),v(e);else if(N.isElementsForm(t)){if(b(e,"elements"),Array.isArray(r))for(let[i,o]of r.entries())$(e,i.toString()),D(e,t.elements,o),L(e);else w(e);v(e)}else if(N.isPropertiesForm(t))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){if(t.properties!==void 0){b(e,"properties");for(let[i,o]of Object.entries(t.properties))b(e,i),r.hasOwnProperty(i)?($(e,i),D(e,o,r[i]),L(e)):w(e),v(e);v(e)}if(t.optionalProperties!==void 0){b(e,"optionalProperties");for(let[i,o]of Object.entries(t.optionalProperties))b(e,i),r.hasOwnProperty(i)&&($(e,i),D(e,o,r[i]),L(e)),v(e);v(e)}if(t.additionalProperties!==!0)for(let i of Object.keys(r)){let o=t.properties&&i in t.properties,a=t.optionalProperties&&i in t.optionalProperties;!o&&!a&&i!==n&&($(e,i),w(e),L(e))}}else t.properties!==void 0?b(e,"properties"):b(e,"optionalProperties"),w(e),v(e);else if(N.isValuesForm(t)){if(b(e,"values"),typeof r=="object"&&r!==null&&!Array.isArray(r))for(let[i,o]of Object.entries(r))$(e,i),D(e,t.values,o),L(e);else w(e);v(e)}else if(N.isDiscriminatorForm(t))if(typeof r=="object"&&r!==null&&!Array.isArray(r))if(r.hasOwnProperty(t.discriminator)){let i=r[t.discriminator];typeof i=="string"?i in t.mapping?(b(e,"mapping"),b(e,i),D(e,t.mapping[i],r,t.discriminator),v(e),v(e)):(b(e,"mapping"),$(e,t.discriminator),w(e),L(e),v(e)):(b(e,"discriminator"),$(e,t.discriminator),w(e),L(e),v(e))}else b(e,"discriminator"),w(e),v(e);else b(e,"discriminator"),w(e),v(e)}}function H(e,t,r,n){(typeof t!="number"||!Number.isInteger(t)||t<r||t>n)&&w(e)}function $(e,t){e.instanceTokens.push(t)}function L(e){e.instanceTokens.pop()}function b(e,t){e.schemaTokens[e.schemaTokens.length-1].push(t)}function v(e){e.schemaTokens[e.schemaTokens.length-1].pop()}function w(e){if(e.errors.push({instancePath:[...e.instanceTokens],schemaPath:[...e.schemaTokens[e.schemaTokens.length-1]]}),e.errors.length===e.config.maxErrors)throw new re}});var qe=S(j=>{"use strict";var Bt=j&&j.__createBinding||(Object.create?function(e,t,r,n){n===void 0&&(n=r),Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,n){n===void 0&&(n=r),e[n]=t[r]}),Ve=j&&j.__exportStar||function(e,t){for(var r in e)r!=="default"&&!t.hasOwnProperty(r)&&Bt(t,e,r)};Object.defineProperty(j,"__esModule",{value:!0});Ve(me(),j);Ve(Je(),j)});var Ke=oe(Ee()),We=oe(je());var ee,bt=new Uint8Array(16);function ce(){if(!ee&&(ee=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!ee))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return ee(bt)}var h=[];for(let e=0;e<256;++e)h.push((e+256).toString(16).slice(1));function Be(e,t=0){return(h[e[t+0]]+h[e[t+1]]+h[e[t+2]]+h[e[t+3]]+"-"+h[e[t+4]]+h[e[t+5]]+"-"+h[e[t+6]]+h[e[t+7]]+"-"+h[e[t+8]]+h[e[t+9]]+"-"+h[e[t+10]]+h[e[t+11]]+h[e[t+12]]+h[e[t+13]]+h[e[t+14]]+h[e[t+15]]).toLowerCase()}var wt=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),pe={randomUUID:wt};function vt(e,t,r){if(pe.randomUUID&&!t&&!e)return pe.randomUUID();e=e||{};let n=e.random||(e.rng||ce)();if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,t){r=r||0;for(let i=0;i<16;++i)t[r+i]=n[i];return t}return Be(n)}var q=vt;function de(e){return[...new Uint8Array(e)].map(t=>t.toString(16).padStart(2,"0")).join("")}function Re(e){return new Uint8Array((e.match(/../g)??[]).map(t=>parseInt(t,16)))}function Ie(e){let t=0;for(let i of e)t+=i.length;let r=new Uint8Array(t),n=0;for(let i of e)r.set(i,n),n+=i.length;return r}var ze=oe(qe());function z(e,t){if((0,ze.validate)(e,t).length)throw new Error(`couldn't validate schema: ${JSON.stringify(t)} didn't match schema ${JSON.stringify(e)}`)}var Ge="3",Qe="https://webapp-prod.cloud.remarkable.engineering",Rt="https://internal.cloud.remarkable.com",Ye="x-goog-generation",It="x-goog-if-generation-match",_t="x-goog-content-length-range",gr=["Ballpoint","Ballpointv2","Brush","Calligraphy","ClearPage","EraseSection","Eraser","Fineliner","Finelinerv2","Highlighter","Highlighterv2","Marker","Markerv2","Paintbrush","Paintbrushv2","Pencilv2","SharpPencil","SharpPencilv2","SolidPen","ZoomTool"],br=["Maison Neue","EB Garamond","Noto Sans","Noto Serif","Noto Mono","Noto Sans UI"],Nt={xs:.7,sm:.8,md:1,lg:1.2,xl:1.5,xx:2},$t={sm:50,md:125,rr:180,lg:200},Lt={df:-1,md:100,lg:150,xl:200},Dt={properties:{docID:{type:"string"},hash:{type:"string"}}},Ht={properties:{relative_path:{type:"string"},url:{type:"string"},expires:{type:"timestamp"},method:{enum:["POST","GET","PUT","DELETE"]}},optionalProperties:{maxuploadsize_bytes:{type:"float64"}}},ne={visibleName:{type:"string"},lastModified:{type:"string"}},ie={version:{type:"int32"},pinned:{type:"boolean"},synced:{type:"boolean"},modified:{type:"boolean"},deleted:{type:"boolean"},metadatamodified:{type:"boolean"},parent:{type:"string"}},Ut={discriminator:"type",mapping:{CollectionType:{properties:ne,optionalProperties:ie},DocumentType:{properties:ne,optionalProperties:{...ie,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},Ze={id:{type:"string"},hash:{type:"string"}},Jt={discriminator:"type",mapping:{CollectionType:{properties:{...ne,...Ze},optionalProperties:ie},DocumentType:{properties:{...ne,...Ze,fileType:{enum:["notebook","epub","pdf",""]}},optionalProperties:{...ie,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},U=class extends Error{status;statusText;constructor(t,r,n){super(n),this.status=t,this.statusText=r}},ge=class extends Error{constructor(){super("Generation preconditions failed. This means the current state is out of date with the cloud and needs to be re-synced.")}};async function wr(e,{deviceDesc:t="browser-chrome",uuid:r=q(),authHost:n=Qe,fetch:i=globalThis.fetch}={}){if(e.length!==8)throw new Error(`code should be length 8, but was ${e.length}`);let o=await i(`${n}/token/json/2/device/new`,{method:"POST",headers:{Authorization:"Bearer"},body:JSON.stringify({code:e,deviceDesc:t,deviceID:r})});if(o.ok)return await o.text();throw new U(o.status,o.statusText,"couldn't register api")}function Vt({hash:e,type:t,documentId:r,subfiles:n,size:i}){return`${e}:${t}:${r}:${n}:${i}
|
|
10
|
+
`}function qt(e){let[t,r,n,i,o]=e.split(":");if(t===void 0||r===void 0||n===void 0||i===void 0||o===void 0)throw new Error(`entries line didn't contain five fields: '${e}'`);if(r==="80000000")return{hash:t,type:r,documentId:n,subfiles:parseInt(i),size:BigInt(o)};if(r==="0"){if(i!=="0")throw new Error(`file type entry had nonzero number of subfiles: ${i}`);return{hash:t,type:r,documentId:n,subfiles:0,size:BigInt(o)}}else throw new Error(`entries line contained invalid type: ${r}`)}var be=class{#u;#a;#f;#r;#n;#e=new Map;#t=null;constructor(t,r,n,i,o,a){this.#u=t,this.#a=r,this.#f=n,this.#r=i,this.#n=o;for(let[f,s]of a)this.#e.set(f,Promise.resolve(s))}async#i(t,{body:r,method:n="POST",headers:i={}}){let o=await this.#a(t,{method:n,headers:{Authorization:`Bearer ${this.#u}`,...i},body:r});if(o.ok)return o;{let a=await o.text();throw new U(o.status,o.statusText,`failed reMarkable request: ${a}`)}}async#o({url:t,method:r,maxuploadsize_bytes:n},i,o={}){let a=n?{...o,[_t]:`0,${n}`}:o,f=await this.#a(t,{method:r,body:i,headers:a});if(f.ok)return f;{let s=await f.text();throw new U(f.status,f.statusText,s)}}async#s(t,r,n){let i=r===void 0?"downloads":"uploads",o=n&&r!==null&&r!==void 0?`{ "http_method": "PUT", "relative_path": "${t}", "root_schema": "${n}", "generation": ${r} }`:JSON.stringify({http_method:"GET",relative_path:t}),f=await(await this.#i(`${this.#r}/sync/v2/signed-urls/${i}`,{body:o})).text(),s=JSON.parse(f);return z(Ht,s),s}async getRootHash({cache:t=!0}={}){if(t)for(;this.#t;)try{let[o,a]=await this.#t;return[o,a]}catch{}let r=(async()=>{try{let o=await this.#s("root"),a=await this.#o(o),f=a.headers.get(Ye);if(f)return[await a.text(),BigInt(f)];throw new Error("no generation header in root hash")}catch(o){throw this.#t=null,o}})();this.#t=r;let[n,i]=await r;return[n,i]}async putRootHash(t,r){let n=await this.#s("root",r,t),i;try{i=await this.#o(n,t,{[It]:`${r}`})}catch(f){throw f instanceof U&&f.status===412?(this.#t=null,new ge):f}let o=i.headers.get(Ye);if(!o)throw new Error("no generation header in root hash");let a=BigInt(o);return this.#t=Promise.resolve([t,a]),a}async#l(t){let r=this.#e.get(t);for(;r;)try{let i=await r;if(i)return i;r=void 0}catch{r=this.#e.get(t)}let n=(async()=>{let i=await this.#s(t);return await(await this.#o(i)).arrayBuffer()})();return this.#e.set(t,n.then(i=>i.byteLength<this.#n?i:null,i=>{throw this.#e.delete(t),i})),await n}async getBuffer(t){let r=await this.#l(t);return r.byteLength<this.#n?r.slice(0):r}async getText(t){let r=await this.#l(t);return new TextDecoder().decode(r)}async getJson(t){let r=await this.getText(t);return JSON.parse(r)}async getMetadata(t){let r=await this.getJson(t);return z(Ut,r),r}async getEntries(t){if(t===void 0){let[o]=await this.getRootHash({cache:!0});t=o}let r=await this.getText(t),[n,...i]=r.slice(0,-1).split(`
|
|
11
|
+
`);if(n!==Ge)throw new Error(`got unexpected schema version: ${n}`);return i.map(qt)}async#c(t,r){let n=this.#e.get(t);if(n)try{await n;return}catch{}let i=(async()=>{try{let o=await this.#s(t,null);return await this.#o(o,r),r.byteLength<this.#n?r:null}catch(o){throw this.#e.delete(t),o}})();this.#e.set(t,i),await i}async putEntries(t,r){let n=new TextEncoder;r.sort((u,g)=>u.documentId.localeCompare(g.documentId));let i=Ie(r.map(u=>Re(u.hash))),o=await this.#f.digest("SHA-256",i),a=de(o),f=r.map(Vt).join(""),s=`${Ge}
|
|
12
|
+
${f}`,p=n.encode(s);return await this.#c(a,p),{hash:a,type:"80000000",documentId:t,subfiles:r.length,size:0n}}async putBuffer(t,r){let n=await this.#f.digest("SHA-256",r),i=de(n);return await this.#c(i,r),{hash:i,type:"0",documentId:t,subfiles:0,size:BigInt(r.byteLength)}}async putText(t,r){let n=new TextEncoder;return await this.putBuffer(t,n.encode(r))}async putJson(t,r){return await this.putText(t,(0,We.default)(r))}async putMetadata(t,r){return await this.putJson(`${t}.metadata`,r)}async putCollection(t,r=""){let n=q(),i=`${new Date().valueOf()}`,o=[],a={type:"CollectionType",visibleName:t,version:0,parent:r,synced:!0,lastModified:i};o.push(this.putMetadata(n,a)),o.push(this.putText(`${n}.content`,"{}"));let f=await Promise.all(o);return await this.putEntries(n,f)}async#p(t,r,n,i,o){if(o.fileType!==n)throw new Error(`internal error: fileTypes don't match: ${n}, ${o.fileType}`);let a=q(),f=`${new Date().valueOf()}`,s=[];s.push(this.putBuffer(`${a}.${n}`,r));let p={type:"DocumentType",visibleName:t,version:0,parent:i,synced:!0,lastModified:f};s.push(this.putMetadata(a,p)),s.push(this.putText(`${a}.content`,JSON.stringify(o)));let u=await Promise.all(s);return await this.putEntries(a,u)}async putEpub(t,r,{parent:n="",margins:i=125,orientation:o,textAlignment:a,textScale:f=1,lineHeight:s=-1,fontName:p="",cover:u="visited",lastTool:g}={}){let x={dummyDocument:!1,extraMetadata:{LastTool:g},fileType:"epub",pageCount:0,lastOpenedPage:0,lineHeight:typeof s=="string"?Lt[s]:s,margins:typeof i=="string"?$t[i]:i,textScale:typeof f=="string"?Nt[f]:f,pages:[],coverPageNumber:u==="first"?0:-1,formatVersion:1,orientation:o,textAlignment:a,fontName:p};return await this.#p(t,r,"epub",n,x)}async putPdf(t,r,{parent:n="",orientation:i,cover:o="first",lastTool:a}={}){let f={dummyDocument:!1,extraMetadata:{LastTool:a},fileType:"pdf",pageCount:0,lastOpenedPage:0,lineHeight:-1,margins:125,textScale:1,pages:[],coverPageNumber:o==="first"?0:-1,formatVersion:1,orientation:i};return await this.#p(t,r,"pdf",n,f)}async syncComplete(t){let r=`{ "generation": ${t} }`;await this.#i(`${this.#r}/sync/v2/sync-complete`,{body:r})}async#d(t,r,n){let{hash:i}=await this.putEntries("",r),o=await this.putRootHash(i,t);if(n)try{return await this.syncComplete(o),!0}catch{return!1}else return!1}async create(t,{cache:r=!0,sync:n=!0}={}){let[i,o]=await this.getRootHash({cache:r}),a=await this.getEntries(i);return a.push(t),await this.#d(o,a,n)}async move(t,r,{cache:n=!0,sync:i=!0}={}){let[o,a]=await this.getRootHash({cache:n}),f=await this.getEntries(o);if(!(!r||r==="trash")){let P=f.find(V=>V.documentId===r);if(P){if(P.type!=="80000000")throw new Error(`destination id was a raw file: ${r}`)}else throw new Error(`destination id not found: ${r}`);let A=await this.getEntries(P.hash),[m]=A.filter(V=>V.documentId===`${r}.metadata`);if(!m)throw new Error(`destination id didn't have metadata: ${r}`);if((await this.getMetadata(m.hash)).type!=="CollectionType")throw new Error(`destination id wasn't a collection: ${r}`)}let s=f.findIndex(P=>P.documentId===t);if(s===-1)throw new Error(`document not found: ${t}`);let[p]=f.splice(s,1);if(p.type!=="80000000")throw new Error(`document was a raw file: ${t}`);let u=await this.getEntries(p.hash),g=u.findIndex(P=>P.documentId===`${t}.metadata`);if(g===-1)throw new Error(`document didn't have metadata: ${t}`);let[x]=u.splice(g,1),F=await this.getMetadata(x.hash);F.parent=r;let y=await this.putMetadata(t,F);u.push(y);let J=await this.putEntries(t,u);return f.push(J),await this.#d(a,f,i)}async getEntriesMetadata(){let r=await(await this.#i(`${this.#r}/doc/v2/files`,{method:"GET",headers:{"rm-source":"RoR-Browser"}})).text(),n=JSON.parse(r);return z({elements:Jt},n),n}async#y(t,r,n){let o=new TextEncoder().encode(JSON.stringify({file_name:t})),f=await(await this.#i(`${this.#r}/doc/v2/files`,{body:r,headers:{"content-type":n,"rm-meta":(0,Ke.fromByteArray)(o),"rm-source":"RoR-Browser"}})).text(),s=JSON.parse(f);return z(Dt,s),s}async uploadEpub(t,r){return await this.#y(t,r,"application/epub+zip")}async uploadPdf(t,r){return await this.#y(t,r,"application/pdf")}async getCache(){let t=[];for(let[i,o]of this.#e)t.push(o.then(a=>[i,a],()=>[i,null]));let r=await Promise.all(t),n=new Map;for(let[i,o]of r)o&&n.set(i,o);return n}};async function vr(e,{fetch:t=globalThis.fetch,subtle:r=globalThis.crypto?.subtle,authHost:n=Qe,syncHost:i=Rt,cacheLimitBytes:o=1048576,initCache:a=[]}={}){if(!r)throw new Error("subtle was missing, try specifying it manually");let f=await t(`${n}/token/json/2/user/new`,{method:"POST",headers:{Authorization:`Bearer ${e}`}});if(!f.ok)throw new Error(`couldn't fetch auth token: ${f.statusText}`);let s=await f.text();return new be(s,t,r,i,o,a)}})();
|
package/dist/index.d.ts
CHANGED
|
@@ -188,8 +188,6 @@ export interface Content {
|
|
|
188
188
|
/** text alignment */
|
|
189
189
|
textAlignment?: TextAlignment;
|
|
190
190
|
}
|
|
191
|
-
/** anything that can be awaited */
|
|
192
|
-
export type Awaitable<T> = T | PromiseLike<T>;
|
|
193
191
|
/** stripped down version of RequestInit */
|
|
194
192
|
export interface RequestInitLike {
|
|
195
193
|
/** request method */
|
|
@@ -215,20 +213,21 @@ export interface ResponseLike {
|
|
|
215
213
|
/** headers in response */
|
|
216
214
|
headers: HeadersLike;
|
|
217
215
|
/** get response body as text */
|
|
218
|
-
text():
|
|
216
|
+
text(): Promise<string>;
|
|
219
217
|
/** get response body as an array buffer */
|
|
220
|
-
arrayBuffer():
|
|
218
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
221
219
|
}
|
|
222
220
|
/** stripped down version of fetch */
|
|
223
221
|
export interface FetchLike {
|
|
224
|
-
|
|
222
|
+
/** the rough interface to fetch */
|
|
223
|
+
(url: string, options?: RequestInitLike | undefined): Promise<ResponseLike>;
|
|
225
224
|
}
|
|
226
225
|
/** async storage, map like */
|
|
227
226
|
export interface CacheLike {
|
|
228
227
|
/** get value for key or undefined if missing */
|
|
229
|
-
get(key: string):
|
|
228
|
+
get(key: string): Promise<string | undefined>;
|
|
230
229
|
/** set value for key */
|
|
231
|
-
set(key: string, value: string):
|
|
230
|
+
set(key: string, value: string): Promise<void>;
|
|
232
231
|
}
|
|
233
232
|
/** stripped down version of subtle crypto */
|
|
234
233
|
export interface SubtleCryptoLike {
|
|
@@ -385,28 +384,41 @@ export interface RemarkableApi {
|
|
|
385
384
|
/**
|
|
386
385
|
* get text content associated with hash
|
|
387
386
|
*
|
|
388
|
-
* This call uses the cache if provided since contents of a specific hash
|
|
389
|
-
* should never change. This isn't atomic so calling with the same hash in
|
|
390
|
-
* quick succession could result in two requests being fired instead of the
|
|
391
|
-
* second waiting for the first.
|
|
392
|
-
*
|
|
393
387
|
* @param hash - the hash to get text data from
|
|
394
388
|
*/
|
|
395
389
|
getText(hash: string): Promise<string>;
|
|
390
|
+
/**
|
|
391
|
+
* get a json object associated with a hash
|
|
392
|
+
*
|
|
393
|
+
* This is identical to `getText(hash).then(JSON.parse)` and is only provided
|
|
394
|
+
* for consistency with {@link RemarkableApi.putJson | `putJson`}.
|
|
395
|
+
*/
|
|
396
|
+
getJson(hash: string): Promise<unknown>;
|
|
396
397
|
/** get metadata from hash */
|
|
397
398
|
getMetadata(hash: string): Promise<Metadata>;
|
|
398
|
-
/**
|
|
399
|
-
|
|
399
|
+
/**
|
|
400
|
+
* get entries from a collection hash
|
|
401
|
+
*
|
|
402
|
+
* If omitted, this will use `getRootHash()`.
|
|
403
|
+
*/
|
|
404
|
+
getEntries(hash?: string): Promise<Entry[]>;
|
|
400
405
|
/** put a reference to a set of entries into the cloud */
|
|
401
406
|
putEntries(documentId: string, entries: Entry[]): Promise<CollectionEntry>;
|
|
402
407
|
/** put a raw buffer in the cloud */
|
|
403
|
-
putBuffer(documentId: string, buffer:
|
|
408
|
+
putBuffer(documentId: string, buffer: ArrayBuffer): Promise<FileEntry>;
|
|
404
409
|
/**
|
|
405
|
-
* put a raw text in the cloud
|
|
410
|
+
* put a raw text in the cloud encoded as utf-8
|
|
406
411
|
*
|
|
407
|
-
*
|
|
412
|
+
* this is no different than using `putBuffer(..., new TextEncoder().encode(contents))`
|
|
408
413
|
*/
|
|
409
414
|
putText(documentId: string, contents: string): Promise<FileEntry>;
|
|
415
|
+
/**
|
|
416
|
+
* put json into the cloud
|
|
417
|
+
*
|
|
418
|
+
* This uses a stable (sorted keys) json serilization to preserve consistent
|
|
419
|
+
* hashes.
|
|
420
|
+
*/
|
|
421
|
+
putJson(documentId: string, contents: object): Promise<FileEntry>;
|
|
410
422
|
/**
|
|
411
423
|
* put metadata into the cloud
|
|
412
424
|
*
|
|
@@ -446,7 +458,7 @@ export interface RemarkableApi {
|
|
|
446
458
|
* @param buffer - the epub contents
|
|
447
459
|
* @param opts - extra options you can specify at upload
|
|
448
460
|
*/
|
|
449
|
-
putEpub(visibleName: string, buffer:
|
|
461
|
+
putEpub(visibleName: string, buffer: ArrayBuffer, opts?: PutEpubOptions): Promise<CollectionEntry>;
|
|
450
462
|
/**
|
|
451
463
|
* upload a pdf
|
|
452
464
|
*
|
|
@@ -469,7 +481,7 @@ export interface RemarkableApi {
|
|
|
469
481
|
* @param buffer - the pdf contents
|
|
470
482
|
* @param opts - extra options you can specify at upload
|
|
471
483
|
*/
|
|
472
|
-
putPdf(visibleName: string, buffer:
|
|
484
|
+
putPdf(visibleName: string, buffer: ArrayBuffer, opts?: PutPdfOptions): Promise<CollectionEntry>;
|
|
473
485
|
/**
|
|
474
486
|
* indicate that a sync is complete and push updates to other devices
|
|
475
487
|
*
|
|
@@ -496,6 +508,10 @@ export interface RemarkableApi {
|
|
|
496
508
|
* 2. It includes no handling of concurrent modification or other networking
|
|
497
509
|
* errors, requiring repeat network requests if anything fails.
|
|
498
510
|
*
|
|
511
|
+
* However, with recent changes in the way this library caches results, it
|
|
512
|
+
* won't be terribly inefficient to just do multiple retries of create after
|
|
513
|
+
* uploading the file itself.
|
|
514
|
+
*
|
|
499
515
|
* @example
|
|
500
516
|
* ```ts
|
|
501
517
|
* const entry = await api.putEpub(...);
|
|
@@ -509,13 +525,6 @@ export interface RemarkableApi {
|
|
|
509
525
|
* changed
|
|
510
526
|
*/
|
|
511
527
|
create(entry: CollectionEntry, options?: CreateMoveOptions): Promise<boolean>;
|
|
512
|
-
/**
|
|
513
|
-
* deprecated variant without the ability to specify caching behavior
|
|
514
|
-
*
|
|
515
|
-
* @deprecated in favor of the options syntax: replace `create(entry, sync)`
|
|
516
|
-
* with `create(entry, { cache: false, sync: sync })`
|
|
517
|
-
*/
|
|
518
|
-
create(entry: CollectionEntry, sync: boolean): Promise<boolean>;
|
|
519
528
|
/**
|
|
520
529
|
* high level api to move a document / collection
|
|
521
530
|
*
|
|
@@ -531,6 +540,9 @@ export interface RemarkableApi {
|
|
|
531
540
|
* 2. It includes no handling of concurrent modification or other networking
|
|
532
541
|
* errors, requiring repeat network requests if anything fails.
|
|
533
542
|
*
|
|
543
|
+
* However, with changes to the way this caches results, it won't be terribly
|
|
544
|
+
* inefficient to just retry calling `move` if there's a failure.
|
|
545
|
+
*
|
|
534
546
|
* @example
|
|
535
547
|
* ```ts
|
|
536
548
|
* const [root] = await api.getRootHash();
|
|
@@ -549,14 +561,6 @@ export interface RemarkableApi {
|
|
|
549
561
|
* changed
|
|
550
562
|
*/
|
|
551
563
|
move(documentId: string, dest: string, opts?: CreateMoveOptions): Promise<boolean>;
|
|
552
|
-
/**
|
|
553
|
-
* deprecated variant without the ability to specify caching behavior
|
|
554
|
-
*
|
|
555
|
-
* @deprecated in favor of the options syntax: replace
|
|
556
|
-
* `move(docid, dest, sync)` with
|
|
557
|
-
* `move(docid, dest, { cache: false, sync: sync })`
|
|
558
|
-
*/
|
|
559
|
-
move(documentId: string, dest: string, sync: boolean): Promise<boolean>;
|
|
560
564
|
/**
|
|
561
565
|
* get metadata on all entries
|
|
562
566
|
*
|
|
@@ -579,7 +583,7 @@ export interface RemarkableApi {
|
|
|
579
583
|
* @param visibleName - the name to show for the uploaded epub
|
|
580
584
|
* @param buffer - the epub contents
|
|
581
585
|
*/
|
|
582
|
-
uploadEpub(visibleName: string, buffer:
|
|
586
|
+
uploadEpub(visibleName: string, buffer: ArrayBuffer): Promise<UploadEntry>;
|
|
583
587
|
/**
|
|
584
588
|
* upload a pdf
|
|
585
589
|
*
|
|
@@ -599,7 +603,14 @@ export interface RemarkableApi {
|
|
|
599
603
|
* @param buffer - the epub contents
|
|
600
604
|
* @experimental
|
|
601
605
|
*/
|
|
602
|
-
uploadPdf(visibleName: string, buffer:
|
|
606
|
+
uploadPdf(visibleName: string, buffer: ArrayBuffer): Promise<UploadEntry>;
|
|
607
|
+
/**
|
|
608
|
+
* get the current state of the cache for persisting
|
|
609
|
+
*
|
|
610
|
+
* This won't include items that weren't cached because they were too big,
|
|
611
|
+
* meaning it won't prevent duplicate puts of large content across sessions.
|
|
612
|
+
*/
|
|
613
|
+
getCache(): Promise<Map<string, ArrayBuffer>>;
|
|
603
614
|
}
|
|
604
615
|
/** format an entry */
|
|
605
616
|
export declare function formatEntry({ hash, type, documentId, subfiles, size, }: Entry): string;
|
|
@@ -616,20 +627,10 @@ export interface RemarkableOptions {
|
|
|
616
627
|
*
|
|
617
628
|
* In node you can either use `"node-fetch"`, or `node --experimental-fetch`
|
|
618
629
|
* for node 17.5 or higher.
|
|
619
|
-
*/
|
|
620
|
-
fetch?: FetchLike;
|
|
621
|
-
/**
|
|
622
|
-
* an optional cache for text requests
|
|
623
630
|
*
|
|
624
|
-
*
|
|
625
|
-
* want to keep a cache so that as long as a file's hash doesn't change you
|
|
626
|
-
* don't need to request another copy.
|
|
627
|
-
*
|
|
628
|
-
* @remarks currently there are no mechanisms that actually clear the cache,
|
|
629
|
-
* so be warned if the cache doesn't have an auto clearning mechansim that
|
|
630
|
-
* some old files may stay around for quite a while
|
|
631
|
+
* @defaultValue globalThis.fetch
|
|
631
632
|
*/
|
|
632
|
-
|
|
633
|
+
fetch?: FetchLike;
|
|
633
634
|
/**
|
|
634
635
|
* a subtle-crypto-like object
|
|
635
636
|
*
|
|
@@ -637,14 +638,43 @@ export interface RemarkableOptions {
|
|
|
637
638
|
* default value. In node try
|
|
638
639
|
* `import { webcrypto } from "crypto"; global.crypto = webcrypto` or pass in
|
|
639
640
|
* `webcrypto.subtle`.
|
|
641
|
+
*
|
|
642
|
+
* @defaultValue globalThis.crypto.subtle
|
|
640
643
|
*/
|
|
641
644
|
subtle?: SubtleCryptoLike;
|
|
642
|
-
/**
|
|
645
|
+
/**
|
|
646
|
+
* the url for making authorization requests
|
|
647
|
+
*
|
|
648
|
+
* @defaultValue "https://webapp-prod.cloud.remarkable.engineering"
|
|
649
|
+
*/
|
|
643
650
|
authHost?: string;
|
|
644
|
-
/**
|
|
645
|
-
|
|
646
|
-
|
|
651
|
+
/**
|
|
652
|
+
* the url for making synchronization requests
|
|
653
|
+
*
|
|
654
|
+
* @defaultValue "https://internal.cloud.remarkable.com"
|
|
655
|
+
*/
|
|
647
656
|
syncHost?: string;
|
|
657
|
+
/**
|
|
658
|
+
* the maximum size in bytes to cache the value of a stored object
|
|
659
|
+
*
|
|
660
|
+
* Since the remarkableApi is based around hashes, the value of a hash should
|
|
661
|
+
* never change (barring collisions in ASH256). Any known hash value that's
|
|
662
|
+
* less than this amount will be cached locally to prevent future network
|
|
663
|
+
* requests. In addition, all successful puts and gets will be cached to
|
|
664
|
+
* prevent duplicate puts in the future.
|
|
665
|
+
*
|
|
666
|
+
* To save memory and disable fetch caching, set to 0.
|
|
667
|
+
*
|
|
668
|
+
* @defaultValue 1 MiB
|
|
669
|
+
*/
|
|
670
|
+
cacheLimitBytes?: number;
|
|
671
|
+
/**
|
|
672
|
+
* a set of values to use to initialize the cache
|
|
673
|
+
*
|
|
674
|
+
* If this is inaccurate, then you could encounter errors with other methods.
|
|
675
|
+
* Often this will come from {@link RemarkableApi.getCache | `getCache`}.
|
|
676
|
+
*/
|
|
677
|
+
initCache?: Iterable<readonly [string, ArrayBuffer]>;
|
|
648
678
|
}
|
|
649
679
|
/**
|
|
650
680
|
* create an instance of the api
|
|
@@ -656,4 +686,4 @@ export interface RemarkableOptions {
|
|
|
656
686
|
* registered. Create one with {@link register}.
|
|
657
687
|
* @returns an api instance
|
|
658
688
|
*/
|
|
659
|
-
export declare function remarkable(deviceToken: string, { fetch,
|
|
689
|
+
export declare function remarkable(deviceToken: string, { fetch, subtle, authHost, syncHost, cacheLimitBytes, initCache, }?: RemarkableOptions): Promise<RemarkableApi>;
|
package/dist/index.js
CHANGED
|
@@ -15,9 +15,8 @@
|
|
|
15
15
|
* const token = await register(code)
|
|
16
16
|
* // persist token
|
|
17
17
|
* const api = await remarkable(token);
|
|
18
|
-
* const
|
|
19
|
-
* const
|
|
20
|
-
* for (const entry of fileEntries) {
|
|
18
|
+
* const rootEntries = await api.getEntries();
|
|
19
|
+
* for (const entry of rootEntries) {
|
|
21
20
|
* const children = await api.getEntries(entry.hash);
|
|
22
21
|
* for (const { hash, documentId } of children) {
|
|
23
22
|
* if (documentId.endsWith(".metadata")) {
|
|
@@ -42,6 +41,7 @@
|
|
|
42
41
|
* @packageDocumentation
|
|
43
42
|
*/
|
|
44
43
|
import { fromByteArray } from "base64-js";
|
|
44
|
+
import stringify from "json-stable-stringify";
|
|
45
45
|
import { v4 as uuid4 } from "uuid";
|
|
46
46
|
import { concatBuffers, fromHex, toHex } from "./utils";
|
|
47
47
|
import { validate } from "./validate";
|
|
@@ -298,14 +298,19 @@ class Remarkable {
|
|
|
298
298
|
#subtle;
|
|
299
299
|
#syncHost;
|
|
300
300
|
// caches
|
|
301
|
-
#
|
|
301
|
+
#cacheLimitBytes;
|
|
302
|
+
#cache = new Map();
|
|
302
303
|
#rootCache = null;
|
|
303
|
-
constructor(userToken, fetch,
|
|
304
|
+
constructor(userToken, fetch, subtle, syncHost, cacheLimitBytes, initCache) {
|
|
304
305
|
this.#userToken = userToken;
|
|
305
306
|
this.#fetch = fetch;
|
|
306
|
-
this.#cache = cache;
|
|
307
307
|
this.#subtle = subtle;
|
|
308
308
|
this.#syncHost = syncHost;
|
|
309
|
+
this.#cacheLimitBytes = cacheLimitBytes;
|
|
310
|
+
// set cache
|
|
311
|
+
for (const [hash, val] of initCache) {
|
|
312
|
+
this.#cache.set(hash, Promise.resolve(val));
|
|
313
|
+
}
|
|
309
314
|
}
|
|
310
315
|
/** make an authorized request to remarkable */
|
|
311
316
|
async #authedFetch(url, { body, method = "POST", headers = {}, }) {
|
|
@@ -350,7 +355,7 @@ class Remarkable {
|
|
|
350
355
|
async #getUrl(relativePath, gen, rootHash) {
|
|
351
356
|
const key = gen === undefined ? "downloads" : "uploads";
|
|
352
357
|
// NOTE this is done manually to serialize the bigints appropriately
|
|
353
|
-
const body = rootHash
|
|
358
|
+
const body = rootHash && gen !== null && gen !== undefined
|
|
354
359
|
? `{ "http_method": "PUT", "relative_path": "${relativePath}", "root_schema": "${rootHash}", "generation": ${gen} }`
|
|
355
360
|
: JSON.stringify({ http_method: "GET", relative_path: relativePath });
|
|
356
361
|
const resp = await this.#authedFetch(`${this.#syncHost}/sync/v2/signed-urls/${key}`, { body });
|
|
@@ -423,43 +428,77 @@ class Remarkable {
|
|
|
423
428
|
this.#rootCache = Promise.resolve([hash, gen]);
|
|
424
429
|
return gen;
|
|
425
430
|
}
|
|
431
|
+
/**
|
|
432
|
+
* get content associated with hash
|
|
433
|
+
*/
|
|
434
|
+
async #getHash(hash) {
|
|
435
|
+
let cached = this.#cache.get(hash);
|
|
436
|
+
while (cached) {
|
|
437
|
+
try {
|
|
438
|
+
const val = await cached;
|
|
439
|
+
if (val) {
|
|
440
|
+
return val;
|
|
441
|
+
}
|
|
442
|
+
else {
|
|
443
|
+
cached = undefined; // break
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
catch {
|
|
447
|
+
// try again if promise rejected
|
|
448
|
+
cached = this.#cache.get(hash);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
const prom = (async () => {
|
|
452
|
+
const signed = await this.#getUrl(hash);
|
|
453
|
+
const resp = await this.#signedFetch(signed);
|
|
454
|
+
return await resp.arrayBuffer();
|
|
455
|
+
})();
|
|
456
|
+
// set cache with appropriate promise that cleans up on rejection
|
|
457
|
+
this.#cache.set(hash, prom.then((buff) => (buff.byteLength < this.#cacheLimitBytes ? buff : null), (ex) => {
|
|
458
|
+
this.#cache.delete(hash);
|
|
459
|
+
throw ex;
|
|
460
|
+
}));
|
|
461
|
+
return await prom;
|
|
462
|
+
}
|
|
426
463
|
/**
|
|
427
464
|
* get text content associated with hash
|
|
428
465
|
*/
|
|
429
466
|
async getBuffer(hash) {
|
|
430
|
-
const
|
|
431
|
-
|
|
432
|
-
return
|
|
467
|
+
const buff = await this.#getHash(hash);
|
|
468
|
+
// copy if it is long enough to be cached to preven mutations
|
|
469
|
+
return buff.byteLength < this.#cacheLimitBytes ? buff.slice(0) : buff;
|
|
433
470
|
}
|
|
434
471
|
/**
|
|
435
472
|
* get text content associated with hash
|
|
436
473
|
*/
|
|
437
474
|
async getText(hash) {
|
|
438
|
-
const
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
}
|
|
475
|
+
const buff = await this.#getHash(hash);
|
|
476
|
+
const decoder = new TextDecoder();
|
|
477
|
+
return decoder.decode(buff);
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* get json content associated with hash
|
|
481
|
+
*/
|
|
482
|
+
async getJson(hash) {
|
|
483
|
+
const str = await this.getText(hash);
|
|
484
|
+
return JSON.parse(str);
|
|
449
485
|
}
|
|
450
486
|
/**
|
|
451
487
|
* get metadata from hash
|
|
452
488
|
*/
|
|
453
489
|
async getMetadata(hash) {
|
|
454
|
-
const raw = await this.
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
return parsed;
|
|
490
|
+
const raw = await this.getJson(hash);
|
|
491
|
+
validate(metadataSchema, raw);
|
|
492
|
+
return raw;
|
|
458
493
|
}
|
|
459
494
|
/**
|
|
460
495
|
* get entries from a collection hash
|
|
461
496
|
*/
|
|
462
497
|
async getEntries(hash) {
|
|
498
|
+
if (hash === undefined) {
|
|
499
|
+
const [newHash] = await this.getRootHash({ cache: true });
|
|
500
|
+
hash = newHash;
|
|
501
|
+
}
|
|
463
502
|
const raw = await this.getText(hash);
|
|
464
503
|
// slice for trailing new line
|
|
465
504
|
const [schema, ...lines] = raw.slice(0, -1).split("\n");
|
|
@@ -470,8 +509,31 @@ class Remarkable {
|
|
|
470
509
|
}
|
|
471
510
|
/** upload data to hash */
|
|
472
511
|
async #putHash(hash, body) {
|
|
473
|
-
|
|
474
|
-
|
|
512
|
+
// try cached version
|
|
513
|
+
const cached = this.#cache.get(hash);
|
|
514
|
+
if (cached) {
|
|
515
|
+
try {
|
|
516
|
+
await cached;
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
catch {
|
|
520
|
+
// noop
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
// if missing or rejected then put for real
|
|
524
|
+
const prom = (async () => {
|
|
525
|
+
try {
|
|
526
|
+
const signed = await this.#getUrl(hash, null);
|
|
527
|
+
await this.#signedFetch(signed, body);
|
|
528
|
+
return body.byteLength < this.#cacheLimitBytes ? body : null;
|
|
529
|
+
}
|
|
530
|
+
catch (ex) {
|
|
531
|
+
this.#cache.delete(hash);
|
|
532
|
+
throw ex;
|
|
533
|
+
}
|
|
534
|
+
})();
|
|
535
|
+
this.#cache.set(hash, prom);
|
|
536
|
+
await prom;
|
|
475
537
|
}
|
|
476
538
|
/** put a reference to a set of entries into the cloud */
|
|
477
539
|
async putEntries(documentId, entries) {
|
|
@@ -485,7 +547,6 @@ class Remarkable {
|
|
|
485
547
|
const contents = `${SCHEMA_VERSION}\n${entryContents}`;
|
|
486
548
|
const buffer = enc.encode(contents);
|
|
487
549
|
await this.#putHash(hash, buffer);
|
|
488
|
-
await this.#cache?.set(hash, contents);
|
|
489
550
|
return {
|
|
490
551
|
hash,
|
|
491
552
|
type: "80000000",
|
|
@@ -504,19 +565,21 @@ class Remarkable {
|
|
|
504
565
|
type: "0",
|
|
505
566
|
documentId,
|
|
506
567
|
subfiles: 0,
|
|
507
|
-
size: BigInt(buffer.
|
|
568
|
+
size: BigInt(buffer.byteLength),
|
|
508
569
|
};
|
|
509
570
|
}
|
|
510
|
-
/** put
|
|
571
|
+
/** put text in the cloud */
|
|
511
572
|
async putText(documentId, contents) {
|
|
512
573
|
const enc = new TextEncoder();
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
574
|
+
return await this.putBuffer(documentId, enc.encode(contents));
|
|
575
|
+
}
|
|
576
|
+
/** put json in the cloud */
|
|
577
|
+
async putJson(documentId, contents) {
|
|
578
|
+
return await this.putText(documentId, stringify(contents));
|
|
516
579
|
}
|
|
517
580
|
/** put metadata into the cloud */
|
|
518
581
|
async putMetadata(documentId, metadata) {
|
|
519
|
-
return await this.
|
|
582
|
+
return await this.putJson(`${documentId}.metadata`, metadata);
|
|
520
583
|
}
|
|
521
584
|
/** put a new collection (folder) */
|
|
522
585
|
async putCollection(visibleName, parent = "") {
|
|
@@ -639,16 +702,14 @@ class Remarkable {
|
|
|
639
702
|
}
|
|
640
703
|
}
|
|
641
704
|
/** high level api to create an entry */
|
|
642
|
-
async create(entry,
|
|
643
|
-
const { cache = true, sync = true } = typeof opts === "boolean" ? { cache: false, sync: opts } : opts;
|
|
705
|
+
async create(entry, { cache = true, sync = true } = {}) {
|
|
644
706
|
const [root, gen] = await this.getRootHash({ cache });
|
|
645
707
|
const rootEntries = await this.getEntries(root);
|
|
646
708
|
rootEntries.push(entry);
|
|
647
709
|
return await this.#tryPutRootEntries(gen, rootEntries, sync);
|
|
648
710
|
}
|
|
649
711
|
/** high level api to move a document / collection */
|
|
650
|
-
async move(documentId, dest,
|
|
651
|
-
const { cache = true, sync = true } = typeof opts === "boolean" ? { cache: false, sync: opts } : opts;
|
|
712
|
+
async move(documentId, dest, { cache = true, sync = true } = {}) {
|
|
652
713
|
const [root, gen] = await this.getRootHash({ cache });
|
|
653
714
|
const rootEntries = await this.getEntries(root);
|
|
654
715
|
// check if destination is a collection
|
|
@@ -742,6 +803,20 @@ class Remarkable {
|
|
|
742
803
|
// TODO why doesn't this work
|
|
743
804
|
return await this.#uploadFile(visibleName, buffer, "application/pdf");
|
|
744
805
|
}
|
|
806
|
+
async getCache() {
|
|
807
|
+
const promises = [];
|
|
808
|
+
for (const [hash, prom] of this.#cache) {
|
|
809
|
+
promises.push(prom.then((val) => [hash, val], () => [hash, null]));
|
|
810
|
+
}
|
|
811
|
+
const entries = await Promise.all(promises);
|
|
812
|
+
const cache = new Map();
|
|
813
|
+
for (const [hash, val] of entries) {
|
|
814
|
+
if (val) {
|
|
815
|
+
cache.set(hash, val);
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
return cache;
|
|
819
|
+
}
|
|
745
820
|
}
|
|
746
821
|
/**
|
|
747
822
|
* create an instance of the api
|
|
@@ -753,7 +828,10 @@ class Remarkable {
|
|
|
753
828
|
* registered. Create one with {@link register}.
|
|
754
829
|
* @returns an api instance
|
|
755
830
|
*/
|
|
756
|
-
export async function remarkable(deviceToken, { fetch = globalThis.fetch,
|
|
831
|
+
export async function remarkable(deviceToken, { fetch = globalThis.fetch, subtle = globalThis.crypto?.subtle, authHost = AUTH_HOST, syncHost = SYNC_HOST, cacheLimitBytes = 1048576, initCache = [], } = {}) {
|
|
832
|
+
if (!subtle) {
|
|
833
|
+
throw new Error("subtle was missing, try specifying it manually");
|
|
834
|
+
}
|
|
757
835
|
const resp = await fetch(`${authHost}/token/json/2/user/new`, {
|
|
758
836
|
method: "POST",
|
|
759
837
|
headers: {
|
|
@@ -764,5 +842,5 @@ export async function remarkable(deviceToken, { fetch = globalThis.fetch, cache,
|
|
|
764
842
|
throw new Error(`couldn't fetch auth token: ${resp.statusText}`);
|
|
765
843
|
}
|
|
766
844
|
const userToken = await resp.text();
|
|
767
|
-
return new Remarkable(userToken, fetch,
|
|
845
|
+
return new Remarkable(userToken, fetch, subtle, syncHost, cacheLimitBytes, initCache);
|
|
768
846
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rmapi-js",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
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>",
|
|
@@ -19,44 +19,47 @@
|
|
|
19
19
|
],
|
|
20
20
|
"packageManager": "yarn@3.3.1",
|
|
21
21
|
"scripts": {
|
|
22
|
-
"doc": "typedoc",
|
|
23
|
-
"fmt": "prettier --cache --write 'src/*.ts' '*.json'
|
|
24
|
-
"lint": "
|
|
22
|
+
"doc": "pnpify typedoc",
|
|
23
|
+
"fmt": "pnpify prettier --cache --write 'src/*.ts' '*.json'",
|
|
24
|
+
"lint:es": "pnpify eslint --cache 'src/*.ts'",
|
|
25
|
+
"lint:doc": "pnpify typedoc --emit none",
|
|
26
|
+
"lint": "pnpify tsc && yarn lint:es && yarn lint:doc",
|
|
25
27
|
"test": "jest --coverage",
|
|
26
|
-
"build": "tsc -p tsconfig.build.json &&
|
|
28
|
+
"build": "pnpify tsc -p tsconfig.build.json && esbuild src/index.ts --bundle --minify --platform=node --outfile=bundle/rmapi-js.cjs.min.js && yarn esbuild src/index.ts --bundle --minify --platform=browser --outfile=bundle/rmapi-js.iife.min.js && yarn esbuild src/index.ts --bundle --minify --platform=neutral --outfile=bundle/rmapi-js.esm.min.js --main-fields=module,main",
|
|
27
29
|
"prepack": "yarn lint && yarn test && yarn build"
|
|
28
30
|
},
|
|
29
31
|
"dependencies": {
|
|
30
|
-
"ajv": "^8.
|
|
32
|
+
"ajv": "^8.12.0",
|
|
31
33
|
"base64-js": "^1.5.1",
|
|
34
|
+
"json-stable-stringify": "^1.0.2",
|
|
32
35
|
"jtd": "^0.1.1",
|
|
33
36
|
"uuid": "^9.0.0"
|
|
34
37
|
},
|
|
35
38
|
"devDependencies": {
|
|
36
|
-
"@babel/core": "^7.
|
|
37
|
-
"@babel/preset-env": "^7.
|
|
38
|
-
"@babel/preset-typescript": "^7.
|
|
39
|
-
"@types/babel__core": "^7.1
|
|
39
|
+
"@babel/core": "^7.22.8",
|
|
40
|
+
"@babel/preset-env": "^7.22.7",
|
|
41
|
+
"@babel/preset-typescript": "^7.22.5",
|
|
42
|
+
"@types/babel__core": "^7.20.1",
|
|
40
43
|
"@types/babel__preset-env": "^7.9.2",
|
|
41
|
-
"@types/jest": "^29.
|
|
42
|
-
"@types/
|
|
43
|
-
"@types/
|
|
44
|
-
"@
|
|
45
|
-
"@typescript-eslint/
|
|
46
|
-
"@
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"esbuild": "^0.
|
|
50
|
-
"eslint": "^8.
|
|
51
|
-
"eslint-config-prettier": "^8.
|
|
52
|
-
"eslint-plugin-jest": "^27.
|
|
44
|
+
"@types/jest": "^29.5.3",
|
|
45
|
+
"@types/json-stable-stringify": "^1.0.34",
|
|
46
|
+
"@types/node": "^20.4.1",
|
|
47
|
+
"@types/uuid": "^9.0.2",
|
|
48
|
+
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
|
49
|
+
"@typescript-eslint/parser": "^6.0.0",
|
|
50
|
+
"@yarnpkg/pnpify": "^4.0.0-rc.48",
|
|
51
|
+
"babel-jest": "^29.6.1",
|
|
52
|
+
"esbuild": "^0.18.11",
|
|
53
|
+
"eslint": "^8.44.0",
|
|
54
|
+
"eslint-config-prettier": "^8.8.0",
|
|
55
|
+
"eslint-plugin-jest": "^27.2.2",
|
|
53
56
|
"eslint-plugin-spellcheck": "^0.0.20",
|
|
54
57
|
"eslint-plugin-tsdoc": "^0.2.17",
|
|
55
|
-
"jest": "^29.
|
|
56
|
-
"prettier": "^
|
|
57
|
-
"prettier-plugin-organize-imports": "^3.2.
|
|
58
|
-
"typedoc": "^0.
|
|
59
|
-
"typescript": "^
|
|
58
|
+
"jest": "^29.6.1",
|
|
59
|
+
"prettier": "^3.0.0",
|
|
60
|
+
"prettier-plugin-organize-imports": "^3.2.2",
|
|
61
|
+
"typedoc": "^0.24.8",
|
|
62
|
+
"typescript": "^5.1.6"
|
|
60
63
|
},
|
|
61
64
|
"prettier": {
|
|
62
65
|
"plugins": [
|
|
@@ -88,9 +91,15 @@
|
|
|
88
91
|
"extends": [
|
|
89
92
|
"eslint:recommended",
|
|
90
93
|
"plugin:@typescript-eslint/recommended",
|
|
94
|
+
"plugin:@typescript-eslint/recommended-requiring-type-checking",
|
|
91
95
|
"plugin:jest/recommended",
|
|
92
96
|
"prettier"
|
|
93
97
|
],
|
|
98
|
+
"parserOptions": {
|
|
99
|
+
"project": [
|
|
100
|
+
"./tsconfig.json"
|
|
101
|
+
]
|
|
102
|
+
},
|
|
94
103
|
"env": {
|
|
95
104
|
"node": true
|
|
96
105
|
},
|