@lifeaz/lors-helper 1.0.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/src/main.ts ADDED
@@ -0,0 +1,443 @@
1
+ import { z } from "zod";
2
+ import type { Dayjs } from "dayjs";
3
+ import type { UUID } from "uuidv7";
4
+
5
+ const uuidSchema = z.custom<UUID>((v) => typeof v === "string" && /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(v));
6
+ const dayjsSchema = z.custom<Dayjs>((v) => v != null && typeof (v as { isValid?: () => boolean }).isValid === "function");
7
+
8
+ export type Lang = 'fr' | 'en' | 'nl' | 'de' | 'it' | 'es';
9
+ export const LangSchema = z.union([z.literal('fr'), z.literal('en'), z.literal('nl'), z.literal('de'), z.literal('it'), z.literal('es')]);
10
+
11
+ export type ProfileType = '_Individual_' | '_Small_Business_' | '_Company_';
12
+ export const ProfileTypeSchema = z.union([z.literal('_Individual_'), z.literal('_Small_Business_'), z.literal('_Company_')]);
13
+
14
+ export type CartStep = '_Profile_' | '_Offers_' | '_Information_' | '_Options_' | '_Delivery_' | '_Payment_';
15
+ export const CartStepSchema = z.union([z.literal('_Profile_'), z.literal('_Offers_'), z.literal('_Information_'), z.literal('_Options_'), z.literal('_Delivery_'), z.literal('_Payment_')]);
16
+
17
+ export type CartStatus = '_Draft_' | '_Pending_' | '_Paid_' | '_Abandoned_' | '_Cancelled_';
18
+ export const CartStatusSchema = z.union([z.literal('_Draft_'), z.literal('_Pending_'), z.literal('_Paid_'), z.literal('_Abandoned_'), z.literal('_Cancelled_')]);
19
+
20
+ export type OrderStatus = '_Pending_' | '_Paid_' | '_In_Production_' | '_In_Delivery_' | '_Delivered_' | '_Cancelled_' | '_Refunded_';
21
+ export const OrderStatusSchema = z.union([z.literal('_Pending_'), z.literal('_Paid_'), z.literal('_In_Production_'), z.literal('_In_Delivery_'), z.literal('_Delivered_'), z.literal('_Cancelled_'), z.literal('_Refunded_')]);
22
+
23
+ export type PaymentStatus = '_Open_' | '_Pending_' | '_Authorized_' | '_Paid_' | '_Failed_' | '_Cancelled_' | '_Expired_' | '_Refunded_' | '_Chargeback_';
24
+ export const PaymentStatusSchema = z.union([z.literal('_Open_'), z.literal('_Pending_'), z.literal('_Authorized_'), z.literal('_Paid_'), z.literal('_Failed_'), z.literal('_Cancelled_'), z.literal('_Expired_'), z.literal('_Refunded_'), z.literal('_Chargeback_')]);
25
+
26
+ export type ItemCategory = '_Solution_' | '_Warranty_' | '_Accessory_' | '_Training_' | '_Delivery_';
27
+ export const ItemCategorySchema = z.union([z.literal('_Solution_'), z.literal('_Warranty_'), z.literal('_Accessory_'), z.literal('_Training_'), z.literal('_Delivery_')]);
28
+
29
+ export type OfferType = '_Purchase_' | '_Rental_';
30
+ export const OfferTypeSchema = z.union([z.literal('_Purchase_'), z.literal('_Rental_')]);
31
+
32
+ export type PriceRecurrence = '_One_Time_' | '_Monthly_' | '_Annually_';
33
+ export const PriceRecurrenceSchema = z.union([z.literal('_One_Time_'), z.literal('_Monthly_'), z.literal('_Annually_')]);
34
+
35
+ export type PaymentFrequency = '_Monthly_' | '_Annually_';
36
+ export const PaymentFrequencySchema = z.union([z.literal('_Monthly_'), z.literal('_Annually_')]);
37
+
38
+ export type PaymentMethod = '_Card_' | '_PayPal_' | '_SEPA_' | '_Alma_4x_';
39
+ export const PaymentMethodSchema = z.union([z.literal('_Card_'), z.literal('_PayPal_'), z.literal('_SEPA_'), z.literal('_Alma_4x_')]);
40
+
41
+ export type PaymentProvider = '_Mollie_' | '_Alma_';
42
+ export const PaymentProviderSchema = z.union([z.literal('_Mollie_'), z.literal('_Alma_')]);
43
+
44
+ export type DeliveryMethod = '_Standard_' | '_Express_';
45
+ export const DeliveryMethodSchema = z.union([z.literal('_Standard_'), z.literal('_Express_')]);
46
+
47
+ export type DiscountValueType = '_Percentage_' | '_Fixed_Amount_';
48
+ export const DiscountValueTypeSchema = z.union([z.literal('_Percentage_'), z.literal('_Fixed_Amount_')]);
49
+
50
+ export type DiscountTargetScope = '_Whole_Cart_' | '_Specific_Items_' | '_Item_Category_' | '_Delivery_';
51
+ export const DiscountTargetScopeSchema = z.union([z.literal('_Whole_Cart_'), z.literal('_Specific_Items_'), z.literal('_Item_Category_'), z.literal('_Delivery_')]);
52
+
53
+ export type Surface = '_All_' | '_Checkout_' | '_Storefront_';
54
+ export const SurfaceSchema = z.union([z.literal('_All_'), z.literal('_Checkout_'), z.literal('_Storefront_')]);
55
+
56
+ export type OperationAssetType = '_Banner_Header_' | '_Banner_Mini_' | '_Banner_Sub_Header_' | '_Hero_' | '_Popup_Welcome_' | '_Popup_Operation_' | '_Popup_Technical_' | '_Strikethrough_Price_' | '_Discount_Section_' | '_Tag_' | '_Text_Banner_' | '_Page_Background_';
57
+ export const OperationAssetTypeSchema = z.union([z.literal('_Banner_Header_'), z.literal('_Banner_Mini_'), z.literal('_Banner_Sub_Header_'), z.literal('_Hero_'), z.literal('_Popup_Welcome_'), z.literal('_Popup_Operation_'), z.literal('_Popup_Technical_'), z.literal('_Strikethrough_Price_'), z.literal('_Discount_Section_'), z.literal('_Tag_'), z.literal('_Text_Banner_'), z.literal('_Page_Background_')]);
58
+
59
+ export type AddressType = '_Delivery_' | '_Billing_';
60
+ export const AddressTypeSchema = z.union([z.literal('_Delivery_'), z.literal('_Billing_')]);
61
+
62
+ export type AddressConfidence = '_Verified_' | '_Partial_';
63
+ export const AddressConfidenceSchema = z.union([z.literal('_Verified_'), z.literal('_Partial_')]);
64
+
65
+ export type TermsType = '_Terms_Of_Use_' | '_Terms_Of_Sales_';
66
+ export const TermsTypeSchema = z.union([z.literal('_Terms_Of_Use_'), z.literal('_Terms_Of_Sales_')]);
67
+
68
+ export type TestimonialType = '_Text_' | '_Image_' | '_Video_';
69
+ export const TestimonialTypeSchema = z.union([z.literal('_Text_'), z.literal('_Image_'), z.literal('_Video_')]);
70
+
71
+ export type CartItemSource = '_User_' | '_System_';
72
+ export const CartItemSourceSchema = z.union([z.literal('_User_'), z.literal('_System_')]);
73
+
74
+ export const AmountSchema = z.object({
75
+ excl: z.number(),
76
+ vat: z.number(),
77
+ incl: z.number(),
78
+ });
79
+ export type Amount = z.infer<typeof AmountSchema>;
80
+
81
+ export const GeozoneSchema = z.object({
82
+ id: uuidSchema,
83
+ name: z.string(),
84
+ });
85
+ export type Geozone = z.infer<typeof GeozoneSchema>;
86
+
87
+ export const CountrySchema = z.object({
88
+ id: uuidSchema,
89
+ geozone: GeozoneSchema,
90
+ iso: z.string(),
91
+ phonePrefix: z.string(),
92
+ name: z.string(),
93
+ });
94
+ export type Country = z.infer<typeof CountrySchema>;
95
+
96
+ export const StateSchema = z.object({
97
+ id: uuidSchema,
98
+ country: CountrySchema,
99
+ name: z.string(),
100
+ iso: z.string(),
101
+ });
102
+ export type State = z.infer<typeof StateSchema>;
103
+
104
+ export const CoordinatesSchema = z.object({
105
+ lat: z.number(),
106
+ lng: z.number(),
107
+ });
108
+ export type Coordinates = z.infer<typeof CoordinatesSchema>;
109
+
110
+ export const AddressSchema = z.object({
111
+ id: uuidSchema,
112
+ stringified: z.string(),
113
+ confidence: AddressConfidenceSchema,
114
+ country: CountrySchema.nullable(),
115
+ state: StateSchema.nullable(),
116
+ alias: z.string().nullable(),
117
+ line: z.string(),
118
+ details: z.string().nullable(),
119
+ postcode: z.string().nullable(),
120
+ city: z.string().nullable(),
121
+ placeId: z.string().nullable(),
122
+ coordinates: CoordinatesSchema.nullable(),
123
+ });
124
+ export type Address = z.infer<typeof AddressSchema>;
125
+
126
+ export const ContactSchema = z.object({
127
+ id: uuidSchema,
128
+ firstName: z.string(),
129
+ lastName: z.string(),
130
+ email: z.string().nullable(),
131
+ phone: z.string().nullable(),
132
+ company: z.string().nullable(),
133
+ vatNumber: z.string().nullable(),
134
+ });
135
+ export type Contact = z.infer<typeof ContactSchema>;
136
+
137
+ export const TermsSchema = z.object({
138
+ id: uuidSchema,
139
+ type: TermsTypeSchema,
140
+ lang: LangSchema,
141
+ label: z.string(),
142
+ url: z.string(),
143
+ version: dayjsSchema,
144
+ });
145
+ export type Terms = z.infer<typeof TermsSchema>;
146
+
147
+ export const CartTermsAcceptanceSchema = z.object({
148
+ id: uuidSchema,
149
+ termsId: uuidSchema,
150
+ acceptedAt: dayjsSchema,
151
+ });
152
+ export type CartTermsAcceptance = z.infer<typeof CartTermsAcceptanceSchema>;
153
+
154
+ export const CartTermsViewSchema = z.object({
155
+ current: z.array(TermsSchema),
156
+ required: z.array(TermsTypeSchema),
157
+ accepted: z.array(CartTermsAcceptanceSchema),
158
+ });
159
+ export type CartTermsView = z.infer<typeof CartTermsViewSchema>;
160
+
161
+ export const ItemPriceSchema = z.object({
162
+ recurrence: PriceRecurrenceSchema,
163
+ amount: z.number(),
164
+ currency: z.string(),
165
+ });
166
+ export type ItemPrice = z.infer<typeof ItemPriceSchema>;
167
+
168
+ export const ItemSchema = z.object({
169
+ id: uuidSchema,
170
+ category: ItemCategorySchema,
171
+ offerType: OfferTypeSchema.nullable(),
172
+ sku: z.string().nullable(),
173
+ name: z.string().nullable(),
174
+ description: z.string().nullable(),
175
+ isMainOffer: z.boolean(),
176
+ visible: z.boolean(),
177
+ maxPerCart: z.number().int().positive().nullable(),
178
+ prices: z.array(ItemPriceSchema),
179
+ allowedProfiles: z.array(ProfileTypeSchema),
180
+ });
181
+ export type Item = z.infer<typeof ItemSchema>;
182
+
183
+ export const CartItemSchema = z.object({
184
+ id: uuidSchema,
185
+ cartId: uuidSchema,
186
+ itemId: uuidSchema,
187
+ quantity: z.number().int().positive(),
188
+ addedBy: CartItemSourceSchema,
189
+ category: ItemCategorySchema,
190
+ offerType: OfferTypeSchema.nullable(),
191
+ sku: z.string().nullable(),
192
+ isMainOffer: z.boolean(),
193
+ visible: z.boolean(),
194
+ maxPerCart: z.number().int().positive().nullable(),
195
+ });
196
+ export type CartItem = z.infer<typeof CartItemSchema>;
197
+
198
+ export const PricingContextSchema = z.object({
199
+ cartId: uuidSchema,
200
+ profile: ProfileTypeSchema.nullable(),
201
+ offerType: OfferTypeSchema.nullable(),
202
+ countryIso: z.string(),
203
+ });
204
+ export type PricingContext = z.infer<typeof PricingContextSchema>;
205
+
206
+ export const PricingLineSchema = z.object({
207
+ cartItemId: uuidSchema,
208
+ itemId: uuidSchema,
209
+ quantity: z.number().int().positive(),
210
+ category: ItemCategorySchema,
211
+ sku: z.string().nullable(),
212
+ name: z.string().nullable(),
213
+ recurrence: PriceRecurrenceSchema,
214
+ currency: z.string(),
215
+ unit: AmountSchema,
216
+ line: AmountSchema,
217
+ vatRate: z.number(),
218
+ countryIso: z.string(),
219
+ matchKind: z.string().nullable(),
220
+ });
221
+ export type PricingLine = z.infer<typeof PricingLineSchema>;
222
+
223
+ export const PricingRecurrenceTotalSchema = z.object({
224
+ recurrence: PriceRecurrenceSchema,
225
+ currency: z.string(),
226
+ gross: AmountSchema,
227
+ discount: AmountSchema,
228
+ net: AmountSchema,
229
+ countryIso: z.string(),
230
+ });
231
+ export type PricingRecurrenceTotal = z.infer<typeof PricingRecurrenceTotalSchema>;
232
+
233
+ export const AppliedDiscountBucketSchema = z.object({
234
+ excl: z.number(),
235
+ vat: z.number(),
236
+ incl: z.number(),
237
+ });
238
+ export type AppliedDiscountBucket = z.infer<typeof AppliedDiscountBucketSchema>;
239
+
240
+ export const AppliedDiscountSchema = z.object({
241
+ cartDiscountId: uuidSchema,
242
+ discountId: uuidSchema,
243
+ code: z.string(),
244
+ label: z.string().nullable(),
245
+ targetScope: DiscountTargetScopeSchema,
246
+ valueType: DiscountValueTypeSchema,
247
+ appliesToOneTime: z.boolean(),
248
+ appliesToRecurring: z.boolean(),
249
+ stackable: z.boolean(),
250
+ value: z.number().nullable(),
251
+ byRecurrence: z.record(z.string(), AppliedDiscountBucketSchema),
252
+ });
253
+ export type AppliedDiscount = z.infer<typeof AppliedDiscountSchema>;
254
+
255
+ export const CartTotalSchema = z.object({
256
+ currency: z.string(),
257
+ oneTime: z.object({
258
+ excl: z.number(),
259
+ incl: z.number(),
260
+ }),
261
+ recurring: z.object({
262
+ excl: z.number(),
263
+ incl: z.number(),
264
+ frequency: PaymentFrequencySchema.nullable(),
265
+ }),
266
+ });
267
+ export type CartTotal = z.infer<typeof CartTotalSchema>;
268
+
269
+ export const CartPricingSchema = z.object({
270
+ context: PricingContextSchema,
271
+ lines: z.array(PricingLineSchema),
272
+ totalsByRecurrence: z.record(z.string(), PricingRecurrenceTotalSchema),
273
+ appliedDiscounts: z.array(AppliedDiscountSchema),
274
+ total: CartTotalSchema,
275
+ });
276
+ export type CartPricing = z.infer<typeof CartPricingSchema>;
277
+
278
+ export const CartSchema = z.object({
279
+ id: uuidSchema,
280
+ reference: z.string(),
281
+ secret: z.string(),
282
+ status: CartStatusSchema,
283
+ currentStep: CartStepSchema,
284
+ maxReachedStep: CartStepSchema,
285
+ profile: ProfileTypeSchema.nullable(),
286
+ offerType: OfferTypeSchema.nullable(),
287
+ paymentMethod: PaymentMethodSchema.nullable(),
288
+ paymentFrequency: PaymentFrequencySchema.nullable(),
289
+ deliveryMethod: DeliveryMethodSchema.nullable(),
290
+ devices: z.number().int().nonnegative(),
291
+ locale: LangSchema,
292
+ vatNumber: z.string().nullable(),
293
+ multiAddressesCallback: z.boolean(),
294
+ createdAt: dayjsSchema,
295
+ updatedAt: dayjsSchema,
296
+ });
297
+ export type Cart = z.infer<typeof CartSchema>;
298
+
299
+ export const OrderSchema = z.object({
300
+ id: uuidSchema,
301
+ reference: z.string(),
302
+ secret: z.string(),
303
+ status: OrderStatusSchema,
304
+ cartId: uuidSchema,
305
+ profile: ProfileTypeSchema,
306
+ offerType: OfferTypeSchema,
307
+ paymentFrequency: PaymentFrequencySchema.nullable(),
308
+ deliveryMethod: DeliveryMethodSchema,
309
+ currency: z.string(),
310
+ oneTime: AmountSchema,
311
+ recurring: AmountSchema,
312
+ createdAt: dayjsSchema,
313
+ updatedAt: dayjsSchema,
314
+ });
315
+ export type Order = z.infer<typeof OrderSchema>;
316
+
317
+ export const OperationSummarySchema = z.object({
318
+ id: uuidSchema,
319
+ slug: z.string(),
320
+ name: z.string(),
321
+ description: z.string().nullable(),
322
+ startsAt: dayjsSchema,
323
+ endsAt: dayjsSchema,
324
+ priority: z.number().int(),
325
+ autoApplyDiscount: z.boolean(),
326
+ discountId: uuidSchema.nullable(),
327
+ discountCode: z.string().nullable(),
328
+ discountLabel: z.string().nullable(),
329
+ discountValueType: DiscountValueTypeSchema.nullable(),
330
+ discountValue: z.number().nullable(),
331
+ });
332
+ export type OperationSummary = z.infer<typeof OperationSummarySchema>;
333
+
334
+ export const OperationAssetSchema = z.object({
335
+ id: uuidSchema,
336
+ operationId: uuidSchema,
337
+ type: OperationAssetTypeSchema,
338
+ surface: SurfaceSchema,
339
+ lang: LangSchema.nullable(),
340
+ order: z.number().int(),
341
+ pageUrlPattern: z.string().nullable(),
342
+ content: z.unknown(),
343
+ styles: z.unknown().nullable(),
344
+ createdAt: dayjsSchema,
345
+ updatedAt: dayjsSchema,
346
+ });
347
+ export type OperationAsset = z.infer<typeof OperationAssetSchema>;
348
+
349
+ export const OperationItemPricingSchema = z.object({
350
+ id: uuidSchema,
351
+ operationId: uuidSchema,
352
+ itemId: uuidSchema,
353
+ profile: ProfileTypeSchema,
354
+ recurrence: PriceRecurrenceSchema,
355
+ originalExclVat: z.number(),
356
+ discountedExclVat: z.number(),
357
+ currency: z.string(),
358
+ sku: z.string().nullable(),
359
+ });
360
+ export type OperationItemPricing = z.infer<typeof OperationItemPricingSchema>;
361
+
362
+ export const OperationDetailSchema = OperationSummarySchema.extend({
363
+ assets: z.array(OperationAssetSchema),
364
+ itemsPricing: z.array(OperationItemPricingSchema),
365
+ });
366
+ export type OperationDetail = z.infer<typeof OperationDetailSchema>;
367
+
368
+ export const TestimonialSchema = z.object({
369
+ id: uuidSchema,
370
+ lang: LangSchema,
371
+ type: TestimonialTypeSchema,
372
+ author: z.string(),
373
+ content: z.string().nullable(),
374
+ altText: z.string().nullable(),
375
+ imageUrl: z.string().nullable(),
376
+ videoUrl: z.string().nullable(),
377
+ rating: z.number().int().min(1).max(5).nullable(),
378
+ publishedAt: dayjsSchema,
379
+ order: z.number().int(),
380
+ });
381
+ export type Testimonial = z.infer<typeof TestimonialSchema>;
382
+
383
+ export const TestimonialCategorySchema = z.object({
384
+ id: uuidSchema,
385
+ lang: LangSchema,
386
+ name: z.string(),
387
+ order: z.number().int(),
388
+ });
389
+ export type TestimonialCategory = z.infer<typeof TestimonialCategorySchema>;
390
+
391
+ export const HelpArticleSchema = z.object({
392
+ id: uuidSchema,
393
+ title: z.string(),
394
+ body: z.string(),
395
+ order: z.number().int(),
396
+ });
397
+ export type HelpArticle = z.infer<typeof HelpArticleSchema>;
398
+
399
+ export type HelpCategory = {
400
+ id: UUID;
401
+ parentId: UUID | null;
402
+ lang: Lang;
403
+ name: string;
404
+ description: string | null;
405
+ logoUrl: string | null;
406
+ order: number;
407
+ articles: HelpArticle[];
408
+ subCategories: HelpCategory[];
409
+ };
410
+
411
+ export const HelpCategorySchema: z.ZodType<HelpCategory> = z.object({
412
+ id: uuidSchema,
413
+ parentId: uuidSchema.nullable(),
414
+ lang: LangSchema,
415
+ name: z.string(),
416
+ description: z.string().nullable(),
417
+ logoUrl: z.string().nullable(),
418
+ order: z.number().int(),
419
+ articles: z.array(HelpArticleSchema),
420
+ subCategories: z.array(z.lazy(() => HelpCategorySchema)),
421
+ });
422
+
423
+ export const HelpPageSchema = z.object({
424
+ id: uuidSchema,
425
+ slug: z.string(),
426
+ name: z.string(),
427
+ createdAt: dayjsSchema,
428
+ });
429
+ export type HelpPage = z.infer<typeof HelpPageSchema>;
430
+
431
+ export const ContactRequestInputSchema = z.object({
432
+ firstName: z.string().min(1),
433
+ lastName: z.string().min(1),
434
+ email: z.string().email(),
435
+ phone: z.string().min(1),
436
+ company: z.string().nullable().optional(),
437
+ devices: z.number().int().nonnegative().optional(),
438
+ content: z.string().min(1).max(5000),
439
+ captchaToken: z.string().min(1),
440
+ profile: ProfileTypeSchema.optional(),
441
+ locale: LangSchema.optional(),
442
+ });
443
+ export type ContactRequestInput = z.infer<typeof ContactRequestInputSchema>;