@bisondesk/website-commons-sdk 1.0.43 → 1.0.44
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/lib/types/events.d.ts +31 -5
- package/lib/types/events.d.ts.map +1 -1
- package/lib/types/events.js +17 -1
- package/lib/types/events.js.map +1 -1
- package/lib/types/leasing.d.ts +39 -0
- package/lib/types/leasing.d.ts.map +1 -0
- package/lib/types/leasing.js +12 -0
- package/lib/types/leasing.js.map +1 -0
- package/lib/types/user.d.ts +44 -34
- package/lib/types/user.d.ts.map +1 -1
- package/lib/types/user.js +24 -19
- package/lib/types/user.js.map +1 -1
- package/lib/types/vehicle.d.ts +1 -0
- package/lib/types/vehicle.d.ts.map +1 -1
- package/lib/types/vehicle.js.map +1 -1
- package/package.json +2 -1
- package/src/types/events.test.ts +107 -0
- package/src/types/events.ts +21 -15
- package/src/types/leasing.ts +30 -0
- package/src/types/user.ts +33 -27
- package/src/types/vehicle.ts +1 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {
|
|
2
|
+
WebsiteLeasingContract,
|
|
3
|
+
WebsiteLeasingContractStatus,
|
|
4
|
+
} from '@bisondesk/websites-sdk/types/contracts';
|
|
5
|
+
import { WebsiteFinanceDocument } from '@bisondesk/websites-sdk/types/documents';
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import { WebsiteVehicle } from './vehicle.js';
|
|
8
|
+
|
|
9
|
+
export type LeasingContractBFF = {
|
|
10
|
+
contract: WebsiteLeasingContract;
|
|
11
|
+
vehicle: WebsiteVehicle | undefined | WebsiteLeasingContract['vehicle'];
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const paginationSchema = z.object({
|
|
15
|
+
limit: z.number().int().nonnegative(),
|
|
16
|
+
offset: z.number().int().nonnegative().optional().default(0),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export const ListLeasingContractsQueryParams = paginationSchema.extend({
|
|
20
|
+
status: z.nativeEnum(WebsiteLeasingContractStatus).optional(),
|
|
21
|
+
overdue: z.boolean().optional(),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export type ListLeasingContractsQueryParams = z.input<typeof ListLeasingContractsQueryParams>;
|
|
25
|
+
|
|
26
|
+
export type { WebsiteFinanceDocument };
|
|
27
|
+
|
|
28
|
+
export const ListFinanceDocumentsQueryParams = paginationSchema;
|
|
29
|
+
|
|
30
|
+
export type ListFinanceDocumentsQueryParams = z.input<typeof ListFinanceDocumentsQueryParams>;
|
package/src/types/user.ts
CHANGED
|
@@ -11,7 +11,10 @@ export enum FleetSize {
|
|
|
11
11
|
Large = '6+',
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
export const VatSchema = z
|
|
14
|
+
export const VatSchema = z
|
|
15
|
+
.string()
|
|
16
|
+
.toUpperCase()
|
|
17
|
+
.transform((v) => v || undefined);
|
|
15
18
|
|
|
16
19
|
/**
|
|
17
20
|
* Light VAT-number validation patterns by country.
|
|
@@ -83,6 +86,34 @@ const getVatPrefix = (country: string): string => {
|
|
|
83
86
|
return match ? match[1] : '';
|
|
84
87
|
};
|
|
85
88
|
|
|
89
|
+
export const CompanySchema = z.object({
|
|
90
|
+
country: z.string().optional(),
|
|
91
|
+
city: z.string().optional(),
|
|
92
|
+
name: z.string().optional(),
|
|
93
|
+
vat: VatSchema.optional(),
|
|
94
|
+
postalCode: z.string().optional(),
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
/* TODO when updating to zod v4, change addIssue options to
|
|
98
|
+
message: 'vat.invalidFormat',
|
|
99
|
+
path: ['vat'],
|
|
100
|
+
*/
|
|
101
|
+
export function refineCompanySchema(schema: z.ZodRawShape) {
|
|
102
|
+
return CompanySchema.extend(schema).superRefine((data, ctx) => {
|
|
103
|
+
if (!data.vat || !data.country) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (!isValidVatForCountry({ vat: data.vat, country: data.country })) {
|
|
107
|
+
const prefix = getVatPrefix(data.country);
|
|
108
|
+
ctx.addIssue({
|
|
109
|
+
code: z.ZodIssueCode.custom,
|
|
110
|
+
path: ['vat'],
|
|
111
|
+
params: { prefix, messageKey: 'vat.invalidFormat' },
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
86
117
|
export const UserDetails = z.object({
|
|
87
118
|
firstName: z.string().optional(),
|
|
88
119
|
lastName: z.string().optional(),
|
|
@@ -91,32 +122,7 @@ export const UserDetails = z.object({
|
|
|
91
122
|
fleetSize: z.nativeEnum(FleetSize).optional(),
|
|
92
123
|
trader: z.boolean().optional(),
|
|
93
124
|
email: z.string().email().toLowerCase(),
|
|
94
|
-
company:
|
|
95
|
-
.object({
|
|
96
|
-
country: z.string().optional(),
|
|
97
|
-
city: z.string().optional(),
|
|
98
|
-
name: z.string().optional(),
|
|
99
|
-
vat: VatSchema.optional(),
|
|
100
|
-
postalCode: z.string().optional(),
|
|
101
|
-
})
|
|
102
|
-
/* TODO when updating to zod v4, change addIssue options to
|
|
103
|
-
message: 'vat.invalidFormat',
|
|
104
|
-
path: ['vat'],
|
|
105
|
-
*/
|
|
106
|
-
.superRefine((data, ctx) => {
|
|
107
|
-
if (!data.vat || !data.country) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
if (!isValidVatForCountry({ vat: data.vat, country: data.country })) {
|
|
111
|
-
const prefix = getVatPrefix(data.country);
|
|
112
|
-
|
|
113
|
-
ctx.addIssue({
|
|
114
|
-
code: z.ZodIssueCode.custom,
|
|
115
|
-
path: ['vat'],
|
|
116
|
-
params: { prefix, messageKey: 'vat.invalidFormat' },
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
}),
|
|
125
|
+
company: refineCompanySchema({}),
|
|
120
126
|
marketingChannels: z.array(z.nativeEnum(MarketingChannel)),
|
|
121
127
|
});
|
|
122
128
|
|