@v-office/website-sdk 2.38.0 → 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.
@@ -1830,7 +1830,13 @@ var core_default$1 = {
1830
1830
  "voucher.validate.reason.unknown": "Dieser Gutscheincode ist unbekannt.",
1831
1831
  "voucher.validate.reason.stay_too_short": "Der Aufenthalt ist für diesen Gutscheincode zu kurz.",
1832
1832
  "voucher.validate.reason.outside_booking_window": "Der gewählte Anreisetag liegt außerhalb des Buchungszeitraums dieses Gutscheincodes.",
1833
- "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"
1834
1840
  };
1835
1841
  //#endregion
1836
1842
  //#region translations/v9/de-DE/filter.json
@@ -2576,7 +2582,13 @@ var core_default = {
2576
2582
  "voucher.validate.reason.unknown": "This voucher code is unknown.",
2577
2583
  "voucher.validate.reason.stay_too_short": "The stay is too short for this voucher code.",
2578
2584
  "voucher.validate.reason.outside_booking_window": "The selected arrival date is outside this voucher code's booking window.",
2579
- "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"
2580
2592
  };
2581
2593
  //#endregion
2582
2594
  //#region translations/v9/en-US/filter.json
@@ -4517,10 +4529,10 @@ const RANGE_STATUS = {
4517
4529
  N: "unavailable",
4518
4530
  Q: "on_request"
4519
4531
  };
4520
- const toLocalDate = (date) => DateTime.formatIsoDate(date);
4532
+ const toLocalDate$1 = (date) => DateTime.formatIsoDate(date);
4521
4533
  const toRentalBlockedRanges = ({ rentalId, availability, availabilityUpdate }) => {
4522
4534
  const firstDay = DateTime.removeTime(DateTime.makeZonedUnsafe(availabilityUpdate, { timeZone: "Europe/Berlin" }));
4523
- const dayAt = (index) => toLocalDate(DateTime.add(firstDay, { days: index }));
4535
+ const dayAt = (index) => toLocalDate$1(DateTime.add(firstDay, { days: index }));
4524
4536
  const ranges = [];
4525
4537
  let runStart = 0;
4526
4538
  for (let index = 1; index <= availability.length; index++) {
@@ -4535,7 +4547,7 @@ const toRentalBlockedRanges = ({ rentalId, availability, availabilityUpdate }) =
4535
4547
  }
4536
4548
  return {
4537
4549
  rentalId,
4538
- availableFrom: toLocalDate(firstDay),
4550
+ availableFrom: toLocalDate$1(firstDay),
4539
4551
  ranges
4540
4552
  };
4541
4553
  };
@@ -4594,6 +4606,11 @@ const makeV9BlockedRangesApi = ({ config }) => {
4594
4606
  })) };
4595
4607
  };
4596
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
4597
4614
  //#region src/legacy-v9/parser/insurance/index.ts
4598
4615
  const urvInsuranceOptionAmounts = /* @__PURE__ */ new WeakMap();
4599
4616
  const urvInsuranceOptionAmountsByKey = /* @__PURE__ */ new Map();
@@ -4662,17 +4679,30 @@ const getErgoPlans = (raw) => {
4662
4679
  ];
4663
4680
  };
4664
4681
  const toSelectableErgoAvailablePlans = (plans) => {
4665
- const plansWithCode = plans.flatMap((entry) => {
4682
+ const products = /* @__PURE__ */ new Map();
4683
+ for (const entry of plans) {
4666
4684
  const plan = asRecord(entry);
4667
4685
  const planCode = firstString(plan.PlanCode);
4668
- 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] ??= {
4669
4691
  plan,
4670
- planCode
4671
- }];
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];
4672
4701
  });
4673
- const plansWithoutExcess = plansWithCode.filter(({ planCode }) => planCode.endsWith("O"));
4674
- if (plansWithoutExcess.length > 0) return plansWithoutExcess.map(({ plan }) => plan);
4675
- 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);
4676
4706
  };
4677
4707
  const getErgoPlanPrice = (plan) => {
4678
4708
  const premium = asRecord(plan.premium);
@@ -4742,11 +4772,28 @@ const toInsuranceDocuments = (value) => {
4742
4772
  });
4743
4773
  return documents.length === 0 ? void 0 : documents;
4744
4774
  };
