From 3f2968a314f687ca40f72e93c6981036fc9b537c Mon Sep 17 00:00:00 2001 From: Ryan Block Date: Wed, 1 Sep 2021 14:57:11 -0700 Subject: [PATCH 1/3] Add standard eslint config, move Sandbox to explicit version --- package.json | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index ad960a3..248f265 100644 --- a/package.json +++ b/package.json @@ -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" } } From 412087a3a5974679e6580c7c509cf9a95cf206f5 Mon Sep 17 00:00:00 2001 From: Ryan Block Date: Wed, 1 Sep 2021 15:01:51 -0700 Subject: [PATCH 2/3] Meta-linted --- src/http/get-login/github.js | 6 ++--- src/http/get-login/index.js | 4 ++-- src/http/post-graphql/middleware/auth.js | 2 +- src/http/post-graphql/middleware/query.js | 14 ++++++------ src/http/post-graphql/resolvers.js | 28 +++++++++++------------ src/http/post-logout/index.js | 2 +- 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/http/get-login/github.js b/src/http/get-login/github.js index cb3ddd8..09bec78 100644 --- a/src/http/get-login/github.js +++ b/src/http/get-login/github.js @@ -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, @@ -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 diff --git a/src/http/get-login/index.js b/src/http/get-login/index.js index 9d8e83a..da0ba03 100644 --- a/src/http/get-login/index.js +++ b/src/http/get-login/index.js @@ -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: '/' } } diff --git a/src/http/post-graphql/middleware/auth.js b/src/http/post-graphql/middleware/auth.js index ae84038..87c1ce8 100644 --- a/src/http/post-graphql/middleware/auth.js +++ b/src/http/post-graphql/middleware/auth.js @@ -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 diff --git a/src/http/post-graphql/middleware/query.js b/src/http/post-graphql/middleware/query.js index 2971137..d49ddcf 100644 --- a/src/http/post-graphql/middleware/query.js +++ b/src/http/post-graphql/middleware/query.js @@ -11,8 +11,8 @@ 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 } @@ -20,15 +20,15 @@ let schema = makeExecutableSchema({ }) /** 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 } } } diff --git a/src/http/post-graphql/resolvers.js b/src/http/post-graphql/resolvers.js index 68076a1..e0932e3 100644 --- a/src/http/post-graphql/resolvers.js +++ b/src/http/post-graphql/resolvers.js @@ -9,7 +9,7 @@ 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 @@ -17,23 +17,23 @@ async function account(root, args, session) { 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}`) @@ -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 }) } diff --git a/src/http/post-logout/index.js b/src/http/post-logout/index.js index 1413419..794d99d 100644 --- a/src/http/post-logout/index.js +++ b/src/http/post-logout/index.js @@ -1,6 +1,6 @@ let arc = require('@architect/functions') -async function logout(req) { +async function logout () { return { session: {}, location: '/' From f0be2db497a566749517bc7e7a03db1881a430ba Mon Sep 17 00:00:00 2001 From: Ryan Block Date: Wed, 1 Sep 2021 15:25:35 -0700 Subject: [PATCH 3/3] Reduce test surface area, tune dependabot --- .github/dependabot.yml | 15 --------------- .github/workflows/integration-tester.yml | 2 +- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 88de6c8..cce1bf6 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -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 diff --git a/.github/workflows/integration-tester.yml b/.github/workflows/integration-tester.yml index 55a78ca..34e8853 100644 --- a/.github/workflows/integration-tester.yml +++ b/.github/workflows/integration-tester.yml @@ -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