@revolugo/common 6.9.7 → 6.10.0-beta.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.
Files changed (68) hide show
  1. package/package.json +13 -7
  2. package/src/cancellation-policies.test.ts +12 -9
  3. package/src/cancellation-policies.ts +31 -26
  4. package/src/constants/countries.ts +0 -2515
  5. package/src/constants/currencies.ts +0 -1812
  6. package/src/constants/environment.ts +1 -0
  7. package/src/constants/hotel-offers.ts +2 -0
  8. package/src/constants/hotel.ts +3 -0
  9. package/src/constants/locales.ts +6 -0
  10. package/src/constants/measurement.ts +1 -0
  11. package/src/constants/time.ts +1 -0
  12. package/src/countries/constants.ts +2518 -0
  13. package/src/countries/index.ts +7 -0
  14. package/src/currencies/index.ts +1817 -0
  15. package/src/map/distance.ts +22 -0
  16. package/src/map/index.ts +1 -0
  17. package/src/models/paginated-queries.ts +1 -0
  18. package/src/types/country.ts +1 -1
  19. package/src/types/elements/amenity.ts +266 -0
  20. package/src/types/elements/bed.ts +20 -0
  21. package/src/types/elements/booking-policy.ts +80 -0
  22. package/src/types/elements/booking.ts +236 -0
  23. package/src/types/elements/cancellation-policy.ts +20 -0
  24. package/src/types/elements/contact-person.ts +158 -0
  25. package/src/types/elements/currency.ts +3 -0
  26. package/src/types/elements/event-metadata.ts +38 -0
  27. package/src/types/elements/event.ts +14 -0
  28. package/src/types/elements/hotel-image.ts +44 -0
  29. package/src/types/elements/hotel-images.ts +47 -0
  30. package/src/types/elements/hotel-offer-request.ts +82 -0
  31. package/src/types/elements/hotel-offer.ts +208 -0
  32. package/src/types/elements/hotel-review-rating.ts +14 -0
  33. package/src/types/elements/hotel-room-offer-package-type.ts +8 -0
  34. package/src/types/elements/hotel-room-offer-request.ts +77 -0
  35. package/src/types/elements/hotel-room-offer-type.ts +6 -0
  36. package/src/types/elements/hotel-room-offer.ts +192 -0
  37. package/src/types/elements/hotel-room.ts +102 -0
  38. package/src/types/elements/hotel-rooming-list.ts +49 -0
  39. package/src/types/elements/hotel.ts +184 -0
  40. package/src/types/elements/index.ts +22 -0
  41. package/src/types/elements/invoice.ts +21 -0
  42. package/src/types/elements/payment-method.ts +159 -0
  43. package/src/types/elements/source-market.ts +247 -0
  44. package/src/types/elements/tag.ts +32 -0
  45. package/src/types/elements/tax.ts +52 -0
  46. package/src/types/elements/travel-times.ts +45 -0
  47. package/src/types/geo-coordinates.ts +4 -0
  48. package/src/types/index.ts +2 -0
  49. package/src/utils/array-tools.ts +3 -2
  50. package/src/utils/case-transformers.ts +1 -0
  51. package/src/utils/colors.ts +4 -4
  52. package/src/utils/currency.ts +30 -18
  53. package/src/utils/dates.ts +6 -10
  54. package/src/utils/debounce.ts +2 -2
  55. package/src/utils/find-unique-keys.ts +2 -2
  56. package/src/utils/get-guest-count.ts +1 -0
  57. package/src/utils/images.ts +58 -0
  58. package/src/utils/index.ts +2 -1
  59. package/src/utils/lang-default-fallbacks.ts +1 -1
  60. package/src/utils/math.ts +3 -3
  61. package/src/utils/numbers.ts +8 -7
  62. package/src/utils/object-tools.ts +66 -2
  63. package/src/utils/poller.ts +1 -0
  64. package/src/utils/random.ts +12 -0
  65. package/src/utils/strings.ts +5 -2
  66. package/src/utils/uniq-by.ts +12 -9
  67. package/src/utils/validators.ts +1 -0
  68. package/src/utils/countries.ts +0 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revolugo/common",
