mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 18:41:14 +00:00
feat(JWT Node): New node (#9005)
Co-authored-by: Giulio Andreini <andreini@netseven.it>
This commit is contained in:
@@ -2341,7 +2341,8 @@ export type FieldType =
|
||||
| 'array'
|
||||
| 'object'
|
||||
| 'options'
|
||||
| 'url';
|
||||
| 'url'
|
||||
| 'jwt';
|
||||
|
||||
export type ValidationResult = {
|
||||
valid: boolean;
|
||||
|
||||
@@ -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 };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user