This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { AuthenticationError } from "../errors"; | |
import config from "../keys"; | |
import crypto from "crypto"; | |
export default class Service { | |
getHandler({ crc_token: crcToken }) { | |
if (crcToken) { | |
return { | |
response_token: this.createCrcResponseToken(crcToken), | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const AccessDeniedError = class AccessDeniedError { | |
constructor(message) { | |
this.message = message; | |
} | |
}; | |
export const AuthenticationError = class AuthenticationError { | |
constructor(message) { | |
this.message = message; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
ValidationError, | |
AuthenticationError, | |
AccessDeniedError, | |
NotFoundError, | |
} from "../errors"; | |
import chalk from "chalk"; | |
const errorLogger = (err, req, res, next) => { | |
if (err.message) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import config from "../keys"; | |
import bodyParser from "body-parser"; | |
import crypto from "crypto"; | |
import { AuthenticationError } from "../errors"; | |
const verifyGetRequest = (req, res, next) => { | |
const { crc_token, nonce } = req?.query || {}; | |
const hmac = crypto | |
.createHmac("sha256", config.TWITTER_CONSUMER_SECRET) | |
.update(`crc_token=${crc_token}&nonce=${nonce}`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bodyParser from "body-parser"; | |
import morgan from "morgan"; | |
import cors from "cors"; | |
import helmet from "helmet"; | |
import TwitterValidator from "./twitter-validator"; | |
const CommonMiddleware = (app) => { | |
app.use(bodyParser.json()); | |
app.use(morgan("dev")); | |
app.use(cors()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Joi from "joi"; | |
const PostValidationSchema = Joi.object({ | |
for_user_id: Joi.string().required(), | |
}); | |
export default { | |
PostValidationSchema, | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Main from "../models"; | |
import { ValidationError } from "../errors"; | |
const validators = { | |
Main: { | |
scopes: { | |
post: Main.PostValidationSchema, | |
}, | |
}, | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { RequestHandler } from "express"; | |
export default AsyncWrapper; | |
declare function AsyncWrapper( | |
fn: RequestHandler | |
): (req: any, res: any, next: any) => any; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const AsyncWrapper = (fn) => { | |
return (req, res, next) => { | |
return fn(req, res).catch(next); | |
}; | |
}; | |
export default AsyncWrapper; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Router } from "express"; | |
import asyncWrapper from "../utilities/async-wrapper"; | |
import Service from "../services"; | |
import validator from "../middleware/validator"; | |
const service = new Service(); | |
const router = Router(); | |
/** @route GET /callback | |
* @desc Get CRC Check |