Skip to content

Meta lint #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,3 @@ updates:
schedule:
interval: daily
open-pull-requests-limit: 99
- package-ecosystem: npm
directory: "/src/http/get-login/"
schedule:
interval: daily
open-pull-requests-limit: 99
- package-ecosystem: npm
directory: "/src/http/post-graphql/"
schedule:
interval: daily
open-pull-requests-limit: 99
- package-ecosystem: npm
directory: "/src/http/post-logout/"
schedule:
interval: daily
open-pull-requests-limit: 99
2 changes: 1 addition & 1 deletion .github/workflows/integration-tester.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
HAS_CUSTOM_TESTS: true
strategy:
matrix:
node-version: [10.x, 12.x, 14.x]
node-version: [12.x, 14.x]
os: [windows-latest, ubuntu-latest, macOS-latest]
steps:
- name: Check out repo
Expand Down
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@
},
"dependencies": {
"@architect/functions": "^4.0.0",
"@architect/sandbox": "latest",
"@architect/sandbox": "^4.0.1",
"@begin/data": "^3.0.0",
"graphql": "^15.5.2",
"graphql-tools": "^8.2.0",
"npm-run-all": "^4.1.5",
"tiny-json-http": "^7.3.0",
"xss": "^1.0.9"
},
"devDependencies": {
"@architect/eslint-config": "^2.0.0",
"eslint": "^7.32.0"
},
"eslintConfig": {
"extends": "@architect/eslint-config"
}
}
6 changes: 3 additions & 3 deletions src/http/get-login/github.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
let tiny = require('tiny-json-http')

module.exports = async function github(req) {
module.exports = async function github (req) {

// trade the code for an access token
let result = await tiny.post({
url: 'https://github.com/login/oauth/access_token',
headers: {Accept: 'application/json'},
headers: { accept: 'application/json' },
data: {
code: req.query.code,
client_id: process.env.GITHUB_CLIENT_ID,
Expand All @@ -19,7 +19,7 @@ module.exports = async function github(req) {
// use the access token to get the user account
let user = await tiny.get({
url: `https://api.github.com/user?access_token=${token}`,
headers: {Accept: 'application/json'},
headers: { accept: 'application/json' },
})

// create a clean acccount obj
Expand Down
4 changes: 2 additions & 2 deletions src/http/get-login/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
let arc = require('@architect/functions')
let github = require('./github')

async function login(req) {
async function login (req) {
if (req.query.code) {
let account = await github(req)
return {
session: {account},
session: { account },
location: '/'
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/http/post-graphql/middleware/auth.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// mutations require req.session.account
module.exports = async function auth(req) {
module.exports = async function auth (req) {

let client_id = process.env.GITHUB_CLIENT_ID
let redirect_uri = process.env.GITHUB_REDIRECT
Expand Down
14 changes: 7 additions & 7 deletions src/http/post-graphql/middleware/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ let { account, draft, drafts, save, destroy } = require('../resolvers')
let typeDefs = fs.readFileSync(path.join(__dirname, '..', 'schema.graphql')).toString()

// 3. combine resolvers and schema
let schema = makeExecutableSchema({
typeDefs,
let schema = makeExecutableSchema({
typeDefs,
resolvers: {
Query: { draft, drafts },
Mutation: { account, save, destroy }
}
})

/** graphql middleware */
module.exports = async function query(req) {
module.exports = async function query (req) {
try {
let result = await graphql(schema, req.body.query, {}, req.session, req.body.variables, req.body.operationName)
return {
let result = await graphql(schema, req.body.query, {}, req.session, req.body.variables, req.body.operationName)
return {
json: result
}
}
catch(e) {
return {
catch (e) {
return {
json: { error: e.name, message: e.message, stack: e.stack }
}
}
Expand Down
28 changes: 14 additions & 14 deletions src/http/post-graphql/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@ module.exports = {
destroy
}

async function account(root, args, session) {
async function account (root, args, session) {
if (!session.account)
throw Error('not authorized')
let copy = session.account
delete copy.token
return copy
}

async function draft(root, args, session) {
return await data.get({
table: 'drafts',
async function draft (root, args) {
return data.get({
table: 'drafts',
...args
})
}

async function drafts(root, args, session) {
return await data.get({
table: 'drafts',
async function drafts () {
return data.get({
table: 'drafts',
})
}

async function save(root, draft, session) {
async function save (root, draft, session) {
if (!session.account)
throw Error('not authorized')
let required = ['title', 'body']//, 'author', 'avatar']
let required = [ 'title', 'body' ]// , 'author', 'avatar']
for (let param of required) {
if (!draft[param])
throw ReferenceError(`missing param ${param}`)
Expand All @@ -44,17 +44,17 @@ async function save(root, draft, session) {
draft.avatar = session.account.avatar
draft.title = xss(draft.title)
draft.body = xss(draft.body)
return await data.set({
table: 'drafts',
return data.set({
table: 'drafts',
...draft
})
}

async function destroy(root, draft, session) {
async function destroy (root, draft, session) {
if (!session.account)
throw Error('not authorized')
return await data.destroy({
table: 'drafts',
return data.destroy({
table: 'drafts',
...draft
})
}
2 changes: 1 addition & 1 deletion src/http/post-logout/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let arc = require('@architect/functions')

async function logout(req) {
async function logout () {
return {
session: {},
location: '/'
Expand Down