Socket
Socket
Sign inDemoInstall

next-tinacms-github

Package Overview
Dependencies
17
Maintainers
1
Versions
266
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.2-canary4.1 to 0.0.2-canary4.2

dist/get-github-preview-props.d.ts

1

dist/index.d.ts

@@ -22,1 +22,2 @@ /**

export * from './github/content';
export * from './get-github-preview-props';

@@ -496,2 +496,56 @@ 'use strict';

var getGithubPreviewProps = function getGithubPreviewProps(options) {
try {
var _temp3 = function _temp3(_result) {
return _exit2 ? _result : {
props: {
file: file,
sourceProvider: sourceProvider,
preview: true,
error: error
}
};
};
var _exit2 = false;
var accessToken = options.github_access_token;
var sourceProvider = {
forkFullName: options.fork_full_name || '',
headBranch: options.head_branch || 'master'
};
var error = null;
var file = null;
var _temp4 = _catch(function () {
var getParsedFile = options.format === 'markdown' ? getMarkdownFile : getJsonFile;
return Promise.resolve(getParsedFile(options.fileRelativePath, sourceProvider, accessToken)).then(function (_getParsedFile) {
file = _getParsedFile;
});
}, function (e) {
if (e instanceof GithubError) {
console.error(githubErrorMessage({
path: options.fileRelativePath,
sourceProvider: sourceProvider,
accessToken: accessToken
}));
console.error(e);
error = _extends({}, e); //workaround since we cant return error as JSON
} else {
throw e;
}
});
return Promise.resolve(_temp4 && _temp4.then ? _temp4.then(_temp3) : _temp3(_temp4));
} catch (e) {
return Promise.reject(e);
}
};
var githubErrorMessage = function githubErrorMessage(_ref) {
var path = _ref.path,
accessToken = _ref.accessToken,
sourceProvider = _ref.sourceProvider;
return "next-tinacms-github: Failed to fetch file from GitHub\n- file: \t" + path + "\n- repo: \t" + sourceProvider.forkFullName + "\n- branch: \t" + sourceProvider.headBranch + "\n- accessToken: \t" + (accessToken ? '******' : 'undefined') + "\n";
};
exports.GithubError = GithubError;

@@ -502,2 +556,3 @@ exports.apiProxy = apiProxy;

exports.getFiles = getFiles;
exports.getGithubPreviewProps = getGithubPreviewProps;
exports.getJsonFile = getJsonFile;

@@ -504,0 +559,0 @@ exports.getMarkdownFile = getMarkdownFile;

2

dist/next-tinacms-github.cjs.production.min.js

@@ -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 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 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)),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=d((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 y("Failed to get data.",r)}));return Promise.resolve(c&&c.then?c.then(o):o(c))}catch(t){return Promise.reject(t)}};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,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.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=d((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 y("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)}},exports.previewHandler=function(t,e){e.setPreviewData({fork_full_name:t.cookies.fork_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"),h=require("axios"),p=function(t,e,r,n){try{return Promise.resolve(h({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)),m=require("atob"),v=function(t,e,r,n){try{var o=function(t){return i?t:a({},u,{content:(e=u.content,decodeURIComponent(m(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(p(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)}},b=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)}},_=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)}};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=p,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,i=d((function(){return Promise.resolve(p(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 y("Failed to get data.",r)}));return Promise.resolve(i&&i.then?i.then(o):o(i))}catch(t){return Promise.reject(t)}},exports.getGithubPreviewProps=function(t){try{var e=function(t){return r?t:{props:{file:u,sourceProvider:o,preview:!0,error:i}}},r=!1,n=t.github_access_token,o={forkFullName:t.fork_full_name||"",headBranch:t.head_branch||"master"},i=null,u=null,c=d((function(){return Promise.resolve(("markdown"===t.format?_:b)(t.fileRelativePath,o,n)).then((function(t){u=t}))}),(function(e){if(!(e instanceof y))throw e;console.error(function(t){var e=t.sourceProvider;return"next-tinacms-github: Failed to fetch file from GitHub\n- file: \t"+t.path+"\n- repo: \t"+e.forkFullName+"\n- branch: \t"+e.headBranch+"\n- accessToken: \t"+(t.accessToken?"******":"undefined")+"\n"}({path:t.fileRelativePath,sourceProvider:o,accessToken:n})),console.error(e),i=a({},e)}));return Promise.resolve(c&&c.then?c.then(e):e(c))}catch(t){return Promise.reject(t)}},exports.getJsonFile=b,exports.getMarkdownFile=_,exports.previewHandler=function(t,e){e.setPreviewData({fork_full_name:t.cookies.fork_full_name,github_access_token:t.cookies.github_access_token,head_branch:t.cookies.head_branch||"master"}),e.status(200).end()};
//# sourceMappingURL=next-tinacms-github.cjs.production.min.js.map

@@ -490,3 +490,57 @@ import { serialize } from 'cookie';

export { GithubError, apiProxy, createAuthHandler, getContent, getFiles, getJsonFile, getMarkdownFile, previewHandler };
var getGithubPreviewProps = function getGithubPreviewProps(options) {
try {
var _temp3 = function _temp3(_result) {
return _exit2 ? _result : {
props: {
file: file,
sourceProvider: sourceProvider,
preview: true,
error: error
}
};
};
var _exit2 = false;
var accessToken = options.github_access_token;
var sourceProvider = {
forkFullName: options.fork_full_name || '',
headBranch: options.head_branch || 'master'
};
var error = null;
var file = null;
var _temp4 = _catch(function () {
var getParsedFile = options.format === 'markdown' ? getMarkdownFile : getJsonFile;
return Promise.resolve(getParsedFile(options.fileRelativePath, sourceProvider, accessToken)).then(function (_getParsedFile) {
file = _getParsedFile;
});
}, function (e) {
if (e instanceof GithubError) {
console.error(githubErrorMessage({
path: options.fileRelativePath,
sourceProvider: sourceProvider,
accessToken: accessToken
}));
console.error(e);
error = _extends({}, e); //workaround since we cant return error as JSON
} else {
throw e;
}
});
return Promise.resolve(_temp4 && _temp4.then ? _temp4.then(_temp3) : _temp3(_temp4));
} catch (e) {
return Promise.reject(e);
}
};
var githubErrorMessage = function githubErrorMessage(_ref) {
var path = _ref.path,
accessToken = _ref.accessToken,
sourceProvider = _ref.sourceProvider;
return "next-tinacms-github: Failed to fetch file from GitHub\n- file: \t" + path + "\n- repo: \t" + sourceProvider.forkFullName + "\n- branch: \t" + sourceProvider.headBranch + "\n- accessToken: \t" + (accessToken ? '******' : 'undefined') + "\n";
};
export { GithubError, apiProxy, createAuthHandler, getContent, getFiles, getGithubPreviewProps, getJsonFile, getMarkdownFile, previewHandler };
//# sourceMappingURL=next-tinacms-github.esm.js.map
{
"name": "next-tinacms-github",
"version": "0.0.2-canary4.1",
"version": "0.0.2-canary4.2",
"description": "",

@@ -24,4 +24,3 @@ "main": "dist/index.js",

"qs": "6.9.3"
},
"gitHead": "1b64eb2e2236e7df68827b806413b2fe990f8332"
}
}

@@ -74,3 +74,3 @@ # next-tinacms-github

import {
getMarkdownFile as getGithubMarkdownFile,
getGithubPreviewProps
} from 'next-tinacms-github'

@@ -85,44 +85,20 @@

}) {
const { slug } = ctx.params
let file = {}
const filePath = `content/blog/${slug}.md`
const sourceProviderConnection = {
forkFullName: previewData.fork_full_name,
headBranch: previewData.head_branch || 'master',
if (preview) {
return getGithubPreviewProps({
...previewData,
fileRelativePath: 'src/content/home.json',
format: 'json'
});
}
let error = null
if(preview) {
try {
file = await getGithubMarkdownFile(filePath,
sourceProviderConnection,
previewData.accessToken)
}
catch (e) {
// If there is an error initially loading the content from Github, we want to display an actionable error
// to the user. They may need to re-authenticate or create a new fork.
if (e instanceof GithubError) {
error = { ...e } //workaround since we cant return error as JSON
} else {
throw e
}
}
}
else {
// Get your production content here
// when you are not in edit-mode
file = await readLocalMarkdownFile(filePath)
}
return {
props: {
sourceProviderConnection,
editMode: !!preview,
file,
error
sourceProvider: null,
error: null,
preview,
file: {
fileRelativePath: 'src/content/home.json',
data: (await import('../content/home.json')).default,
},
},
}
};
}

@@ -139,3 +115,3 @@ ```

For the **Authorization callback URL**, enter the url for the "authorizing" page that you created above (e.g https://your-url/github/authorizing). Fill out the other fields with your custom values.
_Note: If you are testing your app locally, you may need a separate development Github app (with a localhost redirect), and a production Github app._
_Note: If you are testing your app locally, you may need a separate development Github app (with a localhost redirect), and a production Github app._

@@ -142,0 +118,0 @@ The generated **Client ID** & **Client Secret** will be consumed by the `createCreateAccessTokenFn` [defined above](#createcreateaccesstokenfn).

@@ -23,1 +23,2 @@ /**

export * from './github/content'
export * from './get-github-preview-props'

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc