@v-office/website-sdk 2.37.1 → 3.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.
Files changed (43) hide show
  1. package/dist/cli.mjs +3 -3
  2. package/dist/{client-D53W9Uas.mjs → client-k4Gjwp60.mjs} +735 -235
  3. package/dist/index.d.mts +97 -4
  4. package/dist/index.mjs +1 -1
  5. package/dist/instructions/CHANGELOG.md +2 -0
  6. package/dist/instructions/MIGRATION.md +2 -0
  7. package/dist/instructions/booking.md +1 -1
  8. package/dist/instructions/quote.md +23 -19
  9. package/dist/instructions/rentals.md +65 -4
  10. package/dist/instructions/search.md +2 -1
  11. package/dist/instructions/versions/2.38.0/CHANGELOG.md +123 -0
  12. package/dist/instructions/versions/2.38.0/MIGRATION.md +37 -0
  13. package/dist/instructions/versions/3.0.0/CHANGELOG.md +62 -0
  14. package/dist/instructions/versions/3.0.0/MIGRATION.md +69 -0
  15. package/dist/{operations-C1VMQYN2.mjs → operations-DMqLD3e2.mjs} +333 -1
  16. package/dist/{rentals-BxkYXAVn.mjs → rentals-BIL52z4o.mjs} +10 -14
  17. package/dist/{search-pFLiI6QI.mjs → search-Buua-PAS.mjs} +8 -4
  18. package/dist/{to-rental-highlights-BdxQPpBU.mjs → to-rental-highlights-BE6TdXYa.mjs} +23 -5
  19. package/dist/translations/shared/de-DE/insurance.json +1 -0
  20. package/dist/translations/shared/de-DE/reviews.json +5 -4
  21. package/dist/translations/shared/en-US/insurance.json +1 -0
  22. package/dist/translations/shared/en-US/reviews.json +5 -4
  23. package/dist/translations/v10/de-DE/core.json +17 -4
  24. package/dist/translations/v10/en-US/core.json +53 -40
  25. package/dist/translations/v9/de-DE/core.json +7 -7
  26. package/dist/translations/v9/de-DE/filter.json +4 -0
  27. package/dist/translations/v9/de-DE/rental-attributes.json +2 -2
  28. package/dist/translations/v9/en-US/core.json +7 -7
  29. package/dist/translations/v9/en-US/filter.json +4 -0
  30. package/dist/translations/v9/en-US/rental-attributes.json +2 -2
  31. package/instructions/CHANGELOG.md +2 -0
  32. package/instructions/MIGRATION.md +2 -0
  33. package/instructions/booking.md +1 -1
  34. package/instructions/quote.md +23 -19
  35. package/instructions/rentals.md +65 -4
  36. package/instructions/search.md +2 -1
  37. package/instructions/versions/2.38.0/CHANGELOG.md +123 -0
  38. package/instructions/versions/2.38.0/MIGRATION.md +37 -0
  39. package/instructions/versions/2.38.0/release.json +3 -0
  40. package/instructions/versions/3.0.0/CHANGELOG.md +62 -0
  41. package/instructions/versions/3.0.0/MIGRATION.md +69 -0
  42. package/instructions/versions/3.0.0/release.json +3 -0
  43. package/package.json +5 -4
@@ -1,5 +1,5 @@
1
- import { S as parseVofficeUnitData, _ as customDataAttribute, c as rentalRegionsQuery, f as RegionSchema$1, t as voucherValidityQuery, v as parseJsonData } from "./operations-C1VMQYN2.mjs";
2
- import { AvailabilityService, BookingBookOutput, BookingService, ContactService, CoreSDKError, DEFAULT_RENTAL_HIGHLIGHT_PRIORITIZATION, DEFAULT_RENTAL_PROPERTY_HIGHLIGHT_PRIORITIZATION, DocumentsService, EMPTY_CUSTOM_ATTRIBUTE_REGISTRY, FilterService, QuoteService, RegionsService, RentalService, SEARCH_ALL_RENTALS_AT_ONCE_MAX_RESULTS, SearchService, TranslationService, addGuestQuoteAdditionalServiceSelection, asArray, asRecord, assertNoNestedCustomAttributeFilterCompositions, assertNoReservedQueryKeys, assertUniqueCustomFilterQueryKeys, assertUniqueFilterQueryKeys, buildWebsiteRegions, clearGuestQuoteAdditionalServiceSelections, collectQueryParameters, createCoreRuntime, daysBetweenLocalDates, expandCustomAttributeFilterCompositions, firstNumber, firstString, formatCurrency, formatLocalDate, getBookingBookGuestToken, getGuestQuoteBackendContext, getGuestQuoteInput, isDisplayableCustomAttribute, localeToLanguage, makeMinIntervalLimiter, makeTranslationLive, normalizeV10RateBudget, parseQueryParameters, refreshGuestQuoteInsurancePassthrough, removeGuestQuoteAdditionalServiceSelection, selectGuestQuoteCancellationPolicySelection, toCustomAttributeFilterLabel, toCustomAttributeFilterOutputItem, toCustomAttributeList, toInitialAvailabilityCalendarDays, toIsoDateFromPeriodQueryDate, toQueryString, toResolvedCustomAttributeCategoryTranslationKey, toStartDateSelectedCalendarDays, validateContactSubmitInput, withGuestQuoteInsurance, withGuestQuoteInsuranceRefresh } from "@v-office/sdk-core";
1
+ import { b as parseJsonData, l as rentalRegionsQuery, m as RegionSchema$1, t as voucherValidityQuery, w as parseVofficeUnitData, y as customDataAttribute } from "./operations-DMqLD3e2.mjs";
2
+ import { AvailabilityService, BookingBookOutput, BookingService, ContactService, CoreSDKError, DEFAULT_RENTAL_HIGHLIGHT_PRIORITIZATION, DEFAULT_RENTAL_PROPERTY_HIGHLIGHT_PRIORITIZATION, DocumentsService, EMPTY_CUSTOM_ATTRIBUTE_REGISTRY, FilterService, QuoteService, RegionsService, RentalService, SEARCH_ALL_RENTALS_AT_ONCE_MAX_RESULTS, SearchService, TranslationService, addGuestQuoteAdditionalServiceSelection, asArray, asRecord, assertNoNestedCustomAttributeFilterCompositions, assertNoReservedQueryKeys, assertUniqueCustomFilterQueryKeys, assertUniqueFilterQueryKeys, buildWebsiteRegions, clearGuestQuoteAdditionalServiceSelections, collectQueryParameters, createCoreRuntime, daysBetweenLocalDates, expandCustomAttributeFilterCompositions, firstNumber, firstString, formatCurrency, formatLocalDate, getBookingBookGuestToken, getGuestQuoteBackendContext, getGuestQuoteInput, isDisplayableCustomAttribute, localeToLanguage, makeMinIntervalLimiter, makeTranslationLive, normalizeV10RateBudget, parseQueryParameters, refreshGuestQuoteInsurancePassthrough, removeGuestQuoteAdditionalServiceSelection, selectGuestQuoteCancellationPolicySelection, toCountLabelKey, toCustomAttributeFilterLabel, toCustomAttributeFilterOutputItem, toCustomAttributeList, toInitialAvailabilityCalendarDays, toIsoDateFromPeriodQueryDate, toNoInsuranceOption, toNotOfferedInsurance, toQueryString, toResolvedCustomAttributeCategoryTranslationKey, toStartDateSelectedCalendarDays, validateContactSubmitInput, withGuestQuoteInsurance, withGuestQuoteInsuranceRefresh } from "@v-office/sdk-core";
3
3
  import { Clock, Context, Data, DateTime, Duration, Effect, Layer, Schema, SchemaGetter } from "effect";
4
4
  import { FetchHttpClient, HttpClient, HttpClientRequest } from "effect/unstable/http";
5
5
  import { Kind, print, visit } from "graphql";
