feat(JWT Node): New node (#9005)

Co-authored-by: Giulio Andreini <andreini@netseven.it>
This commit is contained in:
Michael Kret
2024-04-10 13:16:48 +03:00
committed by GitHub
parent 9403657e46
commit 0a9f6b3de8
12 changed files with 1088 additions and 6 deletions

View File

@@ -2341,7 +2341,8 @@ export type FieldType =
| 'array'
| 'object'
| 'options'
| 'url';
| 'url'
| 'jwt';
export type ValidationResult = {
valid: boolean;

View File

@@ -158,6 +158,20 @@ export const tryToParseUrl = (value: unknown): string => {
return String(value);
};
export const tryToParseJwt = (value: unknown): string => {
const error = new ApplicationError(`The value "${String(value)}" is not a valid JWT token.`, {
extra: { value },
});
if (!value) throw error;
const jwtPattern = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_.+/=]*$/;
if (!jwtPattern.test(String(value))) throw error;
return String(value);
};
type ValidateFieldTypeOptions = Partial<{
valueOptions: INodePropertyOptions[];
strict: boolean;
@@ -279,6 +293,16 @@ export const validateFieldType = (
return { valid: false, errorMessage: defaultErrorMessage };
}
}
case 'jwt': {
try {
return { valid: true, newValue: tryToParseJwt(value) };
} catch (e) {
return {
valid: false,
errorMessage: 'Value is not a valid JWT token',
};
}
}
default: {
return { valid: true, newValue: value };
}