@linode/validation
Version:
Yup validation schemas for use with the Linode APIv4
1,137 lines (1,125 loc) • 108 kB
JavaScript
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var index_exports = {};
__export(index_exports, {
AttachVolumeSchema: () => AttachVolumeSchema,
CHECK_ATTEMPTS: () => CHECK_ATTEMPTS,
CHECK_INTERVAL: () => CHECK_INTERVAL,
CHECK_TIMEOUT: () => CHECK_TIMEOUT,
CUSTOM_PORTS_ERROR_MESSAGE: () => CUSTOM_PORTS_ERROR_MESSAGE,
CloneVolumeSchema: () => CloneVolumeSchema,
ConfigProfileInterfaceSchema: () => ConfigProfileInterfaceSchema,
ConfigProfileInterfacesSchema: () => ConfigProfileInterfacesSchema,
CreateBucketSchema: () => CreateBucketSchema,
CreateFirewallDeviceSchema: () => CreateFirewallDeviceSchema,
CreateFirewallSchema: () => CreateFirewallSchema,
CreateLinodeConfigSchema: () => CreateLinodeConfigSchema,
CreateLinodeDiskFromImageSchema: () => CreateLinodeDiskFromImageSchema,
CreateLinodeDiskSchema: () => CreateLinodeDiskSchema,
CreateLinodeInterfaceSchema: () => CreateLinodeInterfaceSchema,
CreateLinodeSchema: () => CreateLinodeSchema,
CreateSnapshotSchema: () => CreateSnapshotSchema,
CreateTransferSchema: () => CreateTransferSchema,
CreateUserSchema: () => CreateUserSchema,
CreateVPCInterfaceSchema: () => CreateVPCInterfaceSchema,
CreateVolumeSchema: () => CreateVolumeSchema,
CreditCardSchema: () => CreditCardSchema,
FirewallDeviceSchema: () => FirewallDeviceSchema,
FirewallRuleSchema: () => FirewallRuleSchema,
FirewallRuleTypeSchema: () => FirewallRuleTypeSchema,
IPAllocationSchema: () => IPAllocationSchema,
IP_EITHER_BOTH_NOT_NEITHER: () => IP_EITHER_BOTH_NOT_NEITHER,
IP_ERROR_MESSAGE: () => IP_ERROR_MESSAGE,
ModifyLinodeInterfaceSchema: () => ModifyLinodeInterfaceSchema,
NodeBalancerSchema: () => NodeBalancerSchema,
PRIVATE_IPV4_REGEX: () => PRIVATE_IPV4_REGEX,
PRIVATE_IPV6_REGEX: () => PRIVATE_IPV6_REGEX,
PaymentMethodSchema: () => PaymentMethodSchema,
PaymentSchema: () => PaymentSchema,
PromoCodeSchema: () => PromoCodeSchema,
RebuildLinodeFromStackScriptSchema: () => RebuildLinodeFromStackScriptSchema,
RebuildLinodeSchema: () => RebuildLinodeSchema,
ResizeLinodeDiskSchema: () => ResizeLinodeDiskSchema,
ResizeVolumeSchema: () => ResizeVolumeSchema,
SecurityQuestionsSchema: () => SecurityQuestionsSchema,
SendCodeToPhoneNumberSchema: () => SendCodeToPhoneNumberSchema,
UpdateAccountSettingsSchema: () => UpdateAccountSettingsSchema,
UpdateBucketAccessSchema: () => UpdateBucketAccessSchema,
UpdateConfigInterfaceOrderSchema: () => UpdateConfigInterfaceOrderSchema,
UpdateConfigInterfaceSchema: () => UpdateConfigInterfaceSchema,
UpdateFirewallSchema: () => UpdateFirewallSchema,
UpdateFirewallSettingsSchema: () => UpdateFirewallSettingsSchema,
UpdateGrantSchema: () => UpdateGrantSchema,
UpdateLinodeConfigSchema: () => UpdateLinodeConfigSchema,
UpdateLinodeDiskSchema: () => UpdateLinodeDiskSchema,
UpdateLinodeInterfaceSettingsSchema: () => UpdateLinodeInterfaceSettingsSchema,
UpdateLinodePasswordSchema: () => UpdateLinodePasswordSchema,
UpdateLinodeSchema: () => UpdateLinodeSchema,
UpdateNodeBalancerConfigSchema: () => UpdateNodeBalancerConfigSchema,
UpdateNodeBalancerSchema: () => UpdateNodeBalancerSchema,
UpdateUserSchema: () => UpdateUserSchema,
UpdateVolumeSchema: () => UpdateVolumeSchema,
UpgradeToLinodeInterfaceSchema: () => UpgradeToLinodeInterfaceSchema,
UploadCertificateSchema: () => UploadCertificateSchema,
VerifyPhoneNumberCodeSchema: () => VerifyPhoneNumberCodeSchema,
allocateIPSchema: () => allocateIPSchema,
assignAddressesSchema: () => assignAddressesSchema,
baseImageSchema: () => baseImageSchema,
clusterLabelSchema: () => clusterLabelSchema,
createAccountLimitSupportTicketSchema: () => createAccountLimitSupportTicketSchema,
createAlertDefinitionSchema: () => createAlertDefinitionSchema,
createCloudNATSchema: () => createCloudNATSchema,
createContactSchema: () => createContactSchema,
createCredentialSchema: () => createCredentialSchema,
createDatabaseSchema: () => createDatabaseSchema,
createDomainSchema: () => createDomainSchema,
createDynamicAdvancedConfigSchema: () => createDynamicAdvancedConfigSchema,
createImageSchema: () => createImageSchema,
createKubeClusterSchema: () => createKubeClusterSchema,
createKubeClusterWithRequiredACLSchema: () => createKubeClusterWithRequiredACLSchema,
createNodeBalancerConfigSchema: () => createNodeBalancerConfigSchema,
createOAuthClientSchema: () => createOAuthClientSchema,
createObjectStorageKeysSchema: () => createObjectStorageKeysSchema,
createPersonalAccessTokenSchema: () => createPersonalAccessTokenSchema,
createPlacementGroupSchema: () => createPlacementGroupSchema,
createRecordSchema: () => createRecordSchema,
createReplySchema: () => createReplySchema,
createSMTPSupportTicketSchema: () => createSMTPSupportTicketSchema,
createSSHKeySchema: () => createSSHKeySchema,
createServiceMonitorSchema: () => createServiceMonitorSchema,
createSubnetSchemaIPv4: () => createSubnetSchemaIPv4,
createSubnetSchemaWithIPv6: () => createSubnetSchemaWithIPv6,
createSupportTicketSchema: () => createSupportTicketSchema,
createVPCSchema: () => createVPCSchema,
credentialLabel: () => credentialLabel,
credentialPassword: () => credentialPassword,
credentialUsername: () => credentialUsername,
determineIPType: () => determineIPType,
dimensionFilters: () => dimensionFilters,
editAlertDefinitionSchema: () => editAlertDefinitionSchema,
enableTwoFactorSchema: () => enableTwoFactorSchema,
getDynamicDatabaseSchema: () => getDynamicDatabaseSchema,
importZoneSchema: () => importZoneSchema,
ipAddress: () => ipAddress,
ipv4Address: () => ipv4Address,
ipv6Address: () => ipv6Address,
isCustomPortsValid: () => isCustomPortsValid,
kubernetesControlPlaneACLPayloadSchema: () => kubernetesControlPlaneACLPayloadSchema,
kubernetesEnterpriseControlPlaneACLPayloadSchema: () => kubernetesEnterpriseControlPlaneACLPayloadSchema,
kubernetesLabelSchema: () => kubernetesLabelSchema,
kubernetesTaintSchema: () => kubernetesTaintSchema,
longviewClientCreate: () => longviewClientCreate,
metricCriteria: () => metricCriteria,
modifySubnetSchema: () => modifySubnetSchema,
nodeBalancerConfigNodeSchema: () => nodeBalancerConfigNodeSchema,
nodePoolBetaSchema: () => nodePoolBetaSchema,
nodePoolSchema: () => nodePoolSchema,
shareAddressesSchema: () => shareAddressesSchema,
sshSettingSchema: () => sshSettingSchema,
stackScriptSchema: () => stackScriptSchema,
triggerConditionValidation: () => triggerConditionValidation,
updateAccountSchema: () => updateAccountSchema,
updateCloudNATSchema: () => updateCloudNATSchema,
updateCredentialSchema: () => updateCredentialSchema,
updateDatabaseSchema: () => updateDatabaseSchema,
updateDomainSchema: () => updateDomainSchema,
updateIPSchema: () => updateIPSchema,
updateImageRegionsSchema: () => updateImageRegionsSchema,
updateImageSchema: () => updateImageSchema,
updateManagedLinodeSchema: () => updateManagedLinodeSchema,
updateOAuthClientSchema: () => updateOAuthClientSchema,
updateObjectStorageKeysSchema: () => updateObjectStorageKeysSchema,
updatePasswordSchema: () => updatePasswordSchema,
updatePlacementGroupSchema: () => updatePlacementGroupSchema,
updatePrivateNetworkSchema: () => updatePrivateNetworkSchema,
updateProfileSchema: () => updateProfileSchema,
updateRecordSchema: () => updateRecordSchema,
updateSSHKeySchema: () => updateSSHKeySchema,
updateStackScriptSchema: () => updateStackScriptSchema,
updateVPCSchema: () => updateVPCSchema,
uploadImageSchema: () => uploadImageSchema,
validateIP: () => validateIP,
vpcsValidateIP: () => vpcsValidateIP
});
module.exports = __toCommonJS(index_exports);
// src/account.schema.ts
var import_yup = require("yup");
var updateAccountSchema = (0, import_yup.object)({
email: (0, import_yup.string)().max(128, "Email must be 128 characters or less."),
address_1: (0, import_yup.string)().max(64, "Address must be 64 characters or less."),
city: (0, import_yup.string)().max(24, "City must be 24 characters or less."),
company: (0, import_yup.string)().max(128, "Company must be 128 characters or less."),
country: (0, import_yup.string)().min(2, "Country code must be two letters.").max(2, "Country code must be two letters."),
first_name: (0, import_yup.string)().max(50, "First name must be 50 characters or less."),
last_name: (0, import_yup.string)().max(50, "Last name must be 50 characters or less."),
address_2: (0, import_yup.string)().max(64, "Address must be 64 characters or less."),
phone: (0, import_yup.string)().max(32, "Phone number must be 32 characters or less."),
state: (0, import_yup.string)().max(24, "State must be 24 characters or less."),
tax_id: (0, import_yup.string)().max(100, "Tax ID must be 100 characters or less."),
zip: (0, import_yup.string)().max(16, "Zip code must be 16 characters or less.")
});
var createOAuthClientSchema = (0, import_yup.object)({
label: (0, import_yup.string)().required("Label is required.").min(1, "Label must be between 1 and 512 characters.").max(512, "Label must be between 1 and 512 characters."),
redirect_uri: (0, import_yup.string)().required("Redirect URI is required.")
});
var updateOAuthClientSchema = (0, import_yup.object)({
label: (0, import_yup.string)().min(1, "Label must be between 1 and 512 characters.").max(512, "Label must be between 1 and 512 characters."),
redirect_uri: (0, import_yup.string)()
});
var PaymentSchema = (0, import_yup.object)({
usd: (0, import_yup.string)().required("USD payment amount is required.")
});
var CreditCardSchema = (0, import_yup.object)({
card_number: (0, import_yup.string)().required("Credit card number is required.").min(13, "Credit card number must be between 13 and 23 characters.").max(23, "Credit card number must be between 13 and 23 characters."),
expiry_year: (0, import_yup.number)().test(
"length",
"Expiration year must be 2 or 4 digits.",
(value) => [2, 4].includes(String(value).length)
).required("Expiration year is required.").typeError("Expiration year must be a number.").min((/* @__PURE__ */ new Date()).getFullYear(), "Expiration year must not be in the past.").max((/* @__PURE__ */ new Date()).getFullYear() + 20, "Expiry too far in the future."),
expiry_month: (0, import_yup.number)().required("Expiration month is required.").typeError("Expiration month must be a number.").min(1, "Expiration month must be a number from 1 to 12.").max(12, "Expiration month must be a number from 1 to 12."),
cvv: (0, import_yup.string)().required("Security code is required.").min(3, "Security code must be between 3 and 4 characters.").max(4, "Security code must be between 3 and 4 characters.")
});
var PaymentMethodSchema = (0, import_yup.object)({
type: (0, import_yup.mixed)().oneOf(
["credit_card", "payment_method_nonce"],
"Type must be credit_card or payment_method_nonce."
),
data: (0, import_yup.object)().when("type", {
is: "credit_card",
then: () => CreditCardSchema,
otherwise: () => (0, import_yup.object)({
nonce: (0, import_yup.string)().required("Payment nonce is required.")
})
}),
is_default: (0, import_yup.boolean)().required(
"You must indicate if this should be your default method of payment."
)
});
var CreateUserSchema = (0, import_yup.object)({
username: (0, import_yup.string)().required("Username is required.").min(3, "Username must be between 3 and 32 characters.").max(32, "Username must be between 3 and 32 characters."),
email: (0, import_yup.string)().required("Email address is required.").email("Must be a valid email address."),
restricted: (0, import_yup.boolean)().required(
"You must indicate if this user should have restricted access."
)
});
var UpdateUserSchema = (0, import_yup.object)({
username: (0, import_yup.string)().min(3, "Username must be between 3 and 32 characters.").max(32, "Username must be between 3 and 32 characters."),
email: (0, import_yup.string)().email("Must be a valid email address."),
restricted: (0, import_yup.boolean)()
});
var GrantSchema = (0, import_yup.object)({
id: (0, import_yup.number)().required("ID is required."),
permissions: (0, import_yup.string)().oneOf(
["read_only", "read_write"],
"Permissions must be null, read_only, or read_write."
).nullable("Permissions must be null, read_only, or read_write.")
});
var UpdateGrantSchema = (0, import_yup.object)({
global: (0, import_yup.object)(),
linode: (0, import_yup.array)().of(GrantSchema),
domain: (0, import_yup.array)().of(GrantSchema),
nodebalancer: (0, import_yup.array)().of(GrantSchema),
image: (0, import_yup.array)().of(GrantSchema),
longview: (0, import_yup.array)().of(GrantSchema),
stackscript: (0, import_yup.array)().of(GrantSchema),
volume: (0, import_yup.array)().of(GrantSchema)
});
var UpdateAccountSettingsSchema = (0, import_yup.object)({
network_helper: (0, import_yup.boolean)(),
backups_enabled: (0, import_yup.boolean)(),
managed: (0, import_yup.boolean)(),
longview_subscription: (0, import_yup.string)().nullable(),
object_storage: (0, import_yup.string)(),
interfaces_for_new_linodes: (0, import_yup.string)()
});
var PromoCodeSchema = (0, import_yup.object)({
promo_code: (0, import_yup.string)().required("Promo code is required.").min(1, "Promo code must be between 1 and 32 characters.").max(32, "Promo code must be between 1 and 32 characters.")
});
// src/buckets.schema.ts
var import_yup2 = require("yup");
var ENDPOINT_TYPES = ["E0", "E1", "E2", "E3"];
var CreateBucketSchema = (0, import_yup2.object)().shape(
{
label: (0, import_yup2.string)().required("Bucket name is required.").min(3, "Bucket name must be between 3 and 63 characters.").matches(/^\S*$/, "Bucket name must not contain spaces.").matches(
/^[a-z0-9].*[a-z0-9]$/,
"Bucket name must start and end with a lowercase letter or number."
).matches(
/^(?!.*[.-]{2})[a-z0-9.-]+$/,
"Bucket name must contain only lowercase letters, numbers, periods (.), and hyphens (-). Adjacent periods and hyphens are not allowed."
).max(63, "Bucket name must be between 3 and 63 characters.").test(
"unique-label",
"A bucket with this name already exists in your selected region",
(value, context) => {
var _a;
const { cluster, region } = context.parent;
const buckets = (_a = context.options.context) == null ? void 0 : _a.buckets;
if (!Array.isArray(buckets)) {
return true;
}
return !buckets.some(
(bucket) => bucket.label === value && (bucket.cluster === cluster || bucket.region === region)
);
}
),
cluster: (0, import_yup2.string)().when("region", {
is: (region) => !region || region.length === 0,
then: (schema) => schema.required("Cluster is required.")
}),
region: (0, import_yup2.string)().when("cluster", {
is: (cluster) => !cluster || cluster.length === 0,
then: (schema) => schema.required("Region is required.")
}),
endpoint_type: (0, import_yup2.string)().oneOf([...ENDPOINT_TYPES]).optional(),
cors_enabled: (0, import_yup2.boolean)().optional(),
acl: (0, import_yup2.string)().oneOf([
"private",
"public-read",
"authenticated-read",
"public-read-write"
]).optional(),
s3_endpoint: (0, import_yup2.string)().optional()
},
[["cluster", "region"]]
).test("cors-enabled-check", "Invalid CORS configuration.", function(value) {
const { endpoint_type, cors_enabled } = value;
if ((endpoint_type === "E0" || endpoint_type === "E1") && !cors_enabled) {
return this.createError({
path: "cors_enabled",
message: "CORS must be enabled for endpoint type E0 or E1."
});
}
if ((endpoint_type === "E2" || endpoint_type === "E3") && cors_enabled) {
return this.createError({
path: "cors_enabled",
message: "CORS must be disabled for endpoint type E2 or E3."
});
}
return true;
});
var UploadCertificateSchema = (0, import_yup2.object)({
certificate: (0, import_yup2.string)().required("Certificate is required."),
private_key: (0, import_yup2.string)().required("Private key is required.")
});
var UpdateBucketAccessSchema = (0, import_yup2.object)({
acl: (0, import_yup2.string)().oneOf([
"private",
"public-read",
"authenticated-read",
"public-read-write"
]).notRequired(),
cors_enabled: (0, import_yup2.boolean)().notRequired()
});
// src/cloudnats.schema.ts
var import_yup3 = require("yup");
var VALID_PORT_SIZES = [
64,
128,
256,
512,
1024,
2048,
4096,
8192,
16384
];
var createCloudNATSchema = (0, import_yup3.object)({
addresses: (0, import_yup3.array)().of(
(0, import_yup3.object)({
address: (0, import_yup3.string)().required("Address must be a string.")
})
).notRequired(),
label: (0, import_yup3.string)().required("Label is required.").max(150, "Label must be 150 characters or fewer."),
port_prefix_default_len: (0, import_yup3.number)().oneOf(VALID_PORT_SIZES, "Invalid port size.").notRequired(),
region: (0, import_yup3.string)().required("Region is required.")
});
var updateCloudNATSchema = (0, import_yup3.object)({
label: (0, import_yup3.string)().max(150, "Label must be 150 characters or fewer.")
});
// src/cloudpulse.schema.ts
var import_yup4 = require("yup");
var fieldErrorMessage = "This field is required.";
var dimensionFilters = (0, import_yup4.object)({
dimension_label: (0, import_yup4.string)().required(fieldErrorMessage),
operator: (0, import_yup4.string)().oneOf(["eq", "neq", "startswith", "endswith"]).required(fieldErrorMessage),
value: (0, import_yup4.string)().required(fieldErrorMessage)
});
var metricCriteria = (0, import_yup4.object)({
metric: (0, import_yup4.string)().required(fieldErrorMessage),
aggregate_function: (0, import_yup4.string)().oneOf(["avg", "count", "max", "min", "sum"]).required(fieldErrorMessage),
operator: (0, import_yup4.string)().oneOf(["eq", "gt", "lt", "gte", "lte"]).required(fieldErrorMessage),
threshold: (0, import_yup4.number)().required(fieldErrorMessage).positive("Enter a positive value.").typeError("The value should be a number."),
dimension_filters: (0, import_yup4.array)().of(dimensionFilters.defined()).optional()
});
var triggerConditionValidation = (0, import_yup4.object)({
criteria_condition: (0, import_yup4.string)().oneOf(["ALL"]).required("Criteria condition is required"),
polling_interval_seconds: (0, import_yup4.number)().required(fieldErrorMessage),
evaluation_period_seconds: (0, import_yup4.number)().required(fieldErrorMessage),
trigger_occurrences: (0, import_yup4.number)().required(fieldErrorMessage).positive("Enter a positive value.").typeError("The value should be a number.")
});
var specialStartEndRegex = /^[^a-zA-Z0-9]/;
var createAlertDefinitionSchema = (0, import_yup4.object)({
label: (0, import_yup4.string)().required(fieldErrorMessage).matches(
/^[^*#&+:<>"?@%{}\\\/]+$/,
"Name cannot contain special characters: * # & + : < > ? @ % { } \\ /."
).max(100, "Name must be 100 characters or less.").test(
"no-special-start-end",
"Name cannot start or end with a special character.",
(value) => {
return !specialStartEndRegex.test(value != null ? value : "");
}
),
description: (0, import_yup4.string)().max(100, "Description must be 100 characters or less.").test(
"no-special-start-end",
"Description cannot start or end with a special character.",
(value) => {
return !specialStartEndRegex.test(value != null ? value : "");
}
).optional(),
severity: (0, import_yup4.number)().oneOf([0, 1, 2, 3]).required(fieldErrorMessage),
rule_criteria: (0, import_yup4.object)({
rules: (0, import_yup4.array)().of(metricCriteria).min(1, "At least one metric criteria is required.").required()
}).required(),
trigger_conditions: triggerConditionValidation,
channel_ids: (0, import_yup4.array)().of((0, import_yup4.number)().required()).required().min(1, "At least one notification channel is required."),
tags: (0, import_yup4.array)().of((0, import_yup4.string)().defined()).optional(),
entity_ids: (0, import_yup4.array)().of((0, import_yup4.string)().defined()).optional(),
regions: (0, import_yup4.array)().of((0, import_yup4.string)().defined()).optional(),
scope: (0, import_yup4.string)().oneOf(["entity", "region", "account"]).nullable().optional()
});
var editAlertDefinitionSchema = (0, import_yup4.object)({
channel_ids: (0, import_yup4.array)().of((0, import_yup4.number)().required()).optional(),
label: (0, import_yup4.string)().matches(
/^[^*#&+:<>"?@%{}\\/]+$/,
"Name cannot contain special characters: * # & + : < > ? @ % { } \\ /."
).max(100, "Name must be 100 characters or less.").test(
"no-special-start-end",
"Name cannot start or end with a special character.",
(value) => {
return !specialStartEndRegex.test(value != null ? value : "");
}
).optional(),
description: (0, import_yup4.string)().max(100, "Description must be 100 characters or less.").test(
"no-special-start-end",
"Description cannot start or end with a special character.",
(value) => {
return !specialStartEndRegex.test(value != null ? value : "");
}
).optional(),
entity_ids: (0, import_yup4.array)().of((0, import_yup4.string)().defined()).optional(),
rule_criteria: (0, import_yup4.object)({
rules: (0, import_yup4.array)().of(metricCriteria).min(1, "At least one metric criteria is required.").required()
}).optional().default(void 0),
tags: (0, import_yup4.array)().of((0, import_yup4.string)().defined()).optional(),
trigger_conditions: triggerConditionValidation.optional().default(void 0),
severity: (0, import_yup4.number)().oneOf([0, 1, 2, 3]).optional(),
status: (0, import_yup4.string)().oneOf(["enabled", "disabled", "in progress", "failed"]).optional(),
scope: (0, import_yup4.string)().oneOf(["entity", "region", "account"]).nullable().optional(),
regions: (0, import_yup4.array)().of((0, import_yup4.string)().defined()).optional()
});
// src/databases.schema.ts
var import_yup5 = require("yup");
var import_yup6 = require("yup");
var LABEL_MESSAGE = "Label must be between 3 and 32 characters";
var createDatabaseSchema = (0, import_yup6.object)({
label: (0, import_yup6.string)().required("Label is required").min(3, LABEL_MESSAGE).max(32, LABEL_MESSAGE),
engine: (0, import_yup6.string)().required("Database Engine is required"),
region: (0, import_yup6.string)().required("Region is required"),
type: (0, import_yup6.string)().required("Type is required"),
cluster_size: (0, import_yup5.number)().oneOf([1, 2, 3], "Nodes are required").required("Nodes are required"),
replication_type: (0, import_yup6.string)().notRequired().nullable(),
// TODO (UIE-8214) remove POST GA
replication_commit_type: (0, import_yup6.string)().notRequired().nullable()
// TODO (UIE-8214) remove POST GA
});
var getDynamicDatabaseSchema = (isVPCSelected) => {
if (!isVPCSelected) {
return createDatabaseSchema;
}
return createDatabaseSchema.shape({
private_network: (0, import_yup6.object)().shape({
subnet_id: (0, import_yup5.number)().nullable().required("Subnet is required.")
})
});
};
var updateDatabaseSchema = (0, import_yup6.object)({
label: (0, import_yup6.string)().notRequired().min(3, LABEL_MESSAGE).max(32, LABEL_MESSAGE),
allow_list: (0, import_yup6.array)().of((0, import_yup6.string)()).notRequired(),
updates: (0, import_yup6.object)().notRequired().shape({
frequency: (0, import_yup6.string)().oneOf(["weekly", "monthly"]),
duration: (0, import_yup5.number)(),
hour_of_day: (0, import_yup5.number)(),
day_of_week: (0, import_yup5.number)(),
week_of_month: (0, import_yup5.number)().nullable()
}).nullable(),
type: (0, import_yup6.string)().notRequired()
});
var updatePrivateNetworkSchema = (0, import_yup6.object)({
private_network: (0, import_yup6.object)().shape({
vpc_id: (0, import_yup5.number)().required("VPC is required."),
subnet_id: (0, import_yup5.number)().required("Subnet is required."),
public_access: (0, import_yup5.boolean)().default(false)
})
});
var createValidator = (key, field) => {
const fieldTypes = Array.isArray(field.type) ? field.type : [field.type];
switch (true) {
case fieldTypes.includes("integer"):
return (0, import_yup5.number)().transform((val, originalVal) => originalVal === "" ? void 0 : val).integer(`${key} must be a whole number`).required(`${key} is required`);
case fieldTypes.includes("number"):
return (0, import_yup5.number)().transform((val, originalVal) => originalVal === "" ? void 0 : val).required(`${key} is required`);
case fieldTypes.includes("string"):
return (0, import_yup6.string)();
case fieldTypes.includes("boolean"):
return (0, import_yup5.boolean)();
default:
return null;
}
};
var applyConstraints = (validator, key, field) => {
if (!validator) return null;
if (field.minimum !== void 0) {
validator = validator.min(
field.minimum,
`${key} must be at least ${field.minimum}`
);
}
if (field.maximum !== void 0) {
if (field.maximum > Number.MAX_SAFE_INTEGER) {
validator = validator.max(
Number.MAX_SAFE_INTEGER,
`${key} must be at most ${Number.MAX_SAFE_INTEGER}`
);
} else {
validator = validator.max(
field.maximum,
`${key} must be at most ${field.maximum}`
);
}
}
if (field.minLength !== void 0) {
validator = validator.min(
field.minLength,
`${key} must be at least ${field.minLength} characters`
);
}
if (field.maxLength !== void 0) {
validator = validator.max(
field.maxLength,
`${key} must be at most ${field.maxLength} characters`
);
}
if (field.pattern) {
const pattern = field.pattern;
if (key === "default_time_zone") {
validator = validator.matches(
new RegExp(pattern),
`${key} must be an IANA timezone, 'SYSTEM', or a valid UTC offset (e.g., '+03:00')`
);
} else {
validator = validator.matches(
new RegExp(pattern),
`Please ensure that ${key} follows the format ${field.example}`
);
}
}
if (key === "wal_sender_timeout") {
validator = validator.test(
"is-zero-or-in-range",
`${key} must be 0 or between 5000 and 10800000`,
(value) => {
if (typeof value !== "number") return false;
return value === 0 || value >= 5e3 && value <= 108e5;
}
);
}
if (key === "timezone") {
if (!field.value) {
validator = validator.required("timezone cannot be empty");
}
}
if (key === "net_buffer_length") {
validator = validator.test(
"is-multiple-of-1024",
`${key} must be a multiple of 1024`,
(value) => {
if (typeof value !== "number") return false;
return value % 1024 === 0;
}
);
}
return validator;
};
var processField = (schemaShape, field) => {
if (!field.label || !field.type) {
return;
}
const key = field.label;
let validator = createValidator(key, field);
validator = applyConstraints(validator, key, field);
if (validator) {
schemaShape[key] = (0, import_yup6.object)().shape({ value: validator });
}
};
var createDynamicAdvancedConfigSchema = (allConfigurations) => {
if (!Array.isArray(allConfigurations) || allConfigurations.length === 0) {
return (0, import_yup6.object)().shape({});
}
const schemaShape = {};
allConfigurations.forEach((field) => processField(schemaShape, field));
return (0, import_yup6.object)().shape({
configs: (0, import_yup6.array)().of(
(0, import_yup6.object)({
label: (0, import_yup6.string)().required(),
value: (0, import_yup5.mixed)().when("label", (label, schema) => {
var _a, _b;
if (Array.isArray(label)) {
label = label[0];
}
if (typeof label !== "string" || !schemaShape[label]) {
return schema;
}
const valueSchema = (_b = (_a = schemaShape[label]) == null ? void 0 : _a.fields) == null ? void 0 : _b.value;
return valueSchema ? valueSchema : schema;
})
})
)
});
};
// src/domains.schema.ts
var import_yup7 = require("yup");
var importZoneSchema = (0, import_yup7.object)({
domain: (0, import_yup7.string)().required("Domain is required."),
remote_nameserver: (0, import_yup7.string)().required("Remote nameserver is required.")
});
var domainSchemaBase = (0, import_yup7.object)().shape({
domain: (0, import_yup7.string)().matches(
// eslint-disable-next-line sonarjs/slow-regex
/([a-zA-Z0-9-_]+\.)+([a-zA-Z]{2,3}\.)?([a-zA-Z]{2,16}|XN--[a-zA-Z0-9]+)/,
"Domain is not valid."
),
status: (0, import_yup7.mixed)().oneOf(["disabled", "active", "edit_mode", "has_errors"]),
tags: (0, import_yup7.array)(),
description: (0, import_yup7.string)().min(1, "Description must be between 1 and 253 characters.").max(253, "Description must be between 1 and 253 characters."),
retry_sec: (0, import_yup7.number)(),
master_ips: (0, import_yup7.array)().of((0, import_yup7.string)()),
axfr_ips: (0, import_yup7.array)().of((0, import_yup7.string)()).typeError("Must be a comma-separated list of IP addresses."),
expire_sec: (0, import_yup7.number)(),
refresh_sec: (0, import_yup7.number)(),
ttl_sec: (0, import_yup7.number)()
});
var createDomainSchema = domainSchemaBase.shape({
domain: (0, import_yup7.string)().required("Domain is required.").matches(
// eslint-disable-next-line sonarjs/slow-regex
/([a-zA-Z0-9-_]+\.)+([a-zA-Z]{2,3}\.)?([a-zA-Z]{2,16}|XN--[a-zA-Z0-9]+)/,
"Domain is not valid."
),
tags: (0, import_yup7.array)().of((0, import_yup7.string)()),
type: (0, import_yup7.mixed)().required().oneOf(["master", "slave"]),
soa_email: (0, import_yup7.string)().when("type", {
is: "master",
then: (schema) => schema.required("SOA Email is required.")
}).email("SOA Email is not valid.").trim(),
master_ips: (0, import_yup7.array)().of((0, import_yup7.string)()).when("type", {
is: "slave",
then: (schema) => schema.compact().ensure().required("At least one primary IP address is required.").min(1, "At least one primary IP address is required.")
})
});
var updateDomainSchema = domainSchemaBase.shape({
domainId: (0, import_yup7.number)(),
soa_email: (0, import_yup7.string)().email("SOA Email is not valid."),
axfr_ips: (0, import_yup7.array)().of((0, import_yup7.string)()),
tags: (0, import_yup7.array)().of((0, import_yup7.string)())
});
// src/firewalls.schema.ts
var import_ipaddr = __toESM(require("ipaddr.js"), 1);
var import_yup8 = require("yup");
var IP_ERROR_MESSAGE = "Must be a valid IPv4 or IPv6 address or range.";
var validateIP = (ipAddress2) => {
if (ipAddress2 !== "" && !ipAddress2) {
return false;
}
const [, mask] = ipAddress2.split("/");
try {
if (mask) {
import_ipaddr.default.parseCIDR(ipAddress2);
} else {
import_ipaddr.default.parse(ipAddress2);
}
} catch (err) {
if (ipAddress2 !== "") {
return false;
}
}
return true;
};
var CreateFirewallDeviceSchema = (0, import_yup8.object)({
linodes: (0, import_yup8.array)().of((0, import_yup8.number)()),
nodebalancers: (0, import_yup8.array)().of((0, import_yup8.number)())
});
var ipAddress = (0, import_yup8.string)().defined().test({
name: "validateIP",
message: IP_ERROR_MESSAGE,
test: validateIP
});
var CUSTOM_PORTS_ERROR_MESSAGE = "";
var validatePort = (port) => {
CUSTOM_PORTS_ERROR_MESSAGE = "Ports must be an integer, range of integers, or a comma-separated list of integers.";
if (!port) {
CUSTOM_PORTS_ERROR_MESSAGE = "Must be 1-65535";
return false;
}
const convertedPort = parseInt(port, 10);
if (!(1 <= convertedPort && convertedPort <= 65535)) {
CUSTOM_PORTS_ERROR_MESSAGE = "Must be 1-65535";
return false;
}
if (port.startsWith("0")) {
CUSTOM_PORTS_ERROR_MESSAGE = "Port must not have leading zeroes";
return false;
}
if (String(convertedPort) !== port) {
return false;
}
return true;
};
var isCustomPortsValid = (ports) => {
const portList = (ports == null ? void 0 : ports.split(",")) || [];
let portLimitCount = 0;
for (const port of portList) {
const cleanedPort = port.trim();
if (cleanedPort.includes("-")) {
const portRange = cleanedPort.split("-");
if (!validatePort(portRange[0]) || !validatePort(portRange[1])) {
return false;
}
if (portRange.length !== 2) {
CUSTOM_PORTS_ERROR_MESSAGE = "Ranges must have 2 values";
return false;
}
if (parseInt(portRange[0], 10) >= parseInt(portRange[1], 10)) {
CUSTOM_PORTS_ERROR_MESSAGE = "Range must start with a smaller number and end with a larger number";
return false;
}
portLimitCount += 2;
} else {
if (!validatePort(cleanedPort)) {
return false;
}
portLimitCount++;
}
}
if (portLimitCount > 15) {
CUSTOM_PORTS_ERROR_MESSAGE = "Number of ports or port range endpoints exceeded. Max allowed is 15";
return false;
}
return true;
};
var validateFirewallPorts = (0, import_yup8.string)().test({
name: "firewall-ports",
message: CUSTOM_PORTS_ERROR_MESSAGE,
test: (value) => {
if (!value) {
return false;
}
try {
isCustomPortsValid(value);
} catch (err) {
return false;
}
return true;
}
});
var FirewallRuleTypeSchema = (0, import_yup8.object)().shape({
action: (0, import_yup8.string)().oneOf(["ACCEPT", "DROP"]).required("Action is required"),
description: (0, import_yup8.string)().nullable(),
label: (0, import_yup8.string)().nullable(),
protocol: (0, import_yup8.string)().oneOf(["ALL", "TCP", "UDP", "ICMP", "IPENCAP"]).required("Protocol is required."),
ports: (0, import_yup8.string)().when("protocol", {
is: (val) => val !== "ICMP" && val !== "IPENCAP",
then: () => validateFirewallPorts,
// Workaround to get the test to fail if ports is defined when protocol === ICMP or IPENCAP
otherwise: (schema) => schema.test({
name: "protocol",
message: "Ports are not allowed for ICMP and IPENCAP protocols.",
test: (value) => typeof value === "undefined"
})
}),
addresses: (0, import_yup8.object)().shape({
ipv4: (0, import_yup8.array)().of(ipAddress).nullable(),
ipv6: (0, import_yup8.array)().of(ipAddress).nullable()
}).strict(true).notRequired().nullable()
});
var FirewallRuleSchema = (0, import_yup8.object)().shape({
inbound: (0, import_yup8.array)(FirewallRuleTypeSchema).nullable(),
outbound: (0, import_yup8.array)(FirewallRuleTypeSchema).nullable(),
inbound_policy: (0, import_yup8.string)().oneOf(["ACCEPT", "DROP"]).required("Inbound policy is required."),
outbound_policy: (0, import_yup8.string)().oneOf(["ACCEPT", "DROP"]).required("Outbound policy is required.")
});
var CreateFirewallDevicesSchema = (0, import_yup8.object)().shape({
linodes: (0, import_yup8.array)().of((0, import_yup8.number)().defined()),
nodebalancers: (0, import_yup8.array)().of((0, import_yup8.number)().defined()),
linode_interfaces: (0, import_yup8.array)().of((0, import_yup8.number)().defined())
}).notRequired();
var CreateFirewallSchema = (0, import_yup8.object)().shape({
label: (0, import_yup8.string)().required("Label is required.").min(3, "Label must be between 3 and 32 characters.").max(32, "Label must be between 3 and 32 characters."),
// Label validation on the back end is more complicated, we only do basic checks here.
tags: (0, import_yup8.array)().of((0, import_yup8.string)().defined()),
rules: FirewallRuleSchema,
devices: CreateFirewallDevicesSchema
});
var UpdateFirewallSchema = (0, import_yup8.object)().shape({
label: (0, import_yup8.string)(),
tags: (0, import_yup8.array)().of((0, import_yup8.string)()),
status: (0, import_yup8.string)().oneOf(["enabled", "disabled"])
// 'deleted' is also a status but it's not settable
});
var FirewallDeviceSchema = (0, import_yup8.object)({
type: (0, import_yup8.string)().oneOf(["linode", "nodebalancer", "linode_interface"]).required("Device type is required."),
id: (0, import_yup8.number)().required("ID is required.")
});
var UpdateFirewallSettingsSchema = (0, import_yup8.object)({
default_firewall_ids: (0, import_yup8.object)({
interface_public: (0, import_yup8.number)().nullable(),
interface_vpc: (0, import_yup8.number)().nullable(),
linode: (0, import_yup8.number)().nullable(),
nodebalancer: (0, import_yup8.number)().nullable()
})
});
// src/images.schema.ts
var import_yup9 = require("yup");
var labelSchema = (0, import_yup9.string)().min(1, "Label must be between 1 and 50 characters.").max(50, "Label must be between 1 and 50 characters.").matches(
/^[a-zA-Z0-9,.?\-_\s']+$/,
"Image labels cannot contain special characters."
);
var baseImageSchema = (0, import_yup9.object)({
label: labelSchema.optional(),
description: (0, import_yup9.string)().optional().min(1).max(65e3),
cloud_init: (0, import_yup9.boolean)().optional(),
tags: (0, import_yup9.array)((0, import_yup9.string)().min(3).max(50).required()).max(500).optional()
});
var createImageSchema = baseImageSchema.shape({
disk_id: (0, import_yup9.number)().typeError("Disk is required.").required("Disk is required.")
});
var uploadImageSchema = baseImageSchema.shape({
label: labelSchema.required("Label is required."),
region: (0, import_yup9.string)().required("Region is required.")
});
var updateImageSchema = (0, import_yup9.object)({
label: labelSchema.optional(),
description: (0, import_yup9.string)().optional().max(65e3, "Length must be 65000 characters or less."),
tags: (0, import_yup9.array)((0, import_yup9.string)().required()).optional()
});
var updateImageRegionsSchema = (0, import_yup9.object)({
regions: (0, import_yup9.array)((0, import_yup9.string)()).required("Regions are required.").min(1, "Must specify at least one region.")
});
// src/kubernetes.schema.ts
var import_yup10 = require("yup");
var nodePoolSchema = (0, import_yup10.object)({
type: (0, import_yup10.string)(),
count: (0, import_yup10.number)()
});
var nodePoolBetaSchema = nodePoolSchema.concat(
(0, import_yup10.object)({
upgrade_strategy: (0, import_yup10.string)(),
k8_version: (0, import_yup10.string)(),
firewall_id: (0, import_yup10.number)()
})
);
var clusterLabelSchema = (0, import_yup10.string)().required("Label is required.").matches(
/^[a-zA-Z0-9-]+$/,
"Cluster labels cannot contain special characters, spaces, or underscores."
).min(3, "Length must be between 3 and 32 characters.").max(32, "Length must be between 3 and 32 characters.");
var ipv4Address = (0, import_yup10.string)().defined().test({
name: "validateIP",
message: "Must be a valid IPv4 address.",
test: validateIP
});
var ipv6Address = (0, import_yup10.string)().defined().test({
name: "validateIP",
message: "Must be a valid IPv6 address.",
test: validateIP
});
var controlPlaneACLOptionsSchema = (0, import_yup10.object)({
enabled: (0, import_yup10.boolean)(),
"revision-id": (0, import_yup10.string)(),
addresses: (0, import_yup10.object)({
ipv4: (0, import_yup10.array)().of(ipv4Address).nullable(),
ipv6: (0, import_yup10.array)().of(ipv6Address).nullable()
}).notRequired()
});
var controlPlaneEnterpriseACLOptionsSchema = (0, import_yup10.object)({
enabled: (0, import_yup10.boolean)(),
"revision-id": (0, import_yup10.string)(),
addresses: (0, import_yup10.object)({
ipv4: (0, import_yup10.array)().of(ipv4Address),
ipv6: (0, import_yup10.array)().of(ipv6Address)
}).required()
});
var createKubeClusterSchema = (0, import_yup10.object)({
label: clusterLabelSchema,
region: (0, import_yup10.string)().required("Region is required."),
k8s_version: (0, import_yup10.string)().required("Kubernetes version is required."),
node_pools: (0, import_yup10.array)().of(nodePoolSchema).min(1, "Please add at least one node pool.")
});
var createKubeClusterWithRequiredACLSchema = (0, import_yup10.object)({
control_plane: (0, import_yup10.object)({
high_availability: (0, import_yup10.boolean)(),
acl: (0, import_yup10.object)({
enabled: (0, import_yup10.boolean)(),
"revision-id": (0, import_yup10.string)(),
addresses: (0, import_yup10.object)({
ipv4: (0, import_yup10.array)().of(ipv4Address),
ipv6: (0, import_yup10.array)().of(ipv6Address)
})
})
}).test(
"validateIPForEnterprise",
"At least one IP address or CIDR range is required for LKE Enterprise.",
function(controlPlane) {
const { ipv4, ipv6 } = controlPlane.acl.addresses;
return ipv4 && ipv4.length > 0 || ipv6 && ipv6.length > 0;
}
).required()
});
var kubernetesControlPlaneACLPayloadSchema = (0, import_yup10.object)({
acl: controlPlaneACLOptionsSchema
});
var kubernetesEnterpriseControlPlaneACLPayloadSchema = (0, import_yup10.object)({
acl: controlPlaneEnterpriseACLOptionsSchema.test(
"validateIPForEnterprise",
"At least one IP address or CIDR range is required for LKE Enterprise.",
function(acl) {
const { ipv4, ipv6 } = acl.addresses || {};
return ipv4 && ipv4.length > 0 && ipv4[0] !== "" || ipv6 && ipv6.length > 0 && ipv6[0] !== "";
}
)
});
var alphaNumericValidCharactersRegex = /^[a-zA-Z0-9]([a-zA-Z0-9-._]*[a-zA-Z0-9])?$/;
var dnsKeyRegex = /^[a-zA-Z0-9]([a-zA-Z0-9-._/]*[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?)*$/;
var MAX_DNS_KEY_TOTAL_LENGTH = 128;
var MAX_DNS_KEY_SUFFIX_LENGTH = 62;
var MAX_SIMPLE_KEY_OR_VALUE_LENGTH = 63;
var validateKubernetesLabel = (labels) => {
if (!labels) {
return false;
}
for (const [labelKey, labelValue] of Object.entries(labels)) {
if (!labelKey || !labelValue) {
return false;
}
if (labelKey.includes("kubernetes.io") || labelKey.includes("linode.com")) {
return false;
}
if (labelKey.includes("/")) {
const suffix = labelKey.split("/")[0];
if (!dnsKeyRegex.test(labelKey)) {
return false;
}
if (labelKey.length > MAX_DNS_KEY_TOTAL_LENGTH || suffix.length > MAX_DNS_KEY_SUFFIX_LENGTH) {
return false;
}
} else {
if (labelKey.length > MAX_SIMPLE_KEY_OR_VALUE_LENGTH || !alphaNumericValidCharactersRegex.test(labelKey)) {
return false;
}
}
if (labelValue.length > MAX_SIMPLE_KEY_OR_VALUE_LENGTH || !alphaNumericValidCharactersRegex.test(labelValue)) {
return false;
}
}
return true;
};
var kubernetesLabelSchema = (0, import_yup10.object)().test({
name: "validateLabels",
message: "Labels must be valid key-value pairs.",
test: validateKubernetesLabel
});
var kubernetesTaintSchema = (0, import_yup10.object)({
key: (0, import_yup10.string)().required("Key is required.").test(
"valid-key",
"Key must start with a letter or number and may contain letters, numbers, hyphens, dots, and underscores, up to 253 characters.",
(value) => {
return alphaNumericValidCharactersRegex.test(value) || dnsKeyRegex.test(value);
}
).max(253, "Key must be between 1 and 253 characters.").min(1, "Key must be between 1 and 253 characters."),
value: (0, import_yup10.string)().matches(
alphaNumericValidCharactersRegex,
"Value must start with a letter or number and may contain letters, numbers, hyphens, dots, and underscores, up to 63 characters."
).max(63, "Value must be between 0 and 63 characters.").notOneOf(
["kubernetes.io", "linode.com"],
'Value cannot be "kubernetes.io" or "linode.com".'
).notRequired()
});
// src/linodes.schema.ts
var import_ipaddr3 = __toESM(require("ipaddr.js"), 1);
var import_yup12 = require("yup");
// src/vpcs.schema.ts
var import_ipaddr2 = __toESM(require("ipaddr.js"), 1);
var import_yup11 = require("yup");
var LABEL_MESSAGE2 = "Label must be between 1 and 64 characters.";
var LABEL_REQUIRED = "Label is required.";
var LABEL_REQUIREMENTS = "Label must include only ASCII letters, numbers, and dashes.";
var labelTestDetails = {
testName: "no two dashes in a row",
testMessage: "Label must not contain two dashes in a row."
};
var IP_EITHER_BOTH_NOT_NEITHER = "A subnet must have either IPv4 or IPv6, or both, but not neither.";
var TEMPORARY_IPV4_REQUIRED_MESSAGE = "A subnet must have an IPv4 range.";
var determineIPType = (ip) => {
try {
let addr;
const [, mask] = ip.split("/");
if (mask) {
const parsed = import_ipaddr2.default.parseCIDR(ip);
addr = parsed[0];
} else {
addr = import_ipaddr2.default.parse(ip);
}
return addr.kind();
} catch (e) {
return void 0;
}
};
var vpcsValidateIP = ({
value,
shouldHaveIPMask,
mustBeIPMask,
checkIPv6PrefixLengthIs64
}) => {
if (!value) {
return false;
}
const [, mask] = value.trim().split("/");
if (mustBeIPMask) {
const valueIsMaskOnly = value === `/${mask}`;
return !mask ? false : import_ipaddr2.default.IPv6.subnetMaskFromPrefixLength(Number(mask)) !== null && valueIsMaskOnly && Number(mask) >= 64 && Number(mask) <= 125;
}
try {
const type = determineIPType(value);
const isIPv4 = type === "ipv4";
const isIPv6 = type === "ipv6";
if (!isIPv4 && !isIPv6) {
return false;
}
if (isIPv4) {
if (shouldHaveIPMask) {
import_ipaddr2.default.IPv4.parseCIDR(value);
} else {
import_ipaddr2.default.IPv4.isValid(value);
import_ipaddr2.default.IPv4.parse(value);
}
}
if (isIPv6) {
if (checkIPv6PrefixLengthIs64) {
return mask === "64";
}
if (shouldHaveIPMask) {
import_ipaddr2.default.IPv6.parseCIDR(value);
} else {
import_ipaddr2.default.IPv6.isValid(value);
import_ipaddr2.default.IPv6.parse(value);
}
}
return true;
} catch (err) {
return false;
}
};
var labelValidation = (0, import_yup11.string)().test(
labelTestDetails.testName,
labelTestDetails.testMessage,
(value) => !(value == null ? void 0 : value.includes("--"))
).min(1, LABEL_MESSAGE2).max(64, LABEL_MESSAGE2).matches(/^[a-zA-Z0-9-]*$/, LABEL_REQUIREMENTS);
var updateVPCSchema = (0, import_yup11.object)({
label: labelValidation,
description: (0, import_yup11.string)()
});
var VPCIPv6Schema = (0, import_yup11.object)({
range: (0, import_yup11.string)().optional().test(
"IPv6 prefix length",
"Must be the prefix length 52, 48, or 44 of the IP, e.g. /52",
(value) => {
if (value && value.length > 0) {
return ["/44", "/48", "/52"].includes(value);
}
}
)
});
var VPCIPv6SubnetSchema = (0, import_yup11.object)({
range: (0, import_yup11.string)().required().test(
"IPv6 prefix length",
"Must be the prefix length (52-62) of the IP, e.g. /52",
(value) => {
if (value && value !== "auto" && value.length > 0) {
const [, mask] = value.split("/");
return +mask >= 52 && +mask <= 62;
}
}
)
});
var createSubnetSchemaIPv4 = (0, import_yup11.object)({
label: labelValidation.required(LABEL_REQUIRED),
ipv4: (0, import_yup11.string)().when("ipv6", {
is: (value) => value === "" || value === null || value === void 0,
then: (schema) => schema.required(TEMPORARY_IPV4_REQUIRED_MESSAGE).test({
name: "IPv4 CIDR format",
message: "The IPv4 range must be in CIDR format.",
test: (value) => vpcsValidateIP({
value,
shouldHaveIPMask: true,
mustBeIPMask: false
})
}),
otherwise: (schema) => (0, import_yup11.lazy)((value) => {
switch (typeof value) {
case "string":
return schema.notRequired().test({
name: "IPv4 CIDR format",
message: "The IPv4 range must be in CIDR format.",
test: (value2) => vpcsValidateIP({
value: value2,
shouldHaveIPMask: true,
mustBeIPMask: false
})
});
case "undefined":
return schema.notRequired().nullable();
default:
return schema.notRequired().nullable();
}
})
})
});
var createSubnetSchemaWithIPv6 = (0, import_yup11.object)().shape(
{
label: labelValidation.required(LABEL_REQUIRED),
ipv4: (0, import_yup11.string)().when("ipv6", {
is: (value) => value === "" || value === null || value === void 0,
then: (schema) => schema.required(I