@verisure-italy/overbooking-types
v1.7.8
Published
Types for Overbooking service
Readme
Overbooking Types
Zod schemas and TypeScript types for Overbooking settings and allocation logic.
Features
- ✅ Discriminated activation model (boolean vs time range)
- ✅ Percentage allocation with invariant (sum = 100)
- ✅ Channel / zip code scoping with
*wildcard or UUID list - ✅ Composable with shared timestamp fields
- ✅ Strong enums for allocation keys
Installation
pnpm add @verisure-italy/overbooking-typesCore Schemas
Allocation
Allocation keys must sum to 100.
import { allocationSchema, overbookingAllocationTypes } from '@verisure-italy/overbooking-types'
const data = { front: 25, ko: 25, telesales: 25, ecommerce: 25 }
const parsed = allocationSchema.safeParse(data)If sum != 100 -> issue with message overbookingAllocationTypes.invalid_sum.
Activation (Discriminated Union)
import { activationSchema } from '@verisure-italy/overbooking-types'
const booleanActivation = {
type: 'boolean',
value: { alwaysActive: true },
}
const timeRangeActivation = {
type: 'time_range',
value: {
from: new Date(),
to: new Date(Date.now() + 3600_000),
days: ['monday', 'tuesday'],
},
}Identify by type field.
Setting
import { settingSchema, type Setting } from '@verisure-italy/overbooking-types'
const result = settingSchema.safeParse({
id: crypto.randomUUID(),
name: 'Test Setting',
outOfArea: false,
channels: '*', // or [uuid1, uuid2]
zipCodes: ['20100'],
activation: booleanActivation,
allocation: { front: 25, ko: 25, telesales: 25, ecommerce: 25 },
createdAt: Date.now(),
updatedAt: Date.now(),
})channels: either literal * or non-empty UUID array.
Enum: Allocation Types
import { overbookingAllocationTypeSchema } from '@verisure-italy/overbooking-types'Values: front | ko | telesales | ecommerce.
Validation Tips
- Always check allocation sum before persisting.
- Use discriminated union narrow:
if (activation.type === 'time_range') {
// activation.value.from is Date
}Related Packages
@verisure-italy/shared-types(daysOfWeek, timestamp fields, zip code)@verisure-italy/alis-types(imports allocation type)
License
Internal Verisure Italy package