@@ -1822,12 +1822,6 @@ const applyV9EndDatePrices = ({ availability, calendarDays, selectedStartDate, l
1822
1822
  var core_default$1 = {
1823
1823
  "Rental.rentalType.option.HOUSE": "Haus",
1824
1824
  "Rental.rentalType.option.FLAT": "Wohnung",
1825
- "Property.propertyType.option.APARTMENT_COMPLEX": "Appartement Komplex",
1826
- "Property.propertyType.option.CAMPGROUND": "Campingplatz",
1827
- "Property.propertyType.option.FARM": "Bauernhof",
1828
- "Property.propertyType.option.HOLIDAY_HOME_COMPLEX": "Ferienpark",
1829
- "Property.propertyType.option.HOSTEL": "Hostel",
1830
- "Property.propertyType.option.HOTEL": "Hotel",
1831
1825
  "reviews.item.guest": "Gast",
1832
1826
  "reviews.item.authorWithCity": "{author} aus {city}",
1833
1827
  "voucher.validate.reason.valid": "Der Gutscheincode ist gültig.",
@@ -1836,13 +1830,23 @@ var core_default$1 = {
1836
1830
  "voucher.validate.reason.unknown": "Dieser Gutscheincode ist unbekannt.",
1837
1831
  "voucher.validate.reason.stay_too_short": "Der Aufenthalt ist für diesen Gutscheincode zu kurz.",
1838
1832
  "voucher.validate.reason.outside_booking_window": "Der gewählte Anreisetag liegt außerhalb des Buchungszeitraums dieses Gutscheincodes.",
1839
- "voucher.validate.reason.rate_limited": "Zu viele Versuche. Bitte versuchen Sie es später erneut."
1833
+ "voucher.validate.reason.rate_limited": "Zu viele Versuche. Bitte versuchen Sie es später erneut.",
1834
+ "insurance.ergo.preContract.documents.PID.label": "Produktinformationsblatt",
1835
+ "insurance.ergo.preContract.documents.TCP.label": "Versicherungsbedingungen",
1836
+ "insurance.ergo.preContract.documents.PRP.label": "Merkblatt zur Datenverarbeitung",
1837
+ "insurance.ergo.preContract.documents.ECI.label": "Kundeninformation elektronischer Geschäftsverkehr",
1838
+ "insurance.ergo.preContract.documents.other.label": "Dokument",
1839
+ "insurance.ergo.policy.document.label": "Versicherungsschein"
1840
1840
  };
1841
1841
  //#endregion
1842
1842
  //#region translations/v9/de-DE/filter.json
1843
1843
  var filter_default$1 = {
1844
1844
  "filter.bedrooms.label": "Schlafzimmer",
1845
+ "filter.bedrooms.count.one": "Schlafzimmer",
1846
+ "filter.bedrooms.count.other": "Schlafzimmer",
1845
1847
  "filter.bathrooms.label": "Badezimmer",
1848
+ "filter.bathrooms.count.one": "Badezimmer",
1849
+ "filter.bathrooms.count.other": "Badezimmer",
1846
1850
  "filter.pool.label": "Pool",
1847
1851
  "filter.wifi.label": "WLAN",
1848
1852
  "filter.pets.label": "Haustiere",
@@ -2518,8 +2522,8 @@ var rental_attributes_default$1 = {
2518
2522
  "RentalAttributes.showerCount.count.other": "Duschen",
2519
2523
  "RentalAttributes.tvCount.count.one": "TV",
2520
2524
  "RentalAttributes.tvCount.count.other": "TVs",
2521
- "RentalAttributes.beds.count.one": "Schlafmöglichkeit",
2522
- "RentalAttributes.beds.count.other": "Schlafmöglichkeiten",
2525
+ "RentalAttributes.beds.count.one": "Gast",
2526
+ "RentalAttributes.beds.count.other": "Gäste",
2523
2527
  "RentalAttributes.beds4kids.count.one": "Schlafplatz für Kinder",
2524
2528
  "RentalAttributes.beds4kids.count.other": "Schlafplätze für Kinder",
2525
2529
  "RentalAttributes.rooms.count.one": "Zimmer",
@@ -2570,12 +2574,6 @@ var rental_attributes_default$1 = {
2570
2574
  var core_default = {
2571
2575
  "Rental.rentalType.option.HOUSE": "House",
2572
2576
  "Rental.rentalType.option.FLAT": "Apartment",
2573
- "Property.propertyType.option.APARTMENT_COMPLEX": "Apartment complex",
2574
- "Property.propertyType.option.CAMPGROUND": "Campground",
2575
- "Property.propertyType.option.FARM": "Farm",
2576
- "Property.propertyType.option.HOLIDAY_HOME_COMPLEX": "Holiday Home Complex",
2577
- "Property.propertyType.option.HOSTEL": "Hostel",
2578
- "Property.propertyType.option.HOTEL": "Hotel",
2579
2577
  "reviews.item.guest": "Guest",
2580
2578
  "reviews.item.authorWithCity": "{author} from {city}",
2581
2579
  "voucher.validate.reason.valid": "The voucher code is valid.",
@@ -2584,13 +2582,23 @@ var core_default = {
2584
2582
  "voucher.validate.reason.unknown": "This voucher code is unknown.",
2585
2583
  "voucher.validate.reason.stay_too_short": "The stay is too short for this voucher code.",
2586
2584
  "voucher.validate.reason.outside_booking_window": "The selected arrival date is outside this voucher code's booking window.",
2587
- "voucher.validate.reason.rate_limited": "Too many attempts. Please try again later."
2585
+ "voucher.validate.reason.rate_limited": "Too many attempts. Please try again later.",
2586
+ "insurance.ergo.preContract.documents.PID.label": "Product information sheet",
2587
+ "insurance.ergo.preContract.documents.TCP.label": "Insurance terms",
2588
+ "insurance.ergo.preContract.documents.PRP.label": "Data processing notice",
2589
+ "insurance.ergo.preContract.documents.ECI.label": "E-commerce customer information",
2590
+ "insurance.ergo.preContract.documents.other.label": "Document",
2591
+ "insurance.ergo.policy.document.label": "Insurance policy"
2588
2592
  };
2589
2593
  //#endregion
2590
2594
  //#region translations/v9/en-US/filter.json
2591
2595
  var filter_default = {
2592
2596
  "filter.bedrooms.label": "Bedrooms",
2597
+ "filter.bedrooms.count.one": "bedroom",
2598
+ "filter.bedrooms.count.other": "bedrooms",
2593
2599
  "filter.bathrooms.label": "Bathrooms",
2600
+ "filter.bathrooms.count.one": "bathroom",
2601
+ "filter.bathrooms.count.other": "bathrooms",
2594
2602
  "filter.pool.label": "Pool",
2595
2603
  "filter.wifi.label": "Wi-Fi",
2596
2604
  "filter.pets.label": "Pets",
@@ -3266,8 +3274,8 @@ var rental_attributes_default = {
3266
3274
  "RentalAttributes.showerCount.count.other": "showers",
3267
3275
  "RentalAttributes.tvCount.count.one": "TV",
3268
3276
  "RentalAttributes.tvCount.count.other": "TVs",
3269
- "RentalAttributes.beds.count.one": "sleeping arrangement",
3270
- "RentalAttributes.beds.count.other": "sleeping arrangements",
3277
+ "RentalAttributes.beds.count.one": "guest",
3278
+ "RentalAttributes.beds.count.other": "guests",
3271
3279
  "RentalAttributes.beds4kids.count.one": "children’s bed",
3272
3280
  "RentalAttributes.beds4kids.count.other": "children’s beds",
3273
3281
  "RentalAttributes.rooms.count.one": "room",
@@ -4521,10 +4529,10 @@ const RANGE_STATUS = {
4521
4529
  N: "unavailable",
4522
4530
  Q: "on_request"
4523
4531
  };
4524
- const toLocalDate = (date) => DateTime.formatIsoDate(date);
4532
+ const toLocalDate$1 = (date) => DateTime.formatIsoDate(date);
4525
4533
  const toRentalBlockedRanges = ({ rentalId, availability, availabilityUpdate }) => {
4526
4534
  const firstDay = DateTime.removeTime(DateTime.makeZonedUnsafe(availabilityUpdate, { timeZone: "Europe/Berlin" }));
4527
- const dayAt = (index) => toLocalDate(DateTime.add(firstDay, { days: index }));
4535
+ const dayAt = (index) => toLocalDate$1(DateTime.add(firstDay, { days: index }));
4528
4536
  const ranges = [];
4529
4537
  let runStart = 0;
4530
4538
  for (let index = 1; index <= availability.length; index++) {
@@ -4539,7 +4547,7 @@ const toRentalBlockedRanges = ({ rentalId, availability, availabilityUpdate }) =
4539
4547
  }
4540
4548
  return {
4541
4549
  rentalId,
4542
- availableFrom: toLocalDate(firstDay),
4550
+ availableFrom: toLocalDate$1(firstDay),
4543
4551
  ranges
4544
4552
  };
4545
4553
  };
@@ -4598,6 +4606,11 @@ const makeV9BlockedRangesApi = ({ config }) => {
4598
4606
  })) };
4599
4607
  };
4600
4608
  //#endregion
4609
+ //#region src/legacy-v9/booking-state.ts
4610
+ const V9BookingInternalState = Symbol("@v-office/website-sdk/V9BookingInternalState");
4611
+ const withV9BookingInternalState = (booking, state) => Object.defineProperty(booking, V9BookingInternalState, { value: state });
4612
+ const getV9BookingInternalState = (booking) => booking[V9BookingInternalState];
4613
+ //#endregion
4601
4614
  //#region src/legacy-v9/parser/insurance/index.ts
4602
4615
  const urvInsuranceOptionAmounts = /* @__PURE__ */ new WeakMap();
4603
4616
  const urvInsuranceOptionAmountsByKey = /* @__PURE__ */ new Map();
@@ -4605,14 +4618,6 @@ const getUrvInsuranceOptionAmount = (option) => urvInsuranceOptionAmounts.get(op
4605
4618
  const toFormattedPrice = (money, locale) => formatCurrency(money.amount, locale, money.currency);
4606
4619
  const toUrvInsuranceOptionAmountKey = (option) => `${option.id}:${option.formattedPrice}`;
4607
4620
  const toMinorUnitAmount = (amount, decimals) => Math.round(amount * 10 ** (2 - decimals));
4608
- const toNoInsuranceOption = (input) => typeof input === "string" ? {
4609
- kind: "none",
4610
- label: input === "de-DE" ? "Keine Versicherung" : "No insurance"
4611
- } : {
4612
- kind: "none",
4613
- label: input.label,
4614
- description: input.description
4615
- };
4616
4621
  const toResource = (label, url) => url === void 0 ? [] : [{
4617
4622
  label,
4618
4623
  url
@@ -4674,17 +4679,30 @@ const getErgoPlans = (raw) => {
4674
4679
  ];
4675
4680
  };
4676
4681
  const toSelectableErgoAvailablePlans = (plans) => {
4677
- const plansWithCode = plans.flatMap((entry) => {
4682
+ const products = /* @__PURE__ */ new Map();
4683
+ for (const entry of plans) {
4678
4684
  const plan = asRecord(entry);
4679
4685
  const planCode = firstString(plan.PlanCode);
4680
- return planCode === void 0 ? [] : [{
4686
+ const variant = planCode?.slice(-1);
4687
+ if (planCode === void 0 || variant !== "O" && variant !== "M") continue;
4688
+ const product = planCode.slice(0, -1);
4689
+ const variants = products.get(product) ?? {};
4690
+ variants[variant] ??= {
4681
4691
  plan,
4682
- planCode
4683
- }];
4692
+ product,
4693
+ variant,
4694
+ premium: getErgoPlanPrice(plan)?.amount ?? Number.POSITIVE_INFINITY
4695
+ };
4696
+ products.set(product, variants);
4697
+ }
4698
+ const cards = [...products.values()].flatMap((variants) => {
4699
+ const card = variants.O ?? variants.M;
4700
+ return card === void 0 ? [] : [card];
4684
4701
  });
4685
- const plansWithoutExcess = plansWithCode.filter(({ planCode }) => planCode.endsWith("O"));
4686
- if (plansWithoutExcess.length > 0) return plansWithoutExcess.map(({ plan }) => plan);
4687
- return plansWithCode.filter(({ planCode }) => planCode.endsWith("M")).slice(0, 2).map(({ plan }) => plan);
4702
+ const [onlyCard] = cards;
4703
+ const fallback = onlyCard === void 0 ? void 0 : products.get(onlyCard.product)?.M;
4704
+ if (cards.length === 1 && fallback !== void 0 && fallback !== onlyCard) cards.push(fallback);
4705
+ return cards.toSorted((left, right) => Number(left.variant === "M") - Number(right.variant === "M") || left.premium - right.premium).map(({ plan }) => plan);
4688
4706
  };
4689
4707
  const getErgoPlanPrice = (plan) => {
4690
4708
  const premium = asRecord(plan.premium);
@@ -4754,11 +4772,28 @@ const toInsuranceDocuments = (value) => {
4754
4772
  });
4755
4773
  return documents.length === 0 ? void 0 : documents;
4756
4774
  };
4757
- const getErgoPreContractDocuments = (raw) => {
4775
+ const toErgoPreContractDocumentLabel = (type, labels) => {
4776
+ switch (type) {
4777
+ case "PID":
4778
+ case "TCP":
4779
+ case "PRP":
4780
+ case "ECI": return labels[type];
4781
+ default: return labels.fallback;
4782
+ }
4783
+ };
4784
+ const getErgoPreContractDocuments = ({ raw, labels }) => {
4758
4785
  const record = asRecord(raw);
4759
4786
  const body = asRecord(record.body);
4760
4787
  const services = asRecord(record.PreContractualInformationServices ?? body.PreContractualInformationServices);
4761
- return toInsuranceDocuments(asArray(services.PreContractualInformationService).flatMap((service) => asArray(asRecord(service).PreContractualInformation)));
4788
+ const documents = asArray(services.PreContractualInformationService).flatMap((service) => asArray(asRecord(service).PreContractualInformation)).flatMap((entry) => {
4789
+ const document = asRecord(entry);
4790
+ const url = firstString(document._, document.url, document.URL);
4791
+ return url === void 0 ? [] : [{
4792
+ label: toErgoPreContractDocumentLabel(firstString(document.Type), labels),
4793
+ url
4794
+ }];
4795
+ });
4796
+ return documents.length === 0 ? void 0 : uniqueResourcesByUrl(documents);
4762
4797
  };
4763
4798
  const toErgoInsuranceOptions = ({ featureLabels, infResourceLabel, locale, raw }) => getErgoPlans(raw).flatMap((entry) => {
4764
4799
  const plan = asRecord(entry);
@@ -4781,26 +4816,29 @@ const toErgoInsuranceOptions = ({ featureLabels, infResourceLabel, locale, raw }
4781
4816
  ...resources === void 0 ? {} : { resources }
4782
4817
  }];
4783
4818
  });
4784
- const toInsurancePreContractOutput = (raw) => {
4819
+ const toInsurancePreContractOutput = ({ raw, labels }) => {
4785
4820
  const record = asRecord(raw);
4786
4821
  const body = asRecord(record.body);
4787
4822
  const id = firstString(record.pre_contractual_information_id, body.pre_contractual_information_id, record.PreContractualInformationID, body.PreContractualInformationID);
4788
4823
  if (id === void 0) return { kind: "not_required" };
4789
- const documents = toInsuranceDocuments(record.documents ?? body.documents) ?? getErgoPreContractDocuments(raw);
4824
+ const documents = toInsuranceDocuments(record.documents ?? body.documents) ?? getErgoPreContractDocuments({
4825
+ raw,
4826
+ labels
4827
+ });
4790
4828
  return {
4791
4829
  kind: "created",
4792
4830
  id,
4793
4831
  ...documents === void 0 ? {} : { documents }
4794
4832
  };
4795
4833
  };
4796
- const toInsuranceBookingOutput = (raw) => {
4834
+ const toInsuranceBookingOutput = ({ raw, policyLabel }) => {
4797
4835
  const record = asRecord(raw);
4798
4836
  const body = asRecord(record.body);
4799
4837
  const policyDetail = asRecord(record.PolicyDetail ?? body.PolicyDetail);
4800
4838
  const policyNumber = firstString(record.policy_number, body.policy_number, policyDetail.PolicyNumber);
4801
4839
  if (policyNumber === void 0) return { kind: "not_required" };
4802
4840
  const documents = toInsuranceDocuments(record.documents ?? body.documents) ?? toInsuranceDocuments([{
4803
- label: "Policy",
4841
+ label: policyLabel,
4804
4842
  url: policyDetail.PolicyPrintURL
4805
4843
  }]);
4806
4844
  return {
@@ -4809,6 +4847,57 @@ const toInsuranceBookingOutput = (raw) => {
4809
4847
  ...documents === void 0 ? {} : { documents }
4810
4848
  };
4811
4849
  };
4850
+ const toErgoRoot = (raw) => {
4851
+ const record = asRecord(raw);
4852
+ return "Success" in record ? record : asRecord(record.body ?? record);
4853
+ };
4854
+ const getErgoErrorEntries = (raw) => asArray(asRecord(toErgoRoot(raw).Errors).Error);
4855
+ const isErgoSuccess = (raw) => {
4856
+ const success = toErgoRoot(raw).Success;
4857
+ return success !== void 0 && success !== null && success !== false && getErgoErrorEntries(raw).length === 0;
4858
+ };
4859
+ const getErgoErrorMessages = (raw) => getErgoErrorEntries(raw).map((entry) => {
4860
+ const error = asRecord(entry);
4861
+ return firstString(error.ErrorMessage) ?? firstString(error.ErrorCode, error.type) ?? "ERGO reported an error.";
4862
+ });
4863
+ const toLocalDate = (value) => {
4864
+ const date = firstString(value)?.slice(0, 10);
4865
+ return date !== void 0 && /^\d{4}-\d{2}-\d{2}$/.test(date) ? date : void 0;
4866
+ };
4867
+ const toErgoPolicy = ({ raw, policyNumber }) => {
4868
+ const root = toErgoRoot(raw);
4869
+ const policyDetail = asRecord(root.PolicyDetail);
4870
+ const tariff = asRecord(asRecord(asArray(asRecord(root.Services).Service)[0]).Tariff);
4871
+ const trip = asRecord(root.CoveredTrip);
4872
+ const start = toLocalDate(trip.StartDate);
4873
+ const end = toLocalDate(trip.EndDate);
4874
+ const revokedAt = toLocalDate(policyDetail.CancelDate);
4875
+ const documentUrl = firstString(policyDetail.PolicyPrintURL);
4876
+ return {
4877
+ policyNumber: firstString(policyDetail.PolicyNumber) ?? policyNumber,
4878
+ status: policyDetail.Status === "XX" ? "revoked" : "active",
4879
+ ...revokedAt === void 0 ? {} : { revokedAt },
4880
+ ...documentUrl === void 0 ? {} : { documentUrl },
4881
+ label: firstString(asRecord(tariff.TariffDescription).Title) ?? policyNumber,
4882
+ ...start === void 0 || end === void 0 ? {} : { travelPeriod: {
4883
+ start,
4884
+ end
4885
+ } },
4886
+ insuredPersons: asArray(asRecord(root.CoveredTravelers).CoveredTraveler).flatMap((entry) => {
4887
+ const traveler = asRecord(entry);
4888
+ const person = asRecord(traveler.CoveredPerson ?? traveler);
4889
+ const name = asRecord(person.PersonName);
4890
+ const forename = firstString(name.GivenName);
4891
+ const surname = firstString(name.Surname);
4892
+ const birthday = toLocalDate(person.Birthdate);
4893
+ return forename === void 0 || surname === void 0 ? [] : [{
4894
+ forename,
4895
+ surname,
4896
+ ...birthday === void 0 ? {} : { birthday }
4897
+ }];
4898
+ })
4899
+ };
4900
+ };
4812
4901
  //#endregion
4813
4902
  //#region src/legacy-v9/parser/booking/to-booking-service-lines.ts
4814
4903
  const hasSelectedAmount = (line) => (line.amount ?? 0) > 0;
@@ -5223,17 +5312,59 @@ const toStripePaymentInput = ({ bookResponse, input, paymentScheduleOption, stri
5223
5312
  };
5224
5313
  });
5225
5314
  //#endregion
5226
- //#region src/legacy-v9/live/booking.ts
5315
+ //#region src/legacy-v9/live/quote-insurance/state.ts
5316
+ const withInsurance = (quote, insurance) => withGuestQuoteInsurance({
5317
+ quote,
5318
+ insurance
5319
+ });
5320
+ const findInsuranceOption = (options, id) => options.find((option) => option.kind === "insurance" && option.id === id);
5321
+ const toSepaDebitLabel = ({ locale, translations }) => translations.translate(locale, "insurance.payment.sepaDebit.label", "SEPA direct debit");
5322
+ const toInsurancePaymentOptions = (option, sepaDebitLabel) => option.requiredInformation.kind === "travelers" ? [{
5323
+ kind: "sepa_debit",
5324
+ label: sepaDebitLabel
5325
+ }] : [];
5326
+ const withRefreshedInsuranceOptions = ({ quote, options, sepaDebitLabel, destinationCountryCode }) => {
5327
+ const nextDestinationCountryCode = destinationCountryCode ?? quote.insurance?.destinationCountryCode;
5328
+ const nextInsurance = {
5329
+ options,
5330
+ selected: { kind: "none" },
5331
+ preContract: { kind: "none_selected" },
5332
+ paymentOptions: [],
5333
+ ...nextDestinationCountryCode === void 0 ? {} : { destinationCountryCode: nextDestinationCountryCode }
5334
+ };
5335
+ const previousSelection = quote.insurance?.selected;
5336
+ if (previousSelection?.kind !== "insurance") return nextInsurance;
5337
+ const previousOption = findInsuranceOption(quote.insurance?.options ?? [], previousSelection.id);
5338
+ const option = findInsuranceOption(options, previousSelection.id);
5339
+ if (option === void 0) return nextInsurance;
5340
+ if (previousOption?.requiredInformation.kind !== option.requiredInformation.kind) return nextInsurance;
5341
+ return {
5342
+ ...nextInsurance,
5343
+ selected: previousSelection,
5344
+ preContract: option.requiredInformation.kind === "none" ? { kind: "not_required" } : { kind: "none_selected" },
5345
+ paymentOptions: toInsurancePaymentOptions(option, sepaDebitLabel),
5346
+ ...nextDestinationCountryCode === void 0 ? {} : { destinationCountryCode: nextDestinationCountryCode },
5347
+ ...quote.insurance?.customerInformation === void 0 ? {} : { customerInformation: quote.insurance.customerInformation },
5348
+ ...quote.insurance?.paymentInformation?.kind === "sepa_debit" && option.requiredInformation.kind === "travelers" ? { paymentInformation: quote.insurance.paymentInformation } : {}
5349
+ };
5350
+ };
5351
+ const selectedInsuranceOption = (quote) => {
5352
+ const insurance = quote.insurance;
5353
+ if (insurance?.selected.kind !== "insurance") return void 0;
5354
+ const selectedInsuranceId = insurance.selected.id;
5355
+ return findInsuranceOption(insurance.options, selectedInsuranceId);
5356
+ };
5227
5357
  const toPostBookingInsurancePaymentOptions = ({ quote, sepaDebitLabel, sepaDebitDescription, canBookInsurance }) => {
5228
5358
  const insurance = quote.insurance;
5229
5359
  if (!canBookInsurance || insurance?.selected.kind !== "insurance") return [];
5230
- if (insurance.preContract.kind !== "created") return [];
5231
5360
  return insurance.paymentOptions.flatMap((option) => option.kind === "sepa_debit" ? [{
5232
5361
  ...option,
5233
5362
  label: sepaDebitLabel,
5234
5363
  description: sepaDebitDescription
5235
5364
  }] : []);
5236
5365
  };
5366
+ //#endregion
5367
+ //#region src/legacy-v9/live/booking.ts
5237
5368
  const book = ({ client, input, translations }) => Effect.gen(function* () {
5238
5369
  const bookingInput = yield* toBookingInput({ input });
5239
5370
  const language = bookingInput.reservation.customer.preferredLanguage ?? "de";
@@ -5328,12 +5459,18 @@ const book = ({ client, input, translations }) => Effect.gen(function* () {
5328
5459
  sepaDebitDescription: insuranceSepaDebitDescription,
5329
5460
  canBookInsurance: reservation.guestToken !== void 0
5330
5461
  });
5331
- return new BookingBookOutput({
5462
+ const output = new BookingBookOutput({
5332
5463
  bookingNumber,
5333
5464
  payment,
5334
5465
  insurancePaymentOptions: [...urvInsurancePaymentOptions, ...postBookingInsurancePaymentOptions],
5335
5466
  ...reservation.guestToken === void 0 ? {} : { guestToken: reservation.guestToken }
5336
5467
  });
5468
+ const bookingId = reservation.bookings?.[0]?.id;
5469
+ return reservation.token === void 0 || bookingId === void 0 ? output : withV9BookingInternalState(output, {
5470
+ token: reservation.token,
5471
+ bookingId,
5472
+ customer: input.contact
5473
+ });
5337
5474
  });
5338
5475
  const makeV9BookingApi = ({ config, options }) => {
5339
5476
  const translations = makeV9TranslationService(options.translationOverrides);
@@ -5455,6 +5592,25 @@ const makeV9ContactApi = ({ config, options }) => {
5455
5592
  }).pipe(Effect.provide(openApiClientLive))) };
5456
5593
  };
5457
5594
  //#endregion
5595
+ //#region src/legacy-v9/live/quote-insurance/errors.ts
5596
+ const toInsuranceError = (message) => (cause) => new CoreSDKError({
5597
+ source: "v9",
5598
+ operation: "v9.insurance",
5599
+ message,
5600
+ cause
5601
+ });
5602
+ const failInsurance = (message) => Effect.fail(new CoreSDKError({
5603
+ source: "v9",
5604
+ operation: "v9.insurance",
5605
+ message
5606
+ }));
5607
+ const requireErgoSuccess = ({ raw, message }) => isErgoSuccess(raw) ? Effect.succeed(raw) : Effect.fail(new CoreSDKError({
5608
+ source: "v9",
5609
+ operation: "v9.insurance",
5610
+ message: [message, ...getErgoErrorMessages(raw)].join(" "),
5611
+ cause: raw
5612
+ }));
5613
+ //#endregion
5458
5614
  //#region src/legacy-v9/live/quote-insurance/quote-values.ts
5459
5615
  const getRawV9Quote = (quote) => {
5460
5616
  const context = getGuestQuoteBackendContext(quote);
@@ -5471,16 +5627,29 @@ const toQuoteTotalAmount = (quote) => {
5471
5627
  return sumQuoteLines(rawQuote?.mandatory) + sumQuoteLines(selectedQuoteLines(rawQuote?.optional)) + sumQuoteLines(selectedQuoteLines(rawQuote?.onsiteOptional));
5472
5628
  };
5473
5629
  const toQuoteCurrency = (quote) => getRawV9Quote(quote)?.currency ?? "EUR";
5474
- //#endregion
5475
- //#region src/legacy-v9/live/quote-insurance/ergo-input.ts
5630
+ const ERGO_CUSTOMER_COUNTRY_CODES = [
5631
+ "DE",
5632
+ "AT",
5633
+ "BE",
5634
+ "DK",
5635
+ "FR",
5636
+ "IT",
5637
+ "LU",
5638
+ "NL",
5639
+ "PL",
5640
+ "CZ"
5641
+ ];
5476
5642
  const toErgoNamePrefix = (salutation) => {
5477
- switch (salutation.trim().toUpperCase()) {
5478
- case "MR":
5479
- case "HERR": return "H";
5480
- case "MRS":
5481
- case "MS":
5482
- case "FRAU": return "F";
5483
- default: return salutation;
5643
+ switch (salutation.trim().toLowerCase()) {
5644
+ case "herr":
5645
+ case "mr":
5646
+ case "mr.": return "H";
5647
+ case "frau":
5648
+ case "mrs":
5649
+ case "mrs.":
5650
+ case "ms":
5651
+ case "ms.": return "D";
5652
+ default: return "";
5484
5653
  }
5485
5654
  };
5486
5655
  const toErgoPerson = (traveler) => ({
@@ -5491,91 +5660,45 @@ const toErgoPerson = (traveler) => ({
5491
5660
  ...traveler.birthday === void 0 ? {} : { birthday: traveler.birthday }
5492
5661
  });
5493
5662
  const toStreetAndNumber = (address) => [address.street, address.housenumber].filter((part) => part !== void 0 && part.length > 0).join(" ");
5494
- const toErgoTripAndCustomerInput = ({ quote, customerInformation, travelers }) => ({
5495
- destination_country: customerInformation.destinationCountryCode,
5496
- start_date: getGuestQuoteInput(quote).period.start,
5497
- end_date: getGuestQuoteInput(quote).period.end,
5498
- total_amount: toQuoteTotalAmount(quote),
5499
- total_currency: toQuoteCurrency(quote),
5500
- total_decimals: 2,
5501
- guests: travelers.length,
5502
- policy_holder: travelers[0],
5503
- travelers,
5504
- address: {
5505
- street_and_nr: toStreetAndNumber(customerInformation.address),
5506
- city_name: customerInformation.address.city,
5507
- postal_code: customerInformation.address.postalcode,
5508
- country_code: customerInformation.address.countryCode
5509
- },
5510
- email: customerInformation.email,
5511
- mobile: customerInformation.mobile
5512
- });
5513
- //#endregion
5514
- //#region src/legacy-v9/live/quote-insurance/state.ts
5515
- const emptyInsurance = (quote) => ({
5516
- options: [toNoInsuranceOption(getGuestQuoteInput(quote).locale)],
5517
- selected: { kind: "none" },
5518
- preContract: { kind: "none_selected" },
5519
- paymentOptions: []
5520
- });
5521
- const withInsurance = (quote, insurance) => withGuestQuoteInsurance({
5522
- quote,
5523
- insurance
5524
- });
5525
- const findInsuranceOption = (options, id) => options.find((option) => option.kind === "insurance" && option.id === id);
5526
- const toInsurancePaymentOptions = (option) => option.requiredInformation.kind === "travelers" ? [{
5527
- kind: "sepa_debit",
5528
- label: "SEPA direct debit"
5529
- }] : [];
5530
- const withRefreshedInsuranceOptions = ({ quote, options, destinationCountryCode }) => {
5531
- const nextDestinationCountryCode = destinationCountryCode ?? quote.insurance?.destinationCountryCode;
5532
- const nextInsurance = {
5533
- ...emptyInsurance(quote),
5534
- options,
5535
- ...nextDestinationCountryCode === void 0 ? {} : { destinationCountryCode: nextDestinationCountryCode }
5536
- };
5537
- const previousSelection = quote.insurance?.selected;
5538
- if (previousSelection?.kind !== "insurance") return nextInsurance;
5539
- const previousOption = findInsuranceOption(quote.insurance?.options ?? [], previousSelection.id);
5540
- const option = findInsuranceOption(options, previousSelection.id);
5541
- if (option === void 0) return nextInsurance;
5542
- if (previousOption?.requiredInformation.kind !== option.requiredInformation.kind) return nextInsurance;
5663
+ const toErgoTripAndCustomerInput = ({ quote, customer, travelers }) => Effect.gen(function* () {
5664
+ if (customer.birthdate === void 0) return yield* failInsurance("ERGO insurance requires the booking customer's birthdate.");
5665
+ if (!("phone" in customer.contactDetails)) return yield* failInsurance("ERGO insurance requires the booking customer's mobile number.");
5666
+ if (!("email" in customer.contactDetails)) return yield* failInsurance("ERGO insurance requires the booking customer's email address.");
5667
+ const countryCode = customer.address.countryCode.toUpperCase();
5668
+ if (!ERGO_CUSTOMER_COUNTRY_CODES.includes(countryCode)) return yield* failInsurance(`ERGO insurance is not available for customers living in "${countryCode}".`);
5669
+ const { period } = getGuestQuoteInput(quote);
5543
5670
  return {
5544
- ...nextInsurance,
5545
- selected: previousSelection,
5546
- preContract: option.requiredInformation.kind === "none" ? { kind: "not_required" } : { kind: "none_selected" },
5547
- paymentOptions: toInsurancePaymentOptions(option),
5548
- ...nextDestinationCountryCode === void 0 ? {} : { destinationCountryCode: nextDestinationCountryCode },
5549
- ...quote.insurance?.customerInformation === void 0 ? {} : { customerInformation: quote.insurance.customerInformation },
5550
- ...quote.insurance?.paymentInformation?.kind === "sepa_debit" && option.requiredInformation.kind === "travelers" ? { paymentInformation: quote.insurance.paymentInformation } : {}
5671
+ destination_country: "DE",
5672
+ start_date: period.start,
5673
+ end_date: period.end,
5674
+ total_amount: toQuoteTotalAmount(quote),
5675
+ total_currency: toQuoteCurrency(quote),
5676
+ total_decimals: 2,
5677
+ guests: travelers.length,
5678
+ policy_holder: toErgoPerson({
5679
+ salutation: customer.title ?? "",
5680
+ forename: customer.forename,
5681
+ surname: customer.surname,
5682
+ birthday: customer.birthdate
5683
+ }),
5684
+ travelers,
5685
+ address: {
5686
+ street_and_nr: toStreetAndNumber(customer.address),
5687
+ city_name: customer.address.city,
5688
+ postal_code: customer.address.postalcode,
5689
+ country_code: countryCode
5690
+ },
5691
+ email: customer.contactDetails.email,
5692
+ mobile: customer.contactDetails.phone
5551
5693
  };
5552
- };
5553
- const selectedInsuranceOption = (quote) => {
5554
- const insurance = quote.insurance;
5555
- if (insurance?.selected.kind !== "insurance") return void 0;
5556
- const selectedInsuranceId = insurance.selected.id;
5557
- return findInsuranceOption(insurance.options, selectedInsuranceId);
5558
- };
5694
+ });
5559
5695
  //#endregion
5560
5696
  //#region src/legacy-v9/live/quote-insurance.ts
5561
- const toInsuranceError = (message) => (cause) => new CoreSDKError({
5562
- source: "v9",
5563
- operation: "v9.insurance",
5564
- message,
5565
- cause
5566
- });
5567
- const failInsurance = (message) => Effect.fail(new CoreSDKError({
5568
- source: "v9",
5569
- operation: "v9.insurance",
5570
- message
5571
- }));
5572
- const toNoInsuranceOptionFromTranslations = ({ locale, translations }) => Effect.gen(function* () {
5573
- const [label, description] = yield* Effect.all([translations.translate(locale, "insurance.none.label"), translations.translate(locale, "insurance.none.description")]);
5574
- return toNoInsuranceOption({
5575
- label,
5576
- description
5577
- });
5578
- });
5697
+ /** The quote's insurance block; a quote that never loaded one offers none. */
5698
+ const currentInsuranceOf = ({ quote, translations }) => quote.insurance === void 0 ? toNotOfferedInsurance({
5699
+ translations,
5700
+ locale: getGuestQuoteInput(quote).locale
5701
+ }) : Effect.succeed(quote.insurance);
5579
5702
  const toUrvInsuranceResourceLabelsFromTranslations = ({ locale, translations }) => Effect.gen(function* () {
5580
5703
  const [quoteDetails, bookingDetails, termsAndConditions, productInformation, disclaimer] = yield* Effect.all([
5581
5704
  translations.translate(locale, "insurance.urv.resources.quoteDetails.label", "Quote details"),
@@ -5608,6 +5731,22 @@ const toErgoInsuranceFeatureLabelsFromTranslations = ({ locale, translations })
5608
5731
  withoutDeductible
5609
5732
  };
5610
5733
  });
5734
+ const toErgoPreContractDocumentLabelsFromTranslations = ({ locale, translations }) => Effect.gen(function* () {
5735
+ const [PID, TCP, PRP, ECI, fallback] = yield* Effect.all([
5736
+ translations.translate(locale, "insurance.ergo.preContract.documents.PID.label", "Product information sheet"),
5737
+ translations.translate(locale, "insurance.ergo.preContract.documents.TCP.label", "Insurance terms"),
5738
+ translations.translate(locale, "insurance.ergo.preContract.documents.PRP.label", "Data processing notice"),
5739
+ translations.translate(locale, "insurance.ergo.preContract.documents.ECI.label", "E-commerce customer information"),
5740
+ translations.translate(locale, "insurance.ergo.preContract.documents.other.label", "Document")
5741
+ ]);
5742
+ return {
5743
+ PID,
5744
+ TCP,
5745
+ PRP,
5746
+ ECI,
5747
+ fallback
5748
+ };
5749
+ });
5611
5750
  const getSettingString = (settings, key) => {
5612
5751
  const value = settings?.[key];
5613
5752
  return typeof value === "string" ? value : void 0;
@@ -5635,17 +5774,31 @@ const toConfiguredInsuranceSettings = (setup) => {
5635
5774
  default: return disabled;
5636
5775
  }
5637
5776
  };
5638
- const getErgoTravelers = (quote) => {
5777
+ const getSelectedTravelers = (quote) => {
5639
5778
  const selected = quote.insurance?.selected;
5640
5779
  if (selected?.kind !== "insurance" || selected.travelers === void 0) return failInsurance("ERGO insurance requires traveler information before pre-contract creation.");
5641
- const travelers = selected.travelers.map(toErgoPerson);
5642
- if (travelers.length > 0) return Effect.succeed(travelers);
5780
+ if (selected.travelers.length > 0) return Effect.succeed(selected.travelers);
5643
5781
  return failInsurance("ERGO insurance requires at least one traveler.");
5644
5782
  };
5783
+ const requireBookingAccess = (booking) => {
5784
+ const guestToken = getBookingBookGuestToken(booking);
5785
+ return guestToken === void 0 ? failInsurance("The booking does not contain the private v9 guest token required for insurance.") : Effect.succeed({
5786
+ bookingNumber: booking.bookingNumber,
5787
+ guestToken
5788
+ });
5789
+ };
5790
+ const requireBookingDetails = (booking) => {
5791
+ const details = getV9BookingInternalState(booking);
5792
+ return details === void 0 ? failInsurance("The booking does not contain the private v9 booking details required for ERGO insurance. Pass the result of live.booking.book.") : Effect.succeed(details);
5793
+ };
5645
5794
  const refreshErgoInsuranceOptions = ({ quote, destinationCountryCode, translations, v1Client }) => Effect.gen(function* () {
5646
5795
  const input = getGuestQuoteInput(quote);
5796
+ if (toGuestCount(quote) > 9) return yield* toNotOfferedInsurance({
5797
+ translations,
5798
+ locale: input.locale
5799
+ });
5647
5800
  const body = {
5648
- destination_country: destinationCountryCode ?? quote.insurance?.destinationCountryCode ?? quote.insurance?.customerInformation?.destinationCountryCode ?? "DE",
5801
+ destination_country: "DE",
5649
5802
  start_date: input.period.start,
5650
5803
  end_date: input.period.end,
5651
5804
  traveler_count: Math.max(toGuestCount(quote), 1),
@@ -5654,24 +5807,33 @@ const refreshErgoInsuranceOptions = ({ quote, destinationCountryCode, translatio
5654
5807
  total_decimals: 2,
5655
5808
  list_type: "DE_TID"
5656
5809
  };
5657
- const result = yield* v1Client.execute("searchErgoTravelCancellationInsurancePlans", { body }).pipe(Effect.mapError(toInsuranceError("Failed to load ERGO insurance plans.")));
5658
- const noInsuranceOption = yield* toNoInsuranceOptionFromTranslations({
5810
+ const result = yield* v1Client.execute("searchErgoTravelCancellationInsurancePlans", { body }).pipe(Effect.mapError(toInsuranceError("Failed to load ERGO insurance plans.")), Effect.flatMap(({ raw }) => requireErgoSuccess({
5811
+ raw,
5812
+ message: "Failed to load ERGO insurance plans."
5813
+ })));
5814
+ const noInsuranceOption = yield* toNoInsuranceOption({
5815
+ translations,
5659
5816
  locale: input.locale,
5660
- translations
5817
+ offered: true
5661
5818
  });
5662
5819
  const infResourceLabel = yield* translations.translate(input.locale, "insurance.ergo.resources.inf.label", "Product description");
5663
5820
  const featureLabels = yield* toErgoInsuranceFeatureLabelsFromTranslations({
5664
5821
  locale: input.locale,
5665
5822
  translations
5666
5823
  });
5824
+ const sepaDebitLabel = yield* toSepaDebitLabel({
5825
+ locale: input.locale,
5826
+ translations
5827
+ });
5667
5828
  return withRefreshedInsuranceOptions({
5668
5829
  quote,
5830
+ sepaDebitLabel,
5669
5831
  ...destinationCountryCode === void 0 ? {} : { destinationCountryCode },
5670
5832
  options: [noInsuranceOption, ...toErgoInsuranceOptions({
5671
5833
  featureLabels,
5672
5834
  infResourceLabel,
5673
5835
  locale: input.locale,
5674
- raw: result.raw
5836
+ raw: result
5675
5837
  })]
5676
5838
  });
5677
5839
  });
@@ -5691,16 +5853,22 @@ const refreshUrvInsuranceOptions = ({ quote, mode, translations, v0Client }) =>
5691
5853
  data: JSON.stringify(data),
5692
5854
  lang: localeToLanguage(input.locale)
5693
5855
  } }).pipe(Effect.mapError(toInsuranceError("Failed to load URV insurance plans.")));
5694
- const noInsuranceOption = yield* toNoInsuranceOptionFromTranslations({
5856
+ const noInsuranceOption = yield* toNoInsuranceOption({
5857
+ translations,
5695
5858
  locale: input.locale,
5696
- translations
5859
+ offered: true
5697
5860
  });
5698
5861
  const resourceLabels = yield* toUrvInsuranceResourceLabelsFromTranslations({
5699
5862
  locale: input.locale,
5700
5863
  translations
5701
5864
  });
5865
+ const sepaDebitLabel = yield* toSepaDebitLabel({
5866
+ locale: input.locale,
5867
+ translations
5868
+ });
5702
5869
  return withRefreshedInsuranceOptions({
5703
5870
  quote,
5871
+ sepaDebitLabel,
5704
5872
  options: [noInsuranceOption, ...toUrvInsuranceOptions({
5705
5873
  locale: input.locale,
5706
5874
  plans: result.raw.plans ?? [],
@@ -5708,100 +5876,274 @@ const refreshUrvInsuranceOptions = ({ quote, mode, translations, v0Client }) =>
5708
5876
  })]
5709
5877
  });
5710
5878
  });
5879
+ const loadInsuranceSetup = (v1Client) => v1Client.execute("getSetup", { query: { include: "booking,search,common" } }).pipe(Effect.map(({ data }) => data.data), Effect.mapError(toInsuranceError("Failed to load v9 insurance settings.")));
5880
+ const requireErgoAccount = (v1Client) => Effect.gen(function* () {
5881
+ const setup = yield* loadInsuranceSetup(v1Client);
5882
+ if (getSettingString(setup.booking, "insurance_type") !== "ERGO") return yield* failInsurance("Insurance policies are only available for ERGO insurance.");
5883
+ });
5711
5884
  const refreshV9InsuranceOptions = ({ quote, destinationCountryCode, translations, v0Client, v1Client }) => Effect.gen(function* () {
5712
- const setup = yield* v1Client.execute("getSetup", { query: { include: "booking,search,common" } }).pipe(Effect.mapError(toInsuranceError("Failed to load v9 insurance settings.")));
5713
- const settings = toConfiguredInsuranceSettings(setup.data.data);
5885
+ const notOffered = toNotOfferedInsurance({
5886
+ translations,
5887
+ locale: getGuestQuoteInput(quote).locale
5888
+ });
5889
+ const notOfferedAfter = (message) => (cause) => Effect.logError(message, cause).pipe(Effect.andThen(notOffered));
5890
+ const settings = yield* loadInsuranceSetup(v1Client).pipe(Effect.map(toConfiguredInsuranceSettings), Effect.catch((cause) => Effect.logError("Insurance is not offered: loading the v9 setup failed.", cause).pipe(Effect.as({ provider: "none" }))));
5714
5891
  switch (settings.provider) {
5715
5892
  case "ergo": return withInsurance(quote, yield* refreshErgoInsuranceOptions({
5716
5893
  quote,
5717
5894
  destinationCountryCode,
5718
5895
  translations,
5719
5896
  v1Client
5720
- }));
5897
+ }).pipe(Effect.catch(notOfferedAfter("Insurance is not offered: loading ERGO plans failed."))));
5721
5898
  case "urv": return withInsurance(quote, yield* refreshUrvInsuranceOptions({
5722
5899
  quote,
5723
5900
  mode: settings.mode,
5724
5901
  translations,
5725
5902
  v0Client
5726
- }));
5727
- case "none": return withInsurance(quote, emptyInsurance(quote));
5903
+ }).pipe(Effect.catch(notOfferedAfter("Insurance is not offered: loading URV plans failed."))));
5904
+ case "none": return withInsurance(quote, yield* notOffered);
5728
5905
  }
5729
5906
  });
5730
- const selectV9Insurance = ({ quote, selection }) => {
5731
- const currentInsurance = quote.insurance ?? emptyInsurance(quote);
5732
- if (selection.kind === "none") return Effect.succeed(withInsurance(quote, {
5907
+ const selectV9Insurance = ({ quote, selection, translations }) => Effect.gen(function* () {
5908
+ const currentInsurance = yield* currentInsuranceOf({
5909
+ quote,
5910
+ translations
5911
+ });
5912
+ if (selection.kind === "none") return withInsurance(quote, {
5733
5913
  ...currentInsurance,
5734
5914
  selected: selection,
5735
5915
  preContract: { kind: "none_selected" },
5736
5916
  paymentOptions: []
5737
- }));
5917
+ });
5738
5918
  const option = findInsuranceOption(currentInsurance.options, selection.id);
5739
- if (option === void 0) return failInsurance(`Unknown insurance option "${selection.id}".`);
5740
- return Effect.succeed(withInsurance(quote, {
5919
+ if (option === void 0) return yield* failInsurance(`Unknown insurance option "${selection.id}".`);
5920
+ if (option.requiredInformation.kind === "travelers" && selection.travelers?.some((traveler) => traveler.birthday === void 0)) return yield* failInsurance("ERGO insurance requires a birthday for every traveler.");
5921
+ const sepaDebitLabel = yield* toSepaDebitLabel({
5922
+ locale: getGuestQuoteInput(quote).locale,
5923
+ translations
5924
+ });
5925
+ return withInsurance(quote, {
5741
5926
  ...currentInsurance,
5742
5927
  selected: option.requiredInformation.kind === "none" ? {
5743
5928
  kind: "insurance",
5744
5929
  id: selection.id
5745
5930
  } : selection,
5746
5931
  preContract: option.requiredInformation.kind === "none" ? { kind: "not_required" } : { kind: "none_selected" },
5747
- paymentOptions: toInsurancePaymentOptions(option)
5748
- }));
5749
- };
5750
- const createV9InsurancePreContract = ({ quote, customerInformation, v1Client }) => Effect.gen(function* () {
5932
+ paymentOptions: toInsurancePaymentOptions(option, sepaDebitLabel)
5933
+ });
5934
+ });
5935
+ const findInsuranceRecord = ({ guestToken, bookingNumber, v1Client }) => v1Client.execute("findTravelInsuranceBooking", { query: {
5936
+ guest_token: guestToken,
5937
+ booking_number: bookingNumber
5938
+ } }).pipe(Effect.mapError(toInsuranceError("Failed to read the stored ERGO insurance booking.")), Effect.map(({ raw }) => {
5939
+ const record = asRecord(raw);
5940
+ const data = asRecord(record.additional_booking_data);
5941
+ const policyNumber = firstString(record.travel_insurance_number);
5942
+ const preContractId = firstString(data.pre_contractual_information_id);
5943
+ const selectedPlanCode = firstString(data.selected_plan_code);
5944
+ return {
5945
+ ...policyNumber === void 0 ? {} : { policyNumber },
5946
+ ...preContractId === void 0 ? {} : { preContractId },
5947
+ ...selectedPlanCode === void 0 ? {} : { selectedPlanCode }
5948
+ };
5949
+ }));
5950
+ const isPolicyActive = ({ policyNumber, v1Client }) => {
5951
+ const message = `Failed to verify the stored ERGO policy ${policyNumber}; not booking again.`;
5952
+ return v1Client.execute("readErgoTravelCancellationInsurance", { body: { policy_number: policyNumber } }).pipe(Effect.mapError(toInsuranceError(message)), Effect.flatMap(({ raw }) => requireErgoSuccess({
5953
+ raw,
5954
+ message
5955
+ })), Effect.map((raw) => toErgoPolicy({
5956
+ raw,
5957
+ policyNumber
5958
+ }).status === "active"));
5959
+ };
5960
+ const checkStoredPolicy = ({ record, planCode, v1Client }) => Effect.gen(function* () {
5961
+ if (record.policyNumber === void 0) return "none";
5962
+ if (!(yield* isPolicyActive({
5963
+ policyNumber: record.policyNumber,
5964
+ v1Client
5965
+ }))) return "revoked";
5966
+ if (record.selectedPlanCode !== planCode) return yield* failInsurance("This booking already has an active ERGO policy for another plan; revoke it before choosing a different plan.");
5967
+ return "matching";
5968
+ });
5969
+ const storeInsuranceRecord = ({ body, v1Client }) => v1Client.execute("storeTravelInsuranceBooking", { body }).pipe(Effect.asVoid, Effect.catch((cause) => Effect.logError("Failed to store the ERGO insurance booking in the Hub.", cause)));
5970
+ const writeTravelersToBooking = ({ locale, travelers, details, v0Client }) => Effect.gen(function* () {
5971
+ const lang = localeToLanguage(locale);
5972
+ const current = yield* v0Client.execute("proxyVofficeAction", { query: {
5973
+ actionName: "getBooking",
5974
+ data: JSON.stringify({ token: details.token }),
5975
+ lang
5976
+ } });
5977
+ const reservation = asRecord(asRecord(current.raw).reservation);
5978
+ const booking = asRecord(asArray(reservation.bookings)[0]);
5979
+ if (asRecord(current.raw).ok === false || asArray(booking.guests).length > 0) return;
5980
+ const data = {
5981
+ token: details.token,
5982
+ noStatusChange: true,
5983
+ bookings: { [details.bookingId]: { addedGuests: travelers.map((traveler) => ({
5984
+ title: traveler.salutation,
5985
+ ...traveler.title === void 0 ? {} : { professionalTitle: traveler.title },
5986
+ forename: traveler.forename,
5987
+ surname: traveler.surname,
5988
+ ...traveler.birthday === void 0 ? {} : { birthdate: traveler.birthday }
5989
+ })) } }
5990
+ };
5991
+ const updated = yield* v0Client.execute("proxyVofficeAction", { query: {
5992
+ actionName: "updateBooking",
5993
+ data: JSON.stringify(data),
5994
+ lang
5995
+ } });
5996
+ if (asRecord(updated.raw).ok === false) return yield* Effect.fail(updated.raw);
5997
+ }).pipe(Effect.catch((cause) => Effect.logWarning("Failed to write the ERGO travelers to the vOffice booking.", cause)));
5998
+ const readPreContractDocuments = ({ preContractId, email, labels, v1Client }) => Effect.gen(function* () {
5999
+ const message = "Failed to read ERGO pre-contract information.";
6000
+ const raw = yield* v1Client.execute("readErgoPreContract", { body: {
6001
+ pre_contractual_information_id: preContractId,
6002
+ email
6003
+ } }).pipe(Effect.mapError(toInsuranceError(message)), Effect.flatMap(({ raw }) => requireErgoSuccess({
6004
+ raw,
6005
+ message
6006
+ })));
6007
+ const documents = getErgoPreContractDocuments({
6008
+ raw,
6009
+ labels
6010
+ });
6011
+ return documents === void 0 ? yield* failInsurance("ERGO returned no pre-contract documents.") : documents;
6012
+ });
6013
+ const createV9InsurancePreContract = ({ quote, booking, translations, v0Client, v1Client }) => Effect.gen(function* () {
5751
6014
  const option = selectedInsuranceOption(quote);
5752
- const currentInsurance = quote.insurance ?? emptyInsurance(quote);
6015
+ const currentInsurance = yield* currentInsuranceOf({
6016
+ quote,
6017
+ translations
6018
+ });
5753
6019
  if (option === void 0) return withInsurance(quote, currentInsurance);
5754
6020
  if (option.requiredInformation.kind === "none") return withInsurance(quote, {
5755
6021
  ...currentInsurance,
5756
- customerInformation,
5757
6022
  preContract: { kind: "not_required" }
5758
6023
  });
5759
- const travelers = yield* getErgoTravelers(quote);
5760
- const body = {
5761
- ...toErgoTripAndCustomerInput({
5762
- quote,
5763
- customerInformation,
5764
- travelers
5765
- }),
6024
+ const access = yield* requireBookingAccess(booking);
6025
+ const details = yield* requireBookingDetails(booking);
6026
+ const travelers = yield* getSelectedTravelers(quote);
6027
+ const ergoTravelers = travelers.map(toErgoPerson);
6028
+ const tripAndCustomer = yield* toErgoTripAndCustomerInput({
6029
+ quote,
6030
+ customer: details.customer,
6031
+ travelers: ergoTravelers
6032
+ });
6033
+ const locale = getGuestQuoteInput(quote).locale;
6034
+ const sepaDebitLabel = yield* toSepaDebitLabel({
6035
+ locale,
6036
+ translations
6037
+ });
6038
+ const labels = yield* toErgoPreContractDocumentLabelsFromTranslations({
6039
+ locale,
6040
+ translations
6041
+ });
6042
+ const withPreContract = (preContract) => withInsurance(quote, {
6043
+ ...currentInsurance,
6044
+ destinationCountryCode: "DE",
6045
+ preContract,
6046
+ paymentOptions: toInsurancePaymentOptions(option, sepaDebitLabel)
6047
+ });
6048
+ const record = yield* findInsuranceRecord({
6049
+ ...access,
6050
+ v1Client
6051
+ });
6052
+ const storedPolicy = yield* checkStoredPolicy({
6053
+ record,
6054
+ planCode: option.id,
6055
+ v1Client
6056
+ });
6057
+ if (record.preContractId !== void 0 && record.selectedPlanCode === option.id && storedPolicy !== "revoked") {
6058
+ const documents = yield* readPreContractDocuments({
6059
+ preContractId: record.preContractId,
6060
+ email: tripAndCustomer.email,
6061
+ labels,
6062
+ v1Client
6063
+ });
6064
+ return withPreContract({
6065
+ kind: "created",
6066
+ id: record.preContractId,
6067
+ documents
6068
+ });
6069
+ }
6070
+ yield* writeTravelersToBooking({
6071
+ locale: getGuestQuoteInput(quote).locale,
6072
+ travelers,
6073
+ details,
6074
+ v0Client
6075
+ });
6076
+ const created = yield* v1Client.execute("createErgoPreContract", { body: {
6077
+ ...tripAndCustomer,
5766
6078
  plan_code: option.id
5767
- };
5768
- const result = yield* v1Client.execute("createErgoPreContract", { body }).pipe(Effect.mapError(toInsuranceError("Failed to create ERGO pre-contract information.")));
5769
- const preContract = toInsurancePreContractOutput(result.raw);
6079
+ } }).pipe(Effect.mapError(toInsuranceError("Failed to create ERGO pre-contract information.")), Effect.flatMap(({ raw }) => requireErgoSuccess({
6080
+ raw,
6081
+ message: "Failed to create ERGO pre-contract information."
6082
+ })));
6083
+ const preContract = toInsurancePreContractOutput({
6084
+ raw: created,
6085
+ labels
6086
+ });
5770
6087
  if (preContract.kind !== "created") return yield* Effect.fail(new CoreSDKError({
5771
6088
  source: "v9",
5772
6089
  operation: "v9.insurance",
5773
6090
  message: "ERGO pre-contract response did not contain a pre-contract ID.",
5774
- cause: result.raw
6091
+ cause: created
5775
6092
  }));
5776
- return withInsurance(quote, {
5777
- ...currentInsurance,
5778
- customerInformation,
5779
- destinationCountryCode: customerInformation.destinationCountryCode,
5780
- preContract,
5781
- paymentOptions: toInsurancePaymentOptions(option)
6093
+ yield* storeInsuranceRecord({
6094
+ body: {
6095
+ guest_token: access.guestToken,
6096
+ booking_number: access.bookingNumber,
6097
+ pre_contractual_information_id: preContract.id,
6098
+ selected_plan_code: option.id
6099
+ },
6100
+ v1Client
5782
6101
  });
5783
- });
5784
- const selectV9InsurancePayment = ({ quote, paymentInformation }) => {
5785
- const currentInsurance = quote.insurance ?? emptyInsurance(quote);
5786
- return Effect.succeed(withInsurance(quote, {
5787
- ...currentInsurance,
5788
- paymentInformation
6102
+ const documents = preContract.documents ?? (yield* readPreContractDocuments({
6103
+ preContractId: preContract.id,
6104
+ email: tripAndCustomer.email,
6105
+ labels,
6106
+ v1Client
5789
6107
  }));
5790
- };
5791
- const bookV9Insurance = ({ quote, bookingNumber, guestToken, v1Client }) => Effect.gen(function* () {
6108
+ return withPreContract({
6109
+ ...preContract,
6110
+ documents
6111
+ });
6112
+ });
6113
+ const selectV9InsurancePayment = ({ quote, paymentInformation, translations }) => Effect.map(currentInsuranceOf({
6114
+ quote,
6115
+ translations
6116
+ }), (currentInsurance) => withInsurance(quote, {
6117
+ ...currentInsurance,
6118
+ paymentInformation
6119
+ }));
6120
+ const bookV9Insurance = ({ quote, booking, translations, v1Client }) => Effect.gen(function* () {
5792
6121
  const option = selectedInsuranceOption(quote);
5793
6122
  const insurance = quote.insurance;
5794
6123
  if (option === void 0 || insurance === void 0) return { kind: "none_selected" };
5795
6124
  if (option.requiredInformation.kind === "none") return { kind: "not_required" };
6125
+ const access = yield* requireBookingAccess(booking);
6126
+ const record = yield* findInsuranceRecord({
6127
+ ...access,
6128
+ v1Client
6129
+ });
6130
+ if (record.policyNumber !== void 0 && (yield* checkStoredPolicy({
6131
+ record,
6132
+ planCode: option.id,
6133
+ v1Client
6134
+ })) === "matching") return {
6135
+ kind: "booked",
6136
+ policyNumber: record.policyNumber
6137
+ };
5796
6138
  if (insurance.preContract.kind !== "created") return yield* failInsurance("ERGO insurance requires created pre-contract information before booking.");
5797
- if (insurance.customerInformation === void 0) return yield* failInsurance("ERGO insurance booking requires customer information.");
5798
6139
  if (insurance.paymentInformation?.kind !== "sepa_debit") return yield* failInsurance("ERGO insurance booking requires SEPA payment information.");
5799
- const travelers = yield* getErgoTravelers(quote);
6140
+ const details = yield* requireBookingDetails(booking);
6141
+ const travelers = yield* getSelectedTravelers(quote);
5800
6142
  const body = {
5801
- ...toErgoTripAndCustomerInput({
6143
+ ...yield* toErgoTripAndCustomerInput({
5802
6144
  quote,
5803
- customerInformation: insurance.customerInformation,
5804
- travelers
6145
+ customer: details.customer,
6146
+ travelers: travelers.map(toErgoPerson)
5805
6147
  }),
5806
6148
  plan_code: option.id,
5807
6149
  pre_contractual_information_id: insurance.preContract.id,
@@ -5810,24 +6152,71 @@ const bookV9Insurance = ({ quote, bookingNumber, guestToken, v1Client }) => Effe
5810
6152
  ...insurance.paymentInformation.bic === void 0 ? {} : { bic: insurance.paymentInformation.bic }
5811
6153
  }
5812
6154
  };
5813
- const result = yield* v1Client.execute("bookErgoTravelCancellationInsurance", { body }).pipe(Effect.mapError(toInsuranceError("Failed to book ERGO insurance.")));
5814
- const bookingOutput = toInsuranceBookingOutput(result.raw);
6155
+ const result = yield* v1Client.execute("bookErgoTravelCancellationInsurance", { body }).pipe(Effect.mapError(toInsuranceError("Failed to book ERGO insurance.")), Effect.flatMap(({ raw }) => requireErgoSuccess({
6156
+ raw,
6157
+ message: "Failed to book ERGO insurance."
6158
+ })));
6159
+ const policyLabel = yield* translations.translate(getGuestQuoteInput(quote).locale, "insurance.ergo.policy.document.label", "Insurance policy");
6160
+ const bookingOutput = toInsuranceBookingOutput({
6161
+ raw: result,
6162
+ policyLabel
6163
+ });
5815
6164
  if (bookingOutput.kind !== "booked") return yield* Effect.fail(new CoreSDKError({
5816
6165
  source: "v9",
5817
6166
  operation: "v9.insurance",
5818
6167
  message: "ERGO insurance booking response did not contain a policy number.",
5819
- cause: result.raw
6168
+ cause: result
5820
6169
  }));
5821
- const persistenceBody = {
5822
- guest_token: guestToken,
5823
- booking_number: bookingNumber,
5824
- travel_insurance_number: bookingOutput.policyNumber,
5825
- pre_contractual_information_id: insurance.preContract.id,
5826
- selected_plan_code: option.id
5827
- };
5828
- yield* v1Client.execute("storeTravelInsuranceBooking", { body: persistenceBody }).pipe(Effect.mapError(toInsuranceError("Failed to persist ERGO insurance booking.")));
6170
+ yield* storeInsuranceRecord({
6171
+ body: {
6172
+ guest_token: access.guestToken,
6173
+ booking_number: access.bookingNumber,
6174
+ travel_insurance_number: bookingOutput.policyNumber,
6175
+ pre_contractual_information_id: insurance.preContract.id,
6176
+ selected_plan_code: option.id
6177
+ },
6178
+ v1Client
6179
+ });
5829
6180
  return bookingOutput;
5830
6181
  });
6182
+ const readV9InsurancePolicy = ({ policyNumber, v1Client }) => Effect.gen(function* () {
6183
+ yield* requireErgoAccount(v1Client);
6184
+ const raw = yield* v1Client.execute("readErgoTravelCancellationInsurance", { body: { policy_number: policyNumber } }).pipe(Effect.mapError(toInsuranceError("Failed to read the ERGO insurance policy.")), Effect.flatMap(({ raw }) => requireErgoSuccess({
6185
+ raw,
6186
+ message: "Failed to read the ERGO insurance policy."
6187
+ })));
6188
+ return toErgoPolicy({
6189
+ raw,
6190
+ policyNumber
6191
+ });
6192
+ });
6193
+ const revokeV9InsurancePolicy = ({ policyNumber, booking, v1Client }) => Effect.gen(function* () {
6194
+ yield* requireErgoAccount(v1Client);
6195
+ const { bookingNumber, guestToken } = yield* requireBookingAccess(booking);
6196
+ const raw = yield* v1Client.execute("cancelErgoTravelCancellationInsurance", { body: { policy_number: policyNumber } }).pipe(Effect.mapError(toInsuranceError("Failed to revoke the ERGO insurance policy.")), Effect.flatMap(({ raw }) => requireErgoSuccess({
6197
+ raw,
6198
+ message: "Failed to revoke the ERGO insurance policy."
6199
+ })));
6200
+ yield* Effect.gen(function* () {
6201
+ if ((yield* findInsuranceRecord({
6202
+ guestToken,
6203
+ bookingNumber,
6204
+ v1Client
6205
+ })).policyNumber !== policyNumber) return yield* Effect.logWarning(`The Hub booking ${bookingNumber} does not hold the revoked ERGO policy ${policyNumber}; its record is kept.`);
6206
+ const { data } = yield* v1Client.execute("deleteTravelInsuranceBooking", {
6207
+ path: { travel_insurance_booking: bookingNumber },
6208
+ query: { guest_token: guestToken }
6209
+ });
6210
+ if (!data.success) return yield* Effect.fail(data);
6211
+ }).pipe(Effect.catch((cause) => Effect.logError("Failed to delete the revoked ERGO insurance booking in the Hub.", cause)));
6212
+ return {
6213
+ ...toErgoPolicy({
6214
+ raw,
6215
+ policyNumber
6216
+ }),
6217
+ status: "revoked"
6218
+ };
6219
+ });
5831
6220
  //#endregion
5832
6221
  //#region src/legacy-v9/live/quote.ts
5833
6222
  const loadQuoteRuntime = Effect.tryPromise({
@@ -5941,26 +6330,35 @@ const makeV9QuoteApi = ({ config, options }) => {
5941
6330
  }),
5942
6331
  refreshInsurance: toRefreshInsurance(clients)
5943
6332
  })),
5944
- selectInsurance: (input) => withClients(() => selectV9Insurance(input)),
5945
- createInsurancePreContract: ({ quote, customerInformation }) => withClients(({ v1Client }) => createV9InsurancePreContract({
6333
+ selectInsurance: (input) => withClients(() => selectV9Insurance({
6334
+ ...input,
6335
+ translations
6336
+ })),
6337
+ createInsurancePreContract: ({ quote, booking }) => withClients(({ v0Client, v1Client }) => createV9InsurancePreContract({
6338
+ quote,
6339
+ booking,
6340
+ translations,
6341
+ v0Client,
6342
+ v1Client
6343
+ })),
6344
+ selectInsurancePayment: (input) => withClients(() => selectV9InsurancePayment({
6345
+ ...input,
6346
+ translations
6347
+ })),
6348
+ bookInsurance: ({ quote, booking }) => withClients(({ v1Client }) => bookV9Insurance({
5946
6349
  quote,
5947
- customerInformation,
6350
+ booking,
6351
+ translations,
5948
6352
  v1Client
5949
6353
  })),
5950
- selectInsurancePayment: (input) => withClients(() => selectV9InsurancePayment(input)),
5951
- bookInsurance: ({ quote, booking }) => withClients(({ v1Client }) => Effect.gen(function* () {
5952
- const guestToken = getBookingBookGuestToken(booking);
5953
- if (guestToken === void 0) return yield* Effect.fail(new CoreSDKError({
5954
- source: "v9",
5955
- operation: "v9.insurance",
5956
- message: "The booking does not contain the private v9 guest token required to book insurance."
5957
- }));
5958
- return yield* bookV9Insurance({
5959
- quote,
5960
- bookingNumber: booking.bookingNumber,
5961
- guestToken,
5962
- v1Client
5963
- });
6354
+ readPolicy: ({ policyNumber }) => withClients(({ v1Client }) => readV9InsurancePolicy({
6355
+ policyNumber,
6356
+ v1Client
6357
+ })),
6358
+ revokePolicy: ({ policyNumber, booking }) => withClients(({ v1Client }) => revokeV9InsurancePolicy({
6359
+ policyNumber,
6360
+ booking,
6361
+ v1Client
5964
6362
  }))
5965
6363
  };
5966
6364
  };
@@ -6177,7 +6575,7 @@ const parseV9SearchCursor = (cursor) => Effect.gen(function* () {
6177
6575
  return page;
6178
6576
  });
6179
6577
  const loadV9SearchRuntime = Effect.tryPromise({
6180
- try: () => import("./search-pFLiI6QI.mjs"),
6578
+ try: () => import("./search-Buua-PAS.mjs"),
6181
6579
  catch: (cause) => new CoreSDKError({
6182
6580
  source: "v9",
6183
6581
  operation: "v9.search.runtime",
@@ -6607,12 +7005,13 @@ const makeV9VoucherApi = ({ config, options }) => {
6607
7005
  };
6608
7006
  //#endregion
6609
7007
  //#region src/legacy-v9/parser/filter/to-options.ts
6610
- const toOptions = ({ stableFilter, label }) => {
7008
+ /** Count filters ("1 bedroom", "2 bedrooms") take the label in both plural forms. */
7009
+ const toOptions = ({ stableFilter, countLabels }) => {
6611
7010
  if (stableFilter.type === "InputFilter" && stableFilter.group === "rooms" && stableFilter.display_type === "number") return Array.from({ length: 10 }, (_, index) => {
6612
7011
  const value = String(index + 1);
6613
7012
  return {
6614
7013
  value,
6615
- label: `${value} ${label}`
7014
+ label: `${value} ${index === 0 ? countLabels.one : countLabels.other}`
6616
7015
  };
6617
7016
  });
6618
7017
  };
@@ -6633,20 +7032,23 @@ const toType = ({ stableFilter }) => {
6633
7032
  //#endregion
6634
7033
  //#region src/legacy-v9/parser/filter/to-get-filters-output-item.ts
6635
7034
  const toGetFiltersOutputItem = ({ locale, stableFilter, translations }) => Effect.gen(function* () {
6636
- const label = yield* translations.translate(locale, `filter.${stableFilter.key}.label`);
7035
+ const labelKey = `filter.${stableFilter.key}.label`;
7036
+ const label = yield* translations.translate(locale, labelKey);
7037
+ const countLabels = {
7038
+ one: yield* translations.translate(locale, toCountLabelKey(labelKey, 1), label),
7039
+ other: yield* translations.translate(locale, toCountLabelKey(labelKey, 2), label)
7040
+ };
7041
+ const options = toOptions({
7042
+ stableFilter,
7043
+ countLabels
7044
+ });
6637
7045
  const category = yield* translations.translate(locale, `filterGroup.${stableFilter.group}.label`);
6638
7046
  return {
6639
7047
  searchParameterQueryKey: toSearchParameterQueryKey({ stableFilter }),
6640
7048
  label,
6641
7049
  category,
6642
7050
  type: toType({ stableFilter }),
6643
- ...toOptions({
6644
- stableFilter,
6645
- label
6646
- }) ? { options: toOptions({
6647
- stableFilter,
6648
- label
6649
- }) } : {}
7051
+ ...options ? { options } : {}
6650
7052
  };
6651
7053
  });
6652
7054
  //#endregion
@@ -6953,6 +7355,61 @@ const checkV9HubFilters = ({ required, hubFilters }) => {
6953
7355
  };
6954
7356
  };
6955
7357
  //#endregion
7358
+ //#region src/legacy-v9/static/description-fallbacks.ts
7359
+ /** The rental and facility data attributes the German comparison reads. */
7360
+ const DESCRIPTION_DATA_ATTRIBUTES = [
7361
+ "intro",
7362
+ "headline",
7363
+ "description",
7364
+ "altDescription",
7365
+ "arrivalInfo",
7366
+ "departureInfo",
7367
+ "locationDescription",
7368
+ "directions"
7369
+ ];
7370
+ /**
7371
+ * The German text of each description field, from data the hub sent for `language: "de"`: a
7372
+ * string as sent, or the German entry of a localized record. Never another language — the
7373
+ * rental parser falls back to English and then to any text, which would make an English-only
7374
+ * text the German baseline and mark it as German.
7375
+ */
7376
+ const toGermanDescription = (known) => {
7377
+ const description = {};
7378
+ for (const field of DESCRIPTION_DATA_ATTRIBUTES) {
7379
+ const value = known[field];
7380
+ const text = typeof value === "object" && value !== null ? [value["de-DE"], value["de"]].find((entry) => typeof entry === "string" && entry.length > 0) : value;
7381
+ if (typeof text === "string" && text.length > 0) description[field] = text;
7382
+ }
7383
+ return description;
7384
+ };
7385
+ /**
7386
+ * The hub answers a missing translation with the German text, without saying so. A field whose
7387
+ * text equals its German text is therefore German.
7388
+ */
7389
+ const toFallbacks = (description, german) => {
7390
+ if (description === void 0 || german === void 0) return void 0;
7391
+ const fallbacks = {};
7392
+ for (const field of DESCRIPTION_DATA_ATTRIBUTES) {
7393
+ const text = description[field];
7394
+ if (text !== void 0 && text === german[field]) fallbacks[field] = "de-DE";
7395
+ }
7396
+ return Object.keys(fallbacks).length > 0 ? fallbacks : void 0;
7397
+ };
7398
+ /** Marks the description fields of a rental and its property that the hub served in German. */
7399
+ const withDescriptionFallbacks = (rental, german) => {
7400
+ const fallbacks = toFallbacks(rental.description, german.rentals.get(rental.id));
7401
+ const property = rental.property;
7402
+ const propertyFallbacks = property === void 0 ? void 0 : toFallbacks(property.description, german.facilities.get(property.id));
7403
+ return {
7404
+ ...rental,
7405
+ ...fallbacks === void 0 ? {} : { descriptionFallbacks: fallbacks },
7406
+ ...property === void 0 || propertyFallbacks === void 0 ? {} : { property: {
7407
+ ...property,
7408
+ descriptionFallbacks: propertyFallbacks
7409
+ } }
7410
+ };
7411
+ };
7412
+ //#endregion
6956
7413
  //#region src/legacy-v9/static/rentals.ts
6957
7414
  const DEFAULT_RENTAL_FACILITY_DATA_ATTRIBUTES = [
6958
7415
  "address",
@@ -6976,6 +7433,8 @@ const DEFAULT_RENTAL_FACILITY_DATA_ATTRIBUTES = [
6976
7433
  ];
6977
7434
  const DEFAULT_RENTAL_RATING_DATA_ATTRIBUTES = [];
6978
7435
  const RENTAL_BATCH_SIZE = 128;
7436
+ /** The language the hub falls back to when a text is missing in the requested one. */
7437
+ const GERMAN = "de";
6979
7438
  const HUB_FILTER_PURPOSES = {
6980
7439
  [V9_HUB_FACILITY_SCOPE_FILTER_KEY]: "searches cannot be limited to rentalScope",
6981
7440
  [V9_HUB_OBJECT_GROUP_SCOPE_FILTER_KEY]: "searches cannot be limited to rentalScope",
@@ -7007,7 +7466,7 @@ const orderRentalsById = ({ rentalIds, rentals, missing }) => {
7007
7466
  });
7008
7467
  };
7009
7468
  const loadV9RentalsRuntime = Effect.tryPromise({
7010
- try: () => import("./rentals-BxkYXAVn.mjs"),
7469
+ try: () => import("./rentals-BIL52z4o.mjs"),
7011
7470
  catch: (cause) => new CoreSDKError({
7012
7471
  source: "v9",
7013
7472
  operation: "v9.rentals.runtime",
@@ -7110,7 +7569,7 @@ const makeV9RentalsApi = ({ config, options }) => {
7110
7569
  ...rental,
7111
7570
  voffice_feedbacks: feedbacksByRentalId.get(rental.voffice_id) ?? null
7112
7571
  }));
7113
- return yield* Effect.all(scopedRentals.map((rental) => toRentalRentalsOutput({
7572
+ const items = yield* Effect.all(scopedRentals.map((rental) => toRentalRentalsOutput({
7114
7573
  rental,
7115
7574
  locale,
7116
7575
  translations,
@@ -7121,6 +7580,43 @@ const makeV9RentalsApi = ({ config, options }) => {
7121
7580
  v9PropertyHighlightSources: options.v9PropertyHighlightSources,
7122
7581
  reviews: options.v9Reviews
7123
7582
  })));
7583
+ if (language === GERMAN) return items;
7584
+ const germanDescriptions = yield* loadGermanDescriptions(scopedRentals.map((rental) => rental.voffice_id));
7585
+ return items.map((item) => withDescriptionFallbacks(item, germanDescriptions));
7586
+ });
7587
+ /**
7588
+ * The German texts of the rentals and their facilities. The hub serves German where the
7589
+ * requested language has no text and does not say so; `withDescriptionFallbacks` compares.
7590
+ * The queries select the texts alone, so the comparison costs no image or rating data.
7591
+ */
7592
+ const loadGermanDescriptions = (rentalIds) => Effect.gen(function* () {
7593
+ const { facilityTextsQuery, parseVofficeFacilityData, parseVofficeUnitData, rentalTextsQuery } = yield* loadV9RentalsRuntime;
7594
+ const textAttributes = [...DESCRIPTION_DATA_ATTRIBUTES];
7595
+ const facilitiesByGroup = config.facilityObjectGroupRelationAttributeId !== void 0;
7596
+ const rentals = /* @__PURE__ */ new Map();
7597
+ const facilities = /* @__PURE__ */ new Map();
7598
+ for (let offset = 0; offset < rentalIds.length; offset += RENTAL_BATCH_SIZE) {
7599
+ const textsData = yield* graphql.execute(rentalTextsQuery, {
7600
+ language: GERMAN,
7601
+ voffice_ids: rentalIds.slice(offset, offset + RENTAL_BATCH_SIZE),
7602
+ textAttributes
7603
+ });
7604
+ for (const rental of textsData.all) {
7605
+ rentals.set(String(rental.voffice_id), toGermanDescription(parseVofficeUnitData(rental.data).known));
7606
+ if (!facilitiesByGroup && rental.voffice_facility != null) facilities.set(rental.voffice_facility.id, toGermanDescription(parseVofficeFacilityData(rental.voffice_facility.data).known));
7607
+ }
7608
+ }
7609
+ if (facilitiesByGroup) {
7610
+ const facilitiesData = yield* graphql.execute(facilityTextsQuery, {
7611
+ language: GERMAN,
7612
+ textAttributes
7613
+ });
7614
+ for (const facility of facilitiesData.facilities) facilities.set(facility.id, toGermanDescription(parseVofficeFacilityData(facility.data).known));
7615
+ }
7616
+ return {
7617
+ rentals,
7618
+ facilities
7619
+ };
7124
7620
  });
7125
7621
  const requiredHubFilterKeys = toV9SdkOwnedHubFilterKeys({
7126
7622
  config,
@@ -7276,6 +7772,10 @@ function createWebsiteSDK({ config, options }) {
7276
7772
  selectInsurancePayment: quote.selectInsurancePayment,
7277
7773
  bookInsurance: quote.bookInsurance
7278
7774
  },
7775
+ insurance: {
7776
+ readPolicy: quote.readPolicy,
7777
+ revokePolicy: quote.revokePolicy
7778
+ },
7279
7779
  booking: {
7280
7780
  book: booking.book,
7281
7781
  submitPaymentOption