4745
- 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 }) => {
4746
4785
  const record = asRecord(raw);
4747
4786
  const body = asRecord(record.body);
4748
4787
  const services = asRecord(record.PreContractualInformationServices ?? body.PreContractualInformationServices);
4749
- 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);
4750
4797
  };
4751
4798
  const toErgoInsuranceOptions = ({ featureLabels, infResourceLabel, locale, raw }) => getErgoPlans(raw).flatMap((entry) => {
4752
4799
  const plan = asRecord(entry);
@@ -4769,26 +4816,29 @@ const toErgoInsuranceOptions = ({ featureLabels, infResourceLabel, locale, raw }
4769
4816
  ...resources === void 0 ? {} : { resources }
4770
4817
  }];
4771
4818
  });
4772
- const toInsurancePreContractOutput = (raw) => {
4819
+ const toInsurancePreContractOutput = ({ raw, labels }) => {
4773
4820
  const record = asRecord(raw);
4774
4821
  const body = asRecord(record.body);
4775
4822
  const id = firstString(record.pre_contractual_information_id, body.pre_contractual_information_id, record.PreContractualInformationID, body.PreContractualInformationID);
4776
4823
  if (id === void 0) return { kind: "not_required" };
4777
- const documents = toInsuranceDocuments(record.documents ?? body.documents) ?? getErgoPreContractDocuments(raw);
4824
+ const documents = toInsuranceDocuments(record.documents ?? body.documents) ?? getErgoPreContractDocuments({
4825
+ raw,
4826
+ labels
4827
+ });
4778
4828
  return {
4779
4829
  kind: "created",
4780
4830
  id,
4781
4831
  ...documents === void 0 ? {} : { documents }
4782
4832
  };
4783
4833
  };
4784
- const toInsuranceBookingOutput = (raw) => {
4834
+ const toInsuranceBookingOutput = ({ raw, policyLabel }) => {
4785
4835
  const record = asRecord(raw);
4786
4836
  const body = asRecord(record.body);
4787
4837
  const policyDetail = asRecord(record.PolicyDetail ?? body.PolicyDetail);
4788
4838
  const policyNumber = firstString(record.policy_number, body.policy_number, policyDetail.PolicyNumber);
4789
4839
  if (policyNumber === void 0) return { kind: "not_required" };
4790
4840
  const documents = toInsuranceDocuments(record.documents ?? body.documents) ?? toInsuranceDocuments([{
4791
- label: "Policy",
4841
+ label: policyLabel,
4792
4842
  url: policyDetail.PolicyPrintURL
4793
4843
  }]);
4794
4844
  return {
@@ -4797,6 +4847,57 @@ const toInsuranceBookingOutput = (raw) => {
4797
4847
  ...documents === void 0 ? {} : { documents }
4798
4848
  };
4799
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
+ };
4800
4901
  //#endregion
4801
4902
  //#region src/legacy-v9/parser/booking/to-booking-service-lines.ts
4802
4903
  const hasSelectedAmount = (line) => (line.amount ?? 0) > 0;
@@ -5211,17 +5312,59 @@ const toStripePaymentInput = ({ bookResponse, input, paymentScheduleOption, stri
5211
5312
  };
5212
5313
  });
5213
5314
  //#endregion
5214
- //#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
+ };
5215
5357
  const toPostBookingInsurancePaymentOptions = ({ quote, sepaDebitLabel, sepaDebitDescription, canBookInsurance }) => {
5216
5358
  const insurance = quote.insurance;
5217
5359
  if (!canBookInsurance || insurance?.selected.kind !== "insurance") return [];
5218
- if (insurance.preContract.kind !== "created") return [];
5219
5360
  return insurance.paymentOptions.flatMap((option) => option.kind === "sepa_debit" ? [{
5220
5361
  ...option,
5221
5362
  label: sepaDebitLabel,
5222
5363
  description: sepaDebitDescription
5223
5364
  }] : []);
5224
5365
  };
5366
+ //#endregion
5367
+ //#region src/legacy-v9/live/booking.ts
5225
5368
  const book = ({ client, input, translations }) => Effect.gen(function* () {
5226
5369
  const bookingInput = yield* toBookingInput({ input });
5227
5370
  const language = bookingInput.reservation.customer.preferredLanguage ?? "de";
@@ -5316,12 +5459,18 @@ const book = ({ client, input, translations }) => Effect.gen(function* () {
5316
5459
  sepaDebitDescription: insuranceSepaDebitDescription,
5317
5460
  canBookInsurance: reservation.guestToken !== void 0
5318
5461
  });
5319
- return new BookingBookOutput({
5462
+ const output = new BookingBookOutput({
5320
5463
  bookingNumber,
5321
5464
  payment,
5322
5465
  insurancePaymentOptions: [...urvInsurancePaymentOptions, ...postBookingInsurancePaymentOptions],
5323
5466
  ...reservation.guestToken === void 0 ? {} : { guestToken: reservation.guestToken }
5324
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
+ });
5325
5474
  });
5326
5475
  const makeV9BookingApi = ({ config, options }) => {
5327
5476
  const translations = makeV9TranslationService(options.translationOverrides);
@@ -5443,6 +5592,25 @@ const makeV9ContactApi = ({ config, options }) => {
5443
5592
  }).pipe(Effect.provide(openApiClientLive))) };
5444
5593
  };
