Skip to content

Commit

Permalink
fix: Move away from non-database enums
Browse files Browse the repository at this point in the history
  • Loading branch information
beverloo committed Feb 7, 2025
1 parent 8f14587 commit c5b4c59
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 119 deletions.
2 changes: 1 addition & 1 deletion app/admin/system/integrations/VertexAI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function ServiceSettings(props: ServiceSettingsProps) {
}
}, [ onSave, settings ]);

const onModelChange = useCallback((value: VertexSupportedModels) => {
const onModelChange = useCallback((value: VertexAISettings['model']) => {
setInvalidated(true);
onChange({ ...settings, model: value });
}, [ onChange, settings ]);
Expand Down
6 changes: 4 additions & 2 deletions app/admin/system/outbox/email/[id]/DetailedLogs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import WarningOutlinedIcon from '@mui/icons-material/WarningOutlined';
import type { EmailLoggerSeverity } from '@lib/integrations/email/EmailLogger';
import type { TaskLogSeverity } from '@lib/scheduler/TaskContext';

type TaskLogSeverityType = typeof TaskLogSeverity[keyof typeof TaskLogSeverity];

/**
* Detailed logs applicable to outbox messages.
*/
Expand All @@ -36,7 +38,7 @@ interface DetailedOutboxLogEntry {
* Detailed logs applicable to tasks.
*/
interface DetailedTaskLogEntry {
severity: TaskLogSeverity;
severity: TaskLogSeverityType;
data: any[];
message: string;
};
Expand All @@ -51,7 +53,7 @@ type DetailedLogEntry = {
/**
* Displays an icon appropriate to the severity level of a log message.
*/
function LogSeverity(props: { severity: EmailLoggerSeverity | TaskLogSeverity }) {
function LogSeverity(props: { severity: EmailLoggerSeverity | TaskLogSeverityType }) {
let icon: React.ReactNode = undefined;

switch (props.severity) {
Expand Down
159 changes: 80 additions & 79 deletions app/lib/Log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,84 +11,85 @@ export { LogSeverity };
/**
* Enumeration containing all the valid log types. Will be stored as a string, so keep alphabetized.
*/
export enum LogType {
AccountActivate = 'account-activate',
AccountIdentifyAccessCode = 'account-identify-access-code',
AccountIdentifyPasskey = 'account-identify-passkey',
AccountIdentifyPassword = 'account-identify-password',
AccountIdentityCheck = 'account-identity-check',
AccountPasskeyCreate = 'account-passkey-create',
AccountPasskeyDelete = 'account-passkey-delete',
AccountPasswordResetRequest = 'account-password-reset-request',
AccountPasswordReset = 'account-password-reset',
AccountPasswordUpdate = 'account-password-update',
AccountRegister = 'account-register',
AccountUpdateAvatar = 'account-update-avatar',
AccountUpdate = 'account-update',
AdminAccessVolunteerInfo = 'admin-access-volunteer-info',
AdminClearHotelPreferences = 'admin-clear-hotel-preferences',
AdminClearRefundRequest = 'admin-clear-refund-request',
AdminClearTrainingPreferences = 'admin-clear-training-preferences',
AdminDisplayMutation = 'admin-display-mutation',
AdminContentMutation = 'admin-content-mutation',
AdminEventApplication = 'admin-event-application',
AdminEventCreate = 'admin-event-create',
AdminEventDeadlineMutation = 'admin-event-deadline-mutation',
AdminEventHotelMutation = 'admin-event-hotel',
AdminEventProgramRequestUpdate = 'admin-event-program-request-update',
AdminEventPublishInfo = 'admin-event-publish-info',
AdminEventRetentionMessage = 'admin-event-retention-message',
AdminEventRetentionUpdate = 'admin-event-retention-update',
AdminEventRoleUpdate = 'admin-event-role-update',
AdminEventShiftCategoryMutation = 'admin-event-shift-category-mutation',
AdminEventShiftMutation = 'admin-event-shift-mutation',
AdminEventTeamUpdate = 'admin-event-team-update',
AdminEventTrainingAssignment = 'admin-event-training-assignment',
AdminEventTrainingMutation = 'admin-event-training',
AdminEventTrainingExtraMutation = 'admin-event-training-extra',
AdminExportMutation = 'admin-export-mutation',
AdminHotelAssignVolunteer = 'admin-hotel-assign-volunteer',
AdminHotelAssignVolunteerDelete = 'admin-hotel-assign-volunteer-delete',
AdminHotelBookingMutation = 'admin-hotel-booking-mutation',
AdminImpersonateVolunteer = 'admin-impersonate-volunteer',
AdminKnowledgeBaseCategoryMutation = 'admin-knowledge-base-category-mutation',
AdminKnowledgeBaseMutation = 'admin-knowledge-base-mutation',
AdminNardoMutation = 'admin-nardo-mutation',
AdminProgramMutation = 'admin-program-mutation',
AdminRefundMutation = 'admin-refund-mutation',
AdminResetAccessCode = 'admin-reset-access-code',
AdminResetPasswordLink = 'admin-reset-password-link',
AdminSubscriptionUpdate = 'admin-subscription-update',
AdminUpdateActivation = 'admin-update-activation',
AdminUpdateAiSetting = 'admin-update-ai-settings',
AdminUpdateAvailabilityPreferences = 'admin-update-availability-preferences',
AdminUpdateAvatar = 'admin-update-avatar',
AdminUpdateEnvironment = 'admin-update-environment',
AdminUpdateEvent = 'admin-update-event',
AdminUpdateHotelPreferences = 'admin-update-hotel-preferences',
AdminUpdateIntegration = 'admin-update-integration',
AdminUpdatePermission = 'admin-update-permission',
AdminUpdateRefundRequest = 'admin-update-refund-request',
AdminUpdateRole = 'admin-update-role',
AdminUpdateSettings = 'admin-update-settings',
AdminUpdateTeam = 'admin-update-team',
AdminUpdateTeamVolunteer = 'admin-update-team-volunteer',
AdminUpdateTeamVolunteerStatus = 'admin-update-team-volunteer-status',
AdminUpdateTrainingPreferences = 'admin-update-training-preferences',
AdminUpdateVolunteer = 'admin-update-volunteer',
AdminVendorMutation = 'admin-vendor-mutation',
AdminVendorScheduleUpdate = 'admin-vendor-schedule-update',
ApplicationAvailabilityPreferences = 'application-availability-preferences',
ApplicationHotelPreferences = 'application-hotel-preferences',
ApplicationRefundRequest = 'application-refund-request',
ApplicationTrainingPreferences = 'application-training-preferences',
DatabaseError = 'database-error',
EventApplication = 'event-application',
EventFeedbackSubmitted = 'event-feedback-submitted',
EventHelpRequestUpdate = 'event-help-request-update',
EventVolunteerNotes = 'event-volunteer-notes',
ExportDataAccess = 'export-data-access',
}
export const LogType = {
AccountActivate: 'account-activate',
AccountIdentifyAccessCode: 'account-identify-access-code',
AccountIdentifyPasskey: 'account-identify-passkey',
AccountIdentifyPassword: 'account-identify-password',
AccountIdentityCheck: 'account-identity-check',
AccountPasskeyCreate: 'account-passkey-create',
AccountPasskeyDelete: 'account-passkey-delete',
AccountPasswordResetRequest: 'account-password-reset-request',
AccountPasswordReset: 'account-password-reset',
AccountPasswordUpdate: 'account-password-update',
AccountRegister: 'account-register',
AccountUpdateAvatar: 'account-update-avatar',
AccountUpdate: 'account-update',
AdminAccessVolunteerInfo: 'admin-access-volunteer-info',
AdminClearHotelPreferences: 'admin-clear-hotel-preferences',
AdminClearRefundRequest: 'admin-clear-refund-request',
AdminClearTrainingPreferences: 'admin-clear-training-preferences',
AdminDisplayMutation: 'admin-display-mutation',
AdminContentMutation: 'admin-content-mutation',
AdminEventApplication: 'admin-event-application',
AdminEventCreate: 'admin-event-create',
AdminEventDeadlineMutation: 'admin-event-deadline-mutation',
AdminEventHotelMutation: 'admin-event-hotel',
AdminEventProgramRequestUpdate: 'admin-event-program-request-update',
AdminEventPublishInfo: 'admin-event-publish-info',
AdminEventRetentionMessage: 'admin-event-retention-message',
AdminEventRetentionUpdate: 'admin-event-retention-update',
AdminEventRoleUpdate: 'admin-event-role-update',
AdminEventShiftCategoryMutation: 'admin-event-shift-category-mutation',
AdminEventShiftMutation: 'admin-event-shift-mutation',
AdminEventTeamUpdate: 'admin-event-team-update',
AdminEventTrainingAssignment: 'admin-event-training-assignment',
AdminEventTrainingMutation: 'admin-event-training',
AdminEventTrainingExtraMutation: 'admin-event-training-extra',
AdminExportMutation: 'admin-export-mutation',
AdminHotelAssignVolunteer: 'admin-hotel-assign-volunteer',
AdminHotelAssignVolunteerDelete: 'admin-hotel-assign-volunteer-delete',
AdminHotelBookingMutation: 'admin-hotel-booking-mutation',
AdminImpersonateVolunteer: 'admin-impersonate-volunteer',
AdminKnowledgeBaseCategoryMutation: 'admin-knowledge-base-category-mutation',
AdminKnowledgeBaseMutation: 'admin-knowledge-base-mutation',
AdminNardoMutation: 'admin-nardo-mutation',
AdminProgramMutation: 'admin-program-mutation',
AdminRefundMutation: 'admin-refund-mutation',
AdminResetAccessCode: 'admin-reset-access-code',
AdminResetPasswordLink: 'admin-reset-password-link',
AdminSubscriptionUpdate: 'admin-subscription-update',
AdminUpdateActivation: 'admin-update-activation',
AdminUpdateAiSetting: 'admin-update-ai-settings',
AdminUpdateAvailabilityPreferences: 'admin-update-availability-preferences',
AdminUpdateAvatar: 'admin-update-avatar',
AdminUpdateEnvironment: 'admin-update-environment',
AdminUpdateEvent: 'admin-update-event',
AdminUpdateHotelPreferences: 'admin-update-hotel-preferences',
AdminUpdateIntegration: 'admin-update-integration',
AdminUpdatePermission: 'admin-update-permission',
AdminUpdateRefundRequest: 'admin-update-refund-request',
AdminUpdateRole: 'admin-update-role',
AdminUpdateSettings: 'admin-update-settings',
AdminUpdateTeam: 'admin-update-team',
AdminUpdateTeamVolunteer: 'admin-update-team-volunteer',
AdminUpdateTeamVolunteerStatus: 'admin-update-team-volunteer-status',
AdminUpdateTrainingPreferences: 'admin-update-training-preferences',
AdminUpdateVolunteer: 'admin-update-volunteer',
AdminVendorMutation: 'admin-vendor-mutation',
AdminVendorScheduleUpdate: 'admin-vendor-schedule-update',
ApplicationAvailabilityPreferences: 'application-availability-preferences',
ApplicationHotelPreferences: 'application-hotel-preferences',
ApplicationRefundRequest: 'application-refund-request',
ApplicationTrainingPreferences: 'application-training-preferences',
DatabaseError: 'database-error',
EventApplication: 'event-application',
EventFeedbackSubmitted: 'event-feedback-submitted',
EventHelpRequestUpdate: 'event-help-request-update',
EventVolunteerNotes: 'event-volunteer-notes',
ExportDataAccess: 'export-data-access',

} as const;

/**
* Information about what happened that should be logged for future inspection. Not all fields are
Expand Down Expand Up @@ -118,7 +119,7 @@ export interface LogEntry {
/**
* The type of log entry that's being written.
*/
type: LogType;
type: typeof LogType[keyof typeof LogType];
}

/**
Expand Down
31 changes: 19 additions & 12 deletions app/lib/LogLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,18 @@ export interface LogMessage {
* Enumeration containing log types that have been deprecated. We still want to be able to display
* the origin log messages in a formatted manner, but autocomplete doesn't have to care.
*/
enum DeprecatedLogType {
AdminHotelBookingCreate = 'admin-hotel-booking-create',
AdminHotelBookingDelete = 'admin-hotel-booking-delete',
AdminHotelBookingUpdate = 'admin-hotel-booking-update',
AdminUpdateAnimeConIntegration = 'admin-update-animecon-integration',
AdminUpdateEmailIntegration = 'admin-update-email-integration',
AdminUpdateGoogleIntegration = 'admin-update-google-integration',
AdminUpdatePromptIntegration = 'admin-update-prompt-integration',
AdminUpdateVertexIntegration = 'admin-update-vertex-integration',
AdminWhatsAppMutation = 'admin-whatsapp-mutation',
};
const DeprecatedLogType = {
AdminHotelBookingCreate: 'admin-hotel-booking-create',
AdminHotelBookingDelete: 'admin-hotel-booking-delete',
AdminHotelBookingUpdate: 'admin-hotel-booking-update',
AdminUpdateAnimeConIntegration: 'admin-update-animecon-integration',
AdminUpdateEmailIntegration: 'admin-update-email-integration',
AdminUpdateGoogleIntegration: 'admin-update-google-integration',
AdminUpdatePromptIntegration: 'admin-update-prompt-integration',
AdminUpdateVertexIntegration: 'admin-update-vertex-integration',
AdminWhatsAppMutation: 'admin-whatsapp-mutation',

} as const;

/**
* Signature of log message formatting functions that can be used in the table below.
Expand All @@ -74,12 +75,18 @@ type LogMessageFormatFn =
(source: LogMessage['source'], target: LogMessage['target'], data: LogMessage['data'])
=> string;

/**
* Type representing the keys that are valid for a given object.
*/
type ValidKeys<T> = T[keyof T];

/**
* Formatting rules for each of the log message types. Strings with a series of special placeholders
* may be used, alternatively a function may be used for more advanced processing.
*/
const kLogMessageFormatter: {
[ key in (DeprecatedLogType | LogType) ]: string | LogMessageFormatFn
[ key in (ValidKeys<typeof DeprecatedLogType> | ValidKeys<typeof LogType>) ]:
string | LogMessageFormatFn
} = {
[LogType.AccountActivate]: 'Activated their account',
[LogType.AccountIdentifyAccessCode]: 'Signed in using an access code',
Expand Down
4 changes: 2 additions & 2 deletions app/lib/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ type SettingsMap = {
'integration-google-project-id': string;

// Google Vertex AI:
'integration-vertex-model': VertexSupportedModels;
'integration-vertex-model': typeof VertexSupportedModels[keyof typeof VertexSupportedModels];
'integration-vertex-temperature': number;
'integration-vertex-token-limit': number;
'integration-vertex-top-k': number;
Expand All @@ -103,7 +103,7 @@ type SettingsMap = {
'integration-twilio-account-sid': string;
'integration-twilio-messaging-sid-sms': string;
'integration-twilio-messaging-sid-whatsapp': string;
'integration-twilio-region': TwilioRegion;
'integration-twilio-region': typeof TwilioRegion[keyof typeof TwilioRegion];

// ---------------------------------------------------------------------------------------------
// Schedule settings:
Expand Down
2 changes: 1 addition & 1 deletion app/lib/integrations/twilio/TwilioClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface TwilioSettings {
/**
* Region in which the Twilio API endpoint should ideally be located.
*/
region?: TwilioRegion;
region?: typeof TwilioRegion[keyof typeof TwilioRegion];
}

/**
Expand Down
11 changes: 6 additions & 5 deletions app/lib/integrations/twilio/TwilioTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import { z } from 'zod';
*
* @see https://www.twilio.com/docs/global-infrastructure#control-data-residency
*/
export enum TwilioRegion {
'US1' = 'US1',
'IE1' = 'IE1',
'AU1' = 'AU1',
}
export const TwilioRegion = {
'US1': 'US1',
'IE1': 'IE1',
'AU1': 'AU1',

} as const;

/**
* Zod type to validate a phone number, inclusive of country code.
Expand Down
2 changes: 1 addition & 1 deletion app/lib/integrations/vertexai/VertexAIClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface VertexAISettings {
*
* @see https://cloud.google.com/vertex-ai/docs/generative-ai/learn/models
*/
model: VertexSupportedModels;
model: typeof VertexSupportedModels[keyof typeof VertexSupportedModels];

/**
* Temperature controls the degree of randomness in token selection. Lower temperatures are good
Expand Down
17 changes: 9 additions & 8 deletions app/lib/integrations/vertexai/VertexSupportedModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
/**
* Enumeration of the models that are supported by the Vertex AI API.
*/
export enum VertexSupportedModels {
'gemini-2.0-flash-exp' = 'gemini-2.0-flash-exp',
'gemini-1.5-flash-002' = 'gemini-1.5-flash-002',
'gemini-1.5-flash-001' = 'gemini-1.5-flash-001',
'gemini-1.5-pro-001' = 'gemini-1.5-pro-001',
'gemini-1.0-pro-002' = 'gemini-1.0-pro-002',
'gemini-exp-1206' = 'gemini-exp-1206',
}
export const VertexSupportedModels = {
'gemini-2.0-flash-exp': 'gemini-2.0-flash-exp',
'gemini-1.5-flash-002': 'gemini-1.5-flash-002',
'gemini-1.5-flash-001': 'gemini-1.5-flash-001',
'gemini-1.5-pro-001': 'gemini-1.5-pro-001',
'gemini-1.0-pro-002': 'gemini-1.0-pro-002',
'gemini-exp-1206': 'gemini-exp-1206',

} as const;
17 changes: 9 additions & 8 deletions app/lib/scheduler/TaskContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,20 @@ interface TaskConfiguration {
/**
* Severity level of an entry logged during task execution.
*/
export enum TaskLogSeverity {
Debug = 'Debug',
Info = 'Info',
Warning = 'Warning',
Error = 'Error',
Exception = 'Exception',
}
export const TaskLogSeverity = {
Debug: 'Debug',
Info: 'Info',
Warning: 'Warning',
Error: 'Error',
Exception: 'Exception',

} as const;

/**
* Individual log entry to be stored each time a task requests something to be logged.
*/
interface TaskLogEntry {
severity: TaskLogSeverity;
severity: typeof TaskLogSeverity[keyof typeof TaskLogSeverity];
time?: number;
message: string;
data: any[];
Expand Down

0 comments on commit c5b4c59

Please sign in to comment.