next-tinacms-github
Advanced tools
Comparing version 0.0.2-canary4 to 0.0.2-canary4.0
@@ -21,1 +21,2 @@ /** | ||
export * from './github/proxy'; | ||
export * from './github/content'; |
@@ -5,3 +5,6 @@ 'use strict'; | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var cookie = require('cookie'); | ||
var matter = _interopDefault(require('gray-matter')); | ||
@@ -110,2 +113,92 @@ /** | ||
function _inheritsLoose(subClass, superClass) { | ||
subClass.prototype = Object.create(superClass.prototype); | ||
subClass.prototype.constructor = subClass; | ||
subClass.__proto__ = superClass; | ||
} | ||
function _getPrototypeOf(o) { | ||
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { | ||
return o.__proto__ || Object.getPrototypeOf(o); | ||
}; | ||
return _getPrototypeOf(o); | ||
} | ||
function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { | ||
o.__proto__ = p; | ||
return o; | ||
}; | ||
return _setPrototypeOf(o, p); | ||
} | ||
function isNativeReflectConstruct() { | ||
if (typeof Reflect === "undefined" || !Reflect.construct) return false; | ||
if (Reflect.construct.sham) return false; | ||
if (typeof Proxy === "function") return true; | ||
try { | ||
Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
function _construct(Parent, args, Class) { | ||
if (isNativeReflectConstruct()) { | ||
_construct = Reflect.construct; | ||
} else { | ||
_construct = function _construct(Parent, args, Class) { | ||
var a = [null]; | ||
a.push.apply(a, args); | ||
var Constructor = Function.bind.apply(Parent, a); | ||
var instance = new Constructor(); | ||
if (Class) _setPrototypeOf(instance, Class.prototype); | ||
return instance; | ||
}; | ||
} | ||
return _construct.apply(null, arguments); | ||
} | ||
function _isNativeFunction(fn) { | ||
return Function.toString.call(fn).indexOf("[native code]") !== -1; | ||
} | ||
function _wrapNativeSuper(Class) { | ||
var _cache = typeof Map === "function" ? new Map() : undefined; | ||
_wrapNativeSuper = function _wrapNativeSuper(Class) { | ||
if (Class === null || !_isNativeFunction(Class)) return Class; | ||
if (typeof Class !== "function") { | ||
throw new TypeError("Super expression must either be null or a function"); | ||
} | ||
if (typeof _cache !== "undefined") { | ||
if (_cache.has(Class)) return _cache.get(Class); | ||
_cache.set(Class, Wrapper); | ||
} | ||
function Wrapper() { | ||
return _construct(Class, arguments, _getPrototypeOf(this).constructor); | ||
} | ||
Wrapper.prototype = Object.create(Class.prototype, { | ||
constructor: { | ||
value: Wrapper, | ||
enumerable: false, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
return _setPrototypeOf(Wrapper, Class); | ||
}; | ||
return _wrapNativeSuper(Class); | ||
} | ||
function _objectWithoutPropertiesLoose(source, excluded) { | ||
@@ -165,5 +258,249 @@ if (source == null) return {}; | ||
/** | ||
Copyright 2019 Forestry.io Inc | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
var axios$2 = | ||
/*#__PURE__*/ | ||
require('axios'); | ||
var getContent = function getContent(repoFullName, headBranch, path, accessToken) { | ||
try { | ||
return Promise.resolve(axios$2({ | ||
method: 'GET', | ||
url: "https://api.github.com/repos/" + repoFullName + "/contents/" + path + "?ref=" + headBranch, | ||
headers: { | ||
Authorization: 'token ' + accessToken | ||
} | ||
})); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}; | ||
// A type of promise-like that resolves synchronously and supports only one observer | ||
var _iteratorSymbol = | ||
/*#__PURE__*/ | ||
typeof Symbol !== "undefined" ? Symbol.iterator || (Symbol.iterator = | ||
/*#__PURE__*/ | ||
Symbol("Symbol.iterator")) : "@@iterator"; // Asynchronously iterate through an object's values | ||
var _asyncIteratorSymbol = | ||
/*#__PURE__*/ | ||
typeof Symbol !== "undefined" ? Symbol.asyncIterator || (Symbol.asyncIterator = | ||
/*#__PURE__*/ | ||
Symbol("Symbol.asyncIterator")) : "@@asyncIterator"; // Asynchronously iterate on a value using it's async iterator if present, or its synchronous iterator if missing | ||
function _catch(body, recover) { | ||
try { | ||
var result = body(); | ||
} catch (e) { | ||
return recover(e); | ||
} | ||
if (result && result.then) { | ||
return result.then(void 0, recover); | ||
} | ||
return result; | ||
} // Asynchronously await a promise and pass the result to a finally continuation | ||
/** | ||
Copyright 2019 Forestry.io Inc | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
var GithubError = | ||
/*#__PURE__*/ | ||
function (_Error) { | ||
_inheritsLoose(GithubError, _Error); | ||
function GithubError(message, status) { | ||
var _this; | ||
_this = _Error.call(this, message) || this; | ||
_this.message = message; | ||
_this.status = status; | ||
return _this; | ||
} | ||
return GithubError; | ||
}( | ||
/*#__PURE__*/ | ||
_wrapNativeSuper(Error)); | ||
var getFiles = function getFiles(filePath, sourceProviderConnection, accessToken) { | ||
try { | ||
var _temp3 = function _temp3(_result) { | ||
return _exit2 ? _result : data.filter(function (file) { | ||
return file.type === 'file'; | ||
}).map(function (file) { | ||
return file.path; | ||
}); | ||
}; | ||
var _exit2 = false; | ||
var data; | ||
var _temp4 = _catch(function () { | ||
; | ||
return Promise.resolve(getContent(sourceProviderConnection.forkFullName, sourceProviderConnection.headBranch || 'master', filePath, accessToken)).then(function (_getContent) { | ||
data = _getContent.data; | ||
}); | ||
}, function (e) { | ||
var _e$response; | ||
var errorStatus = ((_e$response = e.response) === null || _e$response === void 0 ? void 0 : _e$response.status) || 500; | ||
throw new GithubError('Failed to get data.', errorStatus); | ||
}); | ||
return Promise.resolve(_temp4 && _temp4.then ? _temp4.then(_temp3) : _temp3(_temp4)); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}; | ||
var atob = | ||
/*#__PURE__*/ | ||
require('atob'); | ||
var b64DecodeUnicode = function b64DecodeUnicode(str) { | ||
// Going backwards: from bytestream, to percent-encoding, to original string. | ||
return decodeURIComponent(atob(str).split('').map(function (c) { | ||
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); | ||
}).join('')); | ||
}; // TODO - this name kinda sucks, | ||
// Throw a formatted error on 404, and decode github data properly | ||
var getDecodedData = function getDecodedData(repoFullName, headBranch, path, accessToken) { | ||
try { | ||
var _temp3 = function _temp3(_result) { | ||
return _exit2 ? _result : _extends({}, data, { | ||
content: b64DecodeUnicode(data.content) | ||
}); | ||
}; | ||
var _exit2 = false; | ||
var data = null; | ||
var _temp4 = _catch(function () { | ||
; | ||
return Promise.resolve(getContent(repoFullName, headBranch, path, accessToken)).then(function (_getContent) { | ||
data = _getContent.data; | ||
}); | ||
}, function (e) { | ||
var _e$response; | ||
var errorStatus = ((_e$response = e.response) === null || _e$response === void 0 ? void 0 : _e$response.status) || 500; | ||
throw new GithubError('Failed to get data.', errorStatus); | ||
}); | ||
return Promise.resolve(_temp4 && _temp4.then ? _temp4.then(_temp3) : _temp3(_temp4)); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}; | ||
/** | ||
Copyright 2019 Forestry.io Inc | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
var getJsonFile = function getJsonFile(filePath, sourceProviderConnection, accessToken) { | ||
try { | ||
return Promise.resolve(getDecodedData(sourceProviderConnection.forkFullName, sourceProviderConnection.headBranch || 'master', filePath, accessToken)).then(function (response) { | ||
return { | ||
sha: response.sha, | ||
fileRelativePath: filePath, | ||
data: JSON.parse(response.content) | ||
}; | ||
}); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}; | ||
/** | ||
Copyright 2019 Forestry.io Inc | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
var getMarkdownFile = function getMarkdownFile(filePath, sourceProviderConnection, accessToken) { | ||
try { | ||
return Promise.resolve(getDecodedData(sourceProviderConnection.forkFullName, sourceProviderConnection.headBranch || 'master', filePath, accessToken)).then(function (response) { | ||
var _matter = matter(response.content), | ||
markdownBody = _matter.content, | ||
frontmatter = _matter.data; | ||
return { | ||
sha: response.sha, | ||
fileRelativePath: filePath, | ||
data: { | ||
frontmatter: frontmatter, | ||
markdownBody: markdownBody | ||
} | ||
}; | ||
}); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}; | ||
exports.GithubError = GithubError; | ||
exports.createCreateAccessTokenFn = createCreateAccessTokenFn; | ||
exports.createPreviewFn = createPreviewFn; | ||
exports.createProxy = createProxy; | ||
exports.getContent = getContent; | ||
exports.getFiles = getFiles; | ||
exports.getJsonFile = getJsonFile; | ||
exports.getMarkdownFile = getMarkdownFile; | ||
//# sourceMappingURL=next-tinacms-github.cjs.development.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("cookie"),t=require("qs"),r=require("axios");function n(){return(n=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}var s=require("axios");exports.createCreateAccessTokenFn=function(n,s){return function(o,a){(function(e,n,s,o){return r.post("https://github.com/login/oauth/access_token",t.stringify({client_id:e,client_secret:n,code:s,state:o}))})(n,s,o.query.code,o.query.state).then((function(r){var n=t.parse(r.data),s=n.access_token,o=n.error;o?a.status(400).json({error:o}):(a.setHeader("Set-Cookie",e.serialize("github_access_token",s,{path:"/",httpOnly:!0})),a.status(200).json({}))}))}},exports.createPreviewFn=function(e,t,r){return function(n,s){s.setPreviewData({fork_full_name:n.cookies[e],github_access_token:n.cookies[r],head_branch:n.cookies[t]||"master"}),s.status(200).end()}},exports.createProxy=function(e){return function(t,r){var o=JSON.parse(t.body),a=o.headers,i=function(e,t){if(null==e)return{};var r,n,s={},o=Object.keys(e);for(n=0;n<o.length;n++)t.indexOf(r=o[n])>=0||(s[r]=e[r]);return s}(o,["headers"]);s(n({},i,{headers:n({},a,{Authorization:"token "+t.cookies[e]})})).then((function(e){r.status(e.status).json(e.data)})).catch((function(e){r.status(e.response.status).json(e.response.data)}))}}; | ||
"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 u(t){return(u=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function i(t,e){return(i=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&&i(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,u(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),i(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 y(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 d=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)),m=require("atob"),v=function(t,e,r,n){try{var o=function(t){return u?t:a({},i,{content:(e=i.content,decodeURIComponent(m(e).split("").map((function(t){return"%"+("00"+t.charCodeAt(0).toString(16)).slice(-2)})).join("")))});var e},u=!1,i=null,c=y((function(){return Promise.resolve(h(t,e,r,n)).then((function(t){i=t.data}))}),(function(t){var e,r=(null===(e=t.response)||void 0===e?void 0:e.status)||500;throw new d("Failed to get data.",r)}));return Promise.resolve(c&&c.then?c.then(o):o(c))}catch(t){return Promise.reject(t)}};exports.GithubError=d,exports.createCreateAccessTokenFn=function(t,r){return function(a,u){(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?u.status(400).json({error:a}):(u.setHeader("Set-Cookie",e.serialize("github_access_token",o,{path:"/",httpOnly:!0})),u.status(200).json({}))}))}},exports.createPreviewFn=function(t,e,r){return function(n,o){o.setPreviewData({fork_full_name:n.cookies[t],github_access_token:n.cookies[r],head_branch:n.cookies[e]||"master"}),o.status(200).end()}},exports.createProxy=function(t){return function(e,r){var n=JSON.parse(e.body),o=n.headers,u=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}(n,["headers"]);l(a({},u,{headers:a({},o,{Authorization:"token "+e.cookies[t]})})).then((function(t){r.status(t.status).json(t.data)})).catch((function(t){r.status(t.response.status).json(t.response.data)}))}},exports.getContent=h,exports.getFiles=function(t,e,r){try{var n,o=function(t){return a?t:n.filter((function(t){return"file"===t.type})).map((function(t){return t.path}))},a=!1,u=y((function(){return Promise.resolve(h(e.forkFullName,e.headBranch||"master",t,r)).then((function(t){n=t.data}))}),(function(t){var e,r=(null===(e=t.response)||void 0===e?void 0:e.status)||500;throw new d("Failed to get data.",r)}));return Promise.resolve(u&&u.then?u.then(o):o(u))}catch(t){return Promise.reject(t)}},exports.getJsonFile=function(t,e,r){try{return Promise.resolve(v(e.forkFullName,e.headBranch||"master",t,r)).then((function(e){return{sha:e.sha,fileRelativePath:t,data:JSON.parse(e.content)}}))}catch(t){return Promise.reject(t)}},exports.getMarkdownFile=function(t,e,n){try{return Promise.resolve(v(e.forkFullName,e.headBranch||"master",t,n)).then((function(e){var n=r(e.content);return{sha:e.sha,fileRelativePath:t,data:{frontmatter:n.data,markdownBody:n.content}}}))}catch(t){return Promise.reject(t)}}; | ||
//# sourceMappingURL=next-tinacms-github.cjs.production.min.js.map |
import { serialize } from 'cookie'; | ||
import matter from 'gray-matter'; | ||
@@ -105,2 +106,92 @@ /** | ||
function _inheritsLoose(subClass, superClass) { | ||
subClass.prototype = Object.create(superClass.prototype); | ||
subClass.prototype.constructor = subClass; | ||
subClass.__proto__ = superClass; | ||
} | ||
function _getPrototypeOf(o) { | ||
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { | ||
return o.__proto__ || Object.getPrototypeOf(o); | ||
}; | ||
return _getPrototypeOf(o); | ||
} | ||
function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { | ||
o.__proto__ = p; | ||
return o; | ||
}; | ||
return _setPrototypeOf(o, p); | ||
} | ||
function isNativeReflectConstruct() { | ||
if (typeof Reflect === "undefined" || !Reflect.construct) return false; | ||
if (Reflect.construct.sham) return false; | ||
if (typeof Proxy === "function") return true; | ||
try { | ||
Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
function _construct(Parent, args, Class) { | ||
if (isNativeReflectConstruct()) { | ||
_construct = Reflect.construct; | ||
} else { | ||
_construct = function _construct(Parent, args, Class) { | ||
var a = [null]; | ||
a.push.apply(a, args); | ||
var Constructor = Function.bind.apply(Parent, a); | ||
var instance = new Constructor(); | ||
if (Class) _setPrototypeOf(instance, Class.prototype); | ||
return instance; | ||
}; | ||
} | ||
return _construct.apply(null, arguments); | ||
} | ||
function _isNativeFunction(fn) { | ||
return Function.toString.call(fn).indexOf("[native code]") !== -1; | ||
} | ||
function _wrapNativeSuper(Class) { | ||
var _cache = typeof Map === "function" ? new Map() : undefined; | ||
_wrapNativeSuper = function _wrapNativeSuper(Class) { | ||
if (Class === null || !_isNativeFunction(Class)) return Class; | ||
if (typeof Class !== "function") { | ||
throw new TypeError("Super expression must either be null or a function"); | ||
} | ||
if (typeof _cache !== "undefined") { | ||
if (_cache.has(Class)) return _cache.get(Class); | ||
_cache.set(Class, Wrapper); | ||
} | ||
function Wrapper() { | ||
return _construct(Class, arguments, _getPrototypeOf(this).constructor); | ||
} | ||
Wrapper.prototype = Object.create(Class.prototype, { | ||
constructor: { | ||
value: Wrapper, | ||
enumerable: false, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
return _setPrototypeOf(Wrapper, Class); | ||
}; | ||
return _wrapNativeSuper(Class); | ||
} | ||
function _objectWithoutPropertiesLoose(source, excluded) { | ||
@@ -160,3 +251,242 @@ if (source == null) return {}; | ||
export { createCreateAccessTokenFn, createPreviewFn, createProxy }; | ||
/** | ||
Copyright 2019 Forestry.io Inc | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
var axios$2 = | ||
/*#__PURE__*/ | ||
require('axios'); | ||
var getContent = function getContent(repoFullName, headBranch, path, accessToken) { | ||
try { | ||
return Promise.resolve(axios$2({ | ||
method: 'GET', | ||
url: "https://api.github.com/repos/" + repoFullName + "/contents/" + path + "?ref=" + headBranch, | ||
headers: { | ||
Authorization: 'token ' + accessToken | ||
} | ||
})); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}; | ||
// A type of promise-like that resolves synchronously and supports only one observer | ||
var _iteratorSymbol = | ||
/*#__PURE__*/ | ||
typeof Symbol !== "undefined" ? Symbol.iterator || (Symbol.iterator = | ||
/*#__PURE__*/ | ||
Symbol("Symbol.iterator")) : "@@iterator"; // Asynchronously iterate through an object's values | ||
var _asyncIteratorSymbol = | ||
/*#__PURE__*/ | ||
typeof Symbol !== "undefined" ? Symbol.asyncIterator || (Symbol.asyncIterator = | ||
/*#__PURE__*/ | ||
Symbol("Symbol.asyncIterator")) : "@@asyncIterator"; // Asynchronously iterate on a value using it's async iterator if present, or its synchronous iterator if missing | ||
function _catch(body, recover) { | ||
try { | ||
var result = body(); | ||
} catch (e) { | ||
return recover(e); | ||
} | ||
if (result && result.then) { | ||
return result.then(void 0, recover); | ||
} | ||
return result; | ||
} // Asynchronously await a promise and pass the result to a finally continuation | ||
/** | ||
Copyright 2019 Forestry.io Inc | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
var GithubError = | ||
/*#__PURE__*/ | ||
function (_Error) { | ||
_inheritsLoose(GithubError, _Error); | ||
function GithubError(message, status) { | ||
var _this; | ||
_this = _Error.call(this, message) || this; | ||
_this.message = message; | ||
_this.status = status; | ||
return _this; | ||
} | ||
return GithubError; | ||
}( | ||
/*#__PURE__*/ | ||
_wrapNativeSuper(Error)); | ||
var getFiles = function getFiles(filePath, sourceProviderConnection, accessToken) { | ||
try { | ||
var _temp3 = function _temp3(_result) { | ||
return _exit2 ? _result : data.filter(function (file) { | ||
return file.type === 'file'; | ||
}).map(function (file) { | ||
return file.path; | ||
}); | ||
}; | ||
var _exit2 = false; | ||
var data; | ||
var _temp4 = _catch(function () { | ||
; | ||
return Promise.resolve(getContent(sourceProviderConnection.forkFullName, sourceProviderConnection.headBranch || 'master', filePath, accessToken)).then(function (_getContent) { | ||
data = _getContent.data; | ||
}); | ||
}, function (e) { | ||
var _e$response; | ||
var errorStatus = ((_e$response = e.response) === null || _e$response === void 0 ? void 0 : _e$response.status) || 500; | ||
throw new GithubError('Failed to get data.', errorStatus); | ||
}); | ||
return Promise.resolve(_temp4 && _temp4.then ? _temp4.then(_temp3) : _temp3(_temp4)); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}; | ||
var atob = | ||
/*#__PURE__*/ | ||
require('atob'); | ||
var b64DecodeUnicode = function b64DecodeUnicode(str) { | ||
// Going backwards: from bytestream, to percent-encoding, to original string. | ||
return decodeURIComponent(atob(str).split('').map(function (c) { | ||
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); | ||
}).join('')); | ||
}; // TODO - this name kinda sucks, | ||
// Throw a formatted error on 404, and decode github data properly | ||
var getDecodedData = function getDecodedData(repoFullName, headBranch, path, accessToken) { | ||
try { | ||
var _temp3 = function _temp3(_result) { | ||
return _exit2 ? _result : _extends({}, data, { | ||
content: b64DecodeUnicode(data.content) | ||
}); | ||
}; | ||
var _exit2 = false; | ||
var data = null; | ||
var _temp4 = _catch(function () { | ||
; | ||
return Promise.resolve(getContent(repoFullName, headBranch, path, accessToken)).then(function (_getContent) { | ||
data = _getContent.data; | ||
}); | ||
}, function (e) { | ||
var _e$response; | ||
var errorStatus = ((_e$response = e.response) === null || _e$response === void 0 ? void 0 : _e$response.status) || 500; | ||
throw new GithubError('Failed to get data.', errorStatus); | ||
}); | ||
return Promise.resolve(_temp4 && _temp4.then ? _temp4.then(_temp3) : _temp3(_temp4)); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}; | ||
/** | ||
Copyright 2019 Forestry.io Inc | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
var getJsonFile = function getJsonFile(filePath, sourceProviderConnection, accessToken) { | ||
try { | ||
return Promise.resolve(getDecodedData(sourceProviderConnection.forkFullName, sourceProviderConnection.headBranch || 'master', filePath, accessToken)).then(function (response) { | ||
return { | ||
sha: response.sha, | ||
fileRelativePath: filePath, | ||
data: JSON.parse(response.content) | ||
}; | ||
}); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}; | ||
/** | ||
Copyright 2019 Forestry.io Inc | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
var getMarkdownFile = function getMarkdownFile(filePath, sourceProviderConnection, accessToken) { | ||
try { | ||
return Promise.resolve(getDecodedData(sourceProviderConnection.forkFullName, sourceProviderConnection.headBranch || 'master', filePath, accessToken)).then(function (response) { | ||
var _matter = matter(response.content), | ||
markdownBody = _matter.content, | ||
frontmatter = _matter.data; | ||
return { | ||
sha: response.sha, | ||
fileRelativePath: filePath, | ||
data: { | ||
frontmatter: frontmatter, | ||
markdownBody: markdownBody | ||
} | ||
}; | ||
}); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}; | ||
export { GithubError, createCreateAccessTokenFn, createPreviewFn, createProxy, getContent, getFiles, getJsonFile, getMarkdownFile }; | ||
//# sourceMappingURL=next-tinacms-github.esm.js.map |
{ | ||
"name": "next-tinacms-github", | ||
"version": "0.0.2-canary4", | ||
"version": "0.0.2-canary4.0", | ||
"description": "", | ||
@@ -15,13 +15,13 @@ "main": "dist/index.js", | ||
"license": "Apache-2.0", | ||
"peerDependencies": { | ||
"cookie": ">=0.4.0", | ||
"qs": ">=6.9.0", | ||
"axios": ">=0.19.0" | ||
"devDependencies": { | ||
"@types/cookie": "0.3.3" | ||
}, | ||
"devDependencies": { | ||
"@types/cookie": "0.3.3", | ||
"dependencies": { | ||
"atob": "2.1.2", | ||
"axios": "0.19.2", | ||
"cookie": "0.4.0", | ||
"qs": "6.9.3", | ||
"axios": "0.19.2" | ||
} | ||
"gray-matter": "4.0.2", | ||
"qs": "6.9.3" | ||
}, | ||
"gitHead": "c2663fa2c089a599d6c031967b972a577d4994fa" | ||
} |
# next-tinacms-github | ||
This package provides helpers for managing the github auth token on the server. | ||
When used with Next.js in the `pages/api` directory, these functions are mapped to `/api/*` endpoints. | ||
# `createCreateAccessTokenFn` | ||
Helper for creating a createCreateAccessToken server function. | ||
## Implementation | ||
``` | ||
// pages/api/create-github-access-token.ts | ||
import { createCreateAccessTokenFn } from 'next-tinacms-github' | ||
export default createCreateAccessTokenFn( | ||
process.env.GITHUB_CLIENT_ID, | ||
process.env.GITHUB_CLIENT_SECRET | ||
) | ||
``` | ||
# `createProxy` | ||
Helper for creating a proxy which attaches this Github access token to the request | ||
## Implementation | ||
``` | ||
// pages/api/proxy-github.ts | ||
import { createProxy } from 'next-tinacms-github' | ||
import { GITHUB_ACCESS_TOKEN_COOKIE_KEY } from './constants' | ||
export default createProxy(GITHUB_ACCESS_TOKEN_COOKIE_KEY) | ||
``` | ||
# `createPreviewFn` | ||
Helper for creating a preview function which will set the preview data from Github cookies | ||
## Implementation | ||
``` | ||
// pages/api/preview.ts | ||
import { createPreviewFn } from 'next-tinacms-github' | ||
export default createPreviewFn( | ||
'fork_full_name', | ||
'head_branch', | ||
'github_access_token' | ||
) | ||
``` |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
189764
1
38
1428
52
5
2
+ Addedatob@2.1.2
+ Addedaxios@0.19.2
+ Addedcookie@0.4.0
+ Addedgray-matter@4.0.2
+ Addedqs@6.9.3
+ Addedargparse@1.0.10(transitive)
+ Addedatob@2.1.2(transitive)
+ Addedaxios@0.19.2(transitive)
+ Addedcookie@0.4.0(transitive)
+ Addedesprima@4.0.1(transitive)
+ Addedextend-shallow@2.0.1(transitive)
+ Addedfollow-redirects@1.5.10(transitive)
+ Addedgray-matter@4.0.2(transitive)
+ Addedis-extendable@0.1.1(transitive)
+ Addedjs-yaml@3.14.1(transitive)
+ Addedkind-of@6.0.3(transitive)
+ Addedqs@6.9.3(transitive)
+ Addedsection-matter@1.0.0(transitive)
+ Addedsprintf-js@1.0.3(transitive)
+ Addedstrip-bom-string@1.0.0(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaxios@1.7.7(transitive)
- Removedcall-bind@1.0.7(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcookie@1.0.1(transitive)
- Removeddefine-data-property@1.1.4(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removedes-define-property@1.0.0(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedfollow-redirects@1.15.9(transitive)
- Removedform-data@4.0.1(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-intrinsic@1.2.4(transitive)
- Removedgopd@1.0.1(transitive)
- Removedhas-property-descriptors@1.0.2(transitive)
- Removedhas-proto@1.0.3(transitive)
- Removedhas-symbols@1.0.3(transitive)
- Removedhasown@2.0.2(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedobject-inspect@1.13.2(transitive)
- Removedproxy-from-env@1.1.0(transitive)
- Removedqs@6.13.0(transitive)
- Removedset-function-length@1.2.2(transitive)
- Removedside-channel@1.0.6(transitive)