5445
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
5446
5614
  //#region src/legacy-v9/live/quote-insurance/quote-values.ts
5447
5615
  const getRawV9Quote = (quote) => {
5448
5616
  const context = getGuestQuoteBackendContext(quote);
@@ -5459,16 +5627,29 @@ const toQuoteTotalAmount = (quote) => {
5459
5627
  return sumQuoteLines(rawQuote?.mandatory) + sumQuoteLines(selectedQuoteLines(rawQuote?.optional)) + sumQuoteLines(selectedQuoteLines(rawQuote?.onsiteOptional));
5460
5628
  };
5461
5629
  const toQuoteCurrency = (quote) => getRawV9Quote(quote)?.currency ?? "EUR";
5462
- //#endregion
5463
- //#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
+ ];
5464
5642
  const toErgoNamePrefix = (salutation) => {
5465
- switch (salutation.trim().toUpperCase()) {
5466
- case "MR":
5467
- case "HERR": return "H";
5468
- case "MRS":
5469
- case "MS":
5470
- case "FRAU": return "F";
5471
- 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 "";
5472
5653
  }
5473
5654
  };
5474
5655
  const toErgoPerson = (traveler) => ({
@@ -5479,80 +5660,40 @@ const toErgoPerson = (traveler) => ({
5479
5660
  ...traveler.birthday === void 0 ? {} : { birthday: traveler.birthday }
5480
5661
  });
5481
5662
  const toStreetAndNumber = (address) => [address.street, address.housenumber].filter((part) => part !== void 0 && part.length > 0).join(" ");
5482
- const toErgoTripAndCustomerInput = ({ quote, customerInformation, travelers }) => ({
5483
- destination_country: customerInformation.destinationCountryCode,
5484
- start_date: getGuestQuoteInput(quote).period.start,
5485
- end_date: getGuestQuoteInput(quote).period.end,
5486
- total_amount: toQuoteTotalAmount(quote),
5487
- total_currency: toQuoteCurrency(quote),
5488
- total_decimals: 2,
5489
- guests: travelers.length,
5490
- policy_holder: travelers[0],
5491
- travelers,
5492
- address: {
5493
- street_and_nr: toStreetAndNumber(customerInformation.address),
5494
- city_name: customerInformation.address.city,
5495
- postal_code: customerInformation.address.postalcode,
5496
- country_code: customerInformation.address.countryCode
5497
- },
5498
- email: customerInformation.email,
5499
- mobile: customerInformation.mobile
5500
- });
5501
- //#endregion
5502
- //#region src/legacy-v9/live/quote-insurance/state.ts
5503
- const withInsurance = (quote, insurance) => withGuestQuoteInsurance({
5504
- quote,
5505
- insurance
5506
- });
5507
- const findInsuranceOption = (options, id) => options.find((option) => option.kind === "insurance" && option.id === id);
5508
- const toInsurancePaymentOptions = (option) => option.requiredInformation.kind === "travelers" ? [{
5509
- kind: "sepa_debit",
5510
- label: "SEPA direct debit"
5511
- }] : [];
5512
- const withRefreshedInsuranceOptions = ({ quote, options, destinationCountryCode }) => {
5513
- const nextDestinationCountryCode = destinationCountryCode ?? quote.insurance?.destinationCountryCode;
5514
- const nextInsurance = {
5515
- options,
5516
- selected: { kind: "none" },
5517
- preContract: { kind: "none_selected" },
5518
- paymentOptions: [],
5519
- ...nextDestinationCountryCode === void 0 ? {} : { destinationCountryCode: nextDestinationCountryCode }
5520
- };
5521
- const previousSelection = quote.insurance?.selected;
5522
- if (previousSelection?.kind !== "insurance") return nextInsurance;
5523
- const previousOption = findInsuranceOption(quote.insurance?.options ?? [], previousSelection.id);
5524
- const option = findInsuranceOption(options, previousSelection.id);
5525
- if (option === void 0) return nextInsurance;
5526
- 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);
5527
5670
  return {
5528
- ...nextInsurance,
5529
- selected: previousSelection,
5530
- preContract: option.requiredInformation.kind === "none" ? { kind: "not_required" } : { kind: "none_selected" },
5531
- paymentOptions: toInsurancePaymentOptions(option),
5532
- ...nextDestinationCountryCode === void 0 ? {} : { destinationCountryCode: nextDestinationCountryCode },
5533
- ...quote.insurance?.customerInformation === void 0 ? {} : { customerInformation: quote.insurance.customerInformation },
5534
- ...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
5535
5693
  };
5536
- };
5537
- const selectedInsuranceOption = (quote) => {
5538
- const insurance = quote.insurance;
5539
- if (insurance?.selected.kind !== "insurance") return void 0;
5540
- const selectedInsuranceId = insurance.selected.id;
5541
- return findInsuranceOption(insurance.options, selectedInsuranceId);
5542
- };
5694
+ });
5543
5695
  //#endregion
