Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | 3x 3x 3x 3x 3x 13x 13x 3x | import { z } from "zod";
import { optionalIndianPhoneSchema } from "@interioring/utils/validation/phone";
import {
addressCitySchema,
addressLine1Schema,
addressLine2Schema,
addressPincodeSchema,
addressStateSchema,
} from "@interioring/utils/validation/address/zod";
import { freeTextSchema } from "@interioring/utils/validation/free-text";
import {
facebookUrlSchema,
googleBusinessUrlSchema,
linkedinUrlSchema,
pinterestUrlSchema,
twitterUrlSchema,
websiteUrlSchema,
youtubeUrlSchema,
} from "@interioring/utils/validation/url";
// Valid enum values from the DB schema
const TEAM_SIZES = ["solo", "2-5", "6-10", "11-25", "25+"] as const;
const PRO_STATUS = ["draft", "published", "archived"] as const;
const RUSH_ORDER_PREMIUMS = [
"10_percent",
"20_percent",
"30_percent",
"50_percent",
"case_by_case",
] as const;
const PRICING_TIERS = ["budget", "mid_range", "premium", "luxury"] as const;
// Issue #619: instagramHandle is a bare handle (e.g. "4inchstudio"), not a URL.
// Normalise the three shapes real users paste — bare handle, @handle, full
// instagram.com URL — to the bare handle the marketplace renders, then
// validate against Instagram's documented 1-30 char `[a-zA-Z0-9._]` rule.
const instagramHandleSchema = z
.string()
.transform((val) =>
val
.trim()
.replace(/^https?:\/\/(www\.)?instagram\.com\//i, "")
.replace(/^@+/, "")
.replace(/\/+$/, ""),
)
.refine((val) => val === "" || /^[a-zA-Z0-9._]{1,30}$/.test(val), {
message:
"Instagram handle must be 1-30 characters: letters, digits, dots, or underscores",
});
export const updateProSchema = z
.object({
// Basic info
businessName: z.string().min(2).max(100).optional(),
tagline: freeTextSchema({ minLen: 3, requireLetter: true, maxLen: 120 }),
// `about`/`processDescription` mirror the rule applied by the onboarding
// step2Schema so the same numeric-only payload can't slip in via the
// profile update route (issue #563 audit consistency fix).
about: freeTextSchema({ minLen: 10, requireLetter: true, maxLen: 5000 }),
processDescription: freeTextSchema({
minLen: 10,
requireLetter: true,
maxLen: 5000,
}),
description: z.string().max(5000).optional().nullable(),
whatsapp: optionalIndianPhoneSchema,
phoneAlternate: optionalIndianPhoneSchema,
email: z.string().email().optional().nullable().or(z.literal("")),
// Enums
status: z.enum(PRO_STATUS).optional(),
teamSize: z.enum(TEAM_SIZES).optional().nullable(),
installationTeamSize: z.enum(TEAM_SIZES).optional().nullable(),
rushOrderPremium: z.enum(RUSH_ORDER_PREMIUMS).optional().nullable(),
pricingTier: z.enum(PRICING_TIERS).optional().nullable(),
// Booleans
acceptsRushOrders: z.boolean().optional(),
hasOwnWorkshop: z.boolean().optional(),
// Numbers
yearsInBusiness: z.number().int().min(0).max(100).optional().nullable(),
establishedYear: z.number().int().min(1900).max(2100).optional().nullable(),
priceRangeMin: z.number().int().min(0).optional().nullable(),
priceRangeMax: z.number().int().min(0).optional().nullable(),
// Taxonomy IDs (arrays of strings)
businessTypeId: z.string().optional().nullable(),
businessTypesSecondary: z.array(z.string()).max(50).optional().nullable(),
cityId: z.string().optional().nullable(),
customerSegmentId: z.string().optional().nullable(),
customerSegmentsSecondary: z.array(z.string()).max(50).optional().nullable(),
timelineCapabilities: z.array(z.string()).max(50).optional().nullable(),
projectScaleIds: z.array(z.string()).max(50).optional().nullable(),
serviceCategoryIds: z.array(z.string()).max(50).optional().nullable(),
materialTagIds: z.array(z.string()).max(50).optional().nullable(),
brandsWorkWith: z.array(z.string()).max(50).optional().nullable(),
brandsOfficialPartner: z.array(z.string()).max(50).optional().nullable(),
serviceAreaIds: z.array(z.string()).max(50).optional().nullable(),
languagesSpoken: z.array(z.string()).max(50).optional().nullable(),
// Social links — issue #642 requires platform-domain enforcement on top
// of basic URL validity. Schemas live in @interioring/utils/validation/url
// so the Portal modal can reuse the same predicates for inline errors.
instagramHandle: instagramHandleSchema.optional().nullable(),
facebookUrl: facebookUrlSchema.optional().nullable(),
youtubeUrl: youtubeUrlSchema.optional().nullable(),
googleBusinessUrl: googleBusinessUrlSchema.optional().nullable(),
websiteUrl: websiteUrlSchema.optional().nullable(),
linkedinUrl: linkedinUrlSchema.optional().nullable(),
twitterUrl: twitterUrlSchema.optional().nullable(),
pinterestUrl: pinterestUrlSchema.optional().nullable(),
whatsappBusinessNumber: optionalIndianPhoneSchema,
// Branding
logoUrl: z.string().optional().nullable(),
brandColorPrimary: z.string().max(20).optional().nullable(),
brandColorSecondary: z.string().max(20).optional().nullable(),
coverImage: z.string().optional().nullable(),
profileImage: z.string().optional().nullable(),
// Address — shared validators in @interioring/utils/validation/address/zod
// enforce: line1/line2 must contain letters (issue #563), city is letters
// only, state is a known Indian state (normalized to canonical casing),
// pincode is 6 digits not starting with 0.
addressLine1: addressLine1Schema,
addressLine2: addressLine2Schema,
addressCity: addressCitySchema,
addressState: addressStateSchema,
addressPincode: addressPincodeSchema,
businessAddress: z.string().max(500).optional().nullable(),
// Workshop
workshopLocation: z.string().max(500).optional().nullable(),
// SEO
metaTitle: z.string().max(200).optional().nullable(),
metaDescription: z.string().max(500).optional().nullable(),
ogImage: z.string().optional().nullable(),
// JSON fields
profileFields: z.record(z.string(), z.unknown()).optional().nullable(),
typicalTimelines: z.record(z.string(), z.string()).optional().nullable(),
})
.strip(); // Strip unknown fields — prevents unvalidated data reaching the service layer
export type UpdateProInput = z.infer<typeof updateProSchema>;
|