Skip to content

Commit c0fe33f

Browse files
committed
feat: update schemas to use nullish instead of optional for improved validation
1 parent 7451d0a commit c0fe33f

10 files changed

Lines changed: 91 additions & 132 deletions

actions/gls-action/src/data_types/glsAddress.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ import { z } from "zod";
33

44
export const AddressSchema = z.object({
55
Name1: z.string().max(40).describe("Primary name line (person or company). Max 40 characters."),
6-
Name2: z.string().max(40).optional().describe("Optional second name line (e.g., department or additional identifier). Max 40 characters."),
7-
Name3: z.string().max(40).optional().describe("Optional third name line for extended address details. Max 40 characters."),
6+
Name2: z.string().max(40).nullish().describe("Optional second name line (e.g., department or additional identifier). Max 40 characters."),
7+
Name3: z.string().max(40).nullish().describe("Optional third name line for extended address details. Max 40 characters."),
88
CountryCode: z.string().max(2).describe("Two-letter ISO country code (e.g., DE, US)."),
9-
Province: z.string().max(40).optional().describe("State, province, or region. Optional field. Max 40 characters."),
9+
Province: z.string().max(40).nullish().describe("State, province, or region. Optional field. Max 40 characters."),
1010
City: z.string().max(40).describe("City or locality name. Max 40 characters."),
1111
Street: z.string().min(4).describe("Street name. Minimum 4 characters required."),
12-
StreetNumber: z.string().max(40).optional().describe("House or building number. Optional field. Max 40 characters."),
13-
ContactPerson: z.string().max(40).min(6).optional().describe("Full name of a contact person. Optional field. Must be between 6 and 40 characters."),
14-
FixedLinePhonenumber: z.string().max(35).min(4).optional().describe("Landline phone number. Optional field. Must be between 4 and 35 characters."),
15-
MobilePhonenumber: z.string().max(35).min(4).optional().describe("Mobile phone number. Optional field. Must be between 4 and 35 characters."),
16-
eMail: z.string().max(80).optional().describe("Email address. Optional field. Max 80 characters."),
12+
StreetNumber: z.string().max(40).nullish().describe("House or building number. Optional field. Max 40 characters."),
13+
ContactPerson: z.string().max(40).min(6).nullish().describe("Full name of a contact person. Optional field. Must be between 6 and 40 characters."),
14+
FixedLinePhonenumber: z.string().max(35).min(4).nullish().describe("Landline phone number. Optional field. Must be between 4 and 35 characters."),
15+
MobilePhoneNumber: z.string().max(35).min(4).nullish().describe("Mobile phone number. Optional field. Must be between 4 and 35 characters."),
16+
eMail: z.string().max(80).nullish().describe("Email address. Optional field. Max 80 characters."),
1717
ZIPCode: z.string().max(10).describe("Postal or ZIP code. Max 10 characters."),
1818
});
1919
export type Address = z.infer<typeof AddressSchema>;

actions/gls-action/src/data_types/glsAllowedServices.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,10 @@ export type AllowedServicesRequestData = z.infer<typeof AllowedServicesRequestDa
1616

1717
export const AllowedServicesResponseDataSchema = z.object({
1818
AllowedServices: z.array(
19-
z.union([
20-
z.object({
21-
ServiceName: z.string(),
22-
}).strict(),
23-
z.object({
24-
ProductName: z.string(),
25-
}).strict(),
26-
])
19+
z.object({
20+
ServiceName: z.string().optional(),
21+
ProductName: z.string().optional(),
22+
})
2723
),
2824
});
2925
export type AllowedServicesResponseData = z.infer<typeof AllowedServicesResponseDataSchema>;

actions/gls-action/src/data_types/glsConsignee.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { z } from "zod";
33
import { AddressSchema } from "./glsAddress.js";
44

55
export const ConsigneeSchema = z.object({
6-
ConsigneeID: z.string().max(40).optional(),
7-
CostCenter: z.string().max(80).optional(),
8-
Category: z.enum(["BUSINESS", "PRIVATE"]).optional(),
6+
ConsigneeID: z.string().max(40).nullish(),
7+
CostCenter: z.string().max(80).nullish(),
8+
Category: z.enum(["BUSINESS", "PRIVATE"]).nullish(),
99
Address: AddressSchema,
1010
});
1111
export type Consignee = z.infer<typeof ConsigneeSchema>;