5544
5696
  //#region src/legacy-v9/live/quote-insurance.ts
5545
- const toInsuranceError = (message) => (cause) => new CoreSDKError({
5546
- source: "v9",
5547
- operation: "v9.insurance",
5548
- message,
5549
- cause
5550
- });
5551
- const failInsurance = (message) => Effect.fail(new CoreSDKError({
5552
- source: "v9",
5553
- operation: "v9.insurance",
5554
- message
5555
- }));
5556
5697
  /** The quote's insurance block; a quote that never loaded one offers none. */
5557
5698
  const currentInsuranceOf = ({ quote, translations }) => quote.insurance === void 0 ? toNotOfferedInsurance({
5558
5699
  translations,
@@ -5590,6 +5731,22 @@ const toErgoInsuranceFeatureLabelsFromTranslations = ({ locale, translations })
5590
5731
  withoutDeductible
5591
5732
  };
5592
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
+ });
5593
5750
  const getSettingString = (settings, key) => {
5594
5751
  const value = settings?.[key];
5595
5752
  return typeof value === "string" ? value : void 0;
@@ -5617,17 +5774,31 @@ const toConfiguredInsuranceSettings = (setup) => {
5617
5774
  default: return disabled;
5618
5775
  }
5619
5776
  };
5620
- const getErgoTravelers = (quote) => {
5777
+ const getSelectedTravelers = (quote) => {
5621
5778
  const selected = quote.insurance?.selected;
5622
5779
  if (selected?.kind !== "insurance" || selected.travelers === void 0) return failInsurance("ERGO insurance requires traveler information before pre-contract creation.");
5623
- const travelers = selected.travelers.map(toErgoPerson);
5624
- if (travelers.length > 0) return Effect.succeed(travelers);
5780
+ if (selected.travelers.length > 0) return Effect.succeed(selected.travelers);
5625
5781
  return failInsurance("ERGO insurance requires at least one traveler.");
5626
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
+ };
5627
5794
  const refreshErgoInsuranceOptions = ({ quote, destinationCountryCode, translations, v1Client }) => Effect.gen(function* () {
5628
5795
  const input = getGuestQuoteInput(quote);
5796
+ if (toGuestCount(quote) > 9) return yield* toNotOfferedInsurance({
5797
+ translations,
5798
+ locale: input.locale
5799
+ });
5629
5800
  const body = {
5630
- destination_country: destinationCountryCode ?? quote.insurance?.destinationCountryCode ?? quote.insurance?.customerInformation?.destinationCountryCode ?? "DE",
5801
+ destination_country: "DE",
5631
5802
  start_date: input.period.start,
5632
5803
  end_date: input.period.end,
5633
5804
  traveler_count: Math.max(toGuestCount(quote), 1),
@@ -5636,7 +5807,10 @@ const refreshErgoInsuranceOptions = ({ quote, destinationCountryCode, translatio
5636
5807
  total_decimals: 2,
5637
5808
  list_type: "DE_TID"
5638
5809
  };
5639
- const result = yield* v1Client.execute("searchErgoTravelCancellationInsurancePlans", { body }).pipe(Effect.mapError(toInsuranceError("Failed to load ERGO insurance plans.")));
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
+ })));
5640
5814
  const noInsuranceOption = yield* toNoInsuranceOption({
5641
5815
  translations,
5642
5816
  locale: input.locale,
@@ -5647,14 +5821,19 @@ const refreshErgoInsuranceOptions = ({ quote, destinationCountryCode, translatio
5647
5821
  locale: input.locale,
5648
5822
  translations
5649
5823
  });
5824
+ const sepaDebitLabel = yield* toSepaDebitLabel({
5825
+ locale: input.locale,
5826
+ translations
5827
+ });
5650
5828
  return withRefreshedInsuranceOptions({
5651
5829
  quote,
5830
+ sepaDebitLabel,
5652
5831
  ...destinationCountryCode === void 0 ? {} : { destinationCountryCode },
5653
5832
  options: [noInsuranceOption, ...toErgoInsuranceOptions({
5654
5833
  featureLabels,
5655
5834
  infResourceLabel,
5656
5835
  locale: input.locale,
5657
- raw: result.raw
5836
+ raw: result
5658
5837
  })]
5659
5838
  });
5660
5839
  });
@@ -5683,8 +5862,13 @@ const refreshUrvInsuranceOptions = ({ quote, mode, translations, v0Client }) =>
5683
5862
  locale: input.locale,
5684
5863
  translations
5685
5864
  });
