@peektravel/app-utilities 0.9.3 → 0.9.5

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.
package/dist/index.js CHANGED
@@ -939,6 +939,7 @@ function fromBookingMetaDataNode(node) {
939
939
  function fromFieldResponseNode(response) {
940
940
  const field = response.fieldLocation?.field;
941
941
  const prompt = response.fieldLocation?.prompt;
942
+ const { value, displayValue } = fromValueNode(response.value);
942
943
  return {
943
944
  id: field?.id || "",
944
945
  name: field?.name || "",
@@ -948,89 +949,96 @@ function fromFieldResponseNode(response) {
948
949
  promptHint: prompt?.hint ?? null,
949
950
  isRequired: Boolean(prompt?.isRequired),
950
951
  refid: response.refid || "",
951
- value: fromValueNode(response.value)
952
+ displayValue,
953
+ value
952
954
  };
953
955
  }
954
956
  function fromValueNode(value) {
955
- if (!value || !value.__typename) return null;
957
+ if (!value || !value.__typename) return { value: null, displayValue: "" };
956
958
  switch (value.__typename) {
957
959
  case "AgeFieldResponseValue": {
958
960
  const age = value.age ?? 0;
959
- return { kind: "age", age, displayValue: String(age) };
961
+ return { value: { kind: "age", age }, displayValue: String(age) };
960
962
  }
961
963
  case "AttachmentFieldResponseValue": {
962
964
  const attachmentUrl = value.attachmentUrl ?? "";
963
965
  const name = value.name ?? null;
964
966
  return {
965
- kind: "attachment",
966
- attachmentUrl,
967
- mime: value.mime ?? null,
968
- name,
969
- size: value.size ?? null,
967
+ value: {
968
+ kind: "attachment",
969
+ attachmentUrl,
970
+ mime: value.mime ?? null,
971
+ name,
972
+ size: value.size ?? null
973
+ },
970
974
  displayValue: name || attachmentUrl
971
975
  };
972
976
  }
973
977
  case "BarcodeFieldResponseValue": {
974
978
  const barcodeValue = value.barcodeValue ?? "";
975
979
  return {
976
- kind: "barcode",
977
- barcodeType: value.barcodeType ?? null,
978
- barcodeValue,
980
+ value: {
981
+ kind: "barcode",
982
+ barcodeType: value.barcodeType ?? null,
983
+ barcodeValue
984
+ },
979
985
  displayValue: barcodeValue
980
986
  };
981
987
  }
982
988
  case "BooleanFieldResponseValue": {
983
989
  const bool = Boolean(value.boolean);
984
- return { kind: "boolean", boolean: bool, displayValue: yesNo(bool) };
990
+ return { value: { kind: "boolean", boolean: bool }, displayValue: yesNo(bool) };
985
991
  }
986
992
  case "CheckboxFieldResponseValue": {
987
993
  const isChecked = Boolean(value.isChecked);
988
- return { kind: "checkbox", isChecked, displayValue: yesNo(isChecked) };
994
+ return { value: { kind: "checkbox", isChecked }, displayValue: yesNo(isChecked) };
989
995
  }
990
996
  case "CurrencyFieldResponseValue": {
991
997
  const currency = value.currency ?? "";
992
- return { kind: "currency", currency, displayValue: currency };
998
+ return { value: { kind: "currency", currency }, displayValue: currency };
993
999
  }
994
1000
  case "DateFieldResponseValue": {
995
1001
  const date = value.date ?? "";
996
- return { kind: "date", date, displayValue: date };
1002
+ return { value: { kind: "date", date }, displayValue: date };
997
1003
  }
998
1004
  case "DecimalFieldResponseValue": {
999
1005
  const decimal = value.decimal ?? null;
1000
- return { kind: "decimal", decimal, displayValue: decimal ?? "" };
1006
+ return { value: { kind: "decimal", decimal }, displayValue: decimal ?? "" };
1001
1007
  }
1002
1008
  case "DurationFieldResponseValue": {
1003
1009
  const amount = value.duration?.amount ?? 0;
1004
1010
  const unit = value.duration?.unit ?? null;
1005
- return { kind: "duration", amount, unit, displayValue: amountUnit(amount, unit) };
1011
+ return { value: { kind: "duration", amount, unit }, displayValue: amountUnit(amount, unit) };
1006
1012
  }
1007
1013
  case "EmailFieldResponseValue": {
1008
1014
  const email = value.email ?? null;
1009
- return { kind: "email", email, displayValue: email ?? "" };
1015
+ return { value: { kind: "email", email }, displayValue: email ?? "" };
1010
1016
  }
1011
1017
  case "GuestFieldResponseValue": {
1012
1018
  const name = value.name ?? null;
1013
1019
  return {
1014
- kind: "guest",
1015
- name,
1016
- email: value.email ?? null,
1017
- dateOfBirth: value.dateOfBirth ?? null,
1018
- notes: value.notes ?? null,
1019
- waiverSigned: value.waiverSigned ?? null,
1020
+ value: {
1021
+ kind: "guest",
1022
+ name,
1023
+ email: value.email ?? null,
1024
+ dateOfBirth: value.dateOfBirth ?? null,
1025
+ notes: value.notes ?? null,
1026
+ waiverSigned: value.waiverSigned ?? null
1027
+ },
1020
1028
  displayValue: name ?? ""
1021
1029
  };
1022
1030
  }
1023
1031
  case "HtmlFieldResponseValue": {
1024
1032
  const html = value.html ?? "";
1025
- return { kind: "html", html, displayValue: escapeHtml(html) };
1033
+ return { value: { kind: "html", html }, displayValue: escapeHtml(html) };
1026
1034
  }
1027
1035
  case "ImageUrlFieldResponseValue": {
1028
1036
  const imageUrl = value.imageUrl ?? "";
1029
- return { kind: "imageUrl", imageUrl, displayValue: imageUrl };
1037
+ return { value: { kind: "imageUrl", imageUrl }, displayValue: imageUrl };
1030
1038
  }
1031
1039
  case "IntegerFieldResponseValue": {
1032
1040
  const integer = value.integer ?? 0;
1033
- return { kind: "integer", integer, displayValue: String(integer) };
1041
+ return { value: { kind: "integer", integer }, displayValue: String(integer) };
1034
1042
  }
1035
1043
  case "LocationFieldResponseValue": {
1036
1044
  const streetAddress = value.streetAddress ?? null;
@@ -1039,56 +1047,58 @@ function fromValueNode(value) {
1039
1047
  const postalCode = value.postalCode ?? null;
1040
1048
  const country = value.country ?? null;
1041
1049
  return {
1042
- kind: "location",
1043
- country,
1044
- county: value.county ?? null,
1045
- locality,
1046
- postalCode,
1047
- region,
1048
- streetAddress,
1050
+ value: {
1051
+ kind: "location",
1052
+ country,
1053
+ county: value.county ?? null,
1054
+ locality,
1055
+ postalCode,
1056
+ region,
1057
+ streetAddress
1058
+ },
1049
1059
  displayValue: [streetAddress, locality, region, postalCode, country].filter((part) => part).join(", ")
1050
1060
  };
1051
1061
  }
1052
1062
  case "LongTextFieldResponseValue": {
1053
1063
  const longText = value.longText ?? "";
1054
- return { kind: "longText", longText, displayValue: longText };
1064
+ return { value: { kind: "longText", longText }, displayValue: longText };
1055
1065
  }
1056
1066
  case "MetaFieldResponseValue": {
1057
1067
  const meta = value.meta ?? null;
1058
- return { kind: "meta", meta, displayValue: meta == null ? "" : JSON.stringify(meta) };
1068
+ return { value: { kind: "meta", meta }, displayValue: meta == null ? "" : JSON.stringify(meta) };
1059
1069
  }
1060
1070
  case "PercentFieldResponseValue": {
1061
1071
  const percent = value.percent ?? null;
1062
- return { kind: "percent", percent, displayValue: percent == null ? "" : `${percent}%` };
1072
+ return { value: { kind: "percent", percent }, displayValue: percent == null ? "" : `${percent}%` };
1063
1073
  }
1064
1074
  case "PhoneFieldResponseValue": {
1065
1075
  const phone = value.phone ?? "";
1066
- return { kind: "phone", phone, displayValue: phone };
1076
+ return { value: { kind: "phone", phone }, displayValue: phone };
1067
1077
  }
1068
1078
  case "ShortTextFieldResponseValue": {
1069
1079
  const shortText = value.shortText ?? "";
1070
- return { kind: "shortText", shortText, displayValue: shortText };
1080
+ return { value: { kind: "shortText", shortText }, displayValue: shortText };
1071
1081
  }
1072
1082
  case "TimeFieldResponseValue": {
1073
1083
  const time = value.time ?? "";
1074
- return { kind: "time", time, displayValue: time };
1084
+ return { value: { kind: "time", time }, displayValue: time };
1075
1085
  }
1076
1086
  case "UrlFieldResponseValue": {
1077
1087
  const url = value.url ?? null;
1078
- return { kind: "url", url, displayValue: url ?? "" };
1088
+ return { value: { kind: "url", url }, displayValue: url ?? "" };
1079
1089
  }
1080
1090
  case "VolumeFieldResponseValue": {
1081
1091
  const amount = value.volume?.amount ?? "0";
1082
1092
  const unit = value.volume?.unit ?? null;
1083
- return { kind: "volume", amount, unit, displayValue: amountUnit(amount, unit) };
1093
+ return { value: { kind: "volume", amount, unit }, displayValue: amountUnit(amount, unit) };
1084
1094
  }
1085
1095
  case "WeightFieldResponseValue": {
1086
1096
  const amount = value.weight?.amount ?? "0";
1087
1097
  const unit = value.weight?.unit ?? null;
1088
- return { kind: "weight", amount, unit, displayValue: amountUnit(amount, unit) };
1098
+ return { value: { kind: "weight", amount, unit }, displayValue: amountUnit(amount, unit) };
1089
1099
  }
1090
1100
  default:
1091
- return null;
1101
+ return { value: null, displayValue: "" };
1092
1102
  }
1093
1103
  }
1094
1104
  function yesNo(value) {
@@ -1108,7 +1118,7 @@ function toSetMetaDataResult(node, bookingId) {
1108
1118
  };
1109
1119
  }
1110
1120
  function filterMetaDataByIntegrator(metaData, integrator) {
1111
- const prefix = `integrator:${integrator}:`;
1121
+ const prefix = `integrators:${integrator}:`;
1112
1122
  return metaData.filter((entry) => entry.slug.startsWith(prefix)).map((entry) => ({ ...entry, slug: entry.slug.slice(prefix.length) }));
1113
1123
  }
1114
1124
 
@@ -1604,7 +1614,7 @@ var BookingService = class {
1604
1614
  /**
1605
1615
  * Returns a booking's custom-field metadata (its `fieldResponses`), scoped to
1606
1616
  * this service's integrator. Only fields whose slug starts with
1607
- * `integrator:<integrator>:` are returned, and that prefix is stripped from
1617
+ * `integrators:<integrator>:` are returned, and that prefix is stripped from
1608
1618
  * each returned `slug`. Returns `[]` when the booking is not found or has no
1609
1619
  * matching fields.
1610
1620
  *
@@ -2464,6 +2474,123 @@ function buildCancellation(items, addonOptionId, quantity) {
2464
2474
  return { bookingQuotes, canceledCount };
2465
2475
  }
2466
2476
 
2477
+ // src/internal/peek/custom-questions/custom-question-converter.ts
2478
+ function fromQuestionConfigurations(configs) {
2479
+ return configs.map(
2480
+ (config) => fromQuestionNode(config.question, config.order, config.isRequired)
2481
+ );
2482
+ }
2483
+ function fromQuestionNodes(questions) {
2484
+ return questions.map((question) => fromQuestionNode(question));
2485
+ }
2486
+ function fromQuestionNode(question, order, isRequired) {
2487
+ return {
2488
+ id: question.id,
2489
+ order: order ?? 0,
2490
+ isRequired: isRequired ?? false,
2491
+ questionText: question.text,
2492
+ hintText: question.hint ?? null,
2493
+ questionType: question.questionType,
2494
+ internalLabel: question.internalLabel ?? null,
2495
+ perGuest: question.perGuest ?? false,
2496
+ defaultValue: question.answerDefaultValue ?? null,
2497
+ options: (question.options ?? []).map(fromQuestionOption)
2498
+ };
2499
+ }
2500
+ function fromQuestionOption(option) {
2501
+ return {
2502
+ id: option.id,
2503
+ order: option.order,
2504
+ value: option.text
2505
+ };
2506
+ }
2507
+
2508
+ // src/internal/peek/custom-questions/custom-question-queries.ts
2509
+ var ALL_CUSTOM_QUESTIONS_QUERY = `
2510
+ query Sales {
2511
+ questions {
2512
+ id
2513
+ questionType
2514
+ text
2515
+ answerDefaultValue
2516
+ hint
2517
+ internalLabel
2518
+ perGuest
2519
+ ... on ChoiceQuestion {
2520
+ options {
2521
+ id
2522
+ text
2523
+ order
2524
+ }
2525
+ }
2526
+ }
2527
+ }
2528
+ `;
2529
+ var CUSTOM_QUESTIONS_QUERY = `
2530
+ query Sales($id: ID!) {
2531
+ activity(id: $id) {
2532
+ id
2533
+ name
2534
+ questionActivityConfigurations {
2535
+ isRequired
2536
+ order
2537
+ question {
2538
+ id
2539
+ questionType
2540
+ text
2541
+ answerDefaultValue
2542
+ hint
2543
+ internalLabel
2544
+ perGuest
2545
+ ... on ChoiceQuestion {
2546
+ options {
2547
+ id
2548
+ text
2549
+ order
2550
+ }
2551
+ }
2552
+ }
2553
+ }
2554
+ }
2555
+ }
2556
+ `;
2557
+
2558
+ // src/internal/peek/custom-questions/custom-question-service.ts
2559
+ var CustomQuestionService = class {
2560
+ constructor(client) {
2561
+ this.client = client;
2562
+ }
2563
+ client;
2564
+ /**
2565
+ * Returns every custom question defined on the account, across all
2566
+ * activities. Choice-style questions (`SELECT_ONE`, `LOCATION`, …) carry their
2567
+ * selectable {@link CustomQuestion.options}; free-text/checkbox questions
2568
+ * return an empty option list.
2569
+ *
2570
+ * These are account-wide question **definitions**, not customer answers — no
2571
+ * PII is involved, so the result is unaffected by `fullCustomerAccess`. Unlike
2572
+ * {@link ProductService.getCustomQuestions}, the catalog carries no
2573
+ * per-activity configuration, so {@link CustomQuestion.order} is `0` and
2574
+ * {@link CustomQuestion.isRequired} is `false` on every entry.
2575
+ *
2576
+ * @returns Every custom question on the account, or an empty list when none
2577
+ * are defined.
2578
+ *
2579
+ * @example
2580
+ * ```ts
2581
+ * const questions = await peek.getCustomQuestionService().getAll();
2582
+ * ```
2583
+ */
2584
+ async getAll() {
2585
+ const body = await this.client.request(
2586
+ SALES_ENDPOINT,
2587
+ ALL_CUSTOM_QUESTIONS_QUERY,
2588
+ {}
2589
+ );
2590
+ return fromQuestionNodes(body.data?.questions ?? []);
2591
+ }
2592
+ };
2593
+
2467
2594
  // src/internal/peek/daily-notes/daily-note-converter.ts
2468
2595
  function toDailyNote(response) {
2469
2596
  const union = response?.dailyNote;
@@ -2642,7 +2769,7 @@ async function requestWithRetry(http, url, init, label, onResponse) {
2642
2769
  // src/internal/sdk-headers.ts
2643
2770
  var SDK_HEADER_NAME = "x-peek-sdk";
2644
2771
  var SDK_PLATFORM = "js";
2645
- var SDK_VERSION = "0.9.3";
2772
+ var SDK_VERSION = "0.9.5";
2646
2773
  var SDK_HEADER_VALUE = `${SDK_PLATFORM}-${SDK_VERSION}`;
2647
2774
 
2648
2775
  // src/internal/peek/graphql-client.ts
@@ -3668,33 +3795,6 @@ function fromItemOptionNodes(nodes) {
3668
3795
  return Array.from(grouped.values());
3669
3796
  }
3670
3797
 
3671
- // src/internal/peek/products/custom-question-converter.ts
3672
- function fromQuestionConfigurations(configs) {
3673
- return configs.map(fromQuestionConfiguration);
3674
- }
3675
- function fromQuestionConfiguration(config) {
3676
- const question = config.question;
3677
- return {
3678
- id: question.id,
3679
- order: config.order ?? 0,
3680
- isRequired: config.isRequired ?? false,
3681
- questionText: question.text,
3682
- hintText: question.hint ?? null,
3683
- questionType: question.questionType,
3684
- internalLabel: question.internalLabel ?? null,
3685
- perGuest: question.perGuest ?? false,
3686
- defaultValue: question.answerDefaultValue ?? null,
3687
- options: (question.options ?? []).map(fromQuestionOption)
3688
- };
3689
- }
3690
- function fromQuestionOption(option) {
3691
- return {
3692
- id: option.id,
3693
- order: option.order,
3694
- value: option.text
3695
- };
3696
- }
3697
-
3698
3798
  // src/internal/peek/products/product-queries.ts
3699
3799
  var PRODUCTS_QUERY = `
3700
3800
  query Sales {
@@ -3753,36 +3853,6 @@ var ITEM_OPTIONS_QUERY = `
3753
3853
  }
3754
3854
  `;
3755
3855
 
3756
- // src/internal/peek/products/custom-question-queries.ts
3757
- var CUSTOM_QUESTIONS_QUERY = `
3758
- query Sales($id: ID!) {
3759
- activity(id: $id) {
3760
- id
3761
- name
3762
- questionActivityConfigurations {
3763
- isRequired
3764
- order
3765
- question {
3766
- id
3767
- questionType
3768
- text
3769
- answerDefaultValue
3770
- hint
3771
- internalLabel
3772
- perGuest
3773
- ... on ChoiceQuestion {
3774
- options {
3775
- id
3776
- text
3777
- order
3778
- }
3779
- }
3780
- }
3781
- }
3782
- }
3783
- }
3784
- `;
3785
-
3786
3856
  // src/internal/peek/products/product-service.ts
3787
3857
  var ERROR_PRODUCT_ID_REQUIRED2 = "A non-empty product id is required.";
3788
3858
  var DEFAULT_ITEM_OPTIONS_PAGE_SIZE = 50;
@@ -4361,6 +4431,7 @@ var PeekAccessService = class {
4361
4431
  membershipService;
4362
4432
  bookingServices = /* @__PURE__ */ new Map();
4363
4433
  reviewService;
4434
+ customQuestionService;
4364
4435
  constructor(config) {
4365
4436
  const hasApiUrl = !!config.apiUrl;
4366
4437
  const isV2 = config.mode === "v2";
@@ -4561,6 +4632,16 @@ var PeekAccessService = class {
4561
4632
  }
4562
4633
  return this.reviewService;
4563
4634
  }
4635
+ /**
4636
+ * Returns the {@link CustomQuestionService} for this install, bound to the
4637
+ * shared authenticated transport. The instance is created lazily and reused.
4638
+ */
4639
+ getCustomQuestionService() {
4640
+ if (!this.customQuestionService) {
4641
+ this.customQuestionService = new CustomQuestionService(this.client);
4642
+ }
4643
+ return this.customQuestionService;
4644
+ }
4564
4645
  // ─── Product short-forms ─────────────────────────────────────────────────
4565
4646
  /** All products (activities + add-ons). @deprecated The access service exposes only its resource-service accessors; call the service directly instead. See {@link ProductService.getAllProducts}. */
4566
4647
  getAllProducts() {
@@ -5197,6 +5278,6 @@ function verifyInstallWebhook(token, secret) {
5197
5278
  };
5198
5279
  }
5199
5280
 
5200
- export { ACTIVITY_PRODUCT_TYPE, ADD_ON_PRODUCT_TYPE, AccountUserService, AcmeAccessService, AcmeApiError, AcmeProductService, AdminAccountRequiredError, AvailabilityService, BookingService, CngAccessService, CngApiError, CngPermissionError, CngProductService, DailyNoteService, INSTALL_STATUSES, MembershipService, PeekAccessService, PeekGraphQLError, PeekHttpError, PiiAccessDisabledError, PricingService, ProductService, PromoCodeService, RENTAL_PRODUCT_TYPE, RateLimitError, ResellerService, ResourcePoolService, ReviewService, TimeslotService, createAccessServiceForInstall, noopLogger, parseBookingWebhook, parseInstallWebhook, parseWaiverWebhook, verifyInstallWebhook };
5281
+ export { ACTIVITY_PRODUCT_TYPE, ADD_ON_PRODUCT_TYPE, AccountUserService, AcmeAccessService, AcmeApiError, AcmeProductService, AdminAccountRequiredError, AvailabilityService, BookingService, CngAccessService, CngApiError, CngPermissionError, CngProductService, CustomQuestionService, DailyNoteService, INSTALL_STATUSES, MembershipService, PeekAccessService, PeekGraphQLError, PeekHttpError, PiiAccessDisabledError, PricingService, ProductService, PromoCodeService, RENTAL_PRODUCT_TYPE, RateLimitError, ResellerService, ResourcePoolService, ReviewService, TimeslotService, createAccessServiceForInstall, noopLogger, parseBookingWebhook, parseInstallWebhook, parseWaiverWebhook, verifyInstallWebhook };
5201
5282
  //# sourceMappingURL=index.js.map
5202
5283
  //# sourceMappingURL=index.js.map