@revolugo/common 7.10.0 → 7.11.0-rc.1
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/package.json +3 -3
- package/src/currencies/stripe.ts +0 -1
- package/src/icons/index.ts +1 -0
- package/src/schemas/booking-policy.ts +4 -0
- package/src/schemas/booking.ts +1 -1
- package/src/schemas/extend-zod.ts +9 -0
- package/src/schemas/hotel-offer.ts +2 -1
- package/src/schemas/hotel-room-offer.ts +1 -1
- package/src/schemas/hotel-room.ts +5 -1
- package/src/schemas/hotel.ts +1 -3
- package/src/schemas/index.ts +4 -0
- package/src/schemas/order-addon.ts +20 -0
- package/src/schemas/payment-methods.ts +64 -48
- package/src/types/addon.ts +1 -1
- package/src/types/elements/booking.ts +7 -0
- package/src/types/elements/elements-events.ts +2 -0
- package/src/types/elements/hotel-room-offer.ts +1 -1
- package/src/types/elements/hotel.ts +1 -1
- package/src/types/elements/order-addon.ts +10 -0
- package/src/utils/case-transformers.ts +4 -0
- package/src/utils/dates.ts +13 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@revolugo/common",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.11.0-rc.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Revolugo common",
|
|
6
6
|
"author": "Revolugo",
|
|
@@ -30,10 +30,10 @@
|
|
|
30
30
|
"slugify": "1.6.9",
|
|
31
31
|
"type-fest": "5.6.0",
|
|
32
32
|
"uuid": "14.0.0",
|
|
33
|
-
"zod": "4.3
|
|
33
|
+
"zod": "4.4.3"
|
|
34
34
|
},
|
|
35
35
|
"engines": {
|
|
36
|
-
"node": ">=
|
|
36
|
+
"node": ">=24.15.0 <25"
|
|
37
37
|
},
|
|
38
38
|
"volta": {
|
|
39
39
|
"extends": "../../package.json"
|
package/src/currencies/stripe.ts
CHANGED
package/src/icons/index.ts
CHANGED
|
@@ -13,9 +13,13 @@ import {
|
|
|
13
13
|
IS_PRICE_INCREASED,
|
|
14
14
|
} from './global.ts'
|
|
15
15
|
import { HOTEL_ROOM_OFFER_SCHEMA } from './hotel-room-offer.ts'
|
|
16
|
+
import { ADDON_SCHEMA } from './order-addon.ts'
|
|
16
17
|
|
|
17
18
|
export const BOOKING_POLICY_SCHEMA = z
|
|
18
19
|
.object({
|
|
20
|
+
addons: z.array(ADDON_SCHEMA).optional().openapi({
|
|
21
|
+
description: 'Available add-ons (e.g. insurance)',
|
|
22
|
+
}),
|
|
19
23
|
adult_count: ADULT_COUNT_SCHEMA,
|
|
20
24
|
cancellation_policies: z.array(CANCELLATION_POLICY_SCHEMA).openapi({
|
|
21
25
|
description:
|
package/src/schemas/booking.ts
CHANGED
|
@@ -36,7 +36,7 @@ export const FILTER_BOOKING_STATUS_SCHEMA = z
|
|
|
36
36
|
|
|
37
37
|
export const BOOKING_METADATA_SCHEMA = z
|
|
38
38
|
.record(z.string(), z.string())
|
|
39
|
-
.openapi(
|
|
39
|
+
.openapi({
|
|
40
40
|
description:
|
|
41
41
|
"You can use this parameter to attach key-value data to bookings. Metadata is useful for storing additional, structured information on a booking. As an example, you could store your user's full name and corresponding unique identifier from your system on a booking. Metadata is not used internally by the Booking Engine and won't be seen by your users unless you choose to show it to them.",
|
|
42
42
|
})
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { extendZodWithOpenApi } from '@asteasolutions/zod-to-openapi'
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
|
|
4
|
+
// Schemas in this package use `.openapi()` to attach OpenAPI metadata. The
|
|
5
|
+
// method is added to Zod's prototype via this side effect so consumers don't
|
|
6
|
+
// need to depend on `@hono/zod-openapi` (or remember to call this themselves).
|
|
7
|
+
// Imported as a side effect before any schema module so the prototype is
|
|
8
|
+
// patched before any `.openapi()` call evaluates.
|
|
9
|
+
extendZodWithOpenApi(z)
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { z } from 'zod'
|
|
3
3
|
|
|
4
4
|
import { CURRENCY_SCHEMA } from './currency.ts'
|
|
5
|
+
import { EVENT_SCHEMA } from './event.ts'
|
|
5
6
|
import {
|
|
6
7
|
ADULT_COUNT_SCHEMA,
|
|
7
8
|
CHECK_IN_DATE_SCHEMA,
|
|
@@ -57,7 +58,7 @@ export const HOTEL_OFFERS_RESPONSE_SCHEMA = z
|
|
|
57
58
|
description: 'Minimum price of available returned **Hotel Offers**',
|
|
58
59
|
}),
|
|
59
60
|
}),
|
|
60
|
-
event:
|
|
61
|
+
event: EVENT_SCHEMA.optional().openapi({
|
|
61
62
|
description:
|
|
62
63
|
'Event associated with the Hotel Offers response, when applicable.',
|
|
63
64
|
}),
|
|
@@ -62,7 +62,7 @@ export const HOTEL_ROOM_OFFER_SCHEMA = z
|
|
|
62
62
|
.openapi({
|
|
63
63
|
description: PACKAGE_TYPES_DESCRIPTION,
|
|
64
64
|
})
|
|
65
|
-
.
|
|
65
|
+
.optional(),
|
|
66
66
|
price: z.number().openapi({
|
|
67
67
|
description:
|
|
68
68
|
'Price with taxes NOT INCLUDED of the given **Hotel Room Offer** including breakfast(s) when applicable, expressed in the requested **currency**.',
|
|
@@ -13,8 +13,12 @@ export const BED_SCHEMA = z
|
|
|
13
13
|
})
|
|
14
14
|
.openapi('bedApi')
|
|
15
15
|
|
|
16
|
+
export const BED_COMBINATION_SCHEMA = z
|
|
17
|
+
.array(BED_SCHEMA)
|
|
18
|
+
.openapi('bedCombinationApi')
|
|
19
|
+
|
|
16
20
|
export const BEDS_SCHEMA = z
|
|
17
|
-
.array(
|
|
21
|
+
.array(BED_COMBINATION_SCHEMA)
|
|
18
22
|
.openapi({
|
|
19
23
|
description: `Beds list.
|
|
20
24
|
Each nested array of beds represents a single combination of possible beds.
|
package/src/schemas/hotel.ts
CHANGED
|
@@ -277,9 +277,7 @@ export const HOTEL_SCHEMA = z
|
|
|
277
277
|
)
|
|
278
278
|
.openapi({ description: 'Hotel country code in ISO2.' })
|
|
279
279
|
.nullish(),
|
|
280
|
-
currency: CURRENCY_SCHEMA.
|
|
281
|
-
description: 'Hotel currency.',
|
|
282
|
-
}).nullish(),
|
|
280
|
+
currency: CURRENCY_SCHEMA.optional(),
|
|
283
281
|
description: z
|
|
284
282
|
.string()
|
|
285
283
|
.openapi({ description: 'Hotel description.' })
|
package/src/schemas/index.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// oxlint-disable-next-line import/no-unassigned-import
|
|
2
|
+
import './extend-zod.ts'
|
|
3
|
+
|
|
1
4
|
export * from './booking-policy.ts'
|
|
2
5
|
export * from './booking.ts'
|
|
3
6
|
export * from './breakfast.ts'
|
|
@@ -10,6 +13,7 @@ export * from './hotel-room-offer.ts'
|
|
|
10
13
|
export * from './hotel-room.ts'
|
|
11
14
|
export * from './hotel.ts'
|
|
12
15
|
export * from './list-polling-meta.ts'
|
|
16
|
+
export * from './order-addon.ts'
|
|
13
17
|
export * from './payment-methods.ts'
|
|
14
18
|
export * from './tag.ts'
|
|
15
19
|
export * from './taxes.ts'
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/* eslint-disable camelcase */
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
|
|
4
|
+
import { AddonTypeEnum } from '../types/addon.ts'
|
|
5
|
+
|
|
6
|
+
export const ADDON_SCHEMA = z
|
|
7
|
+
.object({
|
|
8
|
+
price: z.number(),
|
|
9
|
+
tax_included_price: z.number(),
|
|
10
|
+
type: z.enum(AddonTypeEnum),
|
|
11
|
+
})
|
|
12
|
+
.openapi('OrderAddon')
|
|
13
|
+
|
|
14
|
+
export const ADDON_SELECTION_SCHEMA = z
|
|
15
|
+
.object({
|
|
16
|
+
type: z.enum(AddonTypeEnum),
|
|
17
|
+
})
|
|
18
|
+
.openapi('OrderAddonSelection')
|
|
19
|
+
|
|
20
|
+
/* eslint-enable camelcase */
|
|
@@ -63,39 +63,47 @@ export const PAYMENT_METHODS_REQUEST_SCHEMA = z
|
|
|
63
63
|
|
|
64
64
|
export const PAYMENT_METHOD_RESPONSE_SCHEMA = z
|
|
65
65
|
.discriminatedUnion('name', [
|
|
66
|
-
z
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
66
|
+
z
|
|
67
|
+
.object({
|
|
68
|
+
name: z.literal(PaymentMethodNameEnum.CreditCard),
|
|
69
|
+
payload: z.object({
|
|
70
|
+
amount: z.number(),
|
|
71
|
+
couponId: z.string().nullish(),
|
|
72
|
+
token: z.string(),
|
|
73
|
+
}),
|
|
74
|
+
})
|
|
75
|
+
.openapi('paymentMethodCreditCardApi'),
|
|
76
|
+
z
|
|
77
|
+
.object({
|
|
78
|
+
name: z.literal(PaymentMethodNameEnum.Coupon),
|
|
79
|
+
payload: z.object({
|
|
80
|
+
amount: z.number(),
|
|
81
|
+
couponId: z.string(),
|
|
82
|
+
token: z.string().nullish(),
|
|
83
|
+
}),
|
|
84
|
+
})
|
|
85
|
+
.openapi('paymentMethodCouponApi'),
|
|
86
|
+
z
|
|
87
|
+
.object({
|
|
88
|
+
name: z.literal(PaymentMethodNameEnum.DepositAccount),
|
|
89
|
+
payload: z.object({
|
|
90
|
+
amount: z.number(),
|
|
91
|
+
couponId: z.string().nullish(),
|
|
92
|
+
token: z.string().nullish(),
|
|
93
|
+
}),
|
|
94
|
+
})
|
|
95
|
+
.openapi('paymentMethodDepositAccountApi'),
|
|
96
|
+
z
|
|
97
|
+
.object({
|
|
98
|
+
name: z.literal(PaymentMethodNameEnum.PayLater),
|
|
99
|
+
payload: z.object({
|
|
100
|
+
amount: z.number(),
|
|
101
|
+
couponId: z.string().nullish(),
|
|
102
|
+
status: z.enum(PayLaterStatusEnum),
|
|
103
|
+
token: z.string().nullish(),
|
|
104
|
+
}),
|
|
105
|
+
})
|
|
106
|
+
.openapi('paymentMethodPayLaterApi'),
|
|
99
107
|
])
|
|
100
108
|
.openapi('paymentMethodApi')
|
|
101
109
|
|
|
@@ -108,21 +116,29 @@ export const PAYMENT_METHODS_RESPONSE_SCHEMA = z
|
|
|
108
116
|
|
|
109
117
|
export const ALLOWED_PAYMENT_METHOD_RESPONSE_SCHEMA = z
|
|
110
118
|
.discriminatedUnion('name', [
|
|
111
|
-
z
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
})
|
|
125
|
-
|
|
119
|
+
z
|
|
120
|
+
.object({
|
|
121
|
+
name: z.literal(PaymentMethodNameEnum.CreditCard),
|
|
122
|
+
})
|
|
123
|
+
.openapi('allowedPaymentMethodCreditCardApi'),
|
|
124
|
+
z
|
|
125
|
+
.object({
|
|
126
|
+
name: z.literal(PaymentMethodNameEnum.Coupon),
|
|
127
|
+
})
|
|
128
|
+
.openapi('allowedPaymentMethodCouponApi'),
|
|
129
|
+
z
|
|
130
|
+
.object({
|
|
131
|
+
name: z.literal(PaymentMethodNameEnum.DepositAccount),
|
|
132
|
+
})
|
|
133
|
+
.openapi('allowedPaymentMethodDepositAccountApi'),
|
|
134
|
+
z
|
|
135
|
+
.object({
|
|
136
|
+
name: z.literal(PaymentMethodNameEnum.PayLater),
|
|
137
|
+
payload: z.object({
|
|
138
|
+
status: z.enum(PayLaterStatusEnum),
|
|
139
|
+
}),
|
|
140
|
+
})
|
|
141
|
+
.openapi('allowedPaymentMethodPayLaterApi'),
|
|
126
142
|
])
|
|
127
143
|
.openapi('allowedPaymentMethodApi')
|
|
128
144
|
|
package/src/types/addon.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type { Event } from './event.ts'
|
|
|
5
5
|
import type { HotelRoomOffer } from './hotel-room-offer.ts'
|
|
6
6
|
import type { HotelRoomingList } from './hotel-rooming-list.ts'
|
|
7
7
|
import type { InvoiceApi } from './invoice.ts'
|
|
8
|
+
import type { OrderAddon } from './order-addon.ts'
|
|
8
9
|
import type { PaymentMethod } from './payment-method.ts'
|
|
9
10
|
import type { SourceMarket } from './source-market.ts'
|
|
10
11
|
import type { Tax } from './tax.ts'
|
|
@@ -34,6 +35,12 @@ export interface Booking {
|
|
|
34
35
|
* @memberof Booking
|
|
35
36
|
*/
|
|
36
37
|
additionalPolicies?: string | null
|
|
38
|
+
/**
|
|
39
|
+
* Add-ons attached to the order this booking belongs to (e.g. Revolugo Flex insurance). Empty or omitted when the booking has no order-level add-ons.
|
|
40
|
+
* @type {Array<OrderAddon>}
|
|
41
|
+
* @memberof Booking
|
|
42
|
+
*/
|
|
43
|
+
addons?: OrderAddon[]
|
|
37
44
|
/**
|
|
38
45
|
* The total number of adults who will be staying in the property.
|
|
39
46
|
* @type {number}
|
|
@@ -32,6 +32,7 @@ export enum ElementsEvent {
|
|
|
32
32
|
HotelOffersFiltersUpdated = 'hotel-offers:filters:updated',
|
|
33
33
|
HotelOffersItemClick = 'hotel-offer:item:click',
|
|
34
34
|
HotelOffersMarkerClick = 'hotel-offers:marker:click',
|
|
35
|
+
HotelOffersOpenInNewTabClick = 'hotel-offers:open-in-new-tab:click',
|
|
35
36
|
HotelOffersPollingStarted = 'hotel-offers:polling:started',
|
|
36
37
|
HotelOffersRetrieved = 'hotel-offers:retrieved',
|
|
37
38
|
HotelRetrieved = 'hotel:retrieved',
|
|
@@ -65,6 +66,7 @@ export interface ElementsEventCallbacks {
|
|
|
65
66
|
[ElementsEvent.HotelOffersFiltersUpdated]: Partial<HotelOffersFilters>
|
|
66
67
|
[ElementsEvent.HotelOffersItemClick]: HotelOffer | [HotelOffer, number]
|
|
67
68
|
[ElementsEvent.HotelOffersMarkerClick]: HotelOffer | [HotelOffer, number]
|
|
69
|
+
[ElementsEvent.HotelOffersOpenInNewTabClick]: string
|
|
68
70
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
69
71
|
[ElementsEvent.HotelOffersPollingStarted]: any
|
|
70
72
|
[ElementsEvent.HotelOffersRetrieved]: HotelOffer[]
|
|
@@ -157,7 +157,7 @@ export interface HotelRoomOffer {
|
|
|
157
157
|
* @type {string}
|
|
158
158
|
* @memberof HotelRoomOffer
|
|
159
159
|
*/
|
|
160
|
-
packageType?: HotelRoomOfferPackageType
|
|
160
|
+
packageType?: HotelRoomOfferPackageType
|
|
161
161
|
/**
|
|
162
162
|
* Price with taxes NOT INCLUDED of the given **Hotel Room Offer** including breakfast(s) when applicable, expressed in the requested **currency**.
|
|
163
163
|
* @type {number}
|
|
@@ -24,3 +24,13 @@ export interface OrderAddon {
|
|
|
24
24
|
*/
|
|
25
25
|
type: OrderAddonType
|
|
26
26
|
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Customer-side addon selection echoed back on the prebook request body.
|
|
30
|
+
*
|
|
31
|
+
* The booking-api expects `addons: [{ type: 'insurance' }]` when the customer
|
|
32
|
+
* opts into Flex; the field is omitted entirely when declined.
|
|
33
|
+
*/
|
|
34
|
+
export interface OrderAddonSelection {
|
|
35
|
+
type: OrderAddonType
|
|
36
|
+
}
|
package/src/utils/dates.ts
CHANGED
|
@@ -68,6 +68,19 @@ export function sanitizeDateRange(
|
|
|
68
68
|
]
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
export function isValidDateRange(range: [string, string]): boolean {
|
|
72
|
+
const [start, end] = range
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
isValidDate(start) &&
|
|
76
|
+
isValidDate(end) &&
|
|
77
|
+
dayjs(start, 'YYYY-MM-DD', true).isBefore(
|
|
78
|
+
dayjs(end, 'YYYY-MM-DD', true),
|
|
79
|
+
'day',
|
|
80
|
+
)
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
|
|
71
84
|
export function isDate(value: unknown): value is Date {
|
|
72
85
|
return value instanceof Date && !isNaN(value.getTime())
|
|
73
86
|
}
|