@peektravel/app-utilities 0.8.0 → 0.8.1
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.cjs +29 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -2
- package/dist/index.d.ts +11 -2
- package/dist/index.js +29 -8
- package/dist/index.js.map +1 -1
- package/llms.txt +4 -0
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -896,6 +896,14 @@ interface CreateBookingInput {
|
|
|
896
896
|
* invalid checkbox value fails creation before any quote is made.
|
|
897
897
|
*/
|
|
898
898
|
customQuestionAnswers?: CustomQuestionAnswerInput[];
|
|
899
|
+
/**
|
|
900
|
+
* When `true`, creation fails if any of the activity's required custom
|
|
901
|
+
* questions (per-guest questions excluded) is left unanswered. Because this
|
|
902
|
+
* enforces coverage against the activity's questions, it forces custom-question
|
|
903
|
+
* validation to run even when `customQuestionAnswers` is empty or omitted.
|
|
904
|
+
* Default: `false`.
|
|
905
|
+
*/
|
|
906
|
+
requireRequiredQuestions?: boolean;
|
|
899
907
|
/** Suppress the customer confirmation email. Default: false. */
|
|
900
908
|
skipCustomerEmail?: boolean;
|
|
901
909
|
/** Clone the quote from an existing order. */
|
|
@@ -1268,8 +1276,9 @@ declare class BookingService {
|
|
|
1268
1276
|
*
|
|
1269
1277
|
* @throws {Error} when `activityId`, `availabilityTimeId`, a ticket
|
|
1270
1278
|
* `resourceOptionId`/positive `quantity`, or the guest `name` is missing; when
|
|
1271
|
-
* `markAsPaid` is set without an `idempotencyKey`;
|
|
1272
|
-
*
|
|
1279
|
+
* `markAsPaid` is set without an `idempotencyKey`; when
|
|
1280
|
+
* `requireRequiredQuestions` is set and a required custom question is left
|
|
1281
|
+
* unanswered; or when the quote/order mutations fail.
|
|
1273
1282
|
*/
|
|
1274
1283
|
create(input: CreateBookingInput): Promise<CreatedBooking>;
|
|
1275
1284
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -896,6 +896,14 @@ interface CreateBookingInput {
|
|
|
896
896
|
* invalid checkbox value fails creation before any quote is made.
|
|
897
897
|
*/
|
|
898
898
|
customQuestionAnswers?: CustomQuestionAnswerInput[];
|
|
899
|
+
/**
|
|
900
|
+
* When `true`, creation fails if any of the activity's required custom
|
|
901
|
+
* questions (per-guest questions excluded) is left unanswered. Because this
|
|
902
|
+
* enforces coverage against the activity's questions, it forces custom-question
|
|
903
|
+
* validation to run even when `customQuestionAnswers` is empty or omitted.
|
|
904
|
+
* Default: `false`.
|
|
905
|
+
*/
|
|
906
|
+
requireRequiredQuestions?: boolean;
|
|
899
907
|
/** Suppress the customer confirmation email. Default: false. */
|
|
900
908
|
skipCustomerEmail?: boolean;
|
|
901
909
|
/** Clone the quote from an existing order. */
|
|
@@ -1268,8 +1276,9 @@ declare class BookingService {
|
|
|
1268
1276
|
*
|
|
1269
1277
|
* @throws {Error} when `activityId`, `availabilityTimeId`, a ticket
|
|
1270
1278
|
* `resourceOptionId`/positive `quantity`, or the guest `name` is missing; when
|
|
1271
|
-
* `markAsPaid` is set without an `idempotencyKey`;
|
|
1272
|
-
*
|
|
1279
|
+
* `markAsPaid` is set without an `idempotencyKey`; when
|
|
1280
|
+
* `requireRequiredQuestions` is set and a required custom question is left
|
|
1281
|
+
* unanswered; or when the quote/order mutations fail.
|
|
1273
1282
|
*/
|
|
1274
1283
|
create(input: CreateBookingInput): Promise<CreatedBooking>;
|
|
1275
1284
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1059,6 +1059,7 @@ var errInvalidCheckbox = (v, id) => `Checkbox answer for question "${id}" must b
|
|
|
1059
1059
|
var errUnknownOptionId = (v, id) => `No option matches id "${v}" for question "${id}"`;
|
|
1060
1060
|
var errNoOptionMatch = (v, id) => `No option matches "${v}" for question "${id}"`;
|
|
1061
1061
|
var errAmbiguousOption = (v, id) => `Option "${v}" matches more than one option for question "${id}"`;
|
|
1062
|
+
var errMissingRequired = (text, id) => `Custom question "${text}" (${id}) is required but was not answered`;
|
|
1062
1063
|
function normalize(value) {
|
|
1063
1064
|
return value.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
1064
1065
|
}
|
|
@@ -1123,8 +1124,20 @@ function resolveOne(answer, questions) {
|
|
|
1123
1124
|
throw new Error(errUnsupportedType(question.questionType, question.id));
|
|
1124
1125
|
}
|
|
1125
1126
|
}
|
|
1126
|
-
function resolveCustomQuestionAnswers(answers, questions) {
|
|
1127
|
-
|
|
1127
|
+
function resolveCustomQuestionAnswers(answers, questions, options) {
|
|
1128
|
+
const resolved = answers.map((answer) => resolveOne(answer, questions));
|
|
1129
|
+
if (options?.requireRequired) {
|
|
1130
|
+
assertRequiredAnswered(resolved, questions);
|
|
1131
|
+
}
|
|
1132
|
+
return resolved;
|
|
1133
|
+
}
|
|
1134
|
+
function assertRequiredAnswered(resolved, questions) {
|
|
1135
|
+
const answered = new Set(resolved.map((answer) => answer.questionId));
|
|
1136
|
+
for (const question of questions) {
|
|
1137
|
+
if (question.isRequired && !question.perGuest && !answered.has(question.id)) {
|
|
1138
|
+
throw new Error(errMissingRequired(question.questionText, question.id));
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1128
1141
|
}
|
|
1129
1142
|
|
|
1130
1143
|
// src/internal/peek/bookings/booking-service.ts
|
|
@@ -1641,8 +1654,9 @@ ${note}`;
|
|
|
1641
1654
|
*
|
|
1642
1655
|
* @throws {Error} when `activityId`, `availabilityTimeId`, a ticket
|
|
1643
1656
|
* `resourceOptionId`/positive `quantity`, or the guest `name` is missing; when
|
|
1644
|
-
* `markAsPaid` is set without an `idempotencyKey`;
|
|
1645
|
-
*
|
|
1657
|
+
* `markAsPaid` is set without an `idempotencyKey`; when
|
|
1658
|
+
* `requireRequiredQuestions` is set and a required custom question is left
|
|
1659
|
+
* unanswered; or when the quote/order mutations fail.
|
|
1646
1660
|
*/
|
|
1647
1661
|
async create(input) {
|
|
1648
1662
|
validateCreateInput(input);
|
|
@@ -1722,15 +1736,22 @@ ${note}`;
|
|
|
1722
1736
|
* against; throws on the first unmatched/ambiguous/invalid answer.
|
|
1723
1737
|
*/
|
|
1724
1738
|
async buildQuestionAnswers(input) {
|
|
1725
|
-
const answers = input.customQuestionAnswers;
|
|
1726
|
-
|
|
1739
|
+
const answers = input.customQuestionAnswers ?? [];
|
|
1740
|
+
const requireRequired = input.requireRequiredQuestions ?? false;
|
|
1741
|
+
if (answers.length === 0 && !requireRequired) {
|
|
1727
1742
|
return null;
|
|
1728
1743
|
}
|
|
1729
1744
|
const questions = await this.deps.productService.getCustomQuestions(
|
|
1730
1745
|
input.activityId
|
|
1731
1746
|
);
|
|
1732
|
-
|
|
1733
|
-
|
|
1747
|
+
const resolved = resolveCustomQuestionAnswers(answers, questions, {
|
|
1748
|
+
requireRequired
|
|
1749
|
+
});
|
|
1750
|
+
if (resolved.length === 0) {
|
|
1751
|
+
return null;
|
|
1752
|
+
}
|
|
1753
|
+
return resolved.map((answer) => ({
|
|
1754
|
+
...answer,
|
|
1734
1755
|
refid: randomUUID()
|
|
1735
1756
|
}));
|
|
1736
1757
|
}
|