From 80e9b63fa9cad55ab31cd0a7c2ef192f591ffcc1 Mon Sep 17 00:00:00 2001 From: Tony Spiro Date: Wed, 20 Jan 2021 14:48:52 -0600 Subject: [PATCH] update readme :eyes: --- API.md | 16 ++++++++ cosmicjs.browser.min.js | 2 +- dist/bucket/object.js | 85 ++++++++++++++++++++++++++++++++++++++++- package-lock.json | 6 ++- package.json | 3 +- src/bucket/object.js | 64 +++++++++++++++++++++++++++++++ 6 files changed, 171 insertions(+), 5 deletions(-) diff --git a/API.md b/API.md index 946d997..31741638 100644 --- a/API.md +++ b/API.md @@ -291,6 +291,22 @@ bucket.getObjects(params).then(data => { }) ``` +### Get Merge Request Objects [[View Blog Announcement](https://www.cosmicjs.com/blog/introducing-merge-requests)] +Get Objects included in a [Merge Request](https://www.cosmicjs.com/blog/introducing-merge-requests). Same query params options available as `getObjects`. +```javascript +const Cosmic = require('cosmicjs') +const api = Cosmic() +const bucket = api.bucket({ + slug: 'target-bucket-slug', + read_key: 'target-bucket-read-key' +}) +const data = await bucket.getMergeRequestObjects({ + id: 'merge-request-id-found-in-dashboard', + props: 'slug,title,content' // use props to limit response payload +}) +``` +Use these Objects to then overright Objects from the target Bucket response based on unique `slug` and `locale` identifiers. An example of this logic can be found in the [Next Merge template](https://github.com/cosmicjs/next-merge/blob/master/lib/merge.js#L19). + #### Get Single Object [[View Docs](https://docs.cosmicjs.com/rest-api/objects.html#get-object)] Returns a single Object from your Bucket. ```javascript diff --git a/cosmicjs.browser.min.js b/cosmicjs.browser.min.js index ab472c4..90ed736 100644 --- a/cosmicjs.browser.min.js +++ b/cosmicjs.browser.min.js @@ -1 +1 @@ -!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=15)}([function(e,t,n){"use strict";var r=n(4),o=Object.prototype.toString;function c(e){return"[object Array]"===o.call(e)}function a(e){return void 0===e}function i(e){return null!==e&&"object"==typeof e}function s(e){return"[object Function]"===o.call(e)}function u(e,t){if(null!=e)if("object"!=typeof e&&(e=[e]),c(e))for(var n=0,r=e.length;n=200&&e<300}};s.headers={common:{Accept:"application/json, text/plain, */*"}},r.forEach(["delete","get","head"],(function(e){s.headers[e]={}})),r.forEach(["post","put","patch"],(function(e){s.headers[e]=r.merge(c)})),e.exports=s}).call(this,n(8))},function(e,t){var n,r,o=e.exports={};function c(){throw new Error("setTimeout has not been defined")}function a(){throw new Error("clearTimeout has not been defined")}function i(e){if(n===setTimeout)return setTimeout(e,0);if((n===c||!n)&&setTimeout)return n=setTimeout,setTimeout(e,0);try{return n(e,0)}catch(t){try{return n.call(null,e,0)}catch(t){return n.call(this,e,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:c}catch(e){n=c}try{r="function"==typeof clearTimeout?clearTimeout:a}catch(e){r=a}}();var s,u=[],f=!1,p=-1;function l(){f&&s&&(f=!1,s.length?u=s.concat(u):p=-1,u.length&&d())}function d(){if(!f){var e=i(l);f=!0;for(var t=u.length;t;){for(s=u,u=[];++p1)for(var n=1;n=0)return;a[t]="set-cookie"===t?(a[t]?a[t]:[]).concat([n]):a[t]?a[t]+", "+n:n}})),a):a}},function(e,t,n){"use strict";var r=n(0);e.exports=r.isStandardBrowserEnv()?function(){var e,t=/(msie|trident)/i.test(navigator.userAgent),n=document.createElement("a");function o(e){var r=e;return t&&(n.setAttribute("href",r),r=n.href),n.setAttribute("href",r),{href:n.href,protocol:n.protocol?n.protocol.replace(/:$/,""):"",host:n.host,search:n.search?n.search.replace(/^\?/,""):"",hash:n.hash?n.hash.replace(/^#/,""):"",hostname:n.hostname,port:n.port,pathname:"/"===n.pathname.charAt(0)?n.pathname:"/"+n.pathname}}return e=o(window.location.href),function(t){var n=r.isString(t)?o(t):t;return n.protocol===e.protocol&&n.host===e.host}}():function(){return!0}},function(e,t,n){"use strict";var r=n(0);e.exports=r.isStandardBrowserEnv()?{write:function(e,t,n,o,c,a){var i=[];i.push(e+"="+encodeURIComponent(t)),r.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),r.isString(o)&&i.push("path="+o),r.isString(c)&&i.push("domain="+c),!0===a&&i.push("secure"),document.cookie=i.join("; ")},read:function(e){var t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove:function(e){this.write(e,"",Date.now()-864e5)}}:{write:function(){},read:function(){return null},remove:function(){}}},function(e,t,n){"use strict";var r=n(12);function o(e){if("function"!=typeof e)throw new TypeError("executor must be a function.");var t;this.promise=new Promise((function(e){t=e}));var n=this;e((function(e){n.reason||(n.reason=new r(e),t(n.reason))}))}o.prototype.throwIfRequested=function(){if(this.reason)throw this.reason},o.source=function(){var e;return{token:new o((function(t){e=t})),cancel:e}},e.exports=o},function(e,t,n){"use strict";e.exports=function(e){return function(t){return e.apply(null,t)}}},function(e,t,n){var r=n(2),o=n(1).requestHandler,c=n(3).URI,a={authenticate:function(e){var t="".concat(c,"/authenticate");return o(r.POST,t,e)},getBuckets:function(){var e="".concat(c,"/buckets");return o(r.GET,e)},addBucket:function(e){var t="".concat(c,"/buckets");return o(r.POST,t,e)},deleteBucket:function(e){var t="".concat(c,"/buckets/").concat(e.id);return o(r.DELETE,t,e)},importBucket:function(e){var t="".concat(c,"/buckets/").concat(e.id,"/import");return o(r.POST,t,e)},deployApp:function(e){var t="".concat(c,"/buckets/").concat(e.id,"/deploy");return o(r.POST,t,e)}};e.exports=a},function(e,t,n){function r(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function o(e){for(var t=1;t=200&&e<300}};s.headers={common:{Accept:"application/json, text/plain, */*"}},r.forEach(["delete","get","head"],(function(e){s.headers[e]={}})),r.forEach(["post","put","patch"],(function(e){s.headers[e]=r.merge(c)})),e.exports=s}).call(this,n(8))},function(e,t){var n,r,o=e.exports={};function c(){throw new Error("setTimeout has not been defined")}function a(){throw new Error("clearTimeout has not been defined")}function i(e){if(n===setTimeout)return setTimeout(e,0);if((n===c||!n)&&setTimeout)return n=setTimeout,setTimeout(e,0);try{return n(e,0)}catch(t){try{return n.call(null,e,0)}catch(t){return n.call(this,e,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:c}catch(e){n=c}try{r="function"==typeof clearTimeout?clearTimeout:a}catch(e){r=a}}();var s,u=[],f=!1,l=-1;function p(){f&&s&&(f=!1,s.length?u=s.concat(u):l=-1,u.length&&d())}function d(){if(!f){var e=i(p);f=!0;for(var t=u.length;t;){for(s=u,u=[];++l1)for(var n=1;n=0)return;a[t]="set-cookie"===t?(a[t]?a[t]:[]).concat([n]):a[t]?a[t]+", "+n:n}})),a):a}},function(e,t,n){"use strict";var r=n(0);e.exports=r.isStandardBrowserEnv()?function(){var e,t=/(msie|trident)/i.test(navigator.userAgent),n=document.createElement("a");function o(e){var r=e;return t&&(n.setAttribute("href",r),r=n.href),n.setAttribute("href",r),{href:n.href,protocol:n.protocol?n.protocol.replace(/:$/,""):"",host:n.host,search:n.search?n.search.replace(/^\?/,""):"",hash:n.hash?n.hash.replace(/^#/,""):"",hostname:n.hostname,port:n.port,pathname:"/"===n.pathname.charAt(0)?n.pathname:"/"+n.pathname}}return e=o(window.location.href),function(t){var n=r.isString(t)?o(t):t;return n.protocol===e.protocol&&n.host===e.host}}():function(){return!0}},function(e,t,n){"use strict";var r=n(0);e.exports=r.isStandardBrowserEnv()?{write:function(e,t,n,o,c,a){var i=[];i.push(e+"="+encodeURIComponent(t)),r.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),r.isString(o)&&i.push("path="+o),r.isString(c)&&i.push("domain="+c),!0===a&&i.push("secure"),document.cookie=i.join("; ")},read:function(e){var t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove:function(e){this.write(e,"",Date.now()-864e5)}}:{write:function(){},read:function(){return null},remove:function(){}}},function(e,t,n){"use strict";var r=n(12);function o(e){if("function"!=typeof e)throw new TypeError("executor must be a function.");var t;this.promise=new Promise((function(e){t=e}));var n=this;e((function(e){n.reason||(n.reason=new r(e),t(n.reason))}))}o.prototype.throwIfRequested=function(){if(this.reason)throw this.reason},o.source=function(){var e;return{token:new o((function(t){e=t})),cancel:e}},e.exports=o},function(e,t,n){"use strict";e.exports=function(e){return function(t){return e.apply(null,t)}}},function(e,t,n){var r=n(2),o=n(1).requestHandler,c=n(3).URI,a={authenticate:function(e){var t="".concat(c,"/authenticate");return o(r.POST,t,e)},getBuckets:function(){var e="".concat(c,"/buckets");return o(r.GET,e)},addBucket:function(e){var t="".concat(c,"/buckets");return o(r.POST,t,e)},deleteBucket:function(e){var t="".concat(c,"/buckets/").concat(e.id);return o(r.DELETE,t,e)},importBucket:function(e){var t="".concat(c,"/buckets/").concat(e.id,"/import");return o(r.POST,t,e)},deployApp:function(e){var t="".concat(c,"/buckets/").concat(e.id,"/deploy");return o(r.POST,t,e)}};e.exports=a},function(e,t,n){function r(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function o(e){for(var t=1;t ({ } return requestHandler(HTTP_METHODS.GET, endpoint) }, + getMergeRequestObjects: (params) => { + let endpoint = `${URI}/${bucket_config.slug}/merge-requests/${params.id}/objects?read_key=${bucket_config.read_key}` + if (params && params.limit) { + endpoint += `&limit=${params.limit}` + } + if (params && params.skip) { + endpoint += `&skip=${params.skip}` + } + if (params && params.locale) { + endpoint += `&locale=${params.locale}` + } + if (params && params.status) { + endpoint += `&status=${params.status}` + } + if (params && params.sort) { + endpoint += `&sort=${params.sort}` + } + // Type param + if (params && params.type) { + endpoint += `&type=${params.type}` + } + // Search params + if (params && params.q) { + endpoint += `&q=${params.q}` + } + if (params && params.metafield_key) { + endpoint += `&metafield_key=${params.metafield_key}` + } + if (params && params.metafield_value) { + endpoint += `&metafield_value=${params.metafield_value}` + } + if (params && params.metafield_object_id) { + endpoint += `&metafield_object_id=${params.metafield_object_id}` + } + if (params && params.hide_metafields) { + endpoint += `&hide_metafields=${params.hide_metafields}` + } + if (params && params.pretty) { + endpoint += `&pretty=${params.pretty}` + } + if (params && params.filters) { + Object.keys(params.filters).forEach((key) => { + endpoint += `&filters[${key}]=${params.filters[key]}` + }) + } + if (params && params.metadata) { + Object.keys(params.metadata).forEach((key) => { + endpoint += `&metadata[${key}]=${params.metadata[key]}` + }) + } + if (params && params.props) { + endpoint += `&props=${params.props}` + } + if (params && typeof params.created_by !== 'undefined') { + endpoint += `&created_by=${params.created_by}` + } + if (params && typeof params.depth !== 'undefined') { + endpoint += `&depth=${params.depth}` + } + if (params && params.query) { + endpoint += `&query=${encodeURI(JSON.stringify(params.query))}` + } + return requestHandler(HTTP_METHODS.GET, endpoint) + }, addObject: (params) => { const endpoint = `${URI}/${bucket_config.slug}/add-object` if (bucket_config.write_key) {