diff --git a/api_findJobsBySubscriber/function.json b/api_findJobsBySubscriber/function.json deleted file mode 100644 index da274ae..0000000 --- a/api_findJobsBySubscriber/function.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "bindings": [ - { - "type": "httpTrigger", - "direction": "in", - "name": "req", - "authLevel": "anonymous", - "methods": [ - "get", - "post", - "options" - ], - "route": "findJobsBySubscriber" - }, - { - "type": "http", - "direction": "out", - "name": "res" - } - ] -} \ No newline at end of file diff --git a/api_findJobsBySubscriber/index.js b/api_findJobsBySubscriber/index.js deleted file mode 100644 index c10d435..0000000 --- a/api_findJobsBySubscriber/index.js +++ /dev/null @@ -1,23 +0,0 @@ -'use strict' - -const azureWrapper = require('../util/azureWrapper'); -const connect = require('../src/db'); -const checkSubscriberToken = require('../src/auth/checkSubscriberToken'); -const findJobsBySubscriber = require('../src/actions/findJobsBySubscriber'); - -module.exports = azureWrapper(async function (context, req) { - const conn = await connect(); - const { Task } = conn.models; - - const task = await Task.create({ - method: req.method, - url: req.url, - params: req.body - }); - - const params = Object.assign({}, req.body, { authorization: req.headers.authorization }); - - await checkSubscriberToken({ task, conn })(params); - - return findJobsBySubscriber({ task, conn })(params); -}); \ No newline at end of file diff --git a/api_githubLogin/function.json b/api_githubLogin/function.json deleted file mode 100644 index b66163b..0000000 --- a/api_githubLogin/function.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "bindings": [ - { - "type": "httpTrigger", - "direction": "in", - "name": "req", - "authLevel": "anonymous", - "methods": [ - "get", - "post", - "options" - ], - "route": "githubLogin" - }, - { - "type": "http", - "direction": "out", - "name": "res" - } - ] - } \ No newline at end of file diff --git a/api_githubLogin/index.js b/api_githubLogin/index.js deleted file mode 100644 index cf1e7c4..0000000 --- a/api_githubLogin/index.js +++ /dev/null @@ -1,59 +0,0 @@ -'use strict' - -const Archetype = require('archetype'); -const axios = require('axios'); -const azureWrapper = require('../util/azureWrapper'); -const connect = require('../src/db'); -const githubOAuth = require('../src/integrations/githubOAuth'); - -const { githubOAuthClientId, githubOAuthClientSecret } = require('../.config'); - -const GithubLoginParams = new Archetype({ - code: { - $type: 'string', - $required: true - } -}).compile('GithubLoginParams'); - -module.exports = azureWrapper(githubLogin); -module.exports.rawFunction = githubLogin; - -async function githubLogin(context, req) { - const conn = await connect(); - const AccessToken = conn.model('AccessToken'); - const Subscriber = conn.model('Subscriber'); - const Task = conn.model('Task'); - - const task = await Task.create({ - method: req.method, - url: req.url, - params: req.body - }); - - const { code } = new GithubLoginParams(req.query); - - const data = await task.sideEffect(githubOAuth.getAccessToken, code); - - if (data.error != null) { - throw new Error('Login failed: ' + data['error_description']); - } - if (data['access_token'] == null) { - throw new Error('No access token!'); - } - - const githubAccessToken = data['access_token']; - const { login, id } = await task.sideEffect(githubOAuth.getUserFromToken, githubAccessToken); - - const subscriber = await task.sideEffect(function getSubscriberByGithubId({ id }) { - return Subscriber.findOne({ githubUserId: id }); - }, { id }); - - const token = await AccessToken.create({ - githubAccessToken, - githubUserId: id, - githubUserName: login, - subscriberId: subscriber == null ? null : subscriber._id - }); - - return { ok: 1, token, subscriber }; -} \ No newline at end of file diff --git a/api_updateGithubOrganizationMembers/function.json b/api_updateGithubOrganizationMembers/function.json deleted file mode 100644 index 052f168..0000000 --- a/api_updateGithubOrganizationMembers/function.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "bindings": [ - { - "type": "httpTrigger", - "direction": "in", - "name": "req", - "authLevel": "anonymous", - "methods": [ - "get", - "post", - "options" - ], - "route": "updateGithubOrganizationMembers" - }, - { - "type": "http", - "direction": "out", - "name": "res" - } - ] -} \ No newline at end of file diff --git a/api_updateGithubOrganizationMembers/index.js b/api_updateGithubOrganizationMembers/index.js deleted file mode 100644 index 67c7653..0000000 --- a/api_updateGithubOrganizationMembers/index.js +++ /dev/null @@ -1,23 +0,0 @@ -'use strict' - -const azureWrapper = require('../util/azureWrapper'); -const connect = require('../src/db'); -const checkSubscriberToken = require('../src/auth/checkSubscriberToken'); -const updateGithubOrganizationMembers = require('../src/actions/updateGithubOrganizationMembers'); - -module.exports = azureWrapper(async function (context, req) { - const conn = await connect(); - const { Task } = conn.models; - - const task = await Task.create({ - method: req.method, - url: req.url, - params: req.body - }); - - const params = Object.assign({}, req.body, { authorization: req.headers.authorization }); - - await checkSubscriberToken({ task, conn })(params); - - return updateGithubOrganizationMembers({ task, conn })(params); -}); \ No newline at end of file diff --git a/api_updateJobs/function.json b/api_updateJobs/function.json deleted file mode 100644 index bda7dc3..0000000 --- a/api_updateJobs/function.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "bindings": [ - { - "type": "httpTrigger", - "direction": "in", - "name": "req", - "authLevel": "anonymous", - "methods": [ - "get", - "post", - "options" - ], - "route": "updateJobs" - }, - { - "type": "http", - "direction": "out", - "name": "res" - } - ] -} \ No newline at end of file diff --git a/api_updateJobs/index.js b/api_updateJobs/index.js deleted file mode 100644 index d2007a1..0000000 --- a/api_updateJobs/index.js +++ /dev/null @@ -1,23 +0,0 @@ -'use strict' - -const azureWrapper = require('../util/azureWrapper'); -const connect = require('../src/db'); -const checkSubscriberToken = require('../src/auth/checkSubscriberToken'); -const updateJobs = require('../src/actions/updateJobs'); - -module.exports = azureWrapper(async function (context, req) { - const conn = await connect(); - const { Task } = conn.models; - - const task = await Task.create({ - method: req.method, - url: req.url, - params: req.body - }); - - const params = Object.assign({}, req.body, { authorization: req.headers.authorization }); - - await checkSubscriberToken({ task, conn })(params); - - return updateJobs({ task, conn })(params); -}); \ No newline at end of file diff --git a/api_updateSubscriber/function.json b/api_updateSubscriber/function.json deleted file mode 100644 index 2118ff4..0000000 --- a/api_updateSubscriber/function.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "bindings": [ - { - "type": "httpTrigger", - "direction": "in", - "name": "req", - "authLevel": "anonymous", - "methods": [ - "get", - "post", - "options" - ], - "route": "updateSubscriber" - }, - { - "type": "http", - "direction": "out", - "name": "res" - } - ] - } \ No newline at end of file diff --git a/api_updateSubscriber/index.js b/api_updateSubscriber/index.js deleted file mode 100644 index ff38b96..0000000 --- a/api_updateSubscriber/index.js +++ /dev/null @@ -1,20 +0,0 @@ -'use strict' - -const azureWrapper = require('../util/azureWrapper'); -const connect = require('../src/db'); -const updateSubscriber = require('../src/actions/updateSubscriber'); - -module.exports = azureWrapper(async function (context, req) { - const conn = await connect(); - const { Task } = conn.models; - - const task = await Task.create({ - method: req.method, - url: req.url, - params: req.body - }); - - const params = Object.assign({}, req.body, { authorization: req.headers.authorization }); - - return updateSubscriber({ task, conn })(params); -}); \ No newline at end of file diff --git a/api_verifyGithubAccessToken/function.json b/api_verifyGithubAccessToken/function.json deleted file mode 100644 index 79e193c..0000000 --- a/api_verifyGithubAccessToken/function.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "bindings": [ - { - "type": "httpTrigger", - "direction": "in", - "name": "req", - "authLevel": "anonymous", - "methods": [ - "get", - "post", - "options" - ], - "route": "verifyGithubAccessToken" - }, - { - "type": "http", - "direction": "out", - "name": "res" - } - ] - } \ No newline at end of file diff --git a/api_verifyGithubAccessToken/index.js b/api_verifyGithubAccessToken/index.js deleted file mode 100644 index 351ab81..0000000 --- a/api_verifyGithubAccessToken/index.js +++ /dev/null @@ -1,22 +0,0 @@ -'use strict' - -const azureWrapper = require('../util/azureWrapper'); -const connect = require('../src/db'); -const verifyGithubAccessToken = require('../src/actions/verifyGithubAccessToken'); - -module.exports = azureWrapper(async function(context, req) { - const conn = await connect(); - const Task = conn.model('Task'); - - const task = await Task.create({ - method: req.method, - url: req.url, - params: req.body - }); - - const params = { authorization: req.headers.authorization }; - - const res = await verifyGithubAccessToken({ task, conn })(params); - - return res; -}); \ No newline at end of file diff --git a/api_webhookGithubSponsors/function.json b/api_webhookGithubSponsors/function.json deleted file mode 100644 index b394889..0000000 --- a/api_webhookGithubSponsors/function.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "bindings": [ - { - "type": "httpTrigger", - "direction": "in", - "name": "req", - "authLevel": "anonymous", - "methods": [ - "get", - "post", - "options" - ], - "route": "webhookGithubSponsors" - }, - { - "type": "http", - "direction": "out", - "name": "res" - } - ] - } \ No newline at end of file diff --git a/api_webhookGithubSponsors/index.js b/api_webhookGithubSponsors/index.js deleted file mode 100644 index 5d22b7a..0000000 --- a/api_webhookGithubSponsors/index.js +++ /dev/null @@ -1,138 +0,0 @@ -'use strict' - -const Archetype = require('archetype'); -const azureWrapper = require('../util/azureWrapper'); -const connect = require('../src/db'); - -const GithubEntity = new Archetype({ - login: { - $type: 'string', - $required: true - }, - id: { - $type: 'number', - $required: true - }, - type: { - $type: 'string' - } -}).compile('GithubEntity'); - -const GithubSponsorsParams = new Archetype({ - action: { - $type: 'string' - }, - sponsorship: { - sponsor: { - $type: GithubEntity - }, - tier: { - name: { - $type: 'string' - }, - description: { - $type: 'string' - }, - is_one_time: { - $type: 'boolean' - }, - is_custom_amount: { - $type: 'boolean' - } - } - }, - sender: { - $type: GithubEntity - } -}).compile('GithubSponsorsParams'); - -module.exports = azureWrapper(webhookGithubSponsors); -module.exports.rawFunction = webhookGithubSponsors; - -async function webhookGithubSponsors(context, req) { - const conn = await connect(); - const AccessToken = conn.model('AccessToken'); - const Subscriber = conn.model('Subscriber'); - const Task = conn.model('Task'); - - const task = await Task.create({ - method: req.method, - url: req.url, - params: req.body - }); - - const { action, sponsorship, sender } = new GithubSponsorsParams(req.body); - - if (action == null || sponsorship == null) { - return { $ignored: 1 }; - } - - let subscriber; - switch (action) { - case 'created': - const name = sponsorship?.tier?.name || ''; - const description = sponsorship?.tier?.description || ''; - if (!name.includes('Mongoose Pro') && !description.includes('Mongoose Pro')) { - break; - } - if (sponsorship.tier.is_one_time) { - break; - } - if (sponsorship.tier.is_custom_amount) { - break; - } - - const data = { - githubUsername: sender.login, - githubUserId: sender.id - }; - if (sponsorship.sponsor.type === 'Organization') { - Object.assign(data, { - githubOrganization: sponsorship.sponsor.login, - githubOrganizationId: sponsorship.sponsor.id - }); - } - - subscriber = await Subscriber.create(data); - - return { subscriber }; - case 'tier_changed': - if (sponsorship.tier.name !== 'Mongoose Pro Subscriber') { - subscriber = await Subscriber.findOneAndUpdate({ githubOrganizationId: sponsorship.sponsor.id }, { - $set: { - status: 'disabled' - } - }, { returnOriginal: false }); - - if (subscriber == null) { - break; - } - - return { subscriber }; - } - - subscriber = await Subscriber.findOneAndUpdate({ githubOrganizationId: sponsorship.sponsor.id }, { - githubUsername: sender.login, - githubUserId: sender.id, - githubOrganization: sponsorship.sponsor.login - }, { returnOriginal: false, upsert: true }); - - return { subscriber }; - case 'cancelled': - subscriber = await Subscriber.findOneAndUpdate({ githubOrganizationId: sponsorship.sponsor.id }, { - $set: { - status: 'disabled' - } - }, { returnOriginal: false }); - - if (subscriber == null) { - break; - } - - return { subscriber }; - default: - break; - } - - return { $ignored: true }; -}; \ No newline at end of file