export interface IPlatformObjectStorageBindingConfig { bucketName?: string; region?: string; publicRead?: boolean; versioning?: boolean; } export const platformObjectStorageBucketNameLimits = Object.freeze({ minimumBytes: 3, maximumBytes: 63, }); /** Mirrors SmartStorage's canonical S3 bucket boundary without normalizing input. */ export const validatePlatformObjectStorageBucketName = ( bucketNameArg: unknown, pathArg = 'objectstorage bucketName', ): string[] => { if (typeof bucketNameArg !== 'string') { return [`${pathArg} must be a canonical S3 bucket name`]; } const ipv4Parts = bucketNameArg.split('.'); const isIpv4Address = ipv4Parts.length === 4 && ipv4Parts.every((partArg) => ( /^[0-9]+$/.test(partArg) && Number(partArg) <= 255 )); if (bucketNameArg.length < platformObjectStorageBucketNameLimits.minimumBytes || bucketNameArg.length > platformObjectStorageBucketNameLimits.maximumBytes || !/^[a-z0-9][a-z0-9.-]*[a-z0-9]$/.test(bucketNameArg) || bucketNameArg.includes('..') || isIpv4Address) { return [`${pathArg} must be a canonical S3 bucket name`]; } return []; };