@v-office/website-sdk 2.28.1 → 2.30.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/README.md +8 -0
  2. package/dist/cli.mjs +406 -12
  3. package/dist/{client-EtS0Qm3i.mjs → client-CKVwzIQ4.mjs} +381 -53
  4. package/dist/index.d.mts +45 -6
  5. package/dist/index.mjs +1 -1
  6. package/dist/instructions/CHANGELOG.md +2 -0
  7. package/dist/instructions/MIGRATION.md +2 -0
  8. package/dist/instructions/README.md +3 -2
  9. package/dist/instructions/availability.md +22 -2
  10. package/dist/instructions/creation.md +35 -4
  11. package/dist/instructions/custom-attributes.md +2 -2
  12. package/dist/instructions/filter.md +5 -3
  13. package/dist/instructions/quote.md +1 -1
  14. package/dist/instructions/rentals.md +36 -0
  15. package/dist/instructions/search.md +220 -6
  16. package/dist/instructions/versions/2.29.0/CHANGELOG.md +62 -0
  17. package/dist/instructions/versions/2.29.0/MIGRATION.md +97 -0
  18. package/dist/instructions/versions/2.30.0/CHANGELOG.md +40 -0
  19. package/dist/instructions/versions/2.30.0/MIGRATION.md +30 -0
  20. package/dist/{v9-data-C3SWtDGs.mjs → operations-CfjJjdrw.mjs} +3122 -1
  21. package/dist/{rentals-B4g91vwW.mjs → rentals-cmqp5dTw.mjs} +4 -5
  22. package/dist/{search-B-lvOmXL.mjs → search-DPsBki_9.mjs} +6 -5
  23. package/dist/{to-rental-highlights-BL5m3Uen.mjs → to-rental-highlights-D7oepO6s.mjs} +1 -1
  24. package/dist/translations/v9/de-DE/core.json +8 -1
  25. package/dist/translations/v9/en-US/core.json +8 -1
  26. package/instructions/CHANGELOG.md +2 -0
  27. package/instructions/MIGRATION.md +2 -0
  28. package/instructions/README.md +3 -2
  29. package/instructions/availability.md +22 -2
  30. package/instructions/creation.md +35 -4
  31. package/instructions/custom-attributes.md +2 -2
  32. package/instructions/filter.md +5 -3
  33. package/instructions/quote.md +1 -1
  34. package/instructions/rentals.md +36 -0
  35. package/instructions/search.md +220 -6
  36. package/instructions/versions/2.29.0/CHANGELOG.md +62 -0
  37. package/instructions/versions/2.29.0/MIGRATION.md +97 -0
  38. package/instructions/versions/2.29.0/release.json +3 -0
  39. package/instructions/versions/2.30.0/CHANGELOG.md +40 -0
  40. package/instructions/versions/2.30.0/MIGRATION.md +30 -0
  41. package/instructions/versions/2.30.0/release.json +3 -0
  42. package/package.json +6 -4
  43. package/dist/operations-DwURbo0b.mjs +0 -2850
package/README.md CHANGED
@@ -91,6 +91,9 @@ sdk.static.filter.getFilters(input);
91
91
  sdk.static.documents.getTermsAndPrivacyPolicy(input);
92
92
 
93
93
  sdk.live.search.search(input);
94
+ // v9 only:
95
+ sdk.live.rentals.getRentalsByIds(input);
96
+ sdk.live.voucher.validate(input);
94
97
  sdk.live.availability.getInitialAvailability(input);
95
98
  sdk.live.availability.getStartDateSelectedAvailability(input);
96
99
  sdk.live.quote.quote(input);
@@ -122,6 +125,9 @@ Quote mutation helpers are available under `sdk.live.quote`:
122
125
  website-sdk --backend v10 rentals --locale de-DE
123
126
  website-sdk --backend v9 filters --locale en-US
124
127
  website-sdk --backend v10 search --locale de-DE --query "adults=2"