3
- "version": "6.9.7",
3
+ "version": "6.10.0-beta.0",
4
4
  "private": false,
5
5
  "description": "Revolugo common",
6
6
  "author": "Revolugo",
@@ -8,24 +8,30 @@
8
8
  "files": [
9
9
  "src"
10
10
  ],
11
+ "imports": {
12
+ "#constants": "./src/constants/index.ts"
13
+ },
11
14
  "exports": {
12
15
  "./cancellation-policies": "./src/cancellation-policies.ts",
16
+ "./countries": "./src/countries/index.ts",
13
17
  "./constants": "./src/constants/index.ts",
18
+ "./currencies": "./src/currencies/index.ts",
19
+ "./http": "./src/http/index.ts",
20
+ "./map": "./src/map/index.ts",
14
21
  "./models": "./src/models/index.ts",
15
- "./utils": "./src/utils/index.ts",
16
22
  "./types": "./src/types/index.ts",
17
- "./http": "./src/http/index.ts"
23
+ "./utils": "./src/utils/index.ts"
18
24
  },
19
25
  "dependencies": {
20
26
  "change-case": "5.4.4",
21
- "dayjs": "1.11.13",
22
- "ky": "1.8.2",
27
+ "dayjs": "1.11.18",
28
+ "ky": "1.10.0",
23
29
  "lodash-es": "4.17.21",
24
30
  "slugify": "1.6.6",
25
- "uuid": "11.1.0"
31
+ "uuid": "13.0.0"
26
32
  },
27
33
  "engines": {
28
- "node": ">=20.18.1 <23"
34
+ "node": ">=20.18.1 <25"
29
35
  },