actions/gls-action/src/data_types/glsCustomContent.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { z } from "zod";
44
export const CustomContentSchema = z.object({
55
CustomerLogo: z.string(),
66
BarcodeContentType: z.enum(["TRACK_ID", "GLS_SHIPMENT_REFERENCE"]),
7-
Barcode: z.string().optional(),
8-
BarcodeType: z.enum(["EAN_128", "CODE_39"]).optional(),
9-
HideShipperAddress: z.boolean().optional(),
7+
Barcode: z.string().nullish(),
8+
BarcodeType: z.enum(["EAN_128", "CODE_39"]).nullish(),
9+
HideShipperAddress: z.boolean().nullish(),
1010
});
1111
export type CustomContent = z.infer<typeof CustomContentSchema>;
1212

actions/gls-action/src/data_types/glsPrintingOptions.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ export const ReturnLabelsSchema = z.object({
2727
export type ReturnLabels = z.infer<typeof ReturnLabelsSchema>;
2828

2929
export const PrintingOptionsSchema = z.object({
30-
ReturnLabels: ReturnLabelsSchema.optional(),
31-
useDefault: z.string().max(7).optional(),
30+
ReturnLabels: ReturnLabelsSchema.nullish(),
31+
UseDefault: z.string().max(7).nullish(),
3232
DefinePrinter: z.object({
33-
LabelPrinter: z.string().max(255).optional(),
34-
DocumentPrinter: z.string().max(255).optional(),
35-
}).optional(),
33+
LabelPrinter: z.string().max(255).nullish(),
34+
DocumentPrinter: z.string().max(255).nullish(),
35+
}).nullish(),
3636
});
3737
export type PrintingOptions = z.infer<typeof PrintingOptionsSchema>;
3838

actions/gls-action/src/data_types/glsReturnOptions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { DisplayMessage, Identifier, Name, Schema } from "@code0-tech/hercules";
22
import { z } from "zod";
33

44
export const ReturnOptionsSchema = z.object({
5-
ReturnPrintData: z.boolean().default(true).optional(),
6-
ReturnRoutingInfo: z.boolean().default(true).optional(),
5+
ReturnPrintData: z.boolean().default(true).nullish(),
6+
ReturnRoutingInfo: z.boolean().default(true).nullish(),
77
});
88
export type ReturnOptions = z.infer<typeof ReturnOptionsSchema>;
99

actions/gls-action/src/data_types/glsShipment.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,18 @@ import { InternalShipmentUnitSchema, ShipmentUnitSchema } from "./glsShipmentUni
77
import { InternalShipperSchema, ShipperSchema } from "./glsShipper.js";
88

99
export const ShipmentSchema = z.object({
10-
ShipmentReference: z.string().max(40).optional(),
11-
ShipmentDate: z.iso.date().optional(),
12-
IncotermCode: z.int().max(99).optional(),
13-
Identifier: z.string().max(40).optional(),
10+
ShipmentReference: z.string().max(40).nullish(),
11+
ShippingDate: z.iso.date().nullish(),
12+
IncotermCode: z.int().max(99).nullish(),
13+
Identifier: z.string().max(40).nullish(),
1414
Product: z.enum(["PARCEL", "EXPRESS"]).default("PARCEL"),
15-
ExpressAltDeliveryAllowed: z.boolean().optional(),
15+
ExpressAltDeliveryAllowed: z.boolean().nullish(),
1616
Consignee: ConsigneeSchema,
17-
Shipper: ShipperSchema.optional(),
18-
Carrier: z.enum(["ROYALMAIL"]).optional(),
17+
Shipper: ShipperSchema.nullish(),
18+
Carrier: z.enum(["ROYALMAIL"]).nullish(),
1919
ShipmentUnit: z.lazy(() => ShipmentUnitSchema),
2020
Service: z.lazy(() => ShipmentServiceSchema),
21-
Return: z.object({
22-
Address: AddressSchema,
23-
}).optional(),
21+
Return: AddressSchema.nullish(),
2422
});
2523
export type Shipment = z.infer<typeof ShipmentSchema>;
2624

@@ -32,6 +30,7 @@ export const InternalShipmentSchema = ShipmentSchema.extend({
3230
Shipper: InternalShipperSchema,
3331
Service: z.lazy(() => InternalShipmentServiceSchema),
3432
ShipmentUnit: z.lazy(() => InternalShipmentUnitSchema),
33+
Return: z.object({ Address: AddressSchema }).optional(),
3534
});
3635

3736
@Identifier("GLS_SHIPMENT")

actions/gls-action/src/data_types/glsShipmentService.ts