128
+ website-sdk --backend v9 rentals-by-ids --locale de-DE --rental-ids 12,34
129
+ website-sdk --backend v9 voucher validate --code SUMMER26
130
+ website-sdk --backend v9 hub-filters request --object-group
125
131
  ```
126
132
 
127
133
  The CLI can read config from environment variables or from JSON files:
@@ -144,6 +150,8 @@ For v9, environment configuration uses:
144
150
  - `HUB_API_KEY`
145
151
  - `IMAGE_PROXY_BASE_URL`
146
152
  - `HUB_V0_API_BASE_URL` optional
153
+ - `HUB_RENTAL_SCOPE_PROPERTY_KIND` optional, `facility` or `objectGroup`
154
+ - `HUB_RENTAL_IDS_SEARCH` optional, `true` or `false`
147
155
 
148
156
  ## Migration From Legacy
149
157
 
package/dist/cli.mjs CHANGED
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { Ht as defineWebsiteSDKOptions, Wt as defineV9PropertyHighlightSourcesFromUnknown, c as makeV9GraphQLClient, d as makeV0OpenApiClientFetchLive, l as V0OpenApiClient, t as createWebsiteSDK } from "./client-EtS0Qm3i.mjs";
3
- import { c as parseVofficeRatingData } from "./v9-data-C3SWtDGs.mjs";
4
- import { s as rentalsAllWithoutFeedbacksQuery } from "./operations-DwURbo0b.mjs";
2
+ import { $t as V9_HUB_OBJECT_GROUP_SCOPE_FILTER_KEY, Jt as defineV9PropertyHighlightSourcesFromUnknown, Kt as defineWebsiteSDKOptions, Qt as V9_HUB_OBJECT_GROUP_FILTER_KEY, Xt as V9_HUB_FACILITY_SCOPE_FILTER_KEY, Zt as V9_HUB_FACILITY_SEARCH_FILTER_KEY, en as V9_HUB_OFFERS_FILTER_KEY, f as makeV9GraphQLClient, h as makeV0OpenApiClientFetchLive, i as toV9SdkOwnedHubFilterKeys, n as checkV9HubFilters, nn as V9_HUB_RENTAL_IDS_FILTER_KEY, p as V0OpenApiClient, r as toV9RequiredHubFilterKeys, rn as V9_SDK_OWNED_HUB_FILTER_KEYS, t as createWebsiteSDK, tn as V9_HUB_OFFER_FILTER_KEY } from "./client-CKVwzIQ4.mjs";
3
+ import { _ as parseVofficeRatingData, i as hubFiltersQuery, l as rentalsAllWithoutFeedbacksQuery } from "./operations-CfjJjdrw.mjs";
5
4
  import { SearchSearchSortSchema, defineCustomAttributesFromUnknown } from "@v-office/sdk-core";
6
5
  import { ByteSize, Console, Effect, FileSystem, Layer, Option, Path, Schema, Stdio, Terminal } from "effect";
7
6
  import { Command, Flag } from "effect/unstable/cli";
@@ -18,7 +17,7 @@ var CLICheckFailed = class extends Error {
18
17
  const toCLIError = (message, cause) => cause instanceof Error ? new CLICheckFailed(`${message}: ${cause.message}`, { cause }) : new CLICheckFailed(message, { cause });
19
18
  //#endregion
20
19
  //#region package.json
21
- var version = "2.28.1";
20
+ var version = "2.30.0";
22
21
  //#endregion
23
22
  //#region src/cli/output.ts
24
23
  const toJson = (value) => Effect.try({
@@ -71,7 +70,9 @@ const WebsiteV9CLIConfigSchema = Schema.Struct({
71
70
  v0ApiBaseUrl: Schema.optionalKey(NonBlankStringSchema),
72
71
  v1ApiBaseUrl: Schema.optionalKey(NonBlankStringSchema),
73
72
  rentalDataAttributes: Schema.optionalKey(Schema.Array(NonBlankStringSchema)),
74
- facilityObjectGroupRelationAttributeId: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0)))
73
+ facilityObjectGroupRelationAttributeId: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0))),
74
+ rentalScopePropertyKind: Schema.optionalKey(Schema.Literals(["facility", "objectGroup"])),
75
+ rentalIdsSearch: Schema.optionalKey(Schema.Boolean)
75
76
  });
76
77
  const WebsiteV10CLIConfigSchema = Schema.Struct({
77
78
  backend: Schema.optionalKey(Schema.Literal("v10")),
@@ -83,6 +84,11 @@ const WebsiteV10CLIConfigSchema = Schema.Struct({
83
84
  const WebsiteSDKCLIConfigSchema = Schema.Union([WebsiteV9CLIConfigSchema, WebsiteV10CLIConfigSchema]);
84
85
  const decodeCLIConfig = (input, path) => Schema.decodeUnknownEffect(WebsiteSDKCLIConfigSchema)(input).pipe(Effect.mapError((cause) => toCLIError(`Invalid Website SDK config file at ${path}. Expected a complete v9 or v10 config`, cause)));
85
86
  const getRequiredEnv = (name) => Effect.sync(() => process.env[name]).pipe(Effect.flatMap((value) => value === void 0 || value.trim().length === 0 ? Effect.fail(new CLICheckFailed(`Missing required environment variable ${name}.`)) : Effect.succeed(value)));
87
+ const getOptionalEnvChoice = ({ name, choices }) => Effect.sync(() => process.env[name]?.trim()).pipe(Effect.flatMap((value) => {
88
+ if (value === void 0 || value.length === 0) return Effect.succeed(void 0);
89
+ const choice = choices.find((candidate) => candidate === value);
90
+ return choice === void 0 ? Effect.fail(new CLICheckFailed(`Environment variable ${name} must be one of ${choices.join(", ")}, got "${value}".`)) : Effect.succeed(choice);
91
+ }));
86
92
  /**
87
93
  * Registry-shaped options files hold authored inputs rather than trusted registry
88
94
  * snapshots. Build and validate both registries at this boundary.
@@ -118,6 +124,14 @@ const fromEnvironment = (root) => Effect.gen(function* () {
118
124
  const options = yield* readOptions(root, void 0);
119
125
  if (root.backend === "v9") {
120
126
  const v0ApiBaseUrl = process.env.HUB_V0_API_BASE_URL;
127
+ const rentalScopePropertyKind = yield* getOptionalEnvChoice({
128
+ name: "HUB_RENTAL_SCOPE_PROPERTY_KIND",
129
+ choices: ["facility", "objectGroup"]
130
+ });
131
+ const rentalIdsSearch = yield* getOptionalEnvChoice({
132
+ name: "HUB_RENTAL_IDS_SEARCH",
133
+ choices: ["true", "false"]
134
+ });
121
135
  return {
122
136
  config: {
123
137
  backend: "v9",
@@ -125,7 +139,9 @@ const fromEnvironment = (root) => Effect.gen(function* () {
125
139
  apiKey: yield* getRequiredEnv("HUB_API_KEY"),
126
140
  imageProxyBaseUrl: yield* getRequiredEnv("IMAGE_PROXY_BASE_URL"),
127
141
  v1ApiBaseUrl: yield* getRequiredEnv("HUB_V1_API_BASE_URL"),
128
- ...v0ApiBaseUrl === void 0 || v0ApiBaseUrl.length === 0 ? {} : { v0ApiBaseUrl }
142
+ ...v0ApiBaseUrl === void 0 || v0ApiBaseUrl.length === 0 ? {} : { v0ApiBaseUrl },
143
+ ...rentalScopePropertyKind === void 0 ? {} : { rentalScopePropertyKind },
144
+ ...rentalIdsSearch === void 0 ? {} : { rentalIdsSearch: rentalIdsSearch === "true" }
129
145
  },
130
146
  options
131
147
  };
@@ -222,7 +238,11 @@ const env = Command.make("env", {}, Effect.fn(function* () {
222
238
  "VOFFICE_LOCAL_DEV_ACCESS_TOKEN",
223
239
  "VOFFICE_IMAGE_BASE_URL"
224
240
  ],
225
- optional: root.backend === "v9" ? ["HUB_V0_API_BASE_URL"] : []
241
+ optional: root.backend === "v9" ? [
242
+ "HUB_V0_API_BASE_URL",
243
+ "HUB_RENTAL_SCOPE_PROPERTY_KIND",
244
+ "HUB_RENTAL_IDS_SEARCH"
245
+ ] : []
226
246
  });
227
247
  })).pipe(Command.withDescription("List environment variables used by the selected backend."));
228
248
  const configCommand = Command.make("config").pipe(Command.withDescription("Inspect CLI configuration."), Command.withSubcommands([show, env]));
@@ -272,10 +292,26 @@ const bookingBook = Command.make("book", {
272
292
  command: "website-sdk --backend v10 booking book --quote-input ./quote-input.json --contact-input ./booking-contact.json --relative-redirect-url https://example.test/payment --yes",
273
293
  description: "Create a booking from a reusable quote input and booking contact fixture."
274
294
  }]));
295
+ const voucherValidate = Command.make("validate", {
296
+ locale: localeFlag,
297
+ code: Flag.String("code").pipe(Flag.withDescription("Voucher code to check.")),
298
+ start: Flag.String("start").pipe(Flag.optional, Flag.withDescription("Arrival date, DD-MM-YYYY or YYYY-MM-DD.")),
299
+ end: Flag.String("end").pipe(Flag.optional, Flag.withDescription("Departure date, DD-MM-YYYY or YYYY-MM-DD."))
300
+ }, ({ locale, code, start, end }) => websiteSdkCommand.pipe(Effect.flatMap((root) => withSDK(root, (sdk) => sdk.backend === "v9" ? sdk.live.voucher.validate({
301
+ locale,
302
+ code,
303
+ ...Option.isSome(start) ? { start: start.value } : {},
304
+ ...Option.isSome(end) ? { end: end.value } : {}
305
+ }) : Promise.reject(/* @__PURE__ */ new Error("voucher validate requires --backend v9."))).pipe(Effect.flatMap((result) => printOutput(root, result)))))).pipe(Command.withDescription("Check whether a voucher code can be redeemed."), Command.withExamples([{
306
+ command: "website-sdk --backend v9 voucher validate --code SUMMER --start 01-08-2026 --end 08-08-2026",
307
+ description: "Check a voucher code against a stay."
308
+ }]));
309
+ const voucherCommand = Command.make("voucher").pipe(Command.withDescription("Run live voucher operations."), Command.withSubcommands([voucherValidate]));
275
310
  const liveCommands = [
276
311
  quote,
277
312
  Command.make("booking").pipe(Command.withDescription("Run live booking operations."), Command.withSubcommands([bookingBook])),
278
- Command.make("contact").pipe(Command.withDescription("Run live contact operations."), Command.withSubcommands([contactSubmit]))
313
+ Command.make("contact").pipe(Command.withDescription("Run live contact operations."), Command.withSubcommands([contactSubmit])),
314
+ voucherCommand
279
315
  ];
280
316
  //#endregion
281
317
  //#region src/legacy-v9/review-criteria-discovery.ts
@@ -373,13 +409,23 @@ const staticCommands = [
373
409
  command: "website-sdk --backend v9 rentals --locale en-US",
374
410
  description: "Fetch v9 rentals in English."
375
411
  }])),
412
+ Command.make("rentals-by-ids", {
413
+ locale: localeFlag,
414
+ rentalIds: Flag.String("rental-ids").pipe(Flag.withDescription("Comma-separated vOffice rental IDs."))
415
+ }, ({ locale, rentalIds }) => websiteSdkCommand.pipe(Effect.flatMap((root) => withSDK(root, (sdk) => sdk.backend === "v9" ? sdk.live.rentals.getRentalsByIds({
416
+ locale,
417
+ rentalIds: rentalIds.split(",").map((rentalId) => rentalId.trim()).filter((rentalId) => rentalId.length > 0)
418
+ }) : Promise.reject(/* @__PURE__ */ new Error("rentals-by-ids requires --backend v9."))).pipe(Effect.flatMap((result) => printOutput(root, result)))))).pipe(Command.withDescription("Fetch the v9 rentals with the given IDs."), Command.withExamples([{
419
+ command: "website-sdk --backend v9 rentals-by-ids --locale en-US --rental-ids 12,34",
420
+ description: "Fetch two v9 rentals in English."
421
+ }])),
376
422
  Command.make("search", {
377
423
  locale: localeFlag,
378
424
  query: Flag.String("query").pipe(Flag.withDescription("Search query string, for example \"city=munich&adults=2\".")),
379
425
  limit: Flag.Int("limit").pipe(Flag.optional, Flag.withDescription("Optional positive result limit.")),
380
426
  cursor: Flag.String("cursor").pipe(Flag.optional, Flag.withDescription("Optional pagination cursor.")),
381
- rentalIdsIn: Flag.String("rental-ids-in").pipe(Flag.optional, Flag.withDescription("Optional comma-separated rental IDs to restrict v10 search results.")),
382
- voucher: Flag.String("voucher").pipe(Flag.optional, Flag.withDescription("Optional voucher code for v10 search pricing.")),
427
+ rentalIdsIn: Flag.String("rental-ids-in").pipe(Flag.optional, Flag.withDescription("Optional comma-separated rental IDs to restrict search results; v9 needs rentalIdsSearch: true in the config.")),
428
+ voucher: Flag.String("voucher").pipe(Flag.optional, Flag.withDescription("Optional voucher code for search pricing.")),
383
429
  sort: Flag.String("sort").pipe(Flag.optional, Flag.withDescription("Optional SearchSearchSort JSON, for example '{\"by\":\"price\",\"direction\":\"ASC\"}'."))
384
430
  }, ({ locale, query, limit, cursor, rentalIdsIn, voucher, sort }) => websiteSdkCommand.pipe(Effect.flatMap((root) => {
385
431
  return Effect.gen(function* () {
@@ -392,12 +438,12 @@ const staticCommands = [
392
438
  query,
393
439
  ...Option.isSome(limit) ? { limit: limit.value } : {},
394
440
  ...Option.isSome(cursor) ? { cursor: cursor.value } : {},
441
+ ...Option.isSome(voucher) ? { voucher: voucher.value } : {},
442
+ ...parsedRentalIdsIn.length > 0 ? { rentalIdsIn: parsedRentalIdsIn } : {},
395
443
  ...v9Sort === void 0 ? {} : { sort: v9Sort }
396
444
  };
397
445
  return yield* withSDK(root, (sdk) => sdk.backend === "v9" ? sdk.live.search.search(input) : sdk.live.search.search({
398
446
  ...input,
399
- ...parsedRentalIdsIn.length > 0 ? { rentalIdsIn: parsedRentalIdsIn } : {},
400
- ...Option.isSome(voucher) ? { voucher: voucher.value } : {},
401
447
  ...parsedSort === void 0 ? {} : { sort: parsedSort }
402
448
  })).pipe(Effect.flatMap((result) => printOutput(root, result)));
403
449
  });
@@ -414,11 +460,359 @@ const staticCommands = [
414
460
  }]))
415
461
  ];
416
462
  //#endregion
463
+ //#region src/legacy-v9/hub-filters.ts
464
+ const fetchV9HubFilters = (config) => Effect.runPromise(makeV9GraphQLClient(config).execute(hubFiltersQuery, { language: "de" }).pipe(Effect.map((data) => data.filter.map(({ key, name, options }) => ({
465
+ key,
466
+ name,
467
+ options: options ?? []
468
+ })))));
469
+ //#endregion
470
+ //#region src/cli/v9-hub-filters.ts
471
+ const GROUP = "Beliebte Filter";
472
+ const inputFilter = ({ name, queryKey }) => ({
473
+ name,
474
+ type: "InputFilter",
475
+ display_type: "hidden",
476
+ group: GROUP,
477
+ custom_query: { query: [{
478
+ key: queryKey,
479
+ operator: "EQUAL",
480
+ value: null
481
+ }] }
482
+ });
483
+ const HUB_FILTER_REQUESTS = {
484
+ [V9_HUB_FACILITY_SCOPE_FILTER_KEY]: {
485
+ purpose: "Begrenzt die Suche auf die Unterkünfte der Ferienanlage dieser Website. Für Besucher unsichtbar.",
486
+ entry: inputFilter({
487
+ name: "Ferienanlage (Scope)",
488
+ queryKey: "VofficeUnit.voffice_facility_id"
489
+ })
490
+ },
491
+ [V9_HUB_OBJECT_GROUP_SCOPE_FILTER_KEY]: {
492
+ purpose: "Begrenzt die Suche auf die Unterkünfte der Objektgruppe dieser Website. Für Besucher unsichtbar.",
493
+ entry: inputFilter({
494
+ name: "Objektgruppe (Scope)",
495
+ queryKey: "VofficeGroup.voffice_group_id"
496
+ })
497
+ },
498
+ [V9_HUB_RENTAL_IDS_FILTER_KEY]: {
499
+ purpose: "Findet Unterkünfte anhand ihrer vOffice-ID, z. B. für die Merkliste. Für Besucher unsichtbar.",
500
+ entry: inputFilter({
501
+ name: "vOffice ID",
502
+ queryKey: "VofficeUnit.voffice_id"
503
+ })
504
+ },
505
+ [V9_HUB_OBJECT_GROUP_FILTER_KEY]: {
506
+ purpose: "Filter nach Objektgruppe in der Suche der Website.",
507
+ entry: inputFilter({
508
+ name: "Objektgruppe",
509
+ queryKey: "VofficeGroup.voffice_group_id"
510
+ })
511
+ },
512
+ [V9_HUB_FACILITY_SEARCH_FILTER_KEY]: {
513
+ purpose: "Filter nach Ferienanlage in der Suche der Website. Die Auswahl der Ferienanlagen erzeugt der be-on! Hub selbst.",
514
+ entry: {
515
+ name: "Ferienanlage",
516
+ type: "SpecialFilter\\FacilityFilter",
517
+ display_type: "searchselect",
518
+ group: GROUP,
519
+ property: "facility"
520
+ }
521
+ },
522
+ [V9_HUB_OFFERS_FILTER_KEY]: {
523
+ purpose: "Zeigt nur Unterkünfte mit einem Angebot.",
524
+ entry: {
525
+ name: "Angebote",
526
+ type: "SpecialFilter\\OffersFilter",
527
+ display_type: "hidden",
528
+ group: GROUP
529
+ }
530
+ },
531
+ [V9_HUB_OFFER_FILTER_KEY]: {
532
+ purpose: "Zeigt nur Unterkünfte mit einem bestimmten Angebot.",
533
+ entry: inputFilter({
534
+ name: "Angebot",
535
+ queryKey: "VofficeOffer.voffice_offer_id"
536
+ })
537
+ }
538
+ };
539
+ const REQUEST_ORDER = [
540
+ V9_HUB_FACILITY_SCOPE_FILTER_KEY,
541
+ V9_HUB_OBJECT_GROUP_SCOPE_FILTER_KEY,
542
+ V9_HUB_RENTAL_IDS_FILTER_KEY,
543
+ V9_HUB_OBJECT_GROUP_FILTER_KEY,
544
+ V9_HUB_FACILITY_SEARCH_FILTER_KEY,
545
+ V9_HUB_OFFERS_FILTER_KEY,
546
+ V9_HUB_OFFER_FILTER_KEY
547
+ ];
548
+ const toRequestedHubFilterKeys = ({ selection, sdkOwnedKeys }) => {
549
+ const wanted = /* @__PURE__ */ new Set([
550
+ ...sdkOwnedKeys,
551
+ ...selection.unit ? [V9_HUB_RENTAL_IDS_FILTER_KEY] : [],
552
+ ...selection.objectGroup ? [V9_HUB_OBJECT_GROUP_FILTER_KEY] : [],
553
+ ...selection.facility ? [V9_HUB_FACILITY_SEARCH_FILTER_KEY] : [],
554
+ ...selection.offers ? [V9_HUB_OFFERS_FILTER_KEY] : [],
555
+ ...selection.offer ? [V9_HUB_OFFER_FILTER_KEY] : []
556
+ ]);
557
+ return REQUEST_ORDER.filter((key) => wanted.has(key));
558
+ };
559
+ const REQUEST_FLAGS = /* @__PURE__ */ new Map([
560
+ [V9_HUB_OBJECT_GROUP_FILTER_KEY, "--object-group"],
561
+ [V9_HUB_FACILITY_SEARCH_FILTER_KEY, "--facility"],
562
+ [V9_HUB_OFFERS_FILTER_KEY, "--offers"],
563
+ [V9_HUB_OFFER_FILTER_KEY, "--offer"]
564
+ ]);
565
+ const renderMissingHubFilters = (missing) => {
566
+ const flags = missing.flatMap((key) => REQUEST_FLAGS.get(key) ?? []);
567
+ const requestable = missing.filter((key) => REQUEST_FLAGS.has(key) || V9_SDK_OWNED_HUB_FILTER_KEYS.has(key));
568
+ const custom = missing.filter((key) => !requestable.includes(key));
569
+ return [
570
+ `Missing Hub filters: ${missing.join(", ")}.`,
571
+ ...requestable.length === 0 ? [] : [`Run \`website-sdk hub-filters request${flags.map((flag) => ` ${flag}`).join("")}\`; the user adds the entries in the be-on! Hub with the file it writes.`],
572
+ ...custom.length === 0 ? [] : [`hub-filters request cannot write entries for ${custom.join(", ")}; a developer adds them in the be-on! Hub.`]
573
+ ].join(" ");
574
+ };
575
+ const json = (value) => JSON.stringify(value, null, 2);
576
+ const existingHubFilterKeys = ({ keys, hubFilters }) => keys.filter((key) => hubFilters.some((filter) => filter.key === key));
577
+ const code = (keys) => keys.map((key) => `\`${key}\``).join(", ");
578
+ const renderHubFilterRequest = ({ beOnKey, keys, hubFilters }) => {
579
+ const existing = existingHubFilterKeys({
580
+ keys,
581
+ hubFilters
582
+ });
583
+ return [
584
+ "# Filter im be-on! Hub eintragen",
585
+ "",
586
+ `be-on Key: \`${beOnKey}\``,
587
+ "",
588
+ "Die Website braucht die Filter unten im be-on! Hub. Ohne sie filtert die Suche nicht oder die Website lässt sich nicht bauen.",
589
+ "",
590
+ ...existing.length === 0 ? [] : [`> Achtung: Im be-on! Hub stehen für diesen be-on Key schon Filter (${code(existing)}). Den Code unten nicht einfügen, sondern diese Datei an einen Entwickler geben. Er führt die Einträge zusammen.`, ""],
591
+ "## So geht's",
592
+ "",
593
+ `1. Im be-on! Hub den be-on Key \`${beOnKey}\` suchen und öffnen.`,
594
+ "2. Unten im Bereich „vOffice-Filter“ den Filter bearbeiten. Gibt es dort noch keinen, einen neuen anlegen.",
595
+ "3. Das Feld „Filter“ muss leer sein. Steht dort schon etwas, nichts ändern und diese Datei an einen Entwickler geben. Er führt die Einträge zusammen.",
596
+ "4. Den Code unten komplett kopieren, in das leere Feld „Filter“ einfügen und speichern.",
597
+ "5. Danach Bescheid geben, dass die Filter eingetragen sind. Die Website prüft dann, ob alles da ist (`website-sdk hub-filters check`).",
598
+ "",
599
+ "## Code zum Einfügen",
600
+ "",
601
+ "```json",
602
+ json(Object.fromEntries(keys.map((key) => [key, HUB_FILTER_REQUESTS[key].entry]))),
603
+ "```",
604
+ "",
605
+ "## Was die Filter tun",
606
+ "",
607
+ ...keys.map((key) => `- \`${key}\`: ${HUB_FILTER_REQUESTS[key].purpose}`),
608
+ ""
609
+ ].join("\n");
610
+ };
611
+ const definition = ({ key, de, en, ...rest }) => ({
612
+ key,
613
+ source: "backendFilter",
614
+ category: "OTHER",
615
+ label: {
616
+ "de-DE": de,
617
+ "en-US": en
618
+ },
619
+ searchable: true,
620
+ internal: false,
621
+ ...rest
622
+ });
623
+ const toBackendFilterDefinitions = ({ keys, hubFilters }) => {
624
+ const definitions = [];
625
+ const notes = [];
626
+ if (keys.includes("objectGroup")) {
627
+ definitions.push(definition({
628
+ key: V9_HUB_OBJECT_GROUP_FILTER_KEY,
629
+ de: "Objektgruppe",
630
+ en: "Object group",
631
+ type: "option",
632
+ options: [{
633
+ value: "<vOffice object group ID>",
634
+ label: {
635
+ "de-DE": "<Gruppenname>",
636
+ "en-US": "<group name>"
637
+ }
638
+ }]
639
+ }));
640
+ notes.push(`${V9_HUB_OBJECT_GROUP_FILTER_KEY}: add one option per group. The value is the vOffice object group ID; the labels are the group names your site keeps, the Hub returns none.`);
641
+ }
642
+ if (keys.includes("facility_search")) {
643
+ const [firstFacilityOption, ...otherFacilityOptions] = (hubFilters.find(({ key }) => key === "facility_search")?.options ?? []).map(({ key, value }) => ({
644
+ value: key,
645
+ label: {
646
+ "de-DE": value ?? key,
647
+ "en-US": value ?? key
648
+ }
649
+ }));
650
+ definitions.push(definition({
651
+ key: V9_HUB_FACILITY_SEARCH_FILTER_KEY,
652
+ de: "Ferienanlage",
653
+ en: "Facility",
654
+ type: "option",
655
+ options: firstFacilityOption === void 0 ? [{
656
+ value: "<vOffice facility ID>",
657
+ label: {
658
+ "de-DE": "<Name>",
659
+ "en-US": "<name>"
660
+ }
661
+ }] : [firstFacilityOption, ...otherFacilityOptions]
662
+ }));
663
+ notes.push(firstFacilityOption === void 0 ? `${V9_HUB_FACILITY_SEARCH_FILTER_KEY}: the Hub has no options for this key yet. Run this command again once the Hub entry is saved.` : `${V9_HUB_FACILITY_SEARCH_FILTER_KEY}: options come from the Hub (vOffice facility IDs, not rental.property.id). The English labels are the German names; translate them.`);
664
+ }
665
+ if (keys.includes("offers")) definitions.push(definition({
666
+ key: V9_HUB_OFFERS_FILTER_KEY,
667
+ de: "Angebote",
668
+ en: "Special offers",
669
+ type: "boolean"
670
+ }));
671
+ if (keys.includes("offer")) {
672
+ definitions.push(definition({
673
+ key: V9_HUB_OFFER_FILTER_KEY,
674
+ de: "Angebot",
675
+ en: "Special offer",
676
+ type: "int",
677
+ numericBounds: { min: 1 }
678
+ }));
679
+ notes.push(`${V9_HUB_OFFER_FILTER_KEY}: the value is one vOffice offer ID.`);
680
+ }
681
+ return {
682
+ definitions,
683
+ notes
684
+ };
685
+ };
686
+ const renderRequestSummary = ({ file, keys, hubFilters }) => {
687
+ const { definitions, notes } = toBackendFilterDefinitions({
688
+ keys,
689
+ hubFilters
690
+ });
691
+ const existing = existingHubFilterKeys({
692
+ keys,
693
+ hubFilters
694
+ });
695
+ return [
696
+ `Wrote ${file}. Show the user its steps and code: they paste the code into the be-on! Hub themselves. Once they have saved it, run \`website-sdk hub-filters check\`; when it passes, delete ${file}.`,
697
+ ...existing.length === 0 ? [] : [`The be-on! Hub already has ${existing.join(", ")} for this be-on key, so its filter field is not empty: the file asks the user to hand it to a developer instead.`],
698
+ ...definitions.length === 0 ? [] : [
699
+ "",
700
+ "Add these to customAttributeFilterDefinitions:",
701
+ json(definitions),
702
+ ...notes.length === 0 ? [] : ["", ...notes.map((note) => `- ${note}`)]
703
+ ]
704
+ ].join("\n");
705
+ };
706
+ //#endregion
707
+ //#region src/cli/commands/v9-hub-filters.ts
708
+ const DEFAULT_REQUEST_FILE = "hub-filter-request.md";
709
+ const loadV9Context = (root) => Effect.gen(function* () {
710
+ if (root.backend !== "v9") return yield* Effect.fail(new CLICheckFailed("hub-filters requires --backend v9."));
711
+ const { config, options } = yield* loadCLIConfig(root);
712
+ if (config.backend !== "v9") return yield* Effect.fail(new CLICheckFailed("hub-filters needs a v9 config."));
713
+ return {
714
+ config,
715
+ options
716
+ };
717
+ });
718
+ const loadHubFilters = (config) => Effect.tryPromise({
719
+ try: () => fetchV9HubFilters(config),
720
+ catch: (cause) => toCLIError("Failed to read the Hub filters", cause)
721
+ });
722
+ const writeTextFile = ({ path, text }) => Effect.tryPromise({
723
+ try: async () => {
724
+ const { writeFile } = await import("node:fs/promises");
725
+ await writeFile(path, text, "utf8");
726
+ },
727
+ catch: (cause) => toCLIError(`Failed to write ${path}`, cause)
728
+ });
729
+ const flag = ({ name, description }) => Flag.Boolean(name).pipe(Flag.withDescription(description), Flag.withDefault(false));
730
+ const request = Command.make("request", {
731
+ objectGroup: flag({
732
+ name: "object-group",
733
+ description: "Request the object group filter (objectGroup)."
734
+ }),
735
+ facility: flag({
736
+ name: "facility",
737
+ description: "Request the facility filter (facility_search)."
738
+ }),
739
+ offers: flag({
740
+ name: "offers",
741
+ description: "Request the filter for units with any special offer (offers)."
742
+ }),
743
+ offer: flag({
744
+ name: "offer",
745
+ description: "Request the filter for units with one special offer (offer)."
746
+ }),
747
+ unit: flag({
748
+ name: "unit",
749
+ description: "Request the filter by vOffice unit ID, the favourites search (voffice_id)."
750
+ }),
751
+ out: Flag.String("out").pipe(Flag.withDescription("Path of the Markdown file to write."), Flag.withDefault(DEFAULT_REQUEST_FILE))
752
+ }, ({ out, ...selection }) => Effect.gen(function* () {
753
+ const root = yield* websiteSdkCommand;
754
+ const { config, options } = yield* loadV9Context(root);
755
+ const keys = toRequestedHubFilterKeys({
756
+ selection,
757
+ sdkOwnedKeys: toV9SdkOwnedHubFilterKeys({
758
+ config,
759
+ rentalScope: options?.rentalScope
760
+ })
761
+ });
762
+ if (keys.length === 0) return yield* Console.log("Nothing to request: pass --object-group, --facility, --offers, --offer or --unit. No file written.");
763
+ const hubFilters = yield* loadHubFilters(config);
764
+ if (keys.every((key) => hubFilters.some((filter) => filter.key === key))) return yield* Console.log(`The be-on! Hub already has ${keys.join(", ")}. No file written; run \`website-sdk hub-filters check\`.`);
765
+ yield* writeTextFile({
766
+ path: out,
767
+ text: renderHubFilterRequest({
768
+ beOnKey: config.apiKey,
769
+ keys,
770
+ hubFilters
771
+ })
772
+ });
773
+ yield* Console.log(renderRequestSummary({
774
+ file: out,
775
+ keys,
776
+ hubFilters
777
+ }));
778
+ })).pipe(Command.withDescription("Write a Markdown file with the be-on! Hub filters this site needs and how to add them."), Command.withExamples([{
779
+ command: "website-sdk --backend v9 hub-filters request --object-group --offers",
780
+ description: "Write hub-filter-request.md for an object group and an offers filter."
781
+ }, {
782
+ command: "website-sdk --backend v9 --config ./config.json --options ./options.json hub-filters request --out ./request.md",
783
+ description: "Request the scope and favourites filters the configuration already implies."
784
+ }]));
785
+ const check = Command.make("check", {}, () => Effect.gen(function* () {
786
+ const root = yield* websiteSdkCommand;
787
+ const { config, options } = yield* loadV9Context(root);
788
+ const required = toV9RequiredHubFilterKeys({
789
+ config,
790
+ rentalScope: options?.rentalScope,
791
+ customAttributeFilterDefinitions: options?.customAttributeFilterDefinitions ?? []
792
+ });
793
+ if (required.length === 0) return yield* Console.log("This configuration needs no Hub filters.");
794
+ const { present, missing } = checkV9HubFilters({
795
+ required,
796
+ hubFilters: yield* loadHubFilters(config)
797
+ });
798
+ yield* printOutput(root, {
799
+ present,
800
+ missing,
801
+ ...missing.length === 0 ? { note: "All required keys exist. The Hub filter list does not show custom_query, so an entry without it is not detected; an InputFilter without custom_query filters nothing." } : {}
802
+ });
803
+ if (missing.length > 0) return yield* Effect.fail(new CLICheckFailed(renderMissingHubFilters(missing)));
804
+ })).pipe(Command.withDescription("Check that the Hub filters this configuration needs exist for the be-on key."), Command.withExamples([{
805
+ command: "website-sdk --backend v9 --config ./config.json --options ./options.json hub-filters check",
806
+ description: "Compare backend filters, the scope key and voffice_id with the Hub."
807
+ }]));
808
+ const hubFiltersCommand = Command.make("hub-filters").pipe(Command.withDescription("Request and check be-on! Hub filters for v9 sites."), Command.withSubcommands([request, check]));
809
+ //#endregion
417
810
  //#region src/cli/index.ts
418
811
  const cliCommand = websiteSdkCommand.pipe(Command.withSubcommands([
419
812
  configCommand,
420
813
  ...staticCommands,
421
814
  reviewCriteriaCommand,
815
+ hubFiltersCommand,
422
816
  availabilityCommand,
423
817
  ...liveCommands
424
818
  ]));