5865
+ const sepaDebitLabel = yield* toSepaDebitLabel({
5866
+ locale: input.locale,
5867
+ translations
5868
+ });
5686
5869
  return withRefreshedInsuranceOptions({
5687
5870
  quote,
5871
+ sepaDebitLabel,
5688
5872
  options: [noInsuranceOption, ...toUrvInsuranceOptions({
5689
5873
  locale: input.locale,
5690
5874
  plans: result.raw.plans ?? [],
@@ -5692,26 +5876,32 @@ const refreshUrvInsuranceOptions = ({ quote, mode, translations, v0Client }) =>
5692
5876
  })]
5693
5877
  });
5694
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
+ });
5695
5884
  const refreshV9InsuranceOptions = ({ quote, destinationCountryCode, translations, v0Client, v1Client }) => Effect.gen(function* () {
5696
- const setup = yield* v1Client.execute("getSetup", { query: { include: "booking,search,common" } }).pipe(Effect.mapError(toInsuranceError("Failed to load v9 insurance settings.")));
5697
- 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" }))));
5698
5891
  switch (settings.provider) {
5699
5892
  case "ergo": return withInsurance(quote, yield* refreshErgoInsuranceOptions({
5700
5893
  quote,
5701
5894
  destinationCountryCode,
5702
5895
  translations,
5703
5896
  v1Client
5704
- }));
5897
+ }).pipe(Effect.catch(notOfferedAfter("Insurance is not offered: loading ERGO plans failed."))));
5705
5898
  case "urv": return withInsurance(quote, yield* refreshUrvInsuranceOptions({
5706
5899
  quote,
5707
5900
  mode: settings.mode,
5708
5901
  translations,
5709
5902
  v0Client
5710
- }));
5711
- case "none": return withInsurance(quote, yield* toNotOfferedInsurance({
5712
- translations,
5713
- locale: getGuestQuoteInput(quote).locale
5714
- }));
5903
+ }).pipe(Effect.catch(notOfferedAfter("Insurance is not offered: loading URV plans failed."))));
5904
+ case "none": return withInsurance(quote, yield* notOffered);
5715
5905
  }
5716
5906
  });
