@verisure-italy/zipcode-types 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,171 @@
1
+ # ZipCode Types
2
+
3
+ TypeScript types and Zod schemas for ZipCode service entities. This package provides type-safe definitions for areas and enabled zip codes.
4
+
5
+ ## Features
6
+
7
+ - ✅ **Type-Safe** - Full TypeScript support with Zod runtime validation
8
+ - ✅ **Shared Types** - Built on top of `@verisure-italy/shared-types`
9
+ - ✅ **Runtime Validation** - Zod schemas for request/response validation
10
+ - ✅ **Tree-Shakeable** - ESM and CJS support for optimal bundle size
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ pnpm add @verisure-italy/zipcode-types
16
+ ```
17
+
18
+ ## Types
19
+
20
+ ### Area
21
+
22
+ Represents a geographic area with zip code information.
23
+
24
+ ```typescript
25
+ import { Area, areaSchema } from '@verisure-italy/zipcode-types'
26
+
27
+ // TypeScript type
28
+ const area: Area = {
29
+ id: '123e4567-e89b-12d3-a456-426614174000',
30
+ city: 'Milano',
31
+ province: 'MI',
32
+ region: 'Lombardia',
33
+ town: 'Milano',
34
+ zipCode: '20100',
35
+ }
36
+
37
+ // Runtime validation with Zod
38
+ const result = areaSchema.safeParse(data)
39
+ if (result.success) {
40
+ const validArea: Area = result.data
41
+ }
42
+ ```
43
+
44
+ **Schema:**
45
+
46
+ ```typescript
47
+ const areaSchema = z.object({
48
+ id: z.uuid(), // UUID v4
49
+ city: z.string().min(2, 'city.required'), // Min 2 chars
50
+ province: z.string().min(2).max(3), // 2-3 chars (e.g., MI, RM)
51
+ region: z.string().min(2, 'region.required'), // Min 2 chars
52
+ town: z.string().min(2, 'town.required'), // Min 2 chars
53
+ zipCode: zipCodeSchema, // From shared-types
54
+ })
55
+ ```
56
+
57
+ ### Enabled
58
+
59
+ Represents an enabled zip code.
60
+
61
+ ```typescript
62
+ import { Enabled, enabledSchema } from '@verisure-italy/zipcode-types'
63
+
64
+ // TypeScript type
65
+ const enabled: Enabled = {
66
+ zipCode: '20100',
67
+ }
68
+
69
+ // Runtime validation with Zod
70
+ const result = enabledSchema.safeParse(data)
71
+ if (result.success) {
72
+ const validEnabled: Enabled = result.data
73
+ }
74
+ ```
75
+
76
+ **Schema:**
77
+
78
+ ```typescript
79
+ const enabledSchema = z.object({
80
+ zipCode: zipCodeSchema, // From shared-types
81
+ })
82
+ ```
83
+
84
+ ## Usage Examples
85
+
86
+ ### Express Route with Validation
87
+
88
+ ```typescript
89
+ import express from 'express'
90
+ import { areaSchema, type Area } from '@verisure-italy/zipcode-types'
91
+
92
+ const router = express.Router()
93
+
94
+ router.post('/areas', async (req, res) => {
95
+ // Validate request body
96
+ const result = areaSchema.safeParse(req.body)
97
+
98
+ if (!result.success) {
99
+ return res.status(400).json({
100
+ error: 'Invalid area data',
101
+ details: result.error.issues
102
+ })
103
+ }
104
+
105
+ const area: Area = result.data
106
+ // ... save to database ...
107
+
108
+ res.json(area)
109
+ })
110
+ ```
111
+
112
+ ### With Router Middleware
113
+
114
+ ```typescript
115
+ import { createRestResource } from '@verisure-italy/router-middleware'
116
+ import { areaSchema, type Area } from '@verisure-italy/zipcode-types'
117
+
118
+ const areaResource = createRestResource<Area>({
119
+ name: 'area',
120
+ schema: areaSchema,
121
+ // ... repository methods ...
122
+ })
123
+
124
+ // Validation is handled automatically by router-middleware
125
+ ```
126
+
127
+ ### Type Guards
128
+
129
+ ```typescript
130
+ import { areaSchema, type Area } from '@verisure-italy/zipcode-types'
131
+
132
+ function isValidArea(data: unknown): data is Area {
133
+ return areaSchema.safeParse(data).success
134
+ }
135
+
136
+ // Usage
137
+ if (isValidArea(unknownData)) {
138
+ // TypeScript knows this is an Area
139
+ console.log(unknownData.city)
140
+ }
141
+ ```
142
+
143
+ ## Dependencies
144
+
145
+ - `@verisure-italy/shared-types` - Provides `zipCodeSchema` and other shared types
146
+ - `zod` ^4.1.12 - Runtime validation library
147
+
148
+ ## Related Packages
149
+
150
+ - [`@verisure-italy/shared-types`](../shared-types) - Shared types across services
151
+ - [`@verisure-italy/router-middleware`](../router-middleware) - REST resource creation with validation
152
+ - [`@verisure-italy/error-handler-middleware`](../error-handler-middleware) - Handles validation errors
153
+
154
+ ## TypeScript Configuration
155
+
156
+ This package is built with TypeScript 5.9+ and exports both type definitions and runtime schemas.
157
+
158
+ ```json
159
+ {
160
+ "compilerOptions": {
161
+ "moduleResolution": "bundler",
162
+ "module": "ESNext",
163
+ "target": "ES2022"
164
+ }
165
+ }
166
+ ```
167
+
168
+ ## License
169
+
170
+ Internal Verisure Italy package
171
+
package/dist/index.cjs CHANGED
@@ -20,27 +20,17 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
- areaSchema: () => areaSchema,
24
- enabledSchema: () => enabledSchema
23
+ overbookingAllocationTypeSchema: () => overbookingAllocationTypeSchema,
24
+ overbookingAllocationTypes: () => overbookingAllocationTypes
25
25
  });
26
26
  module.exports = __toCommonJS(index_exports);
27
27
 
28
- // src/models.ts
29
- var import_shared_types = require("@verisure-italy/shared-types");
28
+ // src/types.ts
30
29
  var import_zod = require("zod");
31
- var enabledSchema = import_zod.z.object({
32
- zipCode: import_shared_types.zipCodeSchema
33
- });
34
- var areaSchema = import_zod.z.object({
35
- id: import_zod.z.uuid(),
36
- city: import_zod.z.string().min(2, "city.required"),
37
- province: import_zod.z.string().min(2, "province.required").max(3, "province.bad_format"),
38
- region: import_zod.z.string().min(2, "region.required"),
39
- town: import_zod.z.string().min(2, "town.required"),
40
- zipCode: import_shared_types.zipCodeSchema
41
- });
30
+ var overbookingAllocationTypes = ["front", "ko", "telesales", "ecommerce"];
31
+ var overbookingAllocationTypeSchema = import_zod.z.enum(overbookingAllocationTypes);
42
32
  // Annotate the CommonJS export names for ESM import in node:
43
33
  0 && (module.exports = {
44
- areaSchema,
45
- enabledSchema
34
+ overbookingAllocationTypeSchema,
35
+ overbookingAllocationTypes
46
36
  });
package/dist/index.d.cts CHANGED
@@ -1,17 +1,12 @@
1
1
  import { z } from 'zod';
2
2
 
3
- declare const enabledSchema: z.ZodObject<{
4
- zipCode: z.ZodString;
5
- }, z.core.$strip>;
6
- type Enabled = z.infer<typeof enabledSchema>;
7
- declare const areaSchema: z.ZodObject<{
8
- id: z.ZodUUID;
9
- city: z.ZodString;
10
- province: z.ZodString;
11
- region: z.ZodString;
12
- town: z.ZodString;
13
- zipCode: z.ZodString;
14
- }, z.core.$strip>;
15
- type Area = z.infer<typeof areaSchema>;
3
+ declare const overbookingAllocationTypes: readonly ["front", "ko", "telesales", "ecommerce"];
4
+ declare const overbookingAllocationTypeSchema: z.ZodEnum<{
5
+ front: "front";
6
+ ko: "ko";
7
+ telesales: "telesales";
8
+ ecommerce: "ecommerce";
9
+ }>;
10
+ type OverbookingAllocationType = z.infer<typeof overbookingAllocationTypeSchema>;
16
11
 
17
- export { type Area, type Enabled, areaSchema, enabledSchema };
12
+ export { type OverbookingAllocationType, overbookingAllocationTypeSchema, overbookingAllocationTypes };
package/dist/index.d.ts CHANGED
@@ -1,17 +1,12 @@
1
1
  import { z } from 'zod';
2
2
 
3
- declare const enabledSchema: z.ZodObject<{
4
- zipCode: z.ZodString;
5
- }, z.core.$strip>;
6
- type Enabled = z.infer<typeof enabledSchema>;
7
- declare const areaSchema: z.ZodObject<{
8
- id: z.ZodUUID;
9
- city: z.ZodString;
10
- province: z.ZodString;
11
- region: z.ZodString;
12
- town: z.ZodString;
13
- zipCode: z.ZodString;
14
- }, z.core.$strip>;
15
- type Area = z.infer<typeof areaSchema>;
3
+ declare const overbookingAllocationTypes: readonly ["front", "ko", "telesales", "ecommerce"];
4
+ declare const overbookingAllocationTypeSchema: z.ZodEnum<{
5
+ front: "front";
6
+ ko: "ko";
7
+ telesales: "telesales";
8
+ ecommerce: "ecommerce";
9
+ }>;
10
+ type OverbookingAllocationType = z.infer<typeof overbookingAllocationTypeSchema>;
16
11
 
17
- export { type Area, type Enabled, areaSchema, enabledSchema };
12
+ export { type OverbookingAllocationType, overbookingAllocationTypeSchema, overbookingAllocationTypes };
package/dist/index.js CHANGED
@@ -1,18 +1,8 @@
1
- // src/models.ts
2
- import { zipCodeSchema } from "@verisure-italy/shared-types";
1
+ // src/types.ts
3
2
  import { z } from "zod";
4
- var enabledSchema = z.object({
5
- zipCode: zipCodeSchema
6
- });
7
- var areaSchema = z.object({
8
- id: z.uuid(),
9
- city: z.string().min(2, "city.required"),
10
- province: z.string().min(2, "province.required").max(3, "province.bad_format"),
11
- region: z.string().min(2, "region.required"),
12
- town: z.string().min(2, "town.required"),
13
- zipCode: zipCodeSchema
14
- });
3
+ var overbookingAllocationTypes = ["front", "ko", "telesales", "ecommerce"];
4
+ var overbookingAllocationTypeSchema = z.enum(overbookingAllocationTypes);
15
5
  export {
16
- areaSchema,
17
- enabledSchema
6
+ overbookingAllocationTypeSchema,
7
+ overbookingAllocationTypes
18
8
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@verisure-italy/zipcode-types",
3
3
  "description": "Types for ZipCode service",
4
- "version": "1.3.0",
4
+ "version": "1.4.0",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -19,7 +19,7 @@
19
19
  ],
20
20
  "dependencies": {
21
21
  "zod": "4.1.12",
22
- "@verisure-italy/shared-types": "1.3.0"
22
+ "@verisure-italy/shared-types": "1.4.0"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/node": "24.6.0",