next-tinacms-github
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -6,2 +6,13 @@ # Change Log | ||
## [0.1.1](https://github.com/tinacms/tinacms/compare/next-tinacms-github@0.1.0...next-tinacms-github@0.1.1) (2020-05-25) | ||
### Bug Fixes | ||
* fixed setting github working branch ([59b8c81](https://github.com/tinacms/tinacms/commit/59b8c81)) | ||
# [0.1.0](https://github.com/tinacms/tinacms/compare/next-tinacms-github@0.1.0-canary4.1...next-tinacms-github@0.1.0) (2020-04-27) | ||
@@ -8,0 +19,0 @@ |
@@ -52,3 +52,3 @@ 'use strict'; | ||
github_access_token: req.cookies[ACCESS_TOKEN_KEY], | ||
head_branch: req.cookies[HEAD_BRANCH_KEY] || 'master' | ||
head_branch: req.cookies[HEAD_BRANCH_KEY] || process.env.BASE_BRANCH || 'master' | ||
}; | ||
@@ -55,0 +55,0 @@ res.setPreviewData(previewData); |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,e=require("cookie"),r=(t=require("gray-matter"))&&"object"==typeof t&&"default"in t?t.default:t,n=require("qs"),o=require("axios");function a(){return(a=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function i(t){return(i=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function u(t,e){return(u=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function c(){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 s(t,e,r){return(s=c()?Reflect.construct:function(t,e,r){var n=[null];n.push.apply(n,e);var o=new(Function.bind.apply(t,n));return r&&u(o,r.prototype),o}).apply(null,arguments)}function f(t){var e="function"==typeof Map?new Map:void 0;return(f=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return s(t,arguments,i(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),u(r,t)})(t)}var l=require("axios"),p=require("axios"),h=function(t,e,r,n){try{return Promise.resolve(p({method:"GET",url:"https://api.github.com/repos/"+t+"/contents/"+r+"?ref="+e,headers:{Authorization:"token "+n}}))}catch(t){return Promise.reject(t)}};function d(t,e){try{var r=t()}catch(t){return e(t)}return r&&r.then?r.then(void 0,e):r}"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var y=function(t){var e,r;function n(e,r){var n;return(n=t.call(this,e)||this).message=e,n.status=r,n}return r=t,(e=n).prototype=Object.create(r.prototype),e.prototype.constructor=e,e.__proto__=r,n}(f(Error)),v=require("atob");exports.GithubError=y,exports.apiProxy=function(t,e){var r=JSON.parse(t.body),n=r.headers,o=function(t,e){if(null==t)return{};var r,n,o={},a=Object.keys(t);for(n=0;n<a.length;n++)e.indexOf(r=a[n])>=0||(o[r]=t[r]);return o}(r,["headers"]);l(a({},o,{headers:a({},n,{Authorization:"token "+t.cookies.github_access_token})})).then((function(t){e.status(t.status).json(t.data)})).catch((function(t){e.status(t.response.status).json(t.response.data)}))},exports.createAuthHandler=function(t,r){return function(a,i){(function(t,e,r,a){return o.post("https://github.com/login/oauth/access_token",n.stringify({client_id:t,client_secret:e,code:r,state:a}))})(t,r,a.query.code,a.query.state).then((function(t){var r=n.parse(t.data),o=r.access_token,a=r.error;a?i.status(400).json({error:a}):(i.setHeader("Set-Cookie",e.serialize("github_access_token",o,{path:"/",httpOnly:!0})),i.status(200).json({}))}))}},exports.getContent=h,exports.getFiles=function(t,e,r,n){try{var o,a=function(t){return i?t:o.filter((function(t){return"file"===t.type})).map((function(t){return t.path}))},i=!1,u=d((function(){return Promise.resolve(h(e,r||"master",t,n)).then((function(t){o=t.data}))}),(function(t){var e,r=(null===(e=t.response)||void 0===e?void 0:e.status)||500;throw new y("Failed to get data.",r)}));return Promise.resolve(u&&u.then?u.then(a):a(u))}catch(t){return Promise.reject(t)}},exports.getGithubPreviewProps=function(t){try{var e=function(t){return r?t:{props:{file:c,repoFullName:o,branch:i,preview:!0,error:u}}},r=!1,n=t.github_access_token,o=t.working_repo_full_name||"",i=t.head_branch||"master",u=null,c=null,s=d((function(){return Promise.resolve(function(t,e,r,n){try{var o=function(t){return i?t:a({},u,{content:(e=u.content,decodeURIComponent(v(e).split("").map((function(t){return"%"+("00"+t.charCodeAt(0).toString(16)).slice(-2)})).join("")))});var e},i=!1,u=null,c=d((function(){return Promise.resolve(h(t,e,r,n)).then((function(t){u=t.data}))}),(function(t){var e,r=(null===(e=t.response)||void 0===e?void 0:e.status)||500;throw new y("Failed to get data.",r)}));return Promise.resolve(c&&c.then?c.then(o):o(c))}catch(t){return Promise.reject(t)}}(o,i,t.fileRelativePath,n)).then((function(e){c={sha:e.sha,fileRelativePath:t.fileRelativePath,data:t.parse(e.content)}}))}),(function(e){if(!(e instanceof y))throw e;var r;console.error("next-tinacms-github: Failed to fetch file from GitHub\n- file: \t"+(r={path:t.fileRelativePath,repoFullName:o,branch:i,accessToken:n}).path+"\n- repo: \t"+r.repoFullName+"\n- branch: \t"+r.branch+"\n- accessToken: \t"+(r.accessToken?"******":"undefined")+"\n"),console.error(e),u=a({},e)}));return Promise.resolve(s&&s.then?s.then(e):e(s))}catch(t){return Promise.reject(t)}},exports.parseJson=function(t){return JSON.parse(t)},exports.parseMarkdown=function(t){var e=r(t);return{markdownBody:e.content,frontmatter:e.data}},exports.previewHandler=function(t,e){e.setPreviewData({working_repo_full_name:t.cookies.working_repo_full_name,github_access_token:t.cookies.github_access_token,head_branch:t.cookies.head_branch||"master"}),e.status(200).end()}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,e=require("cookie"),r=(t=require("gray-matter"))&&"object"==typeof t&&"default"in t?t.default:t,n=require("qs"),o=require("axios");function a(){return(a=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function i(t){return(i=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function u(t,e){return(u=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function c(){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 s(t,e,r){return(s=c()?Reflect.construct:function(t,e,r){var n=[null];n.push.apply(n,e);var o=new(Function.bind.apply(t,n));return r&&u(o,r.prototype),o}).apply(null,arguments)}function f(t){var e="function"==typeof Map?new Map:void 0;return(f=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return s(t,arguments,i(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),u(r,t)})(t)}var l=require("axios"),p=require("axios"),h=function(t,e,r,n){try{return Promise.resolve(p({method:"GET",url:"https://api.github.com/repos/"+t+"/contents/"+r+"?ref="+e,headers:{Authorization:"token "+n}}))}catch(t){return Promise.reject(t)}};function d(t,e){try{var r=t()}catch(t){return e(t)}return r&&r.then?r.then(void 0,e):r}"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var y=function(t){var e,r;function n(e,r){var n;return(n=t.call(this,e)||this).message=e,n.status=r,n}return r=t,(e=n).prototype=Object.create(r.prototype),e.prototype.constructor=e,e.__proto__=r,n}(f(Error)),v=require("atob");exports.GithubError=y,exports.apiProxy=function(t,e){var r=JSON.parse(t.body),n=r.headers,o=function(t,e){if(null==t)return{};var r,n,o={},a=Object.keys(t);for(n=0;n<a.length;n++)e.indexOf(r=a[n])>=0||(o[r]=t[r]);return o}(r,["headers"]);l(a({},o,{headers:a({},n,{Authorization:"token "+t.cookies.github_access_token})})).then((function(t){e.status(t.status).json(t.data)})).catch((function(t){e.status(t.response.status).json(t.response.data)}))},exports.createAuthHandler=function(t,r){return function(a,i){(function(t,e,r,a){return o.post("https://github.com/login/oauth/access_token",n.stringify({client_id:t,client_secret:e,code:r,state:a}))})(t,r,a.query.code,a.query.state).then((function(t){var r=n.parse(t.data),o=r.access_token,a=r.error;a?i.status(400).json({error:a}):(i.setHeader("Set-Cookie",e.serialize("github_access_token",o,{path:"/",httpOnly:!0})),i.status(200).json({}))}))}},exports.getContent=h,exports.getFiles=function(t,e,r,n){try{var o,a=function(t){return i?t:o.filter((function(t){return"file"===t.type})).map((function(t){return t.path}))},i=!1,u=d((function(){return Promise.resolve(h(e,r||"master",t,n)).then((function(t){o=t.data}))}),(function(t){var e,r=(null===(e=t.response)||void 0===e?void 0:e.status)||500;throw new y("Failed to get data.",r)}));return Promise.resolve(u&&u.then?u.then(a):a(u))}catch(t){return Promise.reject(t)}},exports.getGithubPreviewProps=function(t){try{var e=function(t){return r?t:{props:{file:c,repoFullName:o,branch:i,preview:!0,error:u}}},r=!1,n=t.github_access_token,o=t.working_repo_full_name||"",i=t.head_branch||"master",u=null,c=null,s=d((function(){return Promise.resolve(function(t,e,r,n){try{var o=function(t){return i?t:a({},u,{content:(e=u.content,decodeURIComponent(v(e).split("").map((function(t){return"%"+("00"+t.charCodeAt(0).toString(16)).slice(-2)})).join("")))});var e},i=!1,u=null,c=d((function(){return Promise.resolve(h(t,e,r,n)).then((function(t){u=t.data}))}),(function(t){var e,r=(null===(e=t.response)||void 0===e?void 0:e.status)||500;throw new y("Failed to get data.",r)}));return Promise.resolve(c&&c.then?c.then(o):o(c))}catch(t){return Promise.reject(t)}}(o,i,t.fileRelativePath,n)).then((function(e){c={sha:e.sha,fileRelativePath:t.fileRelativePath,data:t.parse(e.content)}}))}),(function(e){if(!(e instanceof y))throw e;var r;console.error("next-tinacms-github: Failed to fetch file from GitHub\n- file: \t"+(r={path:t.fileRelativePath,repoFullName:o,branch:i,accessToken:n}).path+"\n- repo: \t"+r.repoFullName+"\n- branch: \t"+r.branch+"\n- accessToken: \t"+(r.accessToken?"******":"undefined")+"\n"),console.error(e),u=a({},e)}));return Promise.resolve(s&&s.then?s.then(e):e(s))}catch(t){return Promise.reject(t)}},exports.parseJson=function(t){return JSON.parse(t)},exports.parseMarkdown=function(t){var e=r(t);return{markdownBody:e.content,frontmatter:e.data}},exports.previewHandler=function(t,e){var r={working_repo_full_name:t.cookies.working_repo_full_name,github_access_token:t.cookies.github_access_token,head_branch:t.cookies.head_branch||process.env.BASE_BRANCH||"master"};e.setPreviewData(r),e.status(200).end()}; | ||
//# sourceMappingURL=next-tinacms-github.cjs.production.min.js.map |
@@ -46,3 +46,3 @@ import { serialize } from 'cookie'; | ||
github_access_token: req.cookies[ACCESS_TOKEN_KEY], | ||
head_branch: req.cookies[HEAD_BRANCH_KEY] || 'master' | ||
head_branch: req.cookies[HEAD_BRANCH_KEY] || process.env.BASE_BRANCH || 'master' | ||
}; | ||
@@ -49,0 +49,0 @@ res.setPreviewData(previewData); |
{ | ||
"name": "next-tinacms-github", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "", | ||
@@ -25,3 +25,3 @@ "main": "dist/index.js", | ||
}, | ||
"gitHead": "5e813337106c8f4a23dc33aa8ce56f79afa2d528" | ||
"gitHead": "e4789eefc0dc6aeef08d397884f68766644df0ae" | ||
} |
@@ -121,2 +121,2 @@ # next-tinacms-github | ||
Now that we have configured our backend API functions to manage our Github authentication token, we will need to configure the front-end to use these endpoints. | ||
You may want to use the [next-tinacms-github](https://github.com/tinacms/tinacms/tree/master/packages/react-tinacms-github) package. | ||
You may want to use the [react-tinacms-github](https://github.com/tinacms/tinacms/tree/master/packages/react-tinacms-github) package. |
@@ -29,3 +29,4 @@ /** | ||
github_access_token: req.cookies[ACCESS_TOKEN_KEY], | ||
head_branch: req.cookies[HEAD_BRANCH_KEY] || 'master', | ||
head_branch: | ||
req.cookies[HEAD_BRANCH_KEY] || process.env.BASE_BRANCH || 'master', | ||
} | ||
@@ -32,0 +33,0 @@ res.setPreviewData(previewData) |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
208715
1606
5