@voyant-travel/storefront 0.120.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/LICENSE +201 -0
- package/README.md +231 -0
- package/dist/booking-intents.d.ts +42 -0
- package/dist/booking-intents.d.ts.map +1 -0
- package/dist/booking-intents.js +83 -0
- package/dist/customer-portal/index.d.ts +16 -0
- package/dist/customer-portal/index.d.ts.map +1 -0
- package/dist/customer-portal/index.js +23 -0
- package/dist/customer-portal/route-runtime.d.ts +16 -0
- package/dist/customer-portal/route-runtime.d.ts.map +1 -0
- package/dist/customer-portal/route-runtime.js +27 -0
- package/dist/customer-portal/routes-public.d.ts +1936 -0
- package/dist/customer-portal/routes-public.d.ts.map +1 -0
- package/dist/customer-portal/routes-public.js +165 -0
- package/dist/customer-portal/routes.d.ts +43 -0
- package/dist/customer-portal/routes.d.ts.map +1 -0
- package/dist/customer-portal/routes.js +17 -0
- package/dist/customer-portal/service-public-impl.d.ts +138 -0
- package/dist/customer-portal/service-public-impl.d.ts.map +1 -0
- package/dist/customer-portal/service-public-impl.js +1808 -0
- package/dist/customer-portal/service-public.d.ts +2 -0
- package/dist/customer-portal/service-public.d.ts.map +1 -0
- package/dist/customer-portal/service-public.js +1 -0
- package/dist/customer-portal/validation-public/bookings.d.ts +551 -0
- package/dist/customer-portal/validation-public/bookings.d.ts.map +1 -0
- package/dist/customer-portal/validation-public/bookings.js +132 -0
- package/dist/customer-portal/validation-public/common.d.ts +162 -0
- package/dist/customer-portal/validation-public/common.d.ts.map +1 -0
- package/dist/customer-portal/validation-public/common.js +139 -0
- package/dist/customer-portal/validation-public/profile.d.ts +749 -0
- package/dist/customer-portal/validation-public/profile.d.ts.map +1 -0
- package/dist/customer-portal/validation-public/profile.js +308 -0
- package/dist/customer-portal/validation-public.d.ts +3 -0
- package/dist/customer-portal/validation-public.d.ts.map +1 -0
- package/dist/customer-portal/validation-public.js +2 -0
- package/dist/guest-booking-guard.d.ts +24 -0
- package/dist/guest-booking-guard.d.ts.map +1 -0
- package/dist/guest-booking-guard.js +55 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +41 -0
- package/dist/product-extra-ref.d.ts +238 -0
- package/dist/product-extra-ref.d.ts.map +1 -0
- package/dist/product-extra-ref.js +22 -0
- package/dist/routes-admin.d.ts +220 -0
- package/dist/routes-admin.d.ts.map +1 -0
- package/dist/routes-admin.js +28 -0
- package/dist/routes-public.d.ts +1475 -0
- package/dist/routes-public.d.ts.map +1 -0
- package/dist/routes-public.js +362 -0
- package/dist/service-booking-session-bootstrap.d.ts +227 -0
- package/dist/service-booking-session-bootstrap.d.ts.map +1 -0
- package/dist/service-booking-session-bootstrap.js +287 -0
- package/dist/service-boundary-resource-sql.d.ts +18 -0
- package/dist/service-boundary-resource-sql.d.ts.map +1 -0
- package/dist/service-boundary-resource-sql.js +73 -0
- package/dist/service-boundary-sql.d.ts +103 -0
- package/dist/service-boundary-sql.d.ts.map +1 -0
- package/dist/service-boundary-sql.js +307 -0
- package/dist/service-departures-core.d.ts +41 -0
- package/dist/service-departures-core.d.ts.map +1 -0
- package/dist/service-departures-core.js +92 -0
- package/dist/service-departures-extensions.d.ts +46 -0
- package/dist/service-departures-extensions.d.ts.map +1 -0
- package/dist/service-departures-extensions.js +81 -0
- package/dist/service-departures-offers.d.ts +220 -0
- package/dist/service-departures-offers.d.ts.map +1 -0
- package/dist/service-departures-offers.js +177 -0
- package/dist/service-departures-price-preview.d.ts +306 -0
- package/dist/service-departures-price-preview.d.ts.map +1 -0
- package/dist/service-departures-price-preview.js +383 -0
- package/dist/service-departures-pricing-context.d.ts +115 -0
- package/dist/service-departures-pricing-context.d.ts.map +1 -0
- package/dist/service-departures-pricing-context.js +237 -0
- package/dist/service-departures-pricing.d.ts +5 -0
- package/dist/service-departures-pricing.d.ts.map +1 -0
- package/dist/service-departures-pricing.js +4 -0
- package/dist/service-departures.d.ts +192 -0
- package/dist/service-departures.d.ts.map +1 -0
- package/dist/service-departures.js +213 -0
- package/dist/service-intake.d.ts +130 -0
- package/dist/service-intake.d.ts.map +1 -0
- package/dist/service-intake.js +274 -0
- package/dist/service-transport-eligibility.d.ts +10 -0
- package/dist/service-transport-eligibility.d.ts.map +1 -0
- package/dist/service-transport-eligibility.js +198 -0
- package/dist/service.d.ts +1062 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +332 -0
- package/dist/transport-eligibility.d.ts +4 -0
- package/dist/transport-eligibility.d.ts.map +1 -0
- package/dist/transport-eligibility.js +2 -0
- package/dist/validation/departures.d.ts +1669 -0
- package/dist/validation/departures.d.ts.map +1 -0
- package/dist/validation/departures.js +397 -0
- package/dist/validation/intake.d.ts +147 -0
- package/dist/validation/intake.d.ts.map +1 -0
- package/dist/validation/intake.js +69 -0
- package/dist/validation/offers.d.ts +340 -0
- package/dist/validation/offers.d.ts.map +1 -0
- package/dist/validation/offers.js +117 -0
- package/dist/validation-settings.d.ts +609 -0
- package/dist/validation-settings.d.ts.map +1 -0
- package/dist/validation-settings.js +235 -0
- package/dist/validation-transport-eligibility.d.ts +314 -0
- package/dist/validation-transport-eligibility.d.ts.map +1 -0
- package/dist/validation-transport-eligibility.js +97 -0
- package/dist/validation.d.ts +6 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +4 -0
- package/dist/verification/index.d.ts +12 -0
- package/dist/verification/index.d.ts.map +1 -0
- package/dist/verification/index.js +18 -0
- package/dist/verification/routes-public.d.ts +121 -0
- package/dist/verification/routes-public.d.ts.map +1 -0
- package/dist/verification/routes-public.js +125 -0
- package/dist/verification/schema.d.ts +273 -0
- package/dist/verification/schema.d.ts.map +1 -0
- package/dist/verification/schema.js +50 -0
- package/dist/verification/service.d.ts +114 -0
- package/dist/verification/service.d.ts.map +1 -0
- package/dist/verification/service.js +283 -0
- package/dist/verification/validation.d.ts +98 -0
- package/dist/verification/validation.d.ts.map +1 -0
- package/dist/verification/validation.js +54 -0
- package/package.json +148 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import type { StorefrontOfferMutationResult, StorefrontPromotionalOffer } from "./validation.js";
|
|
2
|
+
export interface StorefrontDeparturePricePreviewOfferResolvers {
|
|
3
|
+
listApplicableOffers?: (input: {
|
|
4
|
+
productId: string;
|
|
5
|
+
departureId?: string;
|
|
6
|
+
locale?: string;
|
|
7
|
+
}) => Promise<StorefrontPromotionalOffer[]> | StorefrontPromotionalOffer[];
|
|
8
|
+
applyOffer?: (input: {
|
|
9
|
+
slug: string;
|
|
10
|
+
body: {
|
|
11
|
+
productId: string;
|
|
12
|
+
departureId?: string | null;
|
|
13
|
+
pax: number;
|
|
14
|
+
audience: "customer";
|
|
15
|
+
market: string;
|
|
16
|
+
basePriceCents: number;
|
|
17
|
+
currency: string;
|
|
18
|
+
locale?: string;
|
|
19
|
+
};
|
|
20
|
+
}) => Promise<StorefrontOfferMutationResult | null> | StorefrontOfferMutationResult | null;
|
|
21
|
+
redeemOffer?: (input: {
|
|
22
|
+
body: {
|
|
23
|
+
code: string;
|
|
24
|
+
productId: string;
|
|
25
|
+
departureId?: string | null;
|
|
26
|
+
pax: number;
|
|
27
|
+
audience: "customer";
|
|
28
|
+
market: string;
|
|
29
|
+
basePriceCents: number;
|
|
30
|
+
currency: string;
|
|
31
|
+
locale?: string;
|
|
32
|
+
};
|
|
33
|
+
}) => Promise<StorefrontOfferMutationResult | null> | StorefrontOfferMutationResult | null;
|
|
34
|
+
}
|
|
35
|
+
export declare function buildOfferPreview(input: {
|
|
36
|
+
resolvers?: StorefrontDeparturePricePreviewOfferResolvers;
|
|
37
|
+
productId: string;
|
|
38
|
+
departureId: string;
|
|
39
|
+
basePriceCents: number;
|
|
40
|
+
currencyCode: string;
|
|
41
|
+
paxTotal: number;
|
|
42
|
+
requestedOffers: Array<{
|
|
43
|
+
slug: string;
|
|
44
|
+
}>;
|
|
45
|
+
offerCode?: string | null;
|
|
46
|
+
locale?: string;
|
|
47
|
+
market: string;
|
|
48
|
+
}): Promise<{
|
|
49
|
+
available: {
|
|
50
|
+
offer: {
|
|
51
|
+
id: string;
|
|
52
|
+
name: string;
|
|
53
|
+
slug: string | null;
|
|
54
|
+
description: string | null;
|
|
55
|
+
discountType: "percentage" | "fixed_amount";
|
|
56
|
+
discountValue: string;
|
|
57
|
+
currency: string | null;
|
|
58
|
+
applicableProductIds: string[];
|
|
59
|
+
applicableDepartureIds: string[];
|
|
60
|
+
validFrom: string | null;
|
|
61
|
+
validTo: string | null;
|
|
62
|
+
minTravelers: number | null;
|
|
63
|
+
imageMobileUrl: string | null;
|
|
64
|
+
imageDesktopUrl: string | null;
|
|
65
|
+
stackable: boolean;
|
|
66
|
+
createdAt: string;
|
|
67
|
+
updatedAt: string;
|
|
68
|
+
};
|
|
69
|
+
status: string;
|
|
70
|
+
reason: string | null;
|
|
71
|
+
selected: boolean;
|
|
72
|
+
discountAppliedCents: number;
|
|
73
|
+
discountedPriceCents: number;
|
|
74
|
+
}[];
|
|
75
|
+
requested: ({
|
|
76
|
+
kind: "slug";
|
|
77
|
+
value: string;
|
|
78
|
+
result: {
|
|
79
|
+
status: "applied" | "not_applicable" | "invalid" | "conflict";
|
|
80
|
+
reason: "currency" | "scope" | "booking_mismatch" | "conflict" | "offer_not_found" | "offer_expired" | "offer_not_yet_valid" | "code_not_found" | "code_required" | "code_expired" | "code_not_yet_valid" | "min_pax" | "eligibility" | "no_discount" | "session_mismatch" | null;
|
|
81
|
+
offer: {
|
|
82
|
+
id: string;
|
|
83
|
+
name: string;
|
|
84
|
+
slug: string | null;
|
|
85
|
+
description: string | null;
|
|
86
|
+
discountType: "percentage" | "fixed_amount";
|
|
87
|
+
discountValue: string;
|
|
88
|
+
currency: string | null;
|
|
89
|
+
applicableProductIds: string[];
|
|
90
|
+
applicableDepartureIds: string[];
|
|
91
|
+
validFrom: string | null;
|
|
92
|
+
validTo: string | null;
|
|
93
|
+
minTravelers: number | null;
|
|
94
|
+
imageMobileUrl: string | null;
|
|
95
|
+
imageDesktopUrl: string | null;
|
|
96
|
+
stackable: boolean;
|
|
97
|
+
createdAt: string;
|
|
98
|
+
updatedAt: string;
|
|
99
|
+
} | null;
|
|
100
|
+
target: {
|
|
101
|
+
bookingId: string | null;
|
|
102
|
+
sessionId: string | null;
|
|
103
|
+
productId: string;
|
|
104
|
+
departureId: string | null;
|
|
105
|
+
};
|
|
106
|
+
pricing: {
|
|
107
|
+
basePriceCents: number;
|
|
108
|
+
currency: string;
|
|
109
|
+
discountAppliedCents: number;
|
|
110
|
+
discountedPriceCents: number;
|
|
111
|
+
};
|
|
112
|
+
appliedOffers: {
|
|
113
|
+
offerId: string;
|
|
114
|
+
offerName: string;
|
|
115
|
+
discountAppliedCents: number;
|
|
116
|
+
discountedPriceCents: number;
|
|
117
|
+
currency: string;
|
|
118
|
+
discountKind: "percentage" | "fixed_amount";
|
|
119
|
+
discountPercent: number | null;
|
|
120
|
+
discountAmountCents: number | null;
|
|
121
|
+
appliedCode: string | null;
|
|
122
|
+
stackable: boolean;
|
|
123
|
+
}[];
|
|
124
|
+
conflict: {
|
|
125
|
+
policy: "best_discount_wins" | "stackable_compose";
|
|
126
|
+
autoAppliedOfferIds: string[];
|
|
127
|
+
manualOfferId: string | null;
|
|
128
|
+
selectedOfferIds: string[];
|
|
129
|
+
message: string;
|
|
130
|
+
} | null;
|
|
131
|
+
} | null;
|
|
132
|
+
} | {
|
|
133
|
+
kind: "code";
|
|
134
|
+
value: string;
|
|
135
|
+
result: {
|
|
136
|
+
status: "applied" | "not_applicable" | "invalid" | "conflict";
|
|
137
|
+
reason: "currency" | "scope" | "booking_mismatch" | "conflict" | "offer_not_found" | "offer_expired" | "offer_not_yet_valid" | "code_not_found" | "code_required" | "code_expired" | "code_not_yet_valid" | "min_pax" | "eligibility" | "no_discount" | "session_mismatch" | null;
|
|
138
|
+
offer: {
|
|
139
|
+
id: string;
|
|
140
|
+
name: string;
|
|
141
|
+
slug: string | null;
|
|
142
|
+
description: string | null;
|
|
143
|
+
discountType: "percentage" | "fixed_amount";
|
|
144
|
+
discountValue: string;
|
|
145
|
+
currency: string | null;
|
|
146
|
+
applicableProductIds: string[];
|
|
147
|
+
applicableDepartureIds: string[];
|
|
148
|
+
validFrom: string | null;
|
|
149
|
+
validTo: string | null;
|
|
150
|
+
minTravelers: number | null;
|
|
151
|
+
imageMobileUrl: string | null;
|
|
152
|
+
imageDesktopUrl: string | null;
|
|
153
|
+
stackable: boolean;
|
|
154
|
+
createdAt: string;
|
|
155
|
+
updatedAt: string;
|
|
156
|
+
} | null;
|
|
157
|
+
target: {
|
|
158
|
+
bookingId: string | null;
|
|
159
|
+
sessionId: string | null;
|
|
160
|
+
productId: string;
|
|
161
|
+
departureId: string | null;
|
|
162
|
+
};
|
|
163
|
+
pricing: {
|
|
164
|
+
basePriceCents: number;
|
|
165
|
+
currency: string;
|
|
166
|
+
discountAppliedCents: number;
|
|
167
|
+
discountedPriceCents: number;
|
|
168
|
+
};
|
|
169
|
+
appliedOffers: {
|
|
170
|
+
offerId: string;
|
|
171
|
+
offerName: string;
|
|
172
|
+
discountAppliedCents: number;
|
|
173
|
+
discountedPriceCents: number;
|
|
174
|
+
currency: string;
|
|
175
|
+
discountKind: "percentage" | "fixed_amount";
|
|
176
|
+
discountPercent: number | null;
|
|
177
|
+
discountAmountCents: number | null;
|
|
178
|
+
appliedCode: string | null;
|
|
179
|
+
stackable: boolean;
|
|
180
|
+
}[];
|
|
181
|
+
conflict: {
|
|
182
|
+
policy: "best_discount_wins" | "stackable_compose";
|
|
183
|
+
autoAppliedOfferIds: string[];
|
|
184
|
+
manualOfferId: string | null;
|
|
185
|
+
selectedOfferIds: string[];
|
|
186
|
+
message: string;
|
|
187
|
+
} | null;
|
|
188
|
+
} | null;
|
|
189
|
+
})[];
|
|
190
|
+
applied: {
|
|
191
|
+
offerId: string;
|
|
192
|
+
offerName: string;
|
|
193
|
+
discountAppliedCents: number;
|
|
194
|
+
discountedPriceCents: number;
|
|
195
|
+
currency: string;
|
|
196
|
+
discountKind: "percentage" | "fixed_amount";
|
|
197
|
+
discountPercent: number | null;
|
|
198
|
+
discountAmountCents: number | null;
|
|
199
|
+
appliedCode: string | null;
|
|
200
|
+
stackable: boolean;
|
|
201
|
+
}[];
|
|
202
|
+
conflict: {
|
|
203
|
+
policy: "best_discount_wins" | "stackable_compose";
|
|
204
|
+
autoAppliedOfferIds: string[];
|
|
205
|
+
manualOfferId: string | null;
|
|
206
|
+
selectedOfferIds: string[];
|
|
207
|
+
message: string;
|
|
208
|
+
} | {
|
|
209
|
+
policy: string;
|
|
210
|
+
autoAppliedOfferIds: string[];
|
|
211
|
+
manualOfferId: null;
|
|
212
|
+
selectedOfferIds: string[];
|
|
213
|
+
message: string;
|
|
214
|
+
} | null;
|
|
215
|
+
discountTotal: number;
|
|
216
|
+
discountTotalCents: number;
|
|
217
|
+
totalAfterDiscount: number;
|
|
218
|
+
currencyCode: string;
|
|
219
|
+
}>;
|
|
220
|
+
//# sourceMappingURL=service-departures-offers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-departures-offers.d.ts","sourceRoot":"","sources":["../src/service-departures-offers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEV,6BAA6B,EAC7B,0BAA0B,EAC3B,MAAM,iBAAiB,CAAA;AAExB,MAAM,WAAW,6CAA6C;IAC5D,oBAAoB,CAAC,EAAE,CAAC,KAAK,EAAE;QAC7B,SAAS,EAAE,MAAM,CAAA;QACjB,WAAW,CAAC,EAAE,MAAM,CAAA;QACpB,MAAM,CAAC,EAAE,MAAM,CAAA;KAChB,KAAK,OAAO,CAAC,0BAA0B,EAAE,CAAC,GAAG,0BAA0B,EAAE,CAAA;IAC1E,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE;QACnB,IAAI,EAAE,MAAM,CAAA;QACZ,IAAI,EAAE;YACJ,SAAS,EAAE,MAAM,CAAA;YACjB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;YAC3B,GAAG,EAAE,MAAM,CAAA;YACX,QAAQ,EAAE,UAAU,CAAA;YACpB,MAAM,EAAE,MAAM,CAAA;YACd,cAAc,EAAE,MAAM,CAAA;YACtB,QAAQ,EAAE,MAAM,CAAA;YAChB,MAAM,CAAC,EAAE,MAAM,CAAA;SAChB,CAAA;KACF,KAAK,OAAO,CAAC,6BAA6B,GAAG,IAAI,CAAC,GAAG,6BAA6B,GAAG,IAAI,CAAA;IAC1F,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE;QACpB,IAAI,EAAE;YACJ,IAAI,EAAE,MAAM,CAAA;YACZ,SAAS,EAAE,MAAM,CAAA;YACjB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;YAC3B,GAAG,EAAE,MAAM,CAAA;YACX,QAAQ,EAAE,UAAU,CAAA;YACpB,MAAM,EAAE,MAAM,CAAA;YACd,cAAc,EAAE,MAAM,CAAA;YACtB,QAAQ,EAAE,MAAM,CAAA;YAChB,MAAM,CAAC,EAAE,MAAM,CAAA;SAChB,CAAA;KACF,KAAK,OAAO,CAAC,6BAA6B,GAAG,IAAI,CAAC,GAAG,6BAA6B,GAAG,IAAI,CAAA;CAC3F;AAwJD,wBAAsB,iBAAiB,CAAC,KAAK,EAAE;IAC7C,SAAS,CAAC,EAAE,6CAA6C,CAAA;IACzD,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,MAAM,CAAA;IACnB,cAAc,EAAE,MAAM,CAAA;IACtB,YAAY,EAAE,MAAM,CAAA;IACpB,QAAQ,EAAE,MAAM,CAAA;IAChB,eAAe,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IACxC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;CACf;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4EA"}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { centsToAmount } from "./service-departures-pricing-context.js";
|
|
2
|
+
function computeOfferDiscountCents(offer, basePriceCents) {
|
|
3
|
+
if (basePriceCents <= 0)
|
|
4
|
+
return 0;
|
|
5
|
+
if (offer.discountType === "percentage") {
|
|
6
|
+
const percent = Number(offer.discountValue);
|
|
7
|
+
return Number.isFinite(percent) ? Math.round((basePriceCents * percent) / 100) : 0;
|
|
8
|
+
}
|
|
9
|
+
const discountCents = Number.parseInt(offer.discountValue, 10);
|
|
10
|
+
return Number.isFinite(discountCents) ? Math.min(discountCents, basePriceCents) : 0;
|
|
11
|
+
}
|
|
12
|
+
function buildAppliedOfferFromDto(input) {
|
|
13
|
+
const discountPercent = input.offer.discountType === "percentage" ? Number(input.offer.discountValue) : null;
|
|
14
|
+
const discountAmountCents = input.offer.discountType === "fixed_amount"
|
|
15
|
+
? Number.parseInt(input.offer.discountValue, 10)
|
|
16
|
+
: null;
|
|
17
|
+
return {
|
|
18
|
+
offerId: input.offer.id,
|
|
19
|
+
offerName: input.offer.name,
|
|
20
|
+
discountAppliedCents: input.discountAppliedCents,
|
|
21
|
+
discountedPriceCents: Math.max(0, input.basePriceCents - input.discountAppliedCents),
|
|
22
|
+
currency: input.currencyCode,
|
|
23
|
+
discountKind: input.offer.discountType,
|
|
24
|
+
discountPercent: Number.isFinite(discountPercent) ? discountPercent : null,
|
|
25
|
+
discountAmountCents: Number.isFinite(discountAmountCents) ? discountAmountCents : null,
|
|
26
|
+
appliedCode: null,
|
|
27
|
+
stackable: input.offer.stackable,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function evaluateAvailableOfferImpacts(input) {
|
|
31
|
+
const candidates = input.offers.map((offer) => {
|
|
32
|
+
const standaloneDiscount = computeOfferDiscountCents(offer, input.basePriceCents);
|
|
33
|
+
const reason = offer.minTravelers != null && input.paxTotal < offer.minTravelers
|
|
34
|
+
? "min_pax"
|
|
35
|
+
: offer.discountType === "fixed_amount" && offer.currency !== input.currencyCode
|
|
36
|
+
? "currency"
|
|
37
|
+
: standaloneDiscount <= 0
|
|
38
|
+
? "no_discount"
|
|
39
|
+
: null;
|
|
40
|
+
return { offer, standaloneDiscount, reason };
|
|
41
|
+
});
|
|
42
|
+
const applicable = candidates.filter((candidate) => candidate.reason == null);
|
|
43
|
+
const stackable = applicable
|
|
44
|
+
.filter((candidate) => candidate.offer.stackable)
|
|
45
|
+
.sort((a, b) => (a.offer.id < b.offer.id ? -1 : a.offer.id > b.offer.id ? 1 : 0));
|
|
46
|
+
const nonStackable = applicable.filter((candidate) => !candidate.offer.stackable);
|
|
47
|
+
let bestNonStackable = null;
|
|
48
|
+
for (const candidate of nonStackable) {
|
|
49
|
+
if (bestNonStackable == null ||
|
|
50
|
+
candidate.standaloneDiscount > bestNonStackable.standaloneDiscount) {
|
|
51
|
+
bestNonStackable = candidate;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
let runningBase = input.basePriceCents;
|
|
55
|
+
const selectedStackable = stackable
|
|
56
|
+
.map((candidate) => {
|
|
57
|
+
const discount = computeOfferDiscountCents(candidate.offer, runningBase);
|
|
58
|
+
runningBase = Math.max(0, runningBase - discount);
|
|
59
|
+
return { ...candidate, selectedDiscount: discount };
|
|
60
|
+
})
|
|
61
|
+
.filter((candidate) => candidate.selectedDiscount > 0);
|
|
62
|
+
const stackableDiscount = input.basePriceCents - runningBase;
|
|
63
|
+
const selected = bestNonStackable && bestNonStackable.standaloneDiscount >= stackableDiscount
|
|
64
|
+
? [{ ...bestNonStackable, selectedDiscount: bestNonStackable.standaloneDiscount }]
|
|
65
|
+
: selectedStackable;
|
|
66
|
+
const selectedByOfferId = new Map(selected.map((candidate) => [candidate.offer.id, candidate]));
|
|
67
|
+
const applied = selected.map((candidate) => buildAppliedOfferFromDto({
|
|
68
|
+
offer: candidate.offer,
|
|
69
|
+
discountAppliedCents: candidate.selectedDiscount,
|
|
70
|
+
basePriceCents: input.basePriceCents,
|
|
71
|
+
currencyCode: input.currencyCode,
|
|
72
|
+
}));
|
|
73
|
+
const discountTotalCents = applied.reduce((sum, offer) => sum + offer.discountAppliedCents, 0);
|
|
74
|
+
const eligibleButNotSelected = applicable.filter((candidate) => !selectedByOfferId.has(candidate.offer.id));
|
|
75
|
+
const conflict = eligibleButNotSelected.length > 0
|
|
76
|
+
? {
|
|
77
|
+
policy: selected.every((candidate) => candidate.offer.stackable)
|
|
78
|
+
? "stackable_compose"
|
|
79
|
+
: "best_discount_wins",
|
|
80
|
+
autoAppliedOfferIds: selected
|
|
81
|
+
.filter((candidate) => candidate.offer.slug == null)
|
|
82
|
+
.map((candidate) => candidate.offer.id),
|
|
83
|
+
manualOfferId: null,
|
|
84
|
+
selectedOfferIds: selected.map((candidate) => candidate.offer.id),
|
|
85
|
+
message: selected.every((candidate) => candidate.offer.stackable)
|
|
86
|
+
? "Stackable offers compose when they beat the best standalone discount."
|
|
87
|
+
: "The best discount wins when non-stackable offers compete.",
|
|
88
|
+
}
|
|
89
|
+
: null;
|
|
90
|
+
return {
|
|
91
|
+
available: candidates.map((candidate) => {
|
|
92
|
+
const selectedCandidate = selectedByOfferId.get(candidate.offer.id);
|
|
93
|
+
const selectedDiscount = selectedCandidate?.selectedDiscount ?? 0;
|
|
94
|
+
const conflictReason = candidate.reason == null && !selectedCandidate && selected.length > 0 ? "conflict" : null;
|
|
95
|
+
const discountAppliedCents = selectedCandidate?.selectedDiscount ?? candidate.standaloneDiscount;
|
|
96
|
+
return {
|
|
97
|
+
offer: candidate.offer,
|
|
98
|
+
status: selectedCandidate ? "applied" : conflictReason ? "conflict" : "not_applicable",
|
|
99
|
+
reason: candidate.reason ?? conflictReason,
|
|
100
|
+
selected: Boolean(selectedCandidate),
|
|
101
|
+
discountAppliedCents,
|
|
102
|
+
discountedPriceCents: Math.max(0, input.basePriceCents -
|
|
103
|
+
(selectedCandidate ? selectedDiscount : candidate.standaloneDiscount)),
|
|
104
|
+
};
|
|
105
|
+
}),
|
|
106
|
+
applied,
|
|
107
|
+
conflict,
|
|
108
|
+
discountTotalCents,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
export async function buildOfferPreview(input) {
|
|
112
|
+
const availableOffers = (await input.resolvers?.listApplicableOffers?.({
|
|
113
|
+
productId: input.productId,
|
|
114
|
+
departureId: input.departureId,
|
|
115
|
+
locale: input.locale,
|
|
116
|
+
})) ?? [];
|
|
117
|
+
const autoPreview = evaluateAvailableOfferImpacts({
|
|
118
|
+
offers: availableOffers,
|
|
119
|
+
basePriceCents: input.basePriceCents,
|
|
120
|
+
currencyCode: input.currencyCode,
|
|
121
|
+
paxTotal: input.paxTotal,
|
|
122
|
+
});
|
|
123
|
+
const target = {
|
|
124
|
+
productId: input.productId,
|
|
125
|
+
departureId: input.departureId,
|
|
126
|
+
pax: input.paxTotal,
|
|
127
|
+
audience: "customer",
|
|
128
|
+
market: input.market,
|
|
129
|
+
basePriceCents: input.basePriceCents,
|
|
130
|
+
currency: input.currencyCode,
|
|
131
|
+
...(input.locale ? { locale: input.locale } : {}),
|
|
132
|
+
};
|
|
133
|
+
const requested = [];
|
|
134
|
+
for (const offer of input.requestedOffers) {
|
|
135
|
+
requested.push({
|
|
136
|
+
kind: "slug",
|
|
137
|
+
value: offer.slug,
|
|
138
|
+
result: (await input.resolvers?.applyOffer?.({
|
|
139
|
+
slug: offer.slug,
|
|
140
|
+
body: target,
|
|
141
|
+
})) ?? null,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
if (input.offerCode) {
|
|
145
|
+
requested.push({
|
|
146
|
+
kind: "code",
|
|
147
|
+
value: input.offerCode,
|
|
148
|
+
result: (await input.resolvers?.redeemOffer?.({
|
|
149
|
+
body: { ...target, code: input.offerCode },
|
|
150
|
+
})) ?? null,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
const bestRequested = requested
|
|
154
|
+
.map((entry) => entry.result)
|
|
155
|
+
.filter((result) => Boolean(result))
|
|
156
|
+
.filter((result) => result.status === "applied" || result.status === "conflict")
|
|
157
|
+
.sort((a, b) => b.pricing.discountAppliedCents - a.pricing.discountAppliedCents)[0];
|
|
158
|
+
const applied = bestRequested && bestRequested.pricing.discountAppliedCents > autoPreview.discountTotalCents
|
|
159
|
+
? bestRequested.appliedOffers
|
|
160
|
+
: autoPreview.applied;
|
|
161
|
+
const conflict = bestRequested && bestRequested.pricing.discountAppliedCents > autoPreview.discountTotalCents
|
|
162
|
+
? bestRequested.conflict
|
|
163
|
+
: autoPreview.conflict;
|
|
164
|
+
const discountTotalCents = bestRequested && bestRequested.pricing.discountAppliedCents > autoPreview.discountTotalCents
|
|
165
|
+
? bestRequested.pricing.discountAppliedCents
|
|
166
|
+
: autoPreview.discountTotalCents;
|
|
167
|
+
return {
|
|
168
|
+
available: autoPreview.available,
|
|
169
|
+
requested,
|
|
170
|
+
applied,
|
|
171
|
+
conflict,
|
|
172
|
+
discountTotal: centsToAmount(discountTotalCents) ?? 0,
|
|
173
|
+
discountTotalCents,
|
|
174
|
+
totalAfterDiscount: centsToAmount(Math.max(0, input.basePriceCents - discountTotalCents)) ?? 0,
|
|
175
|
+
currencyCode: input.currencyCode,
|
|
176
|
+
};
|
|
177
|
+
}
|