|
| 1 | +import { BoxSdkError } from '../box/errors'; |
| 2 | +import { SerializedData } from '../serialization/json'; |
| 3 | +import { sdIsEmpty } from '../serialization/json'; |
| 4 | +import { sdIsBoolean } from '../serialization/json'; |
| 5 | +import { sdIsNumber } from '../serialization/json'; |
| 6 | +import { sdIsString } from '../serialization/json'; |
| 7 | +import { sdIsList } from '../serialization/json'; |
| 8 | +import { sdIsMap } from '../serialization/json'; |
| 9 | +export type SignRequestSignerInputCustomValidationValidationTypeField = |
| 10 | + | 'custom' |
| 11 | + | string; |
| 12 | +export class SignRequestSignerInputCustomValidation { |
| 13 | + /** |
| 14 | + * Defines the validation format for the text input as custom. |
| 15 | + * A custom regular expression is used for validation. */ |
| 16 | + readonly validationType: SignRequestSignerInputCustomValidationValidationTypeField = |
| 17 | + 'custom' as SignRequestSignerInputCustomValidationValidationTypeField; |
| 18 | + /** |
| 19 | + * Regular expression used for validation. */ |
| 20 | + readonly customRegex!: string | null; |
| 21 | + /** |
| 22 | + * Error message shown if input fails custom regular expression validation. */ |
| 23 | + readonly customErrorMessage!: string | null; |
| 24 | + readonly rawData?: SerializedData; |
| 25 | + constructor( |
| 26 | + fields: Omit<SignRequestSignerInputCustomValidation, 'validationType'> & |
| 27 | + Partial<Pick<SignRequestSignerInputCustomValidation, 'validationType'>> |
| 28 | + ) { |
| 29 | + if (fields.validationType !== undefined) { |
| 30 | + this.validationType = fields.validationType; |
| 31 | + } |
| 32 | + if (fields.customRegex !== undefined) { |
| 33 | + this.customRegex = fields.customRegex; |
| 34 | + } |
| 35 | + if (fields.customErrorMessage !== undefined) { |
| 36 | + this.customErrorMessage = fields.customErrorMessage; |
| 37 | + } |
| 38 | + if (fields.rawData !== undefined) { |
| 39 | + this.rawData = fields.rawData; |
| 40 | + } |
| 41 | + } |
| 42 | +} |
| 43 | +export interface SignRequestSignerInputCustomValidationInput { |
| 44 | + /** |
| 45 | + * Defines the validation format for the text input as custom. |
| 46 | + * A custom regular expression is used for validation. */ |
| 47 | + readonly validationType?: SignRequestSignerInputCustomValidationValidationTypeField; |
| 48 | + /** |
| 49 | + * Regular expression used for validation. */ |
| 50 | + readonly customRegex: string | null; |
| 51 | + /** |
| 52 | + * Error message shown if input fails custom regular expression validation. */ |
| 53 | + readonly customErrorMessage: string | null; |
| 54 | + readonly rawData?: SerializedData; |
| 55 | +} |
| 56 | +export function serializeSignRequestSignerInputCustomValidationValidationTypeField( |
| 57 | + val: SignRequestSignerInputCustomValidationValidationTypeField |
| 58 | +): SerializedData { |
| 59 | + return val; |
| 60 | +} |
| 61 | +export function deserializeSignRequestSignerInputCustomValidationValidationTypeField( |
| 62 | + val: SerializedData |
| 63 | +): SignRequestSignerInputCustomValidationValidationTypeField { |
| 64 | + if (val == 'custom') { |
| 65 | + return val; |
| 66 | + } |
| 67 | + if (sdIsString(val)) { |
| 68 | + return val; |
| 69 | + } |
| 70 | + throw new BoxSdkError({ |
| 71 | + message: |
| 72 | + "Can't deserialize SignRequestSignerInputCustomValidationValidationTypeField", |
| 73 | + }); |
| 74 | +} |
| 75 | +export function serializeSignRequestSignerInputCustomValidation( |
| 76 | + val: SignRequestSignerInputCustomValidation |
| 77 | +): SerializedData { |
| 78 | + return { |
| 79 | + ['validation_type']: |
| 80 | + serializeSignRequestSignerInputCustomValidationValidationTypeField( |
| 81 | + val.validationType |
| 82 | + ), |
| 83 | + ['custom_regex']: val.customRegex, |
| 84 | + ['custom_error_message']: val.customErrorMessage, |
| 85 | + }; |
| 86 | +} |
| 87 | +export function deserializeSignRequestSignerInputCustomValidation( |
| 88 | + val: SerializedData |
| 89 | +): SignRequestSignerInputCustomValidation { |
| 90 | + if (!sdIsMap(val)) { |
| 91 | + throw new BoxSdkError({ |
| 92 | + message: 'Expecting a map for "SignRequestSignerInputCustomValidation"', |
| 93 | + }); |
| 94 | + } |
| 95 | + if (val.validation_type == void 0) { |
| 96 | + throw new BoxSdkError({ |
| 97 | + message: |
| 98 | + 'Expecting "validation_type" of type "SignRequestSignerInputCustomValidation" to be defined', |
| 99 | + }); |
| 100 | + } |
| 101 | + const validationType: SignRequestSignerInputCustomValidationValidationTypeField = |
| 102 | + deserializeSignRequestSignerInputCustomValidationValidationTypeField( |
| 103 | + val.validation_type |
| 104 | + ); |
| 105 | + if (val.custom_regex == void 0) { |
| 106 | + throw new BoxSdkError({ |
| 107 | + message: |
| 108 | + 'Expecting "custom_regex" of type "SignRequestSignerInputCustomValidation" to be defined', |
| 109 | + }); |
| 110 | + } |
| 111 | + if (!sdIsString(val.custom_regex)) { |
| 112 | + throw new BoxSdkError({ |
| 113 | + message: |
| 114 | + 'Expecting string for "custom_regex" of type "SignRequestSignerInputCustomValidation"', |
| 115 | + }); |
| 116 | + } |
| 117 | + const customRegex: string = val.custom_regex; |
| 118 | + if (val.custom_error_message == void 0) { |
| 119 | + throw new BoxSdkError({ |
| 120 | + message: |
| 121 | + 'Expecting "custom_error_message" of type "SignRequestSignerInputCustomValidation" to be defined', |
| 122 | + }); |
| 123 | + } |
| 124 | + if (!sdIsString(val.custom_error_message)) { |
| 125 | + throw new BoxSdkError({ |
| 126 | + message: |
| 127 | + 'Expecting string for "custom_error_message" of type "SignRequestSignerInputCustomValidation"', |
| 128 | + }); |
| 129 | + } |
| 130 | + const customErrorMessage: string = val.custom_error_message; |
| 131 | + return { |
| 132 | + validationType: validationType, |
| 133 | + customRegex: customRegex, |
| 134 | + customErrorMessage: customErrorMessage, |
| 135 | + } satisfies SignRequestSignerInputCustomValidation; |
| 136 | +} |
| 137 | +export function serializeSignRequestSignerInputCustomValidationInput( |
| 138 | + val: SignRequestSignerInputCustomValidationInput |
| 139 | +): SerializedData { |
| 140 | + return { |
| 141 | + ['validationType']: |
| 142 | + val.validationType == void 0 |
| 143 | + ? val.validationType |
| 144 | + : serializeSignRequestSignerInputCustomValidationValidationTypeField( |
| 145 | + val.validationType |
| 146 | + ), |
| 147 | + ['custom_regex']: val.customRegex, |
| 148 | + ['custom_error_message']: val.customErrorMessage, |
| 149 | + }; |
| 150 | +} |
| 151 | +export function deserializeSignRequestSignerInputCustomValidationInput( |
| 152 | + val: SerializedData |
| 153 | +): SignRequestSignerInputCustomValidationInput { |
| 154 | + if (!sdIsMap(val)) { |
| 155 | + throw new BoxSdkError({ |
| 156 | + message: |
| 157 | + 'Expecting a map for "SignRequestSignerInputCustomValidationInput"', |
| 158 | + }); |
| 159 | + } |
| 160 | + const validationType: |
| 161 | + | undefined |
| 162 | + | SignRequestSignerInputCustomValidationValidationTypeField = |
| 163 | + val.validationType == void 0 |
| 164 | + ? void 0 |
| 165 | + : deserializeSignRequestSignerInputCustomValidationValidationTypeField( |
| 166 | + val.validationType |
| 167 | + ); |
| 168 | + if (val.custom_regex == void 0) { |
| 169 | + throw new BoxSdkError({ |
| 170 | + message: |
| 171 | + 'Expecting "custom_regex" of type "SignRequestSignerInputCustomValidationInput" to be defined', |
| 172 | + }); |
| 173 | + } |
| 174 | + if (!sdIsString(val.custom_regex)) { |
| 175 | + throw new BoxSdkError({ |
| 176 | + message: |
| 177 | + 'Expecting string for "custom_regex" of type "SignRequestSignerInputCustomValidationInput"', |
| 178 | + }); |
| 179 | + } |
| 180 | + const customRegex: string = val.custom_regex; |
| 181 | + if (val.custom_error_message == void 0) { |
| 182 | + throw new BoxSdkError({ |
| 183 | + message: |
| 184 | + 'Expecting "custom_error_message" of type "SignRequestSignerInputCustomValidationInput" to be defined', |
| 185 | + }); |
| 186 | + } |
| 187 | + if (!sdIsString(val.custom_error_message)) { |
| 188 | + throw new BoxSdkError({ |
| 189 | + message: |
| 190 | + 'Expecting string for "custom_error_message" of type "SignRequestSignerInputCustomValidationInput"', |
| 191 | + }); |
| 192 | + } |
| 193 | + const customErrorMessage: string = val.custom_error_message; |
| 194 | + return { |
| 195 | + validationType: validationType, |
| 196 | + customRegex: customRegex, |
| 197 | + customErrorMessage: customErrorMessage, |
| 198 | + } satisfies SignRequestSignerInputCustomValidationInput; |
| 199 | +} |
0 commit comments