Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
fix(actions): leaking trigger.dev keys due to imports
Browse files Browse the repository at this point in the history
  • Loading branch information
jhdcruz committed Nov 14, 2024
1 parent a3a5f88 commit 73bfab1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 21 deletions.
10 changes: 7 additions & 3 deletions src/app/eval/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type { ImplementerFeedbackProps } from './_components/Forms/ImplementersF
import type { PartnersFeedbackProps } from './_components/Forms/PartnersForm';
import type { BeneficiariesFeedbackProps } from './_components/Forms/BeneficiariesForm';
import type ApiResponse from '@/utils/response';
import { tasks } from '@trigger.dev/sdk/v3';

/**
* Submit feedback for an activity.
Expand Down Expand Up @@ -51,7 +52,8 @@ export async function submitFeedback(
switch (type) {
case 'beneficiaries':
// analyze beneficiary feedback
await analyzeBeneficiary.trigger(
await tasks.trigger<typeof analyzeBeneficiary>(
'analyze-beneficiary',
{ id: data.id, form: feedback as BeneficiariesFeedbackProps },
{
idempotencyKey: idempotencyKey,
Expand All @@ -63,7 +65,8 @@ export async function submitFeedback(

case 'partners':
// analyze partner feedback
await analyzePartner.trigger(
await tasks.trigger<typeof analyzePartner>(
'analyze-partner',
{ id: data.id, form: feedback as PartnersFeedbackProps },
{
idempotencyKey: idempotencyKey,
Expand All @@ -75,7 +78,8 @@ export async function submitFeedback(

case 'implementers':
// analyze implementers feedback
await analyzeImplementer.trigger(
await tasks.trigger<typeof analyzeImplementer>(
'analyze-implementer',
{ id: data.id, form: feedback as ImplementerFeedbackProps },
{
idempotencyKey: idempotencyKey,
Expand Down
15 changes: 8 additions & 7 deletions src/app/portal/activities/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ import {
} from '@/libs/supabase/api/faculty-assignments';
import type { ActivityResponse } from '@/libs/supabase/api/_response';
import type { ActivityFormProps } from './_components/Forms/ActivityFormModal';
import type ApiResponse from '@/utils/response';
import { emailAssigned } from '@/trigger/email-assigned';
import type { emailAssigned } from '@/trigger/email-assigned';
import type { emailUnassigned } from '@/trigger/email-unassigned';
import type { emailDepts } from '@/trigger/email-depts';
import {
rescheduleReminders,
scheduleReminders,
} from '@/libs/triggerdev/reminders';
import { emailUnassigned } from '@/trigger/email-unassigned';
import { revalidate } from '@/app/actions';
import { emailDepts } from '@/trigger/email-depts';
import type ApiResponse from '@/utils/response';
import { tasks } from '@trigger.dev/sdk/v3';

/**
* Create and process new activity.
Expand Down Expand Up @@ -159,7 +160,7 @@ export async function submitActivity(

// email notification to selected departments
if (activity.notify?.length) {
emailDepts.trigger({
await tasks.trigger<typeof emailDepts>('email-depts', {
activityId: activityId,
depts: activity.notify,
});
Expand Down Expand Up @@ -210,7 +211,7 @@ export async function assignFaculty(
if (assignResponse.status !== 0) return assignResponse!;

// send email notice to newly assigned faculties
emailAssigned.trigger({
await tasks.trigger<typeof emailAssigned>('email-assigned', {
activityId: activityId,
ids: faculty.filter((id) => !original?.includes(id)),
});
Expand All @@ -227,7 +228,7 @@ export async function assignFaculty(
if (delResponse.status !== 0) return delResponse;

// send email notice to unassigned faculties
emailUnassigned.trigger({
await tasks.trigger<typeof emailUnassigned>('email-unassigned', {
activityId: activityId,
ids: faculty.filter((id) => !original?.includes(id)),
});
Expand Down
13 changes: 8 additions & 5 deletions src/libs/triggerdev/reminders.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { runs } from '@trigger.dev/sdk/v3';
import { emailReminders } from '@/trigger/email-reminders';
import { tasks, runs } from '@trigger.dev/sdk/v3';
import type { emailReminders } from '@/trigger/email-reminders';

/**
* Schedule email reminders for an activity.
Expand All @@ -21,7 +21,8 @@ export async function scheduleReminders({
// no need to await
if (activityStartingDate.getTime() - 1 * 24 * 60 * 60 * 1000 > Date.now()) {
// schedule new reminder task, 1 day before the activity
await emailReminders.trigger(
await tasks.trigger<typeof emailReminders>(
'email-reminders',
{ activityId: activityId },
{
idempotencyKey: activityId + '_1d',
Expand All @@ -37,7 +38,8 @@ export async function scheduleReminders({
// check if the activity starting date is not within 3 days from now
if (activityStartingDate.getTime() - 3 * 24 * 60 * 60 * 1000 > Date.now()) {
// schedule new reminder task, 3 and 7 days before the activity
await emailReminders.trigger(
await tasks.trigger<typeof emailReminders>(
'email-reminders',
{ activityId: activityId },
{
idempotencyKey: activityId + '_3d',
Expand All @@ -53,7 +55,8 @@ export async function scheduleReminders({
// check if the activity starting date is not within 7 days from now
if (activityStartingDate.getTime() - 7 * 24 * 60 * 60 * 1000 > Date.now()) {
// schedule new reminder task, 7 days before the activity
await emailReminders.trigger(
await tasks.trigger<typeof emailReminders>(
'email-reminders',
{ activityId: activityId },
{
idempotencyKey: activityId + '_7d',
Expand Down
18 changes: 12 additions & 6 deletions src/trigger/analyze-feedback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ export const analyzePartner = task({
const sentimentScore = await analyzeSentiments(textsForSentiment);

// save results
await envvars.retrieve('SUPABASE_URL');
await envvars.retrieve('SUPABASE_SERVICE_KEY');
await Promise.all([
envvars.retrieve('SUPABASE_URL'),
envvars.retrieve('SUPABASE_SERVICE_KEY'),
]);
const supabase = createAdminClient();

const data = {
Expand Down Expand Up @@ -166,8 +168,10 @@ export const analyzeImplementer = task({
const sentimentScore = await analyzeSentiments(textsForSentiment);

// save results
await envvars.retrieve('SUPABASE_URL');
await envvars.retrieve('SUPABASE_SERVICE_KEY');
await Promise.all([
envvars.retrieve('SUPABASE_URL'),
envvars.retrieve('SUPABASE_SERVICE_KEY'),
]);
const supabase = createAdminClient();

const data = {
Expand Down Expand Up @@ -249,8 +253,10 @@ export const analyzeBeneficiary = task({
const sentimentScore = await analyzeSentiments(textsForSentiment);

// save results
await envvars.retrieve('SUPABASE_URL');
await envvars.retrieve('SUPABASE_SERVICE_KEY');
await Promise.all([
envvars.retrieve('SUPABASE_URL'),
envvars.retrieve('SUPABASE_SERVICE_KEY'),
]);
const supabase = createAdminClient();

const data = {
Expand Down

0 comments on commit 73bfab1

Please sign in to comment.