-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Documentation + separate routes and exports into their own file
- Loading branch information
1 parent
645a57a
commit c38f090
Showing
13 changed files
with
248 additions
and
78 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,47 @@ This code drives the majority of the backend responsible for powering the ACM Po | |
|
||
### Portal Functions | ||
|
||
``` | ||
// fill at later point in time | ||
``` | ||
### Typeform Functions | ||
|
||
The typeform functions section is very mature and is responsible for all interactions with the third party service. | ||
|
||
##### Open Webhook | ||
|
||
The `typeform_webhook` function present in [typeform.ts](./typeform.ts) is responsible for receiving all incoming webhook requests from typeform. When creating a new typeform make sure to add in the following url as a webhook: `https://us-central1-acm-core.cloudfunctions.net/challenge/typeform`. | ||
|
||
This function will extract all the information within the typeform response body and save only the relevant fields in the following format. An array of `qa` type objects represents the final state of the object that is persisted in Cloud Firestore. This format makes it easy to quickly retrieve typeform responses and perform additional manipulation with Firestore Triggers. | ||
|
||
``` | ||
export interface qa { | ||
question: string; | ||
answer: string; | ||
type: string; | ||
} | ||
``` | ||
|
||
Hidden fields are also extracted from Typeform submissions and saved in the same format. In this situation the `question` will be the hidden field key and the `answer` will be the hidden field value. | ||
|
||
##### Confirmation Emails | ||
|
||
One essential part to ensuring that members who submit forms to ACM are happy and aware that their submission was received is to send them confirmation emails. While typeform natively supports sending confirmation emails it does not support the ability to customize and design them to match the ACM Brand Guidelines. In [typeform.ts](./typeform.ts) we have the `send_confirmation` firestore trigger. This function gets run anytime a new typeform document gets saved in Cloud Firestore. | ||
|
||
This functions queries the `typeform_meta` firestore collection with the `typeform_id` to see whether there exists a confirmation email that should be sent. If the exists information regarding the Sendgrid template / sender information then this firestore trigger will call the Sendgrid API to send out that specific email. Adding a new configuration can be done through the officer utility [Sendgrid x Typeform](https://survey.acmutd.co/email). | ||
|
||
##### Custom Actions | ||
|
||
Sometimes we want to perform a custom action based on the submission of a typeform. These are typically the internal utilities made for the ACM officer to refine workflows. All custom action functions are saved in [Custom Actions](../custom). These are also Firestore Triggers and get executed anytime a new document is created. The following functions have custom triggers: | ||
|
||
- [Vanity Form](https://survey.acmutd.co/vanity) | ||
- [Sendgrid Form](https://survey.acmutd.co/email) | ||
- [Event Form](https://survey.acmutd.co/event) | ||
|
||
### Questions | ||
|
||
Sometimes you may have additional questions. If the answer was not found in this readme please feel free to reach out to the [Director of Development](mailto:[email protected]) for _ACM_ | ||
|
||
We request that you be as detailed as possible in your questions, doubts or concerns to ensure that we can be of maximum assistance. Thank you! | ||
|
||
![ACM Development](https://www.acmutd.co/brand/Development/Banners/light_dark_background.png) |
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
Empty file.
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
Empty file.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,4 +46,12 @@ Unauthenticated requests can be sent to `/portal`. This is useful for situations | |
https://us-central1-acm-core.cloudfunctions.net/portal | ||
``` | ||
|
||
The endpoints are deployed under `/portal` | ||
The endpoints are deployed under `/portal` | ||
|
||
### Questions | ||
|
||
Sometimes you may have additional questions. If the answer was not found in this readme please feel free to reach out to the [Director of Development](mailto:[email protected]) for _ACM_ | ||
|
||
We request that you be as detailed as possible in your questions, doubts or concerns to ensure that we can be of maximum assistance. Thank you! | ||
|
||
![ACM Development](https://www.acmutd.co/brand/Development/Banners/light_dark_background.png) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* Handle express routing in this file | ||
*/ | ||
import app_cf from "../express_configs/express_cf"; | ||
import { Request, Response } from "express"; | ||
import * as portalFunctions from "../application/portal"; | ||
|
||
app_cf.all("/", (request: Request, response: Response, next: () => void) => { | ||
next(); | ||
}); | ||
|
||
/** | ||
* Cloudflare access protected endpoint | ||
*/ | ||
app_cf.get("/verify", portalFunctions.verify); //to be phased out | ||
app_cf.get("/verify-idp", portalFunctions.verify_idp); | ||
|
||
// http server endpoints | ||
export default app_cf; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* Handle express routing in this file | ||
*/ | ||
import app_open from "../express_configs/express_open"; | ||
|
||
import { Request, Response } from "express"; | ||
|
||
import * as challengeFunctions from "../challenge/challenge"; | ||
import * as hacktoberfestFunctions from "../custom/hacktoberfest"; | ||
import * as typeformFunctions from "../application/typeform"; | ||
import * as errorFunctions from "../services/ErrorService"; | ||
import { debug_logger } from "../services/logging"; | ||
|
||
/** | ||
* Match all requests | ||
*/ | ||
app_open.all("/", (request: Request, response: Response, next) => { | ||
next(); | ||
}); | ||
|
||
/** | ||
* Challenges for ACM Development | ||
*/ | ||
app_open.post("/tags/:tag", challengeFunctions.createTag); | ||
app_open.get("/tags/:tag/:token", challengeFunctions.getTag); | ||
app_open.patch("/tags/:tag/:token", challengeFunctions.patchTag); | ||
app_open.delete("/tags/:tag/:token", challengeFunctions.deleteTag); | ||
|
||
/** | ||
* typeform webhook | ||
*/ | ||
app_open.post("/typeform", typeformFunctions.typeform_webhook); | ||
|
||
/** | ||
* Debugging endpoints | ||
*/ | ||
app_open.get("/debug-sentry", errorFunctions.debug_sentry); | ||
app_open.get("/debug-logger", debug_logger); | ||
|
||
/** | ||
* htf-development retrieval | ||
*/ | ||
app_open.post("/htf-development", hacktoberfestFunctions.retrieve_record); | ||
|
||
export default app_open; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Handle express routing in this file | ||
*/ | ||
import app_portal from "../express_configs/express_portal"; | ||
import { Request, Response } from "express"; | ||
import * as portalFunctions from "../application/portal"; | ||
|
||
//this will match every call made to this api. | ||
app_portal.all("/", (request: Request, response: Response, next) => { | ||
//next() basically says to run the next route that matches the url | ||
next(); | ||
}); | ||
|
||
/** | ||
* The two following endpoints are duplicated across both /auth0 and /gsuite | ||
* This is because they have common requirements | ||
* Additional endpoints for separate forms will be on one or the other path | ||
*/ | ||
app_portal.get("/auth0/verify-idp", portalFunctions.verify_idp); | ||
app_portal.get("/gsuite/verify-idp", portalFunctions.verify_idp); | ||
|
||
app_portal.get("/auth0/verify", portalFunctions.verify); | ||
app_portal.get("/gsuite/verify", portalFunctions.verify); | ||
|
||
//all initialization requests on portal frontend for forms are get requests | ||
app_portal.get("/auth0/create-blank-profile", portalFunctions.create_blank_profile); | ||
app_portal.get("/auth0/profile", portalFunctions.get_profile); | ||
app_portal.get("/auth0/developer", portalFunctions.get_developer_profile); | ||
app_portal.get("/auth0/checkin", portalFunctions.record_event); | ||
|
||
// http server endpoints | ||
export default app_portal; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Logging in ACM Core | ||
|
||
Logging is an important aspect of being able to understand the sequence of events that take place in the API. Several aspects make using regular `console.log` statements not ideal in a production context. We would like to have a logging solution which is robust, scalable, queryable, triggers alerts & more. | ||
|
||
### LogDNA | ||
|
||
The current solution used by ACM Core is using LogDNA as a third party external service. LogDNA has several premium features which are free for students and this guide will explain how to connect your LogDNA account to ACM Core. | ||
|
||
- [LogDNA Student](https://www.logdna.com/github-students) | ||
|
||
Set up a student account by following the steps at the link above. Once you have completed setting up an account grab your ingestion id and return to this readme. | ||
|
||
### Add to Logging Service | ||
|
||
The [logging.ts](./logging.ts) file sets up a `Logger` class that manages sending log information to everyone who has associated an ingestion id with the ACM Core project. | ||
|
||
##### Adding to Firebase Functions Config | ||
|
||
The first thing that we will need to do is add your LogDNA Ingestion ID as an environment variable. You can add it to the firebase functions config as follows. Make sure to replace `yourname` and `your-ingestion-id` in the command below. Make sure to just use your first name and not have any spaces in the command. | ||
|
||
``` | ||
$ firebase functions:config:set logdna.yourname=your-ingestion-id | ||
``` | ||
|
||
After this update the `.runtimeconfig.json` file with the new environment variable. Make sure to be at the root of the repository before running this command. | ||
|
||
``` | ||
$ firebase functions:config:get > functions/.runtimeconfig.json | ||
``` | ||
|
||
##### Updating the Logger | ||
|
||
In [logging.ts](./logging.ts) create a new LogDNA logger instance by duplicating the line below and changing the name of the logger to be your own. Also update the environment variable being passed in to be `functions.config().logdna.yourname` that was set in the previous section. | ||
|
||
``` | ||
const harsha_logger = logdna.createLogger(functions.config().logdna.harsha, options); | ||
``` | ||
|
||
Next append your logger to the array of LogDNA instances within the Logger class. | ||
|
||
``` | ||
private logdna_loggers = [harsha_logger, YOURNAME_logger /*, insert additional loggers */]; | ||
``` | ||
|
||
That's it! Your logger will now receive all the log data from the API and can be accessed in the LogDNA cloud console. | ||
|
||
##### Using the Logger | ||
|
||
An instance of the logger class can be imported into any file as follows | ||
|
||
``` | ||
import logger from "../services/logging"; | ||
``` | ||
|
||
Using the logger is as simple as using the single `.log()` function. | ||
|
||
``` | ||
logger.log("hello world"); | ||
``` | ||
|
||
The logger is capable of receiving objects too which can then be queryed in the LogDNA cloud console for additional visibility. | ||
|
||
``` | ||
logger.log({ | ||
...my_object, | ||
message: "logging a new message", | ||
}); | ||
``` | ||
|
||
You can also log entire request or response bodies when receiving an http request but this is not receommended since it makes log traversal much more challenging. There is also no need to log information like timestamps or environment context. These variables are automatically logged and tracked. | ||
|
||
### Questions | ||
|
||
Sometimes you may have additional questions. If the answer was not found in this readme please feel free to reach out to the [Director of Development](mailto:[email protected]) for _ACM_ | ||
|
||
We request that you be as detailed as possible in your questions, doubts or concerns to ensure that we can be of maximum assistance. Thank you! | ||
|
||
![ACM Development](https://www.acmutd.co/brand/Development/Banners/light_dark_background.png) |