@revolugo/common 6.9.6-beta.7 → 6.9.6

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