Socket
Socket
Sign inDemoInstall

next-tinacms-github

Package Overview
Dependencies
Maintainers
1
Versions
266
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

next-tinacms-github - npm Package Compare versions

Comparing version 0.1.0-canary4.0 to 0.1.0-canary4.1

8

CHANGELOG.md

@@ -6,2 +6,10 @@ # Change Log

# [0.1.0-canary4.1](https://github.com/tinacms/tinacms/compare/next-tinacms-github@0.1.0-canary4.0...next-tinacms-github@0.1.0-canary4.1) (2020-04-24)
**Note:** Version bump only for package next-tinacms-github
# [0.1.0-canary4.0](https://github.com/tinacms/tinacms/compare/next-tinacms-github@0.0.2-canary4.1...next-tinacms-github@0.1.0-canary4.0) (2020-04-20)

@@ -8,0 +16,0 @@

2

dist/constants.d.ts

@@ -19,3 +19,3 @@ /**

export declare const ACCESS_TOKEN_KEY = "github_access_token";
export declare const FORK_KEY = "fork_full_name";
export declare const WORKING_REPO_KEY = "working_repo_full_name";
export declare const HEAD_BRANCH_KEY = "head_branch";

@@ -20,6 +20,5 @@ /**

import { GithubError } from './github/content/GithubError';
import { SourceProviderConnection } from './github/content';
export interface PreviewData<Data> {
github_access_token: string;
fork_full_name: string;
working_repo_full_name: string;
head_branch: string;

@@ -37,3 +36,4 @@ fileRelativePath: string;

preview: boolean;
sourceProvider: SourceProviderConnection;
repoFullName: string;
branch: string;
file: GithubFile<Data> | null;

@@ -40,0 +40,0 @@ error: GithubError | null;

@@ -18,2 +18,2 @@ /**

*/
export declare const getContent: (repoFullName: string, headBranch: string, path: string, accessToken: string) => Promise<any>;
export declare const getContent: (workingRepoFullName: string, headBranch: string, path: string, accessToken: string) => Promise<any>;

@@ -18,3 +18,3 @@ /**

*/
declare const getDecodedData: (repoFullName: string, headBranch: string, path: string, accessToken: string) => Promise<any>;
declare const getDecodedData: (workingRepoFullName: string, headBranch: string, path: string, accessToken: string) => Promise<any>;
export default getDecodedData;

@@ -18,3 +18,2 @@ /**

*/
import { SourceProviderConnection } from './sourceProviderConnection';
export declare const getFiles: (filePath: string, sourceProviderConnection: SourceProviderConnection, accessToken: string) => Promise<any>;
export declare const getFiles: (filePath: string, repoFullName: string, branch: string, accessToken: string) => Promise<any>;

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

export * from './GithubError';
export * from './sourceProviderConnection';

@@ -28,3 +28,3 @@ 'use strict';

var ACCESS_TOKEN_KEY = 'github_access_token';
var FORK_KEY = 'fork_full_name';
var WORKING_REPO_KEY = 'working_repo_full_name';
var HEAD_BRANCH_KEY = 'head_branch';

@@ -51,3 +51,3 @@

var previewData = {
fork_full_name: req.cookies[FORK_KEY],
working_repo_full_name: req.cookies[WORKING_REPO_KEY],
github_access_token: req.cookies[ACCESS_TOKEN_KEY],

@@ -280,7 +280,7 @@ head_branch: req.cookies[HEAD_BRANCH_KEY] || 'master'

var getContent = function getContent(repoFullName, headBranch, path, accessToken) {
var getContent = function getContent(workingRepoFullName, headBranch, path, accessToken) {
try {
return Promise.resolve(axios$2({
method: 'GET',
url: "https://api.github.com/repos/" + repoFullName + "/contents/" + path + "?ref=" + headBranch,
url: "https://api.github.com/repos/" + workingRepoFullName + "/contents/" + path + "?ref=" + headBranch,
headers: {

@@ -357,3 +357,3 @@ Authorization: 'token ' + accessToken

var getFiles = function getFiles(filePath, sourceProviderConnection, accessToken) {
var getFiles = function getFiles(filePath, repoFullName, branch, accessToken) {
try {

@@ -373,3 +373,3 @@ var _temp3 = function _temp3(_result) {

;
return Promise.resolve(getContent(sourceProviderConnection.forkFullName, sourceProviderConnection.headBranch || 'master', filePath, accessToken)).then(function (_getContent) {
return Promise.resolve(getContent(repoFullName, branch || 'master', filePath, accessToken)).then(function (_getContent) {
data = _getContent.data;

@@ -403,3 +403,3 @@ });

var getDecodedData = function getDecodedData(repoFullName, headBranch, path, accessToken) {
var getDecodedData = function getDecodedData(workingRepoFullName, headBranch, path, accessToken) {
try {

@@ -417,3 +417,3 @@ var _temp3 = function _temp3(_result) {

;
return Promise.resolve(getContent(repoFullName, headBranch, path, accessToken)).then(function (_getContent) {
return Promise.resolve(getContent(workingRepoFullName, headBranch, path, accessToken)).then(function (_getContent) {
data = _getContent.data;

@@ -440,3 +440,4 @@ });

file: file,
sourceProvider: sourceProvider,
repoFullName: workingRepoFullName,
branch: headBranch,
preview: true,

@@ -450,6 +451,4 @@ error: error

var accessToken = options.github_access_token;
var sourceProvider = {
forkFullName: options.fork_full_name || '',
headBranch: options.head_branch || 'master'
};
var workingRepoFullName = options.working_repo_full_name || '';
var headBranch = options.head_branch || 'master';
var error = null;

@@ -459,3 +458,3 @@ var file = null;

var _temp4 = _catch(function () {
return Promise.resolve(getDecodedData(sourceProvider.forkFullName, sourceProvider.headBranch || 'master', options.fileRelativePath, accessToken)).then(function (response) {
return Promise.resolve(getDecodedData(workingRepoFullName, headBranch, options.fileRelativePath, accessToken)).then(function (response) {
file = {

@@ -471,3 +470,4 @@ sha: response.sha,

path: options.fileRelativePath,
sourceProvider: sourceProvider,
repoFullName: workingRepoFullName,
branch: headBranch,
accessToken: accessToken

@@ -491,4 +491,5 @@ }));

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";
repoFullName = _ref.repoFullName,
branch = _ref.branch;
return "next-tinacms-github: Failed to fetch file from GitHub\n- file: \t" + path + "\n- repo: \t" + repoFullName + "\n- branch: \t" + branch + "\n- accessToken: \t" + (accessToken ? '******' : 'undefined') + "\n";
};

@@ -495,0 +496,0 @@

@@ -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){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(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(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(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.forkFullName,o.headBranch||"master",t.fileRelativePath,n)).then((function(e){u={sha:e.sha,fileRelativePath:t.fileRelativePath,data:t.parse(e.content)}}))}),(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.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({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"),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()};
//# sourceMappingURL=next-tinacms-github.cjs.production.min.js.map

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

var ACCESS_TOKEN_KEY = 'github_access_token';
var FORK_KEY = 'fork_full_name';
var WORKING_REPO_KEY = 'working_repo_full_name';
var HEAD_BRANCH_KEY = 'head_branch';

@@ -45,3 +45,3 @@

var previewData = {
fork_full_name: req.cookies[FORK_KEY],
working_repo_full_name: req.cookies[WORKING_REPO_KEY],
github_access_token: req.cookies[ACCESS_TOKEN_KEY],

@@ -274,7 +274,7 @@ head_branch: req.cookies[HEAD_BRANCH_KEY] || 'master'

var getContent = function getContent(repoFullName, headBranch, path, accessToken) {
var getContent = function getContent(workingRepoFullName, headBranch, path, accessToken) {
try {
return Promise.resolve(axios$2({
method: 'GET',
url: "https://api.github.com/repos/" + repoFullName + "/contents/" + path + "?ref=" + headBranch,
url: "https://api.github.com/repos/" + workingRepoFullName + "/contents/" + path + "?ref=" + headBranch,
headers: {

@@ -351,3 +351,3 @@ Authorization: 'token ' + accessToken

var getFiles = function getFiles(filePath, sourceProviderConnection, accessToken) {
var getFiles = function getFiles(filePath, repoFullName, branch, accessToken) {
try {

@@ -367,3 +367,3 @@ var _temp3 = function _temp3(_result) {

;
return Promise.resolve(getContent(sourceProviderConnection.forkFullName, sourceProviderConnection.headBranch || 'master', filePath, accessToken)).then(function (_getContent) {
return Promise.resolve(getContent(repoFullName, branch || 'master', filePath, accessToken)).then(function (_getContent) {
data = _getContent.data;

@@ -397,3 +397,3 @@ });

var getDecodedData = function getDecodedData(repoFullName, headBranch, path, accessToken) {
var getDecodedData = function getDecodedData(workingRepoFullName, headBranch, path, accessToken) {
try {

@@ -411,3 +411,3 @@ var _temp3 = function _temp3(_result) {

;
return Promise.resolve(getContent(repoFullName, headBranch, path, accessToken)).then(function (_getContent) {
return Promise.resolve(getContent(workingRepoFullName, headBranch, path, accessToken)).then(function (_getContent) {
data = _getContent.data;

@@ -434,3 +434,4 @@ });

file: file,
sourceProvider: sourceProvider,
repoFullName: workingRepoFullName,
branch: headBranch,
preview: true,

@@ -444,6 +445,4 @@ error: error

var accessToken = options.github_access_token;
var sourceProvider = {
forkFullName: options.fork_full_name || '',
headBranch: options.head_branch || 'master'
};
var workingRepoFullName = options.working_repo_full_name || '';
var headBranch = options.head_branch || 'master';
var error = null;

@@ -453,3 +452,3 @@ var file = null;

var _temp4 = _catch(function () {
return Promise.resolve(getDecodedData(sourceProvider.forkFullName, sourceProvider.headBranch || 'master', options.fileRelativePath, accessToken)).then(function (response) {
return Promise.resolve(getDecodedData(workingRepoFullName, headBranch, options.fileRelativePath, accessToken)).then(function (response) {
file = {

@@ -465,3 +464,4 @@ sha: response.sha,

path: options.fileRelativePath,
sourceProvider: sourceProvider,
repoFullName: workingRepoFullName,
branch: headBranch,
accessToken: accessToken

@@ -485,4 +485,5 @@ }));

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";
repoFullName = _ref.repoFullName,
branch = _ref.branch;
return "next-tinacms-github: Failed to fetch file from GitHub\n- file: \t" + path + "\n- repo: \t" + repoFullName + "\n- branch: \t" + branch + "\n- accessToken: \t" + (accessToken ? '******' : 'undefined') + "\n";
};

@@ -489,0 +490,0 @@

{
"name": "next-tinacms-github",
"version": "0.1.0-canary4.0",
"version": "0.1.0-canary4.1",
"description": "",

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

},
"gitHead": "cefcf557e31482e7640affed2b037b3bf1e231fd"
"gitHead": "92872379dd1a4177686a680faefe412f2a83b104"
}

@@ -20,3 +20,3 @@ /**

export const ACCESS_TOKEN_KEY = 'github_access_token'
export const FORK_KEY = 'fork_full_name'
export const WORKING_REPO_KEY = 'working_repo_full_name'
export const HEAD_BRANCH_KEY = 'head_branch'

@@ -20,3 +20,2 @@ /**

import { GithubError } from './github/content/GithubError'
import { SourceProviderConnection } from './github/content'
import getDecodedData from './github/content/getDecodedData'

@@ -26,3 +25,3 @@

github_access_token: string
fork_full_name: string
working_repo_full_name: string
head_branch: string

@@ -42,3 +41,4 @@ fileRelativePath: string

preview: boolean
sourceProvider: SourceProviderConnection
repoFullName: string
branch: string
file: GithubFile<Data> | null

@@ -53,6 +53,5 @@ error: GithubError | null

const accessToken = options.github_access_token
const sourceProvider = {
forkFullName: options.fork_full_name || '',
headBranch: options.head_branch || 'master',
}
const workingRepoFullName = options.working_repo_full_name || ''
const headBranch = options.head_branch || 'master'
let error: GithubError | null = null

@@ -63,4 +62,4 @@ let file = null

const response = await getDecodedData(
sourceProvider.forkFullName,
sourceProvider.headBranch || 'master',
workingRepoFullName,
headBranch,
options.fileRelativePath,

@@ -80,3 +79,4 @@ accessToken

path: options.fileRelativePath,
sourceProvider,
repoFullName: workingRepoFullName,
branch: headBranch,
accessToken,

@@ -95,3 +95,4 @@ })

file,
sourceProvider,
repoFullName: workingRepoFullName,
branch: headBranch,
preview: true,

@@ -106,3 +107,4 @@ error,

accessToken?: string
sourceProvider: SourceProviderConnection
repoFullName: string
branch: string
}

@@ -112,8 +114,9 @@ const githubErrorMessage = ({

accessToken,
sourceProvider,
repoFullName,
branch,
}: GithubErrorMessageInfo) => `next-tinacms-github: Failed to fetch file from GitHub
- file: \t${path}
- repo: \t${sourceProvider.forkFullName}
- branch: \t${sourceProvider.headBranch}
- repo: \t${repoFullName}
- branch: \t${branch}
- accessToken: \t${accessToken ? '******' : 'undefined'}
`

@@ -22,3 +22,3 @@ /**

export const getContent = async (
repoFullName: string,
workingRepoFullName: string,
headBranch: string,

@@ -30,3 +30,3 @@ path: string,

method: 'GET',
url: `https://api.github.com/repos/${repoFullName}/contents/${path}?ref=${headBranch}`,
url: `https://api.github.com/repos/${workingRepoFullName}/contents/${path}?ref=${headBranch}`,
headers: {

@@ -33,0 +33,0 @@ Authorization: 'token ' + accessToken,

@@ -38,3 +38,3 @@ /**

const getDecodedData = async (
repoFullName: string,
workingRepoFullName: string,
headBranch: string,

@@ -47,3 +47,8 @@ path: string,

try {
;({ data } = await getContent(repoFullName, headBranch, path, accessToken))
;({ data } = await getContent(
workingRepoFullName,
headBranch,
path,
accessToken
))
} catch (e) {

@@ -50,0 +55,0 @@ const errorStatus = e.response?.status || 500

@@ -20,3 +20,2 @@ /**

import { getContent } from './getContent'
import { SourceProviderConnection } from './sourceProviderConnection'
import { GithubError } from './GithubError'

@@ -26,3 +25,4 @@

filePath: string,
sourceProviderConnection: SourceProviderConnection,
repoFullName: string,
branch: string,
accessToken: string

@@ -34,4 +34,4 @@ ) => {

;({ data } = await getContent(
sourceProviderConnection.forkFullName,
sourceProviderConnection.headBranch || 'master',
repoFullName,
branch || 'master',
filePath,

@@ -38,0 +38,0 @@ accessToken

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

export * from './GithubError'
export * from './sourceProviderConnection'

@@ -19,7 +19,11 @@ /**

import { ACCESS_TOKEN_KEY, FORK_KEY, HEAD_BRANCH_KEY } from '../constants'
import {
ACCESS_TOKEN_KEY,
WORKING_REPO_KEY,
HEAD_BRANCH_KEY,
} from '../constants'
export const previewHandler = (req: any, res: any) => {
const previewData = {
fork_full_name: req.cookies[FORK_KEY],
working_repo_full_name: req.cookies[WORKING_REPO_KEY],
github_access_token: req.cookies[ACCESS_TOKEN_KEY],

@@ -26,0 +30,0 @@ head_branch: req.cookies[HEAD_BRANCH_KEY] || 'master',

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc