Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// limitations under the License.
import * as Yup from 'yup'
import randomByteString from '../../../lib/random-bytes'
import m from '../../../components/device-data-form/messages'
import sharedMessages from '../../../../lib/shared-messages'
import { parseLorawanMacVersion } from '../utils'
const random16BytesString = () => randomByteString(32)
const toUndefined = value => (!Boolean(value) ? undefined : value)
const validationSchema = Yup.object()
.shape({
net_id: Yup.nullableString()
.emptyOrLength(3 * 2, m.validate6) // 3 Byte hex
.default(''),
root_keys: Yup.object().when(
['_external_js', '_lorawan_version'],
(externalJs, version, schema) => {
const strippedSchema = Yup.object().strip()
const keySchema = Yup.lazy(() => {
return !externalJs
? Yup.object().shape({
key: Yup.string()
.emptyOrLength(16 * 2, m.validate32) // 16 Byte hex
.transform(toUndefined)
.default(random16BytesString),
})
: Yup.object().strip()
})
gatewayNamePlaceholder: 'My New Gateway',
gsServerAddressDescription: 'The address of the Gateway Server to connect to',
gatewayDescPlaceholder: 'Description for my new gateway',
gatewayDescDescription:
'Optional gateway description; can also be used to save notes about the gateway',
})
const validationSchema = Yup.object().shape({
owner_id: Yup.string(),
ids: Yup.object().shape({
gateway_id: Yup.string()
.matches(gatewayIdRegexp, sharedMessages.validateAlphanum)
.min(2, sharedMessages.validateTooShort)
.max(36, sharedMessages.validateTooLong)
.required(sharedMessages.validateRequired),
eui: Yup.nullableString().length(8 * 2, sharedMessages.validateTooShort),
}),
name: Yup.string()
.min(2, sharedMessages.validateTooShort)
.max(50, sharedMessages.validateTooLong),
description: Yup.string().max(2000, sharedMessages.validateTooLong),
frequency_plan_id: Yup.string().required(sharedMessages.validateRequired),
gateway_server_address: Yup.string().matches(addressRegexp, sharedMessages.validateAddressFormat),
})
@bind
class GatewayDataForm extends React.Component {
onSubmit(values, helpers) {
const { onSubmit } = this.props
const castedValues = validationSchema.cast(values)
onSubmit(castedValues, helpers)