Skip to content

fix(dashboard): add client side validation for apns key #7982

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Input } from '@/components/primitives/input';
import { SecretInput } from '@/components/primitives/secret-input';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/primitives/select';
import { Textarea } from '@/components/primitives/textarea';
import { Switch } from '@/components/primitives/switch';
import { CredentialsKeyEnum, IProviderConfig } from '@novu/shared';
import { Control } from 'react-hook-form';
Expand Down Expand Up @@ -32,14 +33,24 @@ const SECURE_CREDENTIALS = [
];

export function CredentialsSection({ provider, control }: CredentialsSectionProps) {
console.log(provider);
return (
<div className="border-neutral-alpha-200 bg-background text-foreground-600 mx-0 mt-0 flex flex-col gap-2 rounded-lg border p-3">
{provider?.credentials?.map((credential) => (
<FormField
key={credential.key}
control={control}
name={`credentials.${credential.key}`}
rules={{ required: credential.required ? `${credential.displayName} is required` : false }}
rules={{
required: credential.required ? `${credential.displayName} is required` : false,
validate: credential.validation?.validate,
pattern: credential.validation?.pattern
? {
value: credential.validation.pattern,
message: credential.validation.message || 'Invalid format',
}
: undefined,
}}
render={({ field, fieldState }) => (
<FormItem className="mb-2">
<FormLabel htmlFor={credential.key} optional={!credential.required}>
Expand All @@ -66,6 +77,16 @@ export function CredentialsSection({ provider, control }: CredentialsSectionProp
</SelectContent>
</Select>
</FormControl>
) : credential.type === 'textarea' ? (
<FormControl>
<Textarea
id={credential.key}
placeholder={`Enter ${credential.displayName.toLowerCase()}`}
value={field.value || ''}
onChange={field.onChange}
rows={7}
/>
</FormControl>
) : credential.type === 'secret' || SECURE_CREDENTIALS.includes(credential.key as CredentialsKeyEnum) ? (
<FormControl>
<SecretInput
Expand All @@ -88,7 +109,7 @@ export function CredentialsSection({ provider, control }: CredentialsSectionProp
</FormControl>
)}

<FormMessage>{credential.description}</FormMessage>
<FormMessage>{fieldState.error?.message || credential.description}</FormMessage>
</FormItem>
)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -641,8 +641,22 @@ export const apnsConfig: IConfigCredentials[] = [
{
key: CredentialsKeyEnum.SecretKey,
displayName: 'Private Key',
type: 'text',
required: true,
type: 'textarea',
required: true,
validation: {
validate: (value: string) => {
try {
// Check if it's a valid PEM format
if (!value.includes('-----BEGIN PRIVATE KEY-----') || !value.includes('-----END PRIVATE KEY-----')) {
return 'Invalid private key format. Must be in PEM format.';
}

return true;
} catch (e) {
return 'Invalid private key format. Must be in PEM format.';
}
},
},
},
{
key: CredentialsKeyEnum.ApiKey,
Expand All @@ -668,7 +682,6 @@ export const apnsConfig: IConfigCredentials[] = [
type: 'switch',
required: false,
},

...pushConfigBase,
];

Expand Down
5 changes: 5 additions & 0 deletions packages/shared/src/consts/providers/provider.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ export interface IConfigCredentials {
name: string;
value: string | null;
}>;
validation?: {
pattern?: RegExp;
message?: string;
validate?: (value: string) => boolean | string;
};
}

export interface ILogoFileName {
Expand Down
Loading