30
36
  "volta": {
31
37
  "extends": "../../package.json"
@@ -15,13 +15,17 @@ import type {
15
15
  } from './cancellation-policies.ts'
16
16
  import type { ICancellationPolicy } from './types/index.ts'
17
17
 
18
- const getUTCLocalTime = (date: string, timezone: string): Dayjs =>
19
- dayjs.tz(date, timezone).utc()
18
+ function getUTCLocalTime(date: string, timezone: string): Dayjs {
19
+ return dayjs.tz(date, timezone).utc()
20
+ }
20
21
 
21
- const getFormattedUTCLocalTime = (date: string, timezone: string): string =>
22
- getUTCLocalTime(date, timezone).format()
22
+ function getFormattedUTCLocalTime(date: string, timezone: string): string {
23
+ return getUTCLocalTime(date, timezone).format()
24
+ }
23
25
 
24
- const nextDay = (date: string) => dayjs(date).add(1, 'day').utc().format()
26
+ function nextDay(date: string) {
27
+ return dayjs(date).add(1, 'day').utc().format()
28
+ }
25
29
 
26
30
  const timezone = 'America/Los_Angeles'
27
31
 
@@ -79,7 +83,7 @@ const CANCELLATION_POLICIES = [
79
83
  ]
80
84
 
81
85
  describe('sanitizeCancellationPolicies', () => {
82
- const testCancellationPolicies = ({
86
+ function testCancellationPolicies({
83
87
  bookingDatetime,
84
88
  cancellationPolicies,
85
89
  checkInDate,
@@ -93,8 +97,8 @@ describe('sanitizeCancellationPolicies', () => {
93
97
  message: string
94
98
  releaseDate?: string
95
99
  results: ICancellationPolicy[]
96
- }): void => {
97
- test(message, () => {
100
+ }): void {
101
+ return test(message, () => {
98
102
  const sanitizedCancellationPolicies = sanitizeCancellationPolicies({
99
103
  bookingDatetime,
100
104
  cancellationPolicies,
@@ -1034,4 +1038,3 @@ describe('getCurrentPenaltyPercentage', () => {
1034
1038
  ).to.equal(PP_4)
1035
1039
  })
1036
1040
  })
1037
- /* eslint-enable max-lines */
@@ -1,12 +1,12 @@
1
- import { uniq } from 'lodash-es'
2
-
3
1
  import { compact } from './utils/array-tools.ts'
4
2
  import { type Dayjs, dayjs } from './utils/dayjs.ts'
5
3
  import { isEmpty } from './utils/is-empty.ts'
6
4
 
7
5
  import type { ICancellationPolicy } from './types/cancellation-policy.ts'
8
6
 
9
- const nextDay = (date: string) => dayjs(date).add(1, 'day').utc().format()
7
+ function nextDay(date: string) {
8
+ return dayjs(date).add(1, 'day').utc().format()
9
+ }
10
10
 
11
11
  function isUTCDate(date: string) {
12
12
  return /\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])T(?:[01]\d|2[0-3])(?::[0-5]\d){2}(?:\.\d+|)(?:Z|[+-]\d{2}:?\d{2})/u.test(
@@ -14,16 +14,17 @@ function isUTCDate(date: string) {
14
14
  )
15
15
  }
16
16
 
17
- const filterMatchingCancellationPolicies = ({
17
+ function filterMatchingCancellationPolicies({
18
18
  cancellationPolicies,
19
19
  date,
20
20
  }: {
21
21
  cancellationPolicies: ICancellationPolicy[]
22
22
  date: string
23
- }) =>
24
- cancellationPolicies.filter(cp =>
23
+ }) {
24
+ return cancellationPolicies.filter(cp =>
25
25
  dayjs(date).isBetween(cp.dateFrom, cp.dateTo, undefined, '[)'),
26
26
  )
27
+ }
27
28
 
28
29
  export interface SanitizeCancellationPolicies {
29
30
  bookingDatetime?: string
@@ -34,13 +35,13 @@ export interface SanitizeCancellationPolicies {
34
35
  }
35
36
 
36
37
  // eslint-disable-next-line complexity, max-statements, max-lines-per-function
37
- export const sanitizeCancellationPolicies = ({
38
+ export function sanitizeCancellationPolicies({
38
39
  bookingDatetime,
39
40
  cancellationPolicies,
40
41
  checkInDate,
41
42
  releaseDate,
42
43
  timezone,
43
- }: SanitizeCancellationPolicies): ICancellationPolicy[] => {
44
+ }: SanitizeCancellationPolicies): ICancellationPolicy[] {
44
45
  if (!bookingDatetime) {
45
46
  throw new Error('Missing "bookingDatetime" option')
46
47
  }
@@ -129,8 +130,9 @@ export const sanitizeCancellationPolicies = ({
129
130
  cancellationPolicies?.map(cp => ({ ...cp })),
130
131
  )
131
132
 
132
- const isValidCancellationPolicy = (cp: ICancellationPolicy) =>
133
- cp.dateFrom && cp.dateTo && dayjs(cp.dateFrom).isBefore(cp.dateTo)
133
+ function isValidCancellationPolicy(cp: ICancellationPolicy) {
134
+ return cp.dateFrom && cp.dateTo && dayjs(cp.dateFrom).isBefore(cp.dateTo)
135
+ }
134
136
 
135
137
  const isValidCancellationPolicies = compactedCancellationPolicies.every(
136
138
  isValidCancellationPolicy,
@@ -200,7 +202,7 @@ export const sanitizeCancellationPolicies = ({
200
202
 
201
203
  .concat(bookingDatetimeUTC, nextDayCheckInDateUTC)
202
204
 
203
- const sortedDates = uniq(relevantDates).sort((a, b) =>
205
+ const sortedDates = [...new Set(relevantDates)].sort((a, b) =>
204
206
  dayjs(a).isAfter(dayjs(b)) ? 1 : -1,
205
207
  )
206
208
 
@@ -284,14 +286,14 @@ export interface GetPenaltyPercentage {
284
286
  timezone?: string
285
287
  }
286
288
 
287
- export const getPenaltyPercentage = ({
289
+ export function getPenaltyPercentage({
288
290
  bookingDatetime,
289
291
  cancellationPolicies,
290
292
  checkInDate,
291
293
  datetime,
292
294
  releaseDate,
293
295
  timezone,
294
- }: GetPenaltyPercentage): number => {
296
+ }: GetPenaltyPercentage): number {
295
297
  if (!bookingDatetime) {
296
298
  throw new Error('Missing "bookingDatetime" option')
297
299
  }
@@ -344,7 +346,7 @@ export const getPenaltyPercentage = ({
344
346
  )
345
347
  }
346
348
 
347
- export const getCurrentPenaltyPercentage = ({
349
+ export function getCurrentPenaltyPercentage({
348
350
  bookingDatetime,
349
351
  cancellationPolicies,
350
352
  checkInDate,
@@ -356,7 +358,7 @@ export const getCurrentPenaltyPercentage = ({
356
358
  checkInDate: string
357
359
  releaseDate?: string
358
360
  timezone: string
359
- }): number => {
361
+ }): number {
360
362
  const datetimeUTC = dayjs().utc().format()
361
363
 
362
364
  return getPenaltyPercentage({
@@ -369,10 +371,10 @@ export const getCurrentPenaltyPercentage = ({
369
371
  })
370
372
  }
371
373
 
372
- export const isBetterCancellationPolicies = (
374
+ export function isBetterCancellationPolicies(
373
375
  newVal: ICancellationPolicy[],
374
376
  oldVal: ICancellationPolicy[],
375
- ): boolean => {
377
+ ): boolean {
376
378
  if (isEmpty(newVal)) {
377
379
  return true
378
380
  }
@@ -424,13 +426,13 @@ export const isBetterCancellationPolicies = (
424
426
  })
425
427
  }
426
428
 
427
- export const parseCancellationPolicies = (
429
+ export function parseCancellationPolicies(
428
430
  cancellationPolicies: {
429
431
  dateFrom: string
430
432
  dateTo: string
431
433
  penaltyPercentage: number
432
434
  }[],
433
- ): ICancellationPolicy[] => {
435
+ ): ICancellationPolicy[] {
434
436
  if (typeof cancellationPolicies === 'string') {
435
437
  try {
436
438
  return JSON.parse(cancellationPolicies) as ICancellationPolicy[]
@@ -442,7 +444,7 @@ export const parseCancellationPolicies = (
442
444
  return cancellationPolicies
443
445
  }
444
446
 
445
- export const getSanitizedCancellationPolicies = ({
447
+ export function getSanitizedCancellationPolicies({
446
448
  cancellationPolicies,
447
449
  checkInDate,
448
450
  initialDate,
@@ -452,7 +454,7 @@ export const getSanitizedCancellationPolicies = ({
452
454
  cancellationPolicies: ICancellationPolicy[]
453
455
  timezone: string
454
456
  initialDate?: string
455
- }): ICancellationPolicy[] => {
457
+ }): ICancellationPolicy[] {
456
458
  if (!cancellationPolicies.length) {
457
459
  return []
458
460
  }
@@ -465,12 +467,15 @@ export const getSanitizedCancellationPolicies = ({
465
467
  })
466
468
  }
467
469
 
468
- export const getCurrentCancellationPolicy = (
470
+ export function getCurrentCancellationPolicy(
469
471
  sanitizedCancellationPolicies: ICancellationPolicy[],
470
- ): ICancellationPolicy =>
471
- sanitizedCancellationPolicies.find(policy =>
472
- dayjs().isBetween(dayjs(policy.dateFrom), dayjs(policy.dateTo)),
473
- ) || sanitizedCancellationPolicies[0]
472
+ ): ICancellationPolicy {
473
+ return (
474
+ sanitizedCancellationPolicies.find(policy =>
475
+ dayjs().isBetween(dayjs(policy.dateFrom), dayjs(policy.dateTo)),
476
+ ) || sanitizedCancellationPolicies[0]
477
+ )
478
+ }
474
479
 
475
480
  function adjustIfFullHour(date: string): Dayjs {
476
481
  const parsed = dayjs(date)