collected-notes
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -341,2 +341,18 @@ 'use strict'; | ||
function collectedNotes(email, token) { | ||
var reorder = function reorder(site, notes) { | ||
try { | ||
return Promise.resolve(fetch("https://collectednotes.com/sites/" + site + "/notes/reorder", { | ||
method: 'POST', | ||
headers: headers, | ||
body: JSON.stringify({ | ||
ids: notes | ||
}) | ||
})).then(function (response) { | ||
return response.json(); | ||
}); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}; | ||
var me = function me() { | ||
@@ -456,3 +472,4 @@ try { | ||
destroy: destroy, | ||
me: me | ||
me: me, | ||
reorder: reorder | ||
}; | ||
@@ -459,0 +476,0 @@ } |
@@ -1,2 +0,2 @@ | ||
"use strict";function t(e){return(t=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(e)}function e(t,r){return(e=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,r)}function r(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}function n(t,o,i){return(n=r()?Reflect.construct:function(t,r,n){var o=[null];o.push.apply(o,r);var i=new(Function.bind.apply(t,o));return n&&e(i,n.prototype),i}).apply(null,arguments)}function o(r){var i="function"==typeof Map?new Map:void 0;return(o=function(r){if(null===r||-1===Function.toString.call(r).indexOf("[native code]"))return r;if("function"!=typeof r)throw new TypeError("Super expression must either be null or a function");if(void 0!==i){if(i.has(r))return i.get(r);i.set(r,o)}function o(){return n(r,arguments,t(this).constructor)}return o.prototype=Object.create(r.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),e(o,r)})(r)}function i(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}Object.defineProperty(exports,"__esModule",{value:!0});const c=function(){function t(){}return t.prototype.then=function(e,r){const n=new t,o=this.s;if(o){const t=1&o?e:r;if(t){try{s(n,1,t(this.v))}catch(t){s(n,2,t)}return n}return this}return this.o=function(t){try{const o=t.v;1&t.s?s(n,1,e?e(o):o):r?s(n,1,r(o)):s(n,2,o)}catch(t){s(n,2,t)}},n},t}();function s(t,e,r){if(!t.s){if(r instanceof c){if(!r.s)return void(r.o=s.bind(null,t,e));1&e&&(e=r.s),r=r.v}if(r&&r.then)return void r.then(s.bind(null,t,e),s.bind(null,t,2));t.s=e,t.v=r;const n=t.o;n&&n(t)}}"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var u=function(t,e,r){void 0===r&&(r="json");try{return Promise.resolve(function(t,e){var r,n=-1;t:{for(var o=0;o<e.length;o++){var i=e[o][0];if(i){var u=i();if(u&&u.then)break t;if(u===t){n=o;break}}else n=o}if(-1!==n){do{for(var f=e[n][1];!f;)n++,f=e[n][1];var a=f();if(a&&a.then){r=!0;break t}var l=e[n][2];n++}while(l&&!l());return a}}const h=new c,p=s.bind(null,h,2);return(r?a.then(d):u.then((function r(c){for(;;){if(c===t){n=o;break}if(++o===e.length){if(-1!==n)break;return void s(h,1,f)}if(i=e[o][0]){if((c=i())&&c.then)return void c.then(r).then(void 0,p)}else n=o}do{for(var u=e[n][1];!u;)n++,u=e[n][1];var f=u();if(f&&f.then)return void f.then(d).then(void 0,p);var a=e[n][2];n++}while(a&&!a());s(h,1,f)}))).then(void 0,p),h;function d(t){for(;;){var r=e[n][2];if(!r||r())break;n++;for(var o=e[n][1];!o;)n++,o=e[n][1];if((t=o())&&t.then)return void t.then(d).then(void 0,p)}s(h,1,t)}}(r,[[function(){return"json"},function(){return Promise.resolve(fetch("https://collectednotes.com/"+t+"/"+e+".json")).then((function(t){return t.json()}))}],[function(){return"md"},function(){return Promise.resolve(fetch("https://collectednotes.com/"+t+"/"+e+".md")).then((function(t){return t.text()}))}],[function(){return"txt"},function(){return Promise.resolve(fetch("https://collectednotes.com/"+t+"/"+e+".text")).then((function(t){return t.text()}))}]]))}catch(t){return Promise.reject(t)}},f=function(t){try{return Promise.resolve(fetch("https://collectednotes.com/"+t)).then((function(t){return t.json()}))}catch(t){return Promise.reject(t)}},a=function(t){var e,r;function n(e){var r;return r=t.call(this,e)||this,Object.setPrototypeOf(i(r),n.prototype),Error.captureStackTrace&&Error.captureStackTrace(i(r),n),r}return r=t,(e=n).prototype=Object.create(r.prototype),e.prototype.constructor=e,e.__proto__=r,n}(o(Error));exports.CNError=a,exports.collectedNotes=function(t,e){var r={Authorization:t+" "+e,Accept:"application/json","Content-Type":"application/json"};function n(t){if(!t.startsWith("# "))throw new a("The body must start with `# ` to correctly detect the title and generate the slug.")}return{latestNotes:function(t){try{return Promise.resolve(fetch("https://collectednotes.com/sites/"+t+"/notes",{headers:r})).then((function(t){return t.json()}))}catch(t){return Promise.reject(t)}},sites:function(){try{return Promise.resolve(fetch("https://collectednotes.com/sites",{headers:r})).then((function(t){return t.json()}))}catch(t){return Promise.reject(t)}},site:f,create:function(t,e){var o=e.body,i=e.visibility,c=void 0===i?"private":i;try{return n(o),Promise.resolve(fetch("https://collectednotes.com/sites/"+t+"/notes",{method:"POST",headers:r,body:JSON.stringify({note:{body:o,visibility:c}})})).then((function(t){return t.json()}))}catch(t){return Promise.reject(t)}},read:u,update:function(t,e,o){var i=o.body,c=o.visibility,s=void 0===c?"private":c;try{return n(i),Promise.resolve(fetch("https://collectednotes.com/sites/"+t+"/notes/"+e,{method:"POST",headers:r,body:JSON.stringify({note:{body:i,visibility:s}})})).then((function(t){return t.json()}))}catch(t){return Promise.reject(t)}},destroy:function(t,e){try{return Promise.resolve(fetch("https://collectednotes.com/sites/"+t+"/notes/"+e,{headers:r,method:"DELETE"}))}catch(t){return Promise.reject(t)}},me:function(){try{return Promise.resolve(fetch("https://collectednotes.com/accounts/me",{headers:r})).then((function(t){return t.json()}))}catch(t){return Promise.reject(t)}}}},exports.read=u,exports.site=f; | ||
"use strict";function t(e){return(t=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(e)}function e(t,r){return(e=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,r)}function r(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}function n(t,o,i){return(n=r()?Reflect.construct:function(t,r,n){var o=[null];o.push.apply(o,r);var i=new(Function.bind.apply(t,o));return n&&e(i,n.prototype),i}).apply(null,arguments)}function o(r){var i="function"==typeof Map?new Map:void 0;return(o=function(r){if(null===r||-1===Function.toString.call(r).indexOf("[native code]"))return r;if("function"!=typeof r)throw new TypeError("Super expression must either be null or a function");if(void 0!==i){if(i.has(r))return i.get(r);i.set(r,o)}function o(){return n(r,arguments,t(this).constructor)}return o.prototype=Object.create(r.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),e(o,r)})(r)}function i(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}Object.defineProperty(exports,"__esModule",{value:!0});const c=function(){function t(){}return t.prototype.then=function(e,r){const n=new t,o=this.s;if(o){const t=1&o?e:r;if(t){try{s(n,1,t(this.v))}catch(t){s(n,2,t)}return n}return this}return this.o=function(t){try{const o=t.v;1&t.s?s(n,1,e?e(o):o):r?s(n,1,r(o)):s(n,2,o)}catch(t){s(n,2,t)}},n},t}();function s(t,e,r){if(!t.s){if(r instanceof c){if(!r.s)return void(r.o=s.bind(null,t,e));1&e&&(e=r.s),r=r.v}if(r&&r.then)return void r.then(s.bind(null,t,e),s.bind(null,t,2));t.s=e,t.v=r;const n=t.o;n&&n(t)}}"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var u=function(t,e,r){void 0===r&&(r="json");try{return Promise.resolve(function(t,e){var r,n=-1;t:{for(var o=0;o<e.length;o++){var i=e[o][0];if(i){var u=i();if(u&&u.then)break t;if(u===t){n=o;break}}else n=o}if(-1!==n){do{for(var f=e[n][1];!f;)n++,f=e[n][1];var a=f();if(a&&a.then){r=!0;break t}var l=e[n][2];n++}while(l&&!l());return a}}const h=new c,d=s.bind(null,h,2);return(r?a.then(p):u.then((function r(c){for(;;){if(c===t){n=o;break}if(++o===e.length){if(-1!==n)break;return void s(h,1,f)}if(i=e[o][0]){if((c=i())&&c.then)return void c.then(r).then(void 0,d)}else n=o}do{for(var u=e[n][1];!u;)n++,u=e[n][1];var f=u();if(f&&f.then)return void f.then(p).then(void 0,d);var a=e[n][2];n++}while(a&&!a());s(h,1,f)}))).then(void 0,d),h;function p(t){for(;;){var r=e[n][2];if(!r||r())break;n++;for(var o=e[n][1];!o;)n++,o=e[n][1];if((t=o())&&t.then)return void t.then(p).then(void 0,d)}s(h,1,t)}}(r,[[function(){return"json"},function(){return Promise.resolve(fetch("https://collectednotes.com/"+t+"/"+e+".json")).then((function(t){return t.json()}))}],[function(){return"md"},function(){return Promise.resolve(fetch("https://collectednotes.com/"+t+"/"+e+".md")).then((function(t){return t.text()}))}],[function(){return"txt"},function(){return Promise.resolve(fetch("https://collectednotes.com/"+t+"/"+e+".text")).then((function(t){return t.text()}))}]]))}catch(t){return Promise.reject(t)}},f=function(t){try{return Promise.resolve(fetch("https://collectednotes.com/"+t)).then((function(t){return t.json()}))}catch(t){return Promise.reject(t)}},a=function(t){var e,r;function n(e){var r;return r=t.call(this,e)||this,Object.setPrototypeOf(i(r),n.prototype),Error.captureStackTrace&&Error.captureStackTrace(i(r),n),r}return r=t,(e=n).prototype=Object.create(r.prototype),e.prototype.constructor=e,e.__proto__=r,n}(o(Error));exports.CNError=a,exports.collectedNotes=function(t,e){var r={Authorization:t+" "+e,Accept:"application/json","Content-Type":"application/json"};function n(t){if(!t.startsWith("# "))throw new a("The body must start with `# ` to correctly detect the title and generate the slug.")}return{latestNotes:function(t){try{return Promise.resolve(fetch("https://collectednotes.com/sites/"+t+"/notes",{headers:r})).then((function(t){return t.json()}))}catch(t){return Promise.reject(t)}},sites:function(){try{return Promise.resolve(fetch("https://collectednotes.com/sites",{headers:r})).then((function(t){return t.json()}))}catch(t){return Promise.reject(t)}},site:f,create:function(t,e){var o=e.body,i=e.visibility,c=void 0===i?"private":i;try{return n(o),Promise.resolve(fetch("https://collectednotes.com/sites/"+t+"/notes",{method:"POST",headers:r,body:JSON.stringify({note:{body:o,visibility:c}})})).then((function(t){return t.json()}))}catch(t){return Promise.reject(t)}},read:u,update:function(t,e,o){var i=o.body,c=o.visibility,s=void 0===c?"private":c;try{return n(i),Promise.resolve(fetch("https://collectednotes.com/sites/"+t+"/notes/"+e,{method:"POST",headers:r,body:JSON.stringify({note:{body:i,visibility:s}})})).then((function(t){return t.json()}))}catch(t){return Promise.reject(t)}},destroy:function(t,e){try{return Promise.resolve(fetch("https://collectednotes.com/sites/"+t+"/notes/"+e,{headers:r,method:"DELETE"}))}catch(t){return Promise.reject(t)}},me:function(){try{return Promise.resolve(fetch("https://collectednotes.com/accounts/me",{headers:r})).then((function(t){return t.json()}))}catch(t){return Promise.reject(t)}},reorder:function(t,e){try{return Promise.resolve(fetch("https://collectednotes.com/sites/"+t+"/notes/reorder",{method:"POST",headers:r,body:JSON.stringify({ids:e})})).then((function(t){return t.json()}))}catch(t){return Promise.reject(t)}}}},exports.read=u,exports.site=f; | ||
//# sourceMappingURL=collected-notes.cjs.production.min.js.map |
@@ -337,2 +337,18 @@ function _inheritsLoose(subClass, superClass) { | ||
function collectedNotes(email, token) { | ||
var reorder = function reorder(site, notes) { | ||
try { | ||
return Promise.resolve(fetch("https://collectednotes.com/sites/" + site + "/notes/reorder", { | ||
method: 'POST', | ||
headers: headers, | ||
body: JSON.stringify({ | ||
ids: notes | ||
}) | ||
})).then(function (response) { | ||
return response.json(); | ||
}); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}; | ||
var me = function me() { | ||
@@ -452,3 +468,4 @@ try { | ||
destroy: destroy, | ||
me: me | ||
me: me, | ||
reorder: reorder | ||
}; | ||
@@ -455,0 +472,0 @@ } |
@@ -13,2 +13,5 @@ export interface Note { | ||
url: string; | ||
poster: string | null; | ||
curated: boolean; | ||
ordering: number; | ||
} | ||
@@ -28,2 +31,4 @@ export interface Site { | ||
domain: string; | ||
payment_platform: string | null; | ||
is_premium: boolean; | ||
} | ||
@@ -53,2 +58,3 @@ export interface User { | ||
me(): Promise<User>; | ||
reorder(site: number, notes: number[]): Promise<number[]>; | ||
site(path: string): Promise<{ | ||
@@ -55,0 +61,0 @@ site: Site; |
{ | ||
"name": "collected-notes", | ||
"description": "API wrapper for Collected Notes", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "author": "Sergio Xalambrí", |
@@ -153,2 +153,14 @@ # Collected Notes TS Client | ||
### Reorder notes | ||
You can use the client to reorder your notes. | ||
```ts | ||
const siteId = 1; | ||
const notes: number[] = [2, 3, 1]; | ||
const orderedIds = await cn.reorder(siteId, notes); | ||
``` | ||
The returned orderedIds is an array of the ids in their new order, this will be the same as the notes argument. | ||
### Site and Read | ||
@@ -161,3 +173,3 @@ | ||
const note = await cn.site('sergiodxa', 'using-collected-notes-as-cms', 'json'); | ||
``` | ||
```` | ||
@@ -175,3 +187,3 @@ ## API Types | ||
```ts | ||
interface Note { | ||
export interface Note { | ||
id: number; | ||
@@ -188,5 +200,8 @@ site_id: number; | ||
url: string; | ||
poster: string | null; | ||
curated: boolean; | ||
ordering: number; | ||
} | ||
interface Site { | ||
export interface Site { | ||
id: number; | ||
@@ -204,5 +219,7 @@ user_id: number; | ||
domain: string; | ||
payment_platform: string | null; | ||
is_premium: boolean; | ||
} | ||
interface User { | ||
export interface User { | ||
id: number; | ||
@@ -209,0 +226,0 @@ email: string; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
152894
1203
230
33