Skip to content

Commit 172b9a5

Browse files
committed
fixed duplicate types
1 parent 716a86b commit 172b9a5

5 files changed

Lines changed: 43 additions & 100 deletions

File tree

apps/sim/app/api/workspaces/[id]/notifications/[notificationId]/test/route.ts

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import { createLogger } from '@sim/logger'
55
import { and, eq } from 'drizzle-orm'
66
import { type NextRequest, NextResponse } from 'next/server'
77
import { v4 as uuidv4 } from 'uuid'
8-
import { renderWorkflowNotificationEmail } from '@/components/emails'
8+
import {
9+
type EmailRateLimitsData,
10+
type EmailUsageData,
11+
renderWorkflowNotificationEmail,
12+
} from '@/components/emails'
913
import { getSession } from '@/lib/auth'
1014
import { decryptSecret } from '@/lib/core/security/encryption'
1115
import { getBaseUrl } from '@/lib/core/utils/urls'
@@ -27,25 +31,6 @@ interface SlackConfig {
2731
accountId: string
2832
}
2933

30-
interface RateLimitStatus {
31-
requestsPerMinute: number
32-
remaining: number
33-
maxBurst?: number
34-
resetAt?: string
35-
}
36-
37-
interface RateLimitsData {
38-
sync?: RateLimitStatus
39-
async?: RateLimitStatus
40-
}
41-
42-
interface UsageDataProps {
43-
currentPeriodCost: number
44-
limit: number
45-
percentUsed: number
46-
isExceeded?: boolean
47-
}
48-
4934
function generateSignature(secret: string, timestamp: number, body: string): string {
5035
const signatureBase = `${timestamp}.${body}`
5136
const hmac = createHmac('sha256', secret)
@@ -183,15 +168,15 @@ async function testEmail(subscription: typeof workspaceNotificationSubscription.
183168
cost: `$${(((data.cost as Record<string, unknown>)?.total as number) || 0).toFixed(4)}`,
184169
logUrl,
185170
finalOutput: data.finalOutput,
186-
rateLimits: data.rateLimits as RateLimitsData | undefined,
187-
usageData: data.usage as UsageDataProps | undefined,
171+
rateLimits: data.rateLimits as EmailRateLimitsData | undefined,
172+
usageData: data.usage as EmailUsageData | undefined,
188173
})
189174

190175
const result = await sendEmail({
191176
to: subscription.emailRecipients,
192177
subject: `[Test] Workflow Execution: ${data.workflowName}`,
193178
html,
194-
text: `This is a test notification from Sim Studio.\n\nWorkflow: ${data.workflowName}\nStatus: ${data.status}\nDuration: ${data.totalDurationMs}ms\n\nView Log: ${logUrl}\n\nThis notification is configured for workspace notifications.`,
179+
text: `This is a test notification from Sim.\n\nWorkflow: ${data.workflowName}\nStatus: ${data.status}\nDuration: ${data.totalDurationMs}ms\n\nView Log: ${logUrl}\n\nThis notification is configured for workspace notifications.`,
195180
emailType: 'notifications',
196181
})
197182

@@ -245,7 +230,7 @@ async function testSlack(
245230
elements: [
246231
{
247232
type: 'mrkdwn',
248-
text: 'This is a test notification from Sim Studio workspace notifications.',
233+
text: 'This is a test notification from Sim workspace notifications.',
249234
},
250235
],
251236
},

apps/sim/background/workspace-notification-delivery.ts

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ import { createLogger } from '@sim/logger'
1010
import { task } from '@trigger.dev/sdk'
1111
import { and, eq, isNull, lte, or, sql } from 'drizzle-orm'
1212
import { v4 as uuidv4 } from 'uuid'
13-
import { renderWorkflowNotificationEmail } from '@/components/emails'
13+
import {
14+
type EmailRateLimitsData,
15+
type EmailUsageData,
16+
renderWorkflowNotificationEmail,
17+
} from '@/components/emails'
1418
import { checkUsageStatus } from '@/lib/billing/calculations/usage-monitor'
1519
import { getHighestPrioritySubscription } from '@/lib/billing/core/subscription'
1620
import { RateLimiter } from '@/lib/core/rate-limiter'
@@ -30,25 +34,6 @@ function getRetryDelayWithJitter(baseDelay: number): number {
3034
return Math.floor(baseDelay + jitter)
3135
}
3236

