@verisure-italy/coupon-code-types
v1.7.13
Published
Types for Coupon Code service
Downloads
275
Readme
@verisure-italy/coupon-code-types
Domain contracts for offers, one-time coupon batches, regex coupons, and coupon-usage events.
Installation
pnpm add @verisure-italy/coupon-code-typesMain Exports
codeSchemaandtype CodecouponTypeSchemaandcouponTypesburnCouponCodeSchemavalidateCouponCodeSchemaofferSchemaoneTimeCouponCodeSchemaregexCouponCodecouponUsageSchema
What This Package Gives You
- reusable coupon-code validation rules
- persistence models for static and regex-driven coupons
- a lightweight offer contract
- request payload schemas for coupon validation and burn flows
Schema Inventory
| Schema | Type alias | Kind | Purpose |
| --- | --- | --- | --- |
| codeSchema | Code | string schema | Coupon-code primitive |
| couponTypeSchema | n/a | enum | Coupon-type discriminator |
| burnCouponCodeSchema | BurnCouponCode | object schema | Burn request payload |
| validateCouponCodeSchema | ValidateCouponCode | object schema | Validation request payload |
| offerSchema | Offer | object schema | Offer contract |
| oneTimeCouponCodeSchema | OneTimeCouponCode | object schema | Static coupon batch |
| regexCouponCode | RegexCouponCode | object schema | Regex-driven coupon definition |
| couponUsageSchema | n/a | object schema | Coupon-usage event |
Enum Reference
couponTypeSchema
Values:
oneTimeCouponregexCoupon
Schema Reference
codeSchema
| Rule | Value |
| --- | --- |
| Type | string |
| Required | Yes |
| Validation | Must match ^[a-zA-Z0-9_-]+$ |
burnCouponCodeSchema and validateCouponCodeSchema
| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| offerId | string | Yes | Non-empty |
| code | string | Yes | Must match ^[a-zA-Z0-9]+$ |
offerSchema
| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| id | string | Yes | UUID |
| name | string | Yes | Non-empty |
| description | string | Yes | Non-empty |
| validUntilAt | number | Yes | Timestamp |
| createdAt | number | Yes | Shared timestamp |
| updatedAt | number | Yes | Shared timestamp |
oneTimeCouponCodeSchema
| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| id | string | Yes | UUID |
| offerId | string | Yes | Non-empty |
| codes | Code[] | Yes | At least one code |
| createdAt | number | Yes | Shared timestamp |
| updatedAt | number | Yes | Shared timestamp |
regexCouponCode
| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| offerId | string | Yes | UUID |
| regex | string | Yes | Must match /pattern/flags format |
| maxUses | number | Yes | Minimum 1 |
| counter | number | Yes | Current usage counter |
| createdAt | number | Yes | Shared timestamp |
| updatedAt | number | Yes | Shared timestamp |
couponUsageSchema
| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| id | string | Yes | UUID |
| offerId | string | Yes | Non-empty |
| code | string | Yes | Non-empty |
| usedAt | number | Yes | Timestamp |
| type | oneTimeCoupon \| regexCoupon | Yes | Coupon-type discriminator |
Example
import { oneTimeCouponCodeSchema } from '@verisure-italy/coupon-code-types'
const batch = oneTimeCouponCodeSchema.parse({
id: '550e8400-e29b-41d4-a716-446655440000',
offerId: 'offer-1',
codes: ['WELCOME10', 'SPRING20'],
createdAt: 1,
updatedAt: 1,
})