da7f0dda0e
* feat(gatekeeper): add gatekeeper module feature flag * feat(gatekeeper): add workspace pricing table domain * feat(gatekeeper): add checkout session creation * feat(gatekeeper): verify stripe signature * wip(gatekeeper): checkout callbacks * feat(gatekeeper): add unlimited and academia plan types * refactor(envHelper): getStringFromEnv helper * chore(gatekeeper): add future todos * feat(gatekeeper): add productId to the subscription domain * feat(gatekeeper): add in memory repositories * feat(gatekeeper): add more errors * feat(gatekeeper): complete checkout session service * feat(gatekeeper): add stripe client implementation * feat(gatekeeper): add checkout session completion webhook callback path * feat(gendo): fix not needing env vars if gendo module is not enabled * feat(gatekeeper): require a license for billing * chore(gatekeeper): cleanup before testing * feat(gatekeeper): subscriptionData parsing model * ci: add billing integration and gatekeeper modules to test config * test(gatekeeper): add checkout service tests * feat(gatekeeper): make completeCheckout callback idempotent properly * feat(gatekeeper): move to knex based repositories * test(gatekeeper): billing repository tests * feat(gatekeeper): add yearly billing cycle toggle * feat(ci): add stripe integration context to test job * feat(billingPage): conditionally render the checkout CTAs * fix(gatekeeper): remove flaky test condition * feat(helm): add billing integration feature flag * WIP billing gql api * feat(gatekeeper): cancel checkout session api * feat(gatekeeper): handle existing checkout sessions, when trying to create a new one * feat(gatekeeper): add workspace plans gql api * feat(gatekeeper): handle cancelation and subscription updates * fix(gatekeeper): scope initialization * fix(gatekeeper): eliminate stripe client import sideeffect * fix(gatekeeper): eliminate stripe client import sideeffect 2 * feat(gatekeeper): upsize subscription on workspace role change * feat(shared): add command pattern implementation * refactor(eventBus): remove return capabilities from the event bus * refactor(workspaces): use new commandFactory in workspace resolver * feat(core): facelift taskLock * feat(gatekeeper): shedule subscription downscale * feat(gatekeeper): manage subscription downscale * feat(gatekeeper): get workspace subscriptions, that are about to expire * feat(gatekeeper): manage subscription downscale * fix(gatekeeper): do not update subscription to canceled subs * ci: bump postgres and max connections * feat(workspaces): fix command factory event bugs
109 lines
4.0 KiB
TypeScript
109 lines
4.0 KiB
TypeScript
import { Optional, SpeckleModule } from '@/modules/shared/helpers/typeHelper'
|
|
import { initializeEventListenerFactory } from '@/modules/activitystream/services/eventListener'
|
|
import { publishNotification } from '@/modules/notifications/services/publication'
|
|
import { activitiesLogger, moduleLogger } from '@/logging/logging'
|
|
import { weeklyEmailDigestEnabled } from '@/modules/shared/helpers/envHelper'
|
|
import { getEventBus } from '@/modules/shared/services/eventBus'
|
|
import { handleServerInvitesActivitiesFactory } from '@/modules/activitystream/services/serverInvitesActivity'
|
|
import { sendActivityNotificationsFactory } from '@/modules/activitystream/services/summary'
|
|
import {
|
|
getActiveUserStreamsFactory,
|
|
saveActivityFactory
|
|
} from '@/modules/activitystream/repositories'
|
|
import { db } from '@/db/knex'
|
|
import { addStreamInviteSentOutActivityFactory } from '@/modules/activitystream/services/streamActivity'
|
|
import { publish } from '@/modules/shared/utils/subscriptions'
|
|
import { getStreamFactory } from '@/modules/core/repositories/streams'
|
|
import {
|
|
addStreamAccessRequestDeclinedActivityFactory,
|
|
addStreamAccessRequestedActivityFactory
|
|
} from '@/modules/activitystream/services/accessRequestActivity'
|
|
import { ScheduleExecution } from '@/modules/core/domain/scheduledTasks/operations'
|
|
import { scheduleExecutionFactory } from '@/modules/core/services/taskScheduler'
|
|
import {
|
|
acquireTaskLockFactory,
|
|
releaseTaskLockFactory
|
|
} from '@/modules/core/repositories/scheduledTasks'
|
|
|
|
let scheduledTask: ReturnType<ScheduleExecution> | null = null
|
|
let quitEventListeners: Optional<ReturnType<typeof initializeEventListeners>> =
|
|
undefined
|
|
|
|
const initializeEventListeners = () => {
|
|
const handleServerInvitesActivities = handleServerInvitesActivitiesFactory({
|
|
eventBus: getEventBus(),
|
|
logger: activitiesLogger,
|
|
getStream: getStreamFactory({ db }),
|
|
addStreamInviteSentOutActivity: addStreamInviteSentOutActivityFactory({
|
|
saveActivity: saveActivityFactory({ db }),
|
|
publish
|
|
})
|
|
})
|
|
|
|
const quitters = [handleServerInvitesActivities()]
|
|
|
|
return () => quitters.forEach((quitter) => quitter())
|
|
}
|
|
|
|
const scheduleWeeklyActivityNotifications = () => {
|
|
const scheduleExecution = scheduleExecutionFactory({
|
|
acquireTaskLock: acquireTaskLockFactory({ db }),
|
|
releaseTaskLock: releaseTaskLockFactory({ db })
|
|
})
|
|
|
|
// just to test stuff
|
|
// every 1000 seconds
|
|
// const cronExpression = '*/1000 * * * * *'
|
|
// at 00 minutest, 10 (am) hours, every month, every year,
|
|
// every 1st day of the week (monday)
|
|
// cheat sheet https://crontab.guru
|
|
const cronExpression = '00 10 * * 1'
|
|
// configure the number of days, the activities are scraped for
|
|
const numberOfDays = 7
|
|
return scheduleExecution(
|
|
cronExpression,
|
|
'weeklyActivityNotification',
|
|
//task should be locked for 10 minutes
|
|
async (now: Date) => {
|
|
activitiesLogger.info('Sending weekly activity digests notifications.')
|
|
const end = now
|
|
const start = new Date(end.getTime())
|
|
start.setDate(start.getDate() - numberOfDays)
|
|
await sendActivityNotificationsFactory({
|
|
publishNotification,
|
|
getActiveUserStreams: getActiveUserStreamsFactory({ db })
|
|
})(start, end)
|
|
},
|
|
10 * 60 * 1000
|
|
)
|
|
}
|
|
|
|
const activityModule: SpeckleModule = {
|
|
init: async (_, isInitial) => {
|
|
moduleLogger.info('🤺 Init activity module')
|
|
if (isInitial) {
|
|
initializeEventListenerFactory({
|
|
addStreamAccessRequestedActivity: addStreamAccessRequestedActivityFactory({
|
|
saveActivity: saveActivityFactory({ db })
|
|
}),
|
|
addStreamAccessRequestDeclinedActivity:
|
|
addStreamAccessRequestDeclinedActivityFactory({
|
|
saveActivity: saveActivityFactory({ db })
|
|
}),
|
|
saveActivity: saveActivityFactory({ db })
|
|
})()
|
|
if (weeklyEmailDigestEnabled())
|
|
scheduledTask = scheduleWeeklyActivityNotifications()
|
|
}
|
|
quitEventListeners = initializeEventListeners()
|
|
},
|
|
shutdown: () => {
|
|
scheduledTask?.stop()
|
|
quitEventListeners?.()
|
|
}
|
|
}
|
|
|
|
export = {
|
|
...activityModule
|
|
}
|