Lines changed: 52 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,27 @@ import { AddressSchema } from "./glsAddress.js";
44
export const ShipmentServiceSchema = z.array(
55
z.object({
66
Service: z.object({
7-
serviceName: z.string(),
7+
ServiceName: z.enum([
8+
"service_inbound",
9+
"service_documentreturn",
10+
"service_completedeliveryconsignment",
11+
"service_flexdelivery",
12+
"service_signature",
13+
"service_t24",
14+
"service_t48",
15+
"service_guaranteed24",
16+
"service_addresseeonly",
17+
"service_tyre",
18+
"service_eob",
19+
"service_0800",
20+
"service_0900",
21+
"service_1000",
22+
"service_1200",
23+
"service_1300",
24+
"service_saturday_1000",
25+
"service_saturday_1200",
26+
"service_Saturday",
27+
]),
828
}).optional(),
929
ShopDelivery: z.object({
1030
ParcelShopID: z.string().max(50),
@@ -49,56 +69,57 @@ export const ShipmentServiceSchema = z.array(
4969
PickAndReturn: z.object({
5070
PickupDate: z.iso.date(),
5171
}).optional(),
52-
InboundLogistics: z.object({}).optional(),
53-
DocumentReturnService: z.object({}).optional(),
54-
CompleteDeliveryConsignmentService: z.object({}).optional(),
55-
FlexDeliveryService: z.object({}).optional(),
56-
SignatureService: z.object({}).optional(),
57-
T24Service: z.object({}).optional(),
58-
T48Service: z.object({}).optional(),
59-
Guaranteed24Service: z.object({}).optional(),
60-
AddresseeOnlyService: z.object({}).optional(),
61-
TyreService: z.object({}).optional(),
62-
"0800Service": z.object({}).optional(),
63-
"0900Service": z.object({}).optional(),
64-
"1000Service": z.object({}).optional(),
65-
"1200Service": z.object({}).optional(),
66-
"1300Service": z.object({}).optional(),
67-
EOB: z.object({}).optional(),
68-
Saturday1000Service: z.object({}).optional(),
69-
Saturday1200Service: z.object({}).optional(),
70-
SaturdayService: z.object({}).optional(),
7172
})
7273
).optional();
7374
export type ShipmentService = z.infer<typeof ShipmentServiceSchema>;
7475

7576
export const InternalShipmentServiceSchema = z.array(
7677
z.object({
7778
Service: z.object({
78-
serviceName: z.string(),
79+
ServiceName: z.enum([
80+
"service_inbound",
81+
"service_documentreturn",
82+
"service_completedeliveryconsignment",
83+
"service_flexdelivery",
84+
"service_signature",
85+
"service_t24",
86+
"service_t48",
87+
"service_guaranteed24",
88+
"service_addresseeonly",
89+
"service_tyre",
90+
"service_eob",
91+
"service_0800",
92+
"service_0900",
93+
"service_1000",
94+
"service_1200",
95+
"service_1300",
96+
"service_saturday_1000",
97+
"service_saturday_1200",
98+
"service_Saturday",
99+
]),
79100
}).optional(),
80101
ShopDelivery: z.object({
81-
serviceName: z.string().default("service_shopdelivery"),
102+
ServiceName: z.string().default("service_shopdelivery"),
82103
ParcelShopID: z.string().max(50),
83104
}).optional(),
84105
ShopReturn: z.object({
85-
serviceName: z.string().default("service_shopreturn"),
106+
ServiceName: z.string().default("service_shopreturn"),
86107
NumberOfLabels: z.number(),
87108
ReturnQR: z.enum(["PDF", "PNG", "ZPL"]).optional(),
88109
}).optional(),
89110
Intercompany: z.object({
90-
serviceName: z.string().default("service_intercompany"),
111+
ServiceName: z.string().default("service_intercompany"),
91112
Address: AddressSchema,
92113
NumberOfLabels: z.number().min(1),
93114
ExpectedWeight: z.number().min(1).optional(),
94115
}).optional(),
95116
Exchange: z.object({
96-
serviceName: z.string().default("service_exchange"),
117+
ServiceName: z.string().default("service_exchange"),
97118
Address: AddressSchema,
98119
ExpectedWeight: z.number().min(1).optional(),
99120
}).optional(),
100121
DeliveryAtWork: z.object({
101-
serviceName: z.string().default("service_deliveryatwork"),
122+
ServiceName: z.string().default("service_deliveryatwork"),
102123
RecipientName: z.string().max(40),
103124
AlternateRecipientName: z.string().max(40).optional(),
104125
Building: z.string().max(40),
@@ -107,85 +128,28 @@ export const InternalShipmentServiceSchema = z.array(
107128
Phonenumber: z.string().max(35).optional(),
108129
}).optional(),
109130
Deposit: z.object({
110-
serviceName: z.string().default("service_deposit"),
131+
ServiceName: z.string().default("service_deposit"),
111132
PlaceOfDeposit: z.string().max(121),
112133
}).optional(),
113134
IdentPin: z.object({
114-
serviceName: z.string().default("service_identpin"),
135+
ServiceName: z.string().default("service_identpin"),
115136
PIN: z.string().max(4),
116137
Birthdate: z.iso.date().optional(),
117138
}).optional(),
118139
Ident: z.object({
119-
serviceName: z.string().default("service_ident"),
140+
ServiceName: z.string().default("service_ident"),
120141
Birthdate: z.iso.date(),
121142
Firstname: z.string().max(40),
122143
Lastname: z.string().max(40),
123144
Nationality: z.string().max(2),
124145
}).optional(),
125146
PickAndShip: z.object({
126-
serviceName: z.string().default("service_pickandship"),
147+
ServiceName: z.string().default("service_pickandship"),
127148
PickupDate: z.iso.date(),
128149
}).optional(),
129150
PickAndReturn: z.object({
130-
serviceName: z.string().default("service_pickandreturn"),
151+
ServiceName: z.string().default("service_pickandreturn"),
131152
PickupDate: z.iso.date(),
132153
}).optional(),
133-
InboundLogistics: z.object({
134-
serviceName: z.string().default("service_inbound"),
135-
}).optional(),
136-
DocumentReturnService: z.object({
137-
serviceName: z.string().default("service_documentreturn"),
138-
}).optional(),
139-
CompleteDeliveryConsignmentService: z.object({
140-
serviceName: z.string().default("service_completedeliveryconsignment"),
141-
}).optional(),
142-
FlexDeliveryService: z.object({
143-
serviceName: z.string().default("service_flexdelivery"),
144-
}).optional(),
145-
SignatureService: z.object({
146-
serviceName: z.string().default("service_signature"),
147-
}).optional(),
148-
T24Service: z.object({
149-
serviceName: z.string().default("service_t24"),
150-
}).optional(),
151-
T48Service: z.object({
152-
serviceName: z.string().default("service_t48"),
153-
}).optional(),
154-
Guaranteed24Service: z.object({
155-
serviceName: z.string().default("service_guaranteed24"),
156-
}).optional(),
157-
AddresseeOnlyService: z.object({
158-
serviceName: z.string().default("service_addresseeonly"),
159-
}).optional(),
160-
TyreService: z.object({
161-
serviceName: z.string().default("service_tyre"),
162-
}).optional(),
163-
EOB: z.object({
164-
serviceName: z.string().default("service_eob"),
165-
}).optional(),
166-
"0800Service": z.object({
167-
serviceName: z.string().default("service_0800"),
168-
}).optional(),
169-
"0900Service": z.object({
170-
serviceName: z.string().default("service_0900"),
171-
}).optional(),
172-
"1000Service": z.object({
173-
serviceName: z.string().default("service_1000"),
174-
}).optional(),
175-
"1200Service": z.object({
176-
serviceName: z.string().default("service_1200"),
177-
}).optional(),
178-
"1300Service": z.object({
179-
serviceName: z.string().default("service_1300"),
180-
}).optional(),
181-
Saturday1000Service: z.object({
182-
serviceName: z.string().default("service_saturday_1000"),
183-
}).optional(),
184-
Saturday1200Service: z.object({
185-
serviceName: z.string().default("service_saturday_1200"),
186-
}).optional(),
187-
SaturdayService: z.object({
188-
serviceName: z.string().default("service_Saturday"),
189-
}).optional(),
190154
})
191155
).optional();

actions/gls-action/src/data_types/glsShipper.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import { z } from "zod";
33
import { AddressSchema } from "./glsAddress.js";
44

55
export const ShipperSchema = z.object({
6-
AlternativeShipperAddress: AddressSchema.optional(),
7-
Address: AddressSchema.optional(),
6+
AlternativeShipperAddress: AddressSchema.nullish(),
7+
Address: AddressSchema.nullish(),
88
});
99
export type ShipperSchemaType = z.infer<typeof ShipperSchema>;
1010

1111
export const InternalShipperSchema = ShipperSchema.extend({
12-
ContactID: z.string().optional(),
12+
ContactID: z.string().nullish(),
1313
});
1414
export type InternalShipper = z.infer<typeof InternalShipperSchema>;
1515

actions/gls-action/src/data_types/shipmentRequest.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { CustomContentSchema } from "./glsCustomContent.js";
77
export const ShipmentRequestDataSchema = z.object({
88
Shipment: ShipmentSchema,
99
PrintingOptions: PrintingOptionsSchema,
10-
ReturnOptions: ReturnOptionsSchema.optional(),
11-
CustomContent: CustomContentSchema.optional(),
10+
ReturnOptions: ReturnOptionsSchema.nullish(),
11+
CustomContent: CustomContentSchema.nullish(),
1212
});
1313
export type ShipmentRequestData = z.infer<typeof ShipmentRequestDataSchema>;
1414

0 commit comments

Comments
 (0)