Skip to content

Commit

Permalink
NEOS-604: updates (#1039)
Browse files Browse the repository at this point in the history
  • Loading branch information
evisdrenova committed Jan 5, 2024
1 parent 9959219 commit 3639acc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default function UserDefinedTransformJavascriptForm(
<code className="bg-gray-200 px-1 py-0.5 rounded">value</code>{' '}
keyword. Click <b>Validate</b> to check that your code
compiles.{' '}
<LearnMoreTag href="https://docs.neosync.dev/transformers/user-defined" />
<LearnMoreTag href="https://docs.neosync.dev/transformers/user-defined#custom-code-transformers" />
</div>
</div>
<div className="flex flex-row gap-2">
Expand Down
30 changes: 29 additions & 1 deletion frontend/apps/web/app/[account]/new/transformer/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
TransformerConfig,
} from '@neosync/sdk';
import * as Yup from 'yup';
import { IsUserJavascriptCodeValid } from './UserDefinedTransformerForms/UserDefinedTransformJavascriptForm';

const transformEmailConfig = Yup.object().shape({
preserveDomain: Yup.boolean().required('This field is required.'),
Expand Down Expand Up @@ -160,7 +161,34 @@ const userDefinedTransformerConfig = Yup.object().shape({
});

const transformJavascriptConfig = Yup.object().shape({
code: Yup.string().required('This field is required.'),
code: Yup.string()
.required('This field is required.')
.test(
'is-valid-javascript',
'The JavaScript code is invalid.',
async (value, context) => {
const accountId = context?.options?.context?.accountId;
if (!accountId) {
return context.createError({
message: 'Unable to verify Account Id.',
});
}
try {
const res = await IsUserJavascriptCodeValid(value, accountId);
if (res.valid == true) {
return true;
} else {
return context.createError({
message: 'Javascript is not valid',
});
}
} catch (error) {
return context.createError({
message: 'Unable to verify Javascript code.',
});
}
}
),
});

type ConfigType = TransformerConfig['config'];
Expand Down

1 comment on commit 3639acc

@vercel
Copy link

@vercel vercel bot commented on 3639acc Jan 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.