33-
interface RateLimitStatus {
34-
requestsPerMinute: number
35-
remaining: number
36-
maxBurst?: number
37-
resetAt?: string
38-
}
39-
40-
interface RateLimitsData {
41-
sync?: RateLimitStatus
42-
async?: RateLimitStatus
43-
}
44-
45-
interface UsageDataPayload {
46-
currentPeriodCost: number
47-
limit: number
48-
percentUsed: number
49-
isExceeded?: boolean
50-
}
51-
5237
interface NotificationPayload {
5338
id: string
5439
type: 'workflow.execution.completed'
@@ -65,8 +50,8 @@ interface NotificationPayload {
6550
totalDurationMs: number
6651
cost?: Record<string, unknown>
6752
finalOutput?: unknown
68-
rateLimits?: RateLimitsData
69-
usage?: UsageDataPayload
53+
rateLimits?: EmailRateLimitsData
54+
usage?: EmailUsageData
7055
}
7156
}
7257

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1+
export type {
2+
EmailRateLimitStatus,
3+
EmailRateLimitsData,
4+
EmailUsageData,
5+
WorkflowNotificationEmailProps,
6+
} from './workflow-notification-email'
17
export { WorkflowNotificationEmail } from './workflow-notification-email'

apps/sim/components/emails/notifications/workflow-notification-email.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,31 @@ import { baseStyles } from '@/components/emails/_styles'
33
import { EmailLayout } from '@/components/emails/components'
44
import { getBrandConfig } from '@/lib/branding/branding'
55

6-
interface RateLimitStatus {
6+
/**
7+
* Serialized rate limit status for email payloads.
8+
* Note: This differs from the canonical RateLimitStatus in @/lib/core/rate-limiter
9+
* which uses Date for resetAt. This version uses string for JSON serialization.
10+
*/
11+
export interface EmailRateLimitStatus {
712
requestsPerMinute: number
813
remaining: number
914
maxBurst?: number
1015
resetAt?: string
1116
}
1217

13-
interface RateLimitsData {
14-
sync?: RateLimitStatus
15-
async?: RateLimitStatus
18+
export interface EmailRateLimitsData {
19+
sync?: EmailRateLimitStatus
20+
async?: EmailRateLimitStatus
1621
}
1722

18-
interface UsageDataProps {
23+
export interface EmailUsageData {
1924
currentPeriodCost: number
2025
limit: number
2126
percentUsed: number
2227
isExceeded?: boolean
2328
}
2429

25-
interface WorkflowNotificationEmailProps {
30+
export interface WorkflowNotificationEmailProps {
2631
workflowName: string
2732
status: 'success' | 'error'
2833
trigger: string
@@ -31,8 +36,8 @@ interface WorkflowNotificationEmailProps {
3136
logUrl: string
3237
alertReason?: string
3338
finalOutput?: unknown
34-
rateLimits?: RateLimitsData
35-
usageData?: UsageDataProps
39+
rateLimits?: EmailRateLimitsData
40+
usageData?: EmailUsageData
3641
}
3742

3843
function formatJsonForEmail(data: unknown): string {

apps/sim/components/emails/render.ts

Lines changed: 8 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ import {
1515
PollingGroupInvitationEmail,
1616
WorkspaceInvitationEmail,
1717
} from '@/components/emails/invitations'
18-
import { WorkflowNotificationEmail } from '@/components/emails/notifications'
18+
import {
19+
WorkflowNotificationEmail,
20+
type WorkflowNotificationEmailProps,
21+
} from '@/components/emails/notifications'
1922
import { HelpConfirmationEmail } from '@/components/emails/support'
2023
import { getBaseUrl } from '@/lib/core/utils/urls'
2124

@@ -260,49 +263,8 @@ export async function renderCareersSubmissionEmail(params: {
260263
)
261264
}
262265

263-
interface RateLimitStatus {
264-
requestsPerMinute: number
265-
remaining: number
266-
maxBurst?: number
267-
resetAt?: string
268-
}
269-
270-
interface RateLimitsData {
271-
sync?: RateLimitStatus
272-
async?: RateLimitStatus
273-
}
274-
275-
interface UsageDataProps {
276-
currentPeriodCost: number
277-
limit: number
278-
percentUsed: number
279-
isExceeded?: boolean
280-
}
281-
282-
export async function renderWorkflowNotificationEmail(params: {
283-
workflowName: string
284-
status: 'success' | 'error'
285-
trigger: string
286-
duration: string
287-
cost: string
288-
logUrl: string
289-
alertReason?: string
290-
finalOutput?: unknown
291-
rateLimits?: RateLimitsData
292-
usageData?: UsageDataProps
293-
}): Promise<string> {
294-
return await render(
295-
WorkflowNotificationEmail({
296-
workflowName: params.workflowName,
297-
status: params.status,
298-
trigger: params.trigger,
299-
duration: params.duration,
300-
cost: params.cost,
301-
logUrl: params.logUrl,
302-
alertReason: params.alertReason,
303-
finalOutput: params.finalOutput,
304-
rateLimits: params.rateLimits,
305-
usageData: params.usageData,
306-
})
307-
)
266+
export async function renderWorkflowNotificationEmail(
267+
params: WorkflowNotificationEmailProps
268+
): Promise<string> {
269+
return await render(WorkflowNotificationEmail(params))
308270
}

0 commit comments

Comments
 (0)