5717
5907
  const selectV9Insurance = ({ quote, selection, translations }) => Effect.gen(function* () {
@@ -5727,6 +5917,11 @@ const selectV9Insurance = ({ quote, selection, translations }) => Effect.gen(fun
5727
5917
  });
5728
5918
  const option = findInsuranceOption(currentInsurance.options, selection.id);
5729
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
+ });
5730
5925
  return withInsurance(quote, {
5731
5926
  ...currentInsurance,
5732
5927
  selected: option.requiredInformation.kind === "none" ? {
@@ -5734,10 +5929,88 @@ const selectV9Insurance = ({ quote, selection, translations }) => Effect.gen(fun
5734
5929
  id: selection.id
5735
5930
  } : selection,
5736
5931
  preContract: option.requiredInformation.kind === "none" ? { kind: "not_required" } : { kind: "none_selected" },
5737
- paymentOptions: toInsurancePaymentOptions(option)
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
5738
6010
  });
6011
+ return documents === void 0 ? yield* failInsurance("ERGO returned no pre-contract documents.") : documents;
5739
6012
  });
5740
- const createV9InsurancePreContract = ({ quote, customerInformation, translations, v1Client }) => Effect.gen(function* () {
6013
+ const createV9InsurancePreContract = ({ quote, booking, translations, v0Client, v1Client }) => Effect.gen(function* () {
5741
6014
  const option = selectedInsuranceOption(quote);
5742
6015
  const currentInsurance = yield* currentInsuranceOf({
5743
6016
  quote,
@@ -5746,32 +6019,95 @@ const createV9InsurancePreContract = ({ quote, customerInformation, translations
5746
6019
  if (option === void 0) return withInsurance(quote, currentInsurance);
5747
6020
  if (option.requiredInformation.kind === "none") return withInsurance(quote, {
5748
6021
  ...currentInsurance,
5749
- customerInformation,
5750
6022
  preContract: { kind: "not_required" }
5751
6023
  });
5752
- const travelers = yield* getErgoTravelers(quote);
5753
- const body = {
5754
- ...toErgoTripAndCustomerInput({
5755
- quote,
5756
- customerInformation,
5757
- travelers
5758
- }),
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,
5759
6078
  plan_code: option.id
5760
- };
5761
- const result = yield* v1Client.execute("createErgoPreContract", { body }).pipe(Effect.mapError(toInsuranceError("Failed to create ERGO pre-contract information.")));
5762
- 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
+ });
5763
6087
  if (preContract.kind !== "created") return yield* Effect.fail(new CoreSDKError({
5764
6088
  source: "v9",
5765
6089
  operation: "v9.insurance",
5766
6090
  message: "ERGO pre-contract response did not contain a pre-contract ID.",
5767
- cause: result.raw
6091
+ cause: created
5768
6092
  }));
5769
- return withInsurance(quote, {
5770
- ...currentInsurance,
5771
- customerInformation,
5772
- destinationCountryCode: customerInformation.destinationCountryCode,
5773
- preContract,
5774
- 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
6101
+ });
6102
+ const documents = preContract.documents ?? (yield* readPreContractDocuments({
6103
+ preContractId: preContract.id,
6104
+ email: tripAndCustomer.email,
6105
+ labels,
6106
+ v1Client
6107
+ }));
6108
+ return withPreContract({
6109
+ ...preContract,
6110
+ documents
5775
6111
  });
5776
6112
  });
5777
6113
  const selectV9InsurancePayment = ({ quote, paymentInformation, translations }) => Effect.map(currentInsuranceOf({
@@ -5781,20 +6117,33 @@ const selectV9InsurancePayment = ({ quote, paymentInformation, translations }) =
5781
6117
  ...currentInsurance,
5782
6118
  paymentInformation
5783
6119
  }));
5784
- const bookV9Insurance = ({ quote, bookingNumber, guestToken, v1Client }) => Effect.gen(function* () {
6120
+ const bookV9Insurance = ({ quote, booking, translations, v1Client }) => Effect.gen(function* () {
5785
6121
  const option = selectedInsuranceOption(quote);
5786
6122
  const insurance = quote.insurance;
5787
6123
  if (option === void 0 || insurance === void 0) return { kind: "none_selected" };
5788
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
+ };
5789
6138
  if (insurance.preContract.kind !== "created") return yield* failInsurance("ERGO insurance requires created pre-contract information before booking.");
5790
- if (insurance.customerInformation === void 0) return yield* failInsurance("ERGO insurance booking requires customer information.");
5791
6139
  if (insurance.paymentInformation?.kind !== "sepa_debit") return yield* failInsurance("ERGO insurance booking requires SEPA payment information.");
5792
- const travelers = yield* getErgoTravelers(quote);
6140
+ const details = yield* requireBookingDetails(booking);
6141
+ const travelers = yield* getSelectedTravelers(quote);
5793
6142
  const body = {
5794
- ...toErgoTripAndCustomerInput({
6143
+ ...yield* toErgoTripAndCustomerInput({
5795
6144
  quote,
5796
- customerInformation: insurance.customerInformation,
5797
- travelers
6145
+ customer: details.customer,
6146
+ travelers: travelers.map(toErgoPerson)
5798
6147
  }),
5799
6148
  plan_code: option.id,
5800
6149
  pre_contractual_information_id: insurance.preContract.id,
@@ -5803,24 +6152,71 @@ const bookV9Insurance = ({ quote, bookingNumber, guestToken, v1Client }) => Effe
5803
6152
  ...insurance.paymentInformation.bic === void 0 ? {} : { bic: insurance.paymentInformation.bic }
5804
6153
  }
5805
6154
  };
5806
- const result = yield* v1Client.execute("bookErgoTravelCancellationInsurance", { body }).pipe(Effect.mapError(toInsuranceError("Failed to book ERGO insurance.")));
5807
- 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
+ });
5808
6164
  if (bookingOutput.kind !== "booked") return yield* Effect.fail(new CoreSDKError({
5809
6165
  source: "v9",
5810
6166
  operation: "v9.insurance",
5811
6167
  message: "ERGO insurance booking response did not contain a policy number.",
5812
- cause: result.raw
6168
+ cause: result
5813
6169
  }));
5814
- const persistenceBody = {
5815
- guest_token: guestToken,
5816
- booking_number: bookingNumber,
5817
- travel_insurance_number: bookingOutput.policyNumber,
5818
- pre_contractual_information_id: insurance.preContract.id,
5819
- selected_plan_code: option.id
5820
- };
5821
- 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
+ });
5822
6180
  return bookingOutput;
5823
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
+ });
5824
6220
  //#endregion
5825
6221
  //#region src/legacy-v9/live/quote.ts
5826
6222
  const loadQuoteRuntime = Effect.tryPromise({
@@ -5938,29 +6334,31 @@ const makeV9QuoteApi = ({ config, options }) => {
5938
6334
  ...input,
5939
6335
  translations
5940
6336
  })),
5941
- createInsurancePreContract: ({ quote, customerInformation }) => withClients(({ v1Client }) => createV9InsurancePreContract({
6337
+ createInsurancePreContract: ({ quote, booking }) => withClients(({ v0Client, v1Client }) => createV9InsurancePreContract({
5942
6338
  quote,
5943
- customerInformation,
6339
+ booking,
5944
6340
  translations,
6341
+ v0Client,
5945
6342
  v1Client
5946
6343
  })),
5947
6344
  selectInsurancePayment: (input) => withClients(() => selectV9InsurancePayment({
5948
6345
  ...input,
5949
6346
  translations
5950
6347
  })),
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
- });
6348
+ bookInsurance: ({ quote, booking }) => withClients(({ v1Client }) => bookV9Insurance({
6349
+ quote,
6350
+ booking,
6351
+ translations,
6352
+ v1Client
6353
+ })),
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-DqdRIJwF.mjs"),
6578
+ try: () => import("./search-Buua-PAS.mjs"),
6181
6579
  catch: (cause) => new CoreSDKError({
6182
6580
  source: "v9",
6183
6581
  operation: "v9.search.runtime",
@@ -7068,7 +7466,7 @@ const orderRentalsById = ({ rentalIds, rentals, missing }) => {
7068
7466
  });
7069
7467
  };
7070
7468
  const loadV9RentalsRuntime = Effect.tryPromise({
7071
- try: () => import("./rentals-BsHvdwQt.mjs"),
7469
+ try: () => import("./rentals-BIL52z4o.mjs"),
7072
7470
  catch: (cause) => new CoreSDKError({
7073
7471
  source: "v9",
7074
7472
  operation: "v9.rentals.runtime",
@@ -7374,6 +7772,10 @@ function createWebsiteSDK({ config, options }) {
7374
7772
  selectInsurancePayment: quote.selectInsurancePayment,
7375
7773
  bookInsurance: quote.bookInsurance
7376
7774
  },
7775
+ insurance: {
7776
+ readPolicy: quote.readPolicy,
7777
+ revokePolicy: quote.revokePolicy
7778
+ },
7377
7779
  booking: {
7378
7780
  book: booking.book,
7379
7781
  submitPaymentOption