Migrate unsubscribe function to v2 (#637)

* Migrate unsubscribe function to v2

* Move Stripe import because I forgot to do it before
This commit is contained in:
Marshall Polaris 2022-07-10 13:46:00 -07:00 committed by GitHub
parent 83c5f9b323
commit eb9b14d6d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 69 additions and 68 deletions

View File

@ -613,7 +613,7 @@
>our Discord</a >our Discord</a
>! Or, >! Or,
<a <a
href="https://us-central1-mantic-markets.cloudfunctions.net/unsubscribe?id={{userId}}&type=market-resolve" href="https://unsubscribe-nggbo3neva-uc.a.run.app?id={{userId}}&type=market-resolve"
style=" style="
font-family: 'Helvetica Neue', Helvetica, Arial, font-family: 'Helvetica Neue', Helvetica, Arial,
sans-serif; sans-serif;

View File

@ -635,7 +635,7 @@
>our Discord</a >our Discord</a
>! Or, >! Or,
<a <a
href="https://us-central1-mantic-markets.cloudfunctions.net/unsubscribe?id={{userId}}&type=market-resolved" href="https://unsubscribe-nggbo3neva-uc.a.run.app?id={{userId}}&type=market-resolved"
style=" style="
font-family: 'Helvetica Neue', Helvetica, Arial, font-family: 'Helvetica Neue', Helvetica, Arial,
sans-serif; sans-serif;

View File

@ -1,4 +1,4 @@
import { DOMAIN, PROJECT_ID } from '../../common/envs/constants' import { DOMAIN, ENV_CONFIG } from '../../common/envs/constants'
import { Answer } from '../../common/answer' import { Answer } from '../../common/answer'
import { Bet } from '../../common/bet' import { Bet } from '../../common/bet'
import { getProbability } from '../../common/calculate' import { getProbability } from '../../common/calculate'
@ -141,7 +141,8 @@ export const sendWelcomeEmail = async (
const firstName = name.split(' ')[0] const firstName = name.split(' ')[0]
const emailType = 'generic' const emailType = 'generic'
const unsubscribeLink = `https://us-central1-${PROJECT_ID}.cloudfunctions.net/unsubscribe?id=${userId}&type=${emailType}` const { cloudRunId, cloudRunRegion } = ENV_CONFIG
const unsubscribeLink = `https://unsubscribe-${cloudRunId}-${cloudRunRegion}.a.run.app?id=${userId}&type=${emailType}`
await sendTemplateEmail( await sendTemplateEmail(
privateUser.email, privateUser.email,
@ -173,7 +174,8 @@ export const sendOneWeekBonusEmail = async (
const firstName = name.split(' ')[0] const firstName = name.split(' ')[0]
const emailType = 'generic' const emailType = 'generic'
const unsubscribeLink = `https://us-central1-${PROJECT_ID}.cloudfunctions.net/unsubscribe?id=${userId}&type=${emailType}` const { cloudRunId, cloudRunRegion } = ENV_CONFIG
const unsubscribeLink = `https://unsubscribe-${cloudRunId}-${cloudRunRegion}.a.run.app?id=${userId}&type=${emailType}`
await sendTemplateEmail( await sendTemplateEmail(
privateUser.email, privateUser.email,
@ -205,7 +207,8 @@ export const sendThankYouEmail = async (
const firstName = name.split(' ')[0] const firstName = name.split(' ')[0]
const emailType = 'generic' const emailType = 'generic'
const unsubscribeLink = `https://us-central1-${PROJECT_ID}.cloudfunctions.net/unsubscribe?id=${userId}&type=${emailType}` const { cloudRunId, cloudRunRegion } = ENV_CONFIG
const unsubscribeLink = `https://unsubscribe-${cloudRunId}-${cloudRunRegion}.a.run.app?id=${userId}&type=${emailType}`
await sendTemplateEmail( await sendTemplateEmail(
privateUser.email, privateUser.email,
@ -277,8 +280,9 @@ export const sendNewCommentEmail = async (
const { question, creatorUsername, slug } = contract const { question, creatorUsername, slug } = contract
const marketUrl = `https://${DOMAIN}/${creatorUsername}/${slug}#${comment.id}` const marketUrl = `https://${DOMAIN}/${creatorUsername}/${slug}#${comment.id}`
const emailType = 'market-comment'
const unsubscribeUrl = `https://us-central1-${PROJECT_ID}.cloudfunctions.net/unsubscribe?id=${userId}&type=market-comment` const { cloudRunId, cloudRunRegion } = ENV_CONFIG
const unsubscribeUrl = `https://unsubscribe-${cloudRunId}-${cloudRunRegion}.a.run.app?id=${userId}&type=${emailType}`
const { name: commentorName, avatarUrl: commentorAvatarUrl } = commentCreator const { name: commentorName, avatarUrl: commentorAvatarUrl } = commentCreator
const { text } = comment const { text } = comment
@ -359,7 +363,9 @@ export const sendNewAnswerEmail = async (
const { name, avatarUrl, text } = answer const { name, avatarUrl, text } = answer
const marketUrl = `https://${DOMAIN}/${creatorUsername}/${slug}` const marketUrl = `https://${DOMAIN}/${creatorUsername}/${slug}`
const unsubscribeUrl = `https://us-central1-${PROJECT_ID}.cloudfunctions.net/unsubscribe?id=${userId}&type=market-answer` const emailType = 'market-answer'
const { cloudRunId, cloudRunRegion } = ENV_CONFIG
const unsubscribeUrl = `https://unsubscribe-${cloudRunId}-${cloudRunRegion}.a.run.app?id=${userId}&type=${emailType}`
const subject = `New answer on ${question}` const subject = `New answer on ${question}`
const from = `${name} <info@manifold.markets>` const from = `${name} <info@manifold.markets>`

View File

@ -3,12 +3,10 @@ import * as admin from 'firebase-admin'
admin.initializeApp() admin.initializeApp()
// v1 // v1
export * from './stripe'
export * from './create-user' export * from './create-user'
export * from './on-create-bet' export * from './on-create-bet'
export * from './on-create-comment-on-contract' export * from './on-create-comment-on-contract'
export * from './on-view' export * from './on-view'
export * from './unsubscribe'
export * from './update-metrics' export * from './update-metrics'
export * from './update-stats' export * from './update-stats'
export * from './backup-db' export * from './backup-db'
@ -41,3 +39,5 @@ export * from './withdraw-liquidity'
export * from './create-group' export * from './create-group'
export * from './resolve-market' export * from './resolve-market'
export * from './get-daily-bonuses' export * from './get-daily-bonuses'
export * from './unsubscribe'
export * from './stripe'

View File

@ -1,11 +1,9 @@
import * as functions from 'firebase-functions' import { onRequest } from 'firebase-functions/v2/https'
import * as admin from 'firebase-admin' import * as admin from 'firebase-admin'
import { getUser } from './utils' import { getUser } from './utils'
import { PrivateUser } from '../../common/user' import { PrivateUser } from '../../common/user'
export const unsubscribe = functions export const unsubscribe = onRequest({ minInstances: 1 }, async (req, res) => {
.runWith({ minInstances: 1 })
.https.onRequest(async (req, res) => {
const id = req.query.id as string const id = req.query.id as string
let type = req.query.type as string let type = req.query.type as string
if (!id || !type) { if (!id || !type) {
@ -16,12 +14,9 @@ export const unsubscribe = functions
if (type === 'market-resolved') type = 'market-resolve' if (type === 'market-resolved') type = 'market-resolve'
if ( if (
![ !['market-resolve', 'market-comment', 'market-answer', 'generic'].includes(
'market-resolve', type
'market-comment', )
'market-answer',
'generic',
].includes(type)
) { ) {
res.status(400).send('Invalid type parameter.') res.status(400).send('Invalid type parameter.')
return return