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.0.2-canary4.2 to 0.1.0-canary4.0

dist/parse-json.d.ts

11

CHANGELOG.md

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

# [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)
### Features
* **github:** Show error message when github fork fails ([7403015](https://github.com/tinacms/tinacms/commit/7403015))
## [0.0.2-canary4.1](https://github.com/tinacms/tinacms/compare/next-tinacms-github@0.0.2-canary4.0...next-tinacms-github@0.0.2-canary4.1) (2020-04-14)

@@ -8,0 +19,0 @@

17

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

@@ -19,4 +20,4 @@ Copyright 2019 Forestry.io Inc

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

@@ -26,17 +27,17 @@ fork_full_name: string;

fileRelativePath: string;
format?: 'markdown' | 'json';
parse(content: string): Data;
}
export interface GithubFile {
export interface GithubFile<Data> {
sha: string;
fileRelativePath: string;
data: any;
data: Data;
}
export interface GithubPreviewProps {
export interface GithubPreviewProps<Data> {
props: {
preview: boolean;
sourceProvider: SourceProviderConnection;
file: GithubFile | null;
file: GithubFile<Data> | null;
error: GithubError | null;
};
}
export declare function getGithubPreviewProps(options: PreviewData): Promise<GithubPreviewProps>;
export declare function getGithubPreviewProps<Data = any>(options: PreviewData<Data>): Promise<GithubPreviewProps<Data>>;

@@ -21,5 +21,3 @@ /**

export * from './getFiles';
export * from './getJsonFile';
export * from './getMarkdownFile';
export * from './GithubError';
export * from './sourceProviderConnection';

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

export * from './get-github-preview-props';
export * from './parse-markdown';
export * from './parse-json';

@@ -427,71 +427,2 @@ 'use strict';

/**
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);
}
};
var getGithubPreviewProps = function getGithubPreviewProps(options) {

@@ -520,5 +451,8 @@ try {

var _temp4 = _catch(function () {
var getParsedFile = options.format === 'markdown' ? getMarkdownFile : getJsonFile;
return Promise.resolve(getParsedFile(options.fileRelativePath, sourceProvider, accessToken)).then(function (_getParsedFile) {
file = _getParsedFile;
return Promise.resolve(getDecodedData(sourceProvider.forkFullName, sourceProvider.headBranch || 'master', options.fileRelativePath, accessToken)).then(function (response) {
file = {
sha: response.sha,
fileRelativePath: options.fileRelativePath,
data: options.parse(response.content)
};
});

@@ -552,2 +486,56 @@ }, function (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.
*/
function parseMarkdown(content) {
var _matter = matter(content),
markdownBody = _matter.content,
frontmatter = _matter.data;
return {
markdownBody: markdownBody,
frontmatter: frontmatter
};
}
/**
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.
*/
/**
*
* @param content
*/
function parseJson(content) {
return JSON.parse(content);
}
exports.GithubError = GithubError;

@@ -559,5 +547,5 @@ exports.apiProxy = apiProxy;

exports.getGithubPreviewProps = getGithubPreviewProps;
exports.getJsonFile = getJsonFile;
exports.getMarkdownFile = getMarkdownFile;
exports.parseJson = parseJson;
exports.parseMarkdown = parseMarkdown;
exports.previewHandler = previewHandler;
//# sourceMappingURL=next-tinacms-github.cjs.development.js.map

@@ -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"),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()};
"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()};
//# sourceMappingURL=next-tinacms-github.cjs.production.min.js.map

@@ -421,71 +421,2 @@ import { serialize } from 'cookie';

/**
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);
}
};
var getGithubPreviewProps = function getGithubPreviewProps(options) {

@@ -514,5 +445,8 @@ try {

var _temp4 = _catch(function () {
var getParsedFile = options.format === 'markdown' ? getMarkdownFile : getJsonFile;
return Promise.resolve(getParsedFile(options.fileRelativePath, sourceProvider, accessToken)).then(function (_getParsedFile) {
file = _getParsedFile;
return Promise.resolve(getDecodedData(sourceProvider.forkFullName, sourceProvider.headBranch || 'master', options.fileRelativePath, accessToken)).then(function (response) {
file = {
sha: response.sha,
fileRelativePath: options.fileRelativePath,
data: options.parse(response.content)
};
});

@@ -546,3 +480,57 @@ }, function (e) {

export { GithubError, apiProxy, createAuthHandler, getContent, getFiles, getGithubPreviewProps, getJsonFile, getMarkdownFile, previewHandler };
/**
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.
*/
function parseMarkdown(content) {
var _matter = matter(content),
markdownBody = _matter.content,
frontmatter = _matter.data;
return {
markdownBody: markdownBody,
frontmatter: frontmatter
};
}
/**
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.
*/
/**
*
* @param content
*/
function parseJson(content) {
return JSON.parse(content);
}
export { GithubError, apiProxy, createAuthHandler, getContent, getFiles, getGithubPreviewProps, parseJson, parseMarkdown, previewHandler };
//# sourceMappingURL=next-tinacms-github.esm.js.map
{
"name": "next-tinacms-github",
"version": "0.0.2-canary4.2",
"version": "0.1.0-canary4.0",
"description": "",

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

"qs": "6.9.3"
}
},
"gitHead": "cefcf557e31482e7640affed2b037b3bf1e231fd"
}

@@ -75,2 +75,3 @@ # next-tinacms-github

getGithubPreviewProps
parseMarkdown,
} from 'next-tinacms-github'

@@ -89,3 +90,3 @@

fileRelativePath: 'src/content/home.json',
format: 'json'
parse: parseMarkdown
});

@@ -92,0 +93,0 @@ }

/**
*

@@ -19,7 +20,6 @@ Copyright 2019 Forestry.io Inc

import { GithubError } from './github/content/GithubError'
import { getMarkdownFile } from './github/content/getMarkdownFile'
import { getJsonFile } from './github/content/getJsonFile'
import { SourceProviderConnection } from 'github/content'
import { SourceProviderConnection } from './github/content'
import getDecodedData from './github/content/getDecodedData'
export interface PreviewData {
export interface PreviewData<Data> {
github_access_token: string

@@ -29,16 +29,16 @@ fork_full_name: string

fileRelativePath: string
format?: 'markdown' | 'json'
parse(content: string): Data
}
export interface GithubFile {
export interface GithubFile<Data> {
sha: string
fileRelativePath: string
data: any
data: Data
}
export interface GithubPreviewProps {
export interface GithubPreviewProps<Data> {
props: {
preview: boolean
sourceProvider: SourceProviderConnection
file: GithubFile | null
file: GithubFile<Data> | null
error: GithubError | null

@@ -48,5 +48,5 @@ }

export async function getGithubPreviewProps(
options: PreviewData
): Promise<GithubPreviewProps> {
export async function getGithubPreviewProps<Data = any>(
options: PreviewData<Data>
): Promise<GithubPreviewProps<Data>> {
const accessToken = options.github_access_token

@@ -61,10 +61,14 @@ const sourceProvider = {

try {
const getParsedFile =
options.format === 'markdown' ? getMarkdownFile : getJsonFile
file = await getParsedFile(
const response = await getDecodedData(
sourceProvider.forkFullName,
sourceProvider.headBranch || 'master',
options.fileRelativePath,
sourceProvider,
accessToken
)
file = {
sha: response.sha,
fileRelativePath: options.fileRelativePath,
data: options.parse(response.content),
}
} catch (e) {

@@ -71,0 +75,0 @@ if (e instanceof GithubError) {

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

export * from './getFiles'
export * from './getJsonFile'
export * from './getMarkdownFile'
export * from './GithubError'
export * from './sourceProviderConnection'

@@ -24,1 +24,3 @@ /**

export * from './get-github-preview-props'
export * from './parse-markdown'
export * from './parse-json'

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