@fleetbridge/client 0.0.0-stage → 1.4.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.
- package/README.md +308 -2
- package/index.d.ts +1691 -0
- package/index.js +2078 -0
- package/package.json +20 -4
package/index.d.ts
ADDED
|
@@ -0,0 +1,1691 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How the customer booking logic talks to the host site.
|
|
3
|
+
*
|
|
4
|
+
* Every query in this package goes through one `FleetBridgeTransport`, and so
|
|
5
|
+
* does every query in @fleetbridge/ui, which bundles this package. The
|
|
6
|
+
* transport carries a public action (by its short name, e.g.
|
|
7
|
+
* "search_availability") and its string fields to the host site, and reads
|
|
8
|
+
* back the `{ success, data }` envelope WordPress's `wp_send_json_*` uses -
|
|
9
|
+
* the same envelope `createPublicHandler` from `@fleetbridge/ui/server` sends.
|
|
10
|
+
*
|
|
11
|
+
* - WordPress: `wordpressTransport({ ajaxUrl, nonce })` posts to admin-ajax.php
|
|
12
|
+
* as `fleetbridge_<action>`.
|
|
13
|
+
* - Anything else (Next.js, Remix, Express…): `httpTransport({ endpoint })`
|
|
14
|
+
* posts to one route of your own that runs `createPublicHandler`.
|
|
15
|
+
* - Native apps (React Native) use `httpTransport` too, with the absolute
|
|
16
|
+
* URL of that route, and send any headers they need through `headers`.
|
|
17
|
+
*
|
|
18
|
+
* Supplier credentials and the account API key never reach the browser:
|
|
19
|
+
* both transports only ever talk to the host site's own server.
|
|
20
|
+
*/
|
|
21
|
+
type QueryResult<T> = {
|
|
22
|
+
success: true;
|
|
23
|
+
data: T;
|
|
24
|
+
} | {
|
|
25
|
+
success: false;
|
|
26
|
+
error: string;
|
|
27
|
+
/**
|
|
28
|
+
* The HTTP status of the failed answer (for example 401, 404, 409, 429),
|
|
29
|
+
* or 0 when the site could not be reached at all (no connection, a
|
|
30
|
+
* timeout). Missing when the transport does not know it (a custom
|
|
31
|
+
* transport, or the "not connected yet" stand-in).
|
|
32
|
+
*/
|
|
33
|
+
status?: number;
|
|
34
|
+
/**
|
|
35
|
+
* Whatever else came back with the failure. Some of it matters to the
|
|
36
|
+
* customer - a booking that the supplier declined still returns the
|
|
37
|
+
* reference the attempt was recorded under. Partial because a transport
|
|
38
|
+
* failure has no payload at all.
|
|
39
|
+
*/
|
|
40
|
+
data?: Partial<T>;
|
|
41
|
+
};
|
|
42
|
+
interface FleetBridgeTransport {
|
|
43
|
+
/** `action` is the short name, without the "fleetbridge_" prefix. */
|
|
44
|
+
post<T>(action: string, fields?: Record<string, string>): Promise<QueryResult<T>>;
|
|
45
|
+
}
|
|
46
|
+
/** Every public action the booking flow calls. */
|
|
47
|
+
declare const PUBLIC_ACTIONS: readonly ["public_branches", "search_sources", "cache_version", "search_availability", "get_estimation", "get_extras", "get_one_way_fee", "supplier_terms", "booking_request", "request_quote", "lookup_quote", "confirm_quote", "lookup_booking", "cancel_my_booking", "amend_my_booking", "payment_methods", "start_payment", "verify_payment", "claim_coupon", "my_coupons"];
|
|
48
|
+
/**
|
|
49
|
+
* Where a request comes from: the website, the mobile app or a WhatsApp bot.
|
|
50
|
+
* Coupons can be limited to some channels.
|
|
51
|
+
*
|
|
52
|
+
* Kept in step by hand with COUPON_CHANNELS in @fleetbridge/contract
|
|
53
|
+
* (packages/contract/src/promotions.ts), which this package does not depend
|
|
54
|
+
* on at run time. Add a channel there and here together.
|
|
55
|
+
*/
|
|
56
|
+
declare const COUPON_CHANNELS: readonly ["web", "app", "whatsapp"];
|
|
57
|
+
type CouponChannel = (typeof COUPON_CHANNELS)[number];
|
|
58
|
+
/** True for "web", "app" or "whatsapp". */
|
|
59
|
+
declare function isCouponChannel(value: unknown): value is CouponChannel;
|
|
60
|
+
/** The request header httpTransport sends the channel in, and createPublicHandler reads it from. */
|
|
61
|
+
declare const CHANNEL_HEADER = "x-fleetbridge-channel";
|
|
62
|
+
type PublicAction = (typeof PUBLIC_ACTIONS)[number];
|
|
63
|
+
/** Strips a leading "fleetbridge_", so either spelling of an action works. */
|
|
64
|
+
declare function shortAction(action: string): string;
|
|
65
|
+
/** Talks to the FleetBridge WordPress plugin through admin-ajax.php. */
|
|
66
|
+
declare function wordpressTransport(options: {
|
|
67
|
+
ajaxUrl: string;
|
|
68
|
+
nonce: string;
|
|
69
|
+
}): FleetBridgeTransport;
|
|
70
|
+
/** Whether fetch sends cookies (the same values as fetch's own `credentials`). */
|
|
71
|
+
type TransportCredentials = 'omit' | 'same-origin' | 'include';
|
|
72
|
+
interface HttpTransportOptions {
|
|
73
|
+
/** The route that runs `createPublicHandler`. Native apps pass an absolute URL. */
|
|
74
|
+
endpoint: string;
|
|
75
|
+
/** Sent with every request, e.g. an app key or a client version header. */
|
|
76
|
+
headers?: Record<string, string>;
|
|
77
|
+
/** Defaults to 'same-origin'. */
|
|
78
|
+
credentials?: TransportCredentials;
|
|
79
|
+
/**
|
|
80
|
+
* Where the requests come from, sent as the `x-fleetbridge-channel` header.
|
|
81
|
+
* The site decides whether to believe it (createPublicHandler's
|
|
82
|
+
* `getChannel`); coupons limited to other channels are then refused.
|
|
83
|
+
* Leave it out on a web page: the site treats its own pages as "web".
|
|
84
|
+
*/
|
|
85
|
+
channel?: CouponChannel;
|
|
86
|
+
/**
|
|
87
|
+
* Gives up on a request after this many milliseconds, failing with
|
|
88
|
+
* status 0 like a lost connection. A number for every action, or a
|
|
89
|
+
* function that picks one per action (for example longer for
|
|
90
|
+
* "search_availability" and "booking_request"); 0 or undefined from it
|
|
91
|
+
* means no limit. Default: no limit.
|
|
92
|
+
*/
|
|
93
|
+
timeoutMs?: number | ((action: string) => number | undefined);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Talks to a route of the host site that runs `createPublicHandler` (see
|
|
97
|
+
* `@fleetbridge/ui/server`). The action travels as the `action` field.
|
|
98
|
+
*/
|
|
99
|
+
declare function httpTransport(options: HttpTransportOptions): FleetBridgeTransport;
|
|
100
|
+
declare function setTransport(transport: FleetBridgeTransport): void;
|
|
101
|
+
/** The transport in use, or a stand-in that explains what is missing. */
|
|
102
|
+
declare function getTransport(): FleetBridgeTransport;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Public results-grid vehicle shape. Mapped from the availability AJAX
|
|
106
|
+
* response (see lib/offers.ts → NormalizedVehicleListing) — only fields the
|
|
107
|
+
* UI can actually populate from a live supplier search.
|
|
108
|
+
*/
|
|
109
|
+
/** One CDP / km package on a listing — values already cleaned by the API. */
|
|
110
|
+
interface RatePackage {
|
|
111
|
+
cdpCode: string;
|
|
112
|
+
/**
|
|
113
|
+
* Whether this package's CDP code should show the "Discount" badge - set
|
|
114
|
+
* server-side (by the core's search.availability action) once for
|
|
115
|
+
* DIRECT-mode codes, or only once a matching Coupon was submitted and
|
|
116
|
+
* validated for a COUPON_GATED-mode code.
|
|
117
|
+
*/
|
|
118
|
+
isDiscounted: boolean;
|
|
119
|
+
/**
|
|
120
|
+
* False when this option's km allowance is not the one on its CDP. The tab
|
|
121
|
+
* stays visible so the difference is obvious, and it cannot be selected.
|
|
122
|
+
* Omitted on supplier rates, which stay selectable.
|
|
123
|
+
*/
|
|
124
|
+
kmSelectable?: boolean;
|
|
125
|
+
/** The CDP's km allowance when this option cannot be selected. 0 or empty means unlimited. */
|
|
126
|
+
cdpKmAllowance?: number | null;
|
|
127
|
+
dailyRate: number;
|
|
128
|
+
totalRate: number;
|
|
129
|
+
/**
|
|
130
|
+
* Pre-discount daily/total rate - only set when this package actually beat
|
|
131
|
+
* a pricier same-km-tier competitor (see aggregator.ts's
|
|
132
|
+
* dedupeCheapestPerKm() and RateOption.discount). Renders as a struck-
|
|
133
|
+
* through "was" price next to the current one.
|
|
134
|
+
*/
|
|
135
|
+
wasDailyRate?: number;
|
|
136
|
+
wasTotalRate?: number;
|
|
137
|
+
kmPerDay: number;
|
|
138
|
+
unlimitedMileage: boolean;
|
|
139
|
+
deposit: number;
|
|
140
|
+
liability: number;
|
|
141
|
+
/** Drop-off/one-way fee (ZAR) - non-zero only when this rate's pick-up and
|
|
142
|
+
* return branches differ (see rate.resolver.ts/aggregator.ts on the API
|
|
143
|
+
* side, which is where it's actually computed per supplier). */
|
|
144
|
+
dropOffFee: number;
|
|
145
|
+
rentalDays: number;
|
|
146
|
+
/**
|
|
147
|
+
* The supplier's own identifier for the rate this package was quoted at,
|
|
148
|
+
* carried through from RateOption (see the API's rate.resolver). Not
|
|
149
|
+
* cosmetic: Thermeon's NewReservationRequest books against
|
|
150
|
+
* `QuotedRate rateID`, so a booking made without it is a booking made at
|
|
151
|
+
* whatever rate the supplier happens to pick, not the one that was shown.
|
|
152
|
+
*/
|
|
153
|
+
rateNo: string;
|
|
154
|
+
/** Rate serial number - Bluu's MakeBookingWithQuote QuoteNumber. */
|
|
155
|
+
rateSrNo: string;
|
|
156
|
+
/**
|
|
157
|
+
* The supplier's price quote for this package (SaniSixt's QUOTEREF).
|
|
158
|
+
* Each CDP code is quoted on its own, so the quote has to be the one
|
|
159
|
+
* of the package that is booked.
|
|
160
|
+
*/
|
|
161
|
+
quoteRef?: string;
|
|
162
|
+
/**
|
|
163
|
+
* SaniSixt price-quote Options for this package (Code/Rate/Inclusive…).
|
|
164
|
+
* Used to price live extras the way carhire merges catalogue ∩ quote options.
|
|
165
|
+
*/
|
|
166
|
+
options?: QuoteExtraOption[];
|
|
167
|
+
/**
|
|
168
|
+
* Coverage tier label for dailyRate/totalRate above - 'Standard' unless
|
|
169
|
+
* `superCover` was selected via CarCard's coverage toggle. Persisted
|
|
170
|
+
* verbatim on the booking (see ratePackageLabel in booking.queries.ts) so
|
|
171
|
+
* the confirmation email says what was actually quoted.
|
|
172
|
+
*/
|
|
173
|
+
ratePackageLabel: string;
|
|
174
|
+
/** Price of each kilometre over the free allowance, in Rand. 0 when the rate does not say. */
|
|
175
|
+
excessPerKm?: number;
|
|
176
|
+
/**
|
|
177
|
+
* The supplier's higher-cover tier for this same km package (e.g.
|
|
178
|
+
* Europcar's SuperCover), present only when the rate resolver returned a
|
|
179
|
+
* genuinely different total from the standard one above (see
|
|
180
|
+
* rate.resolver.ts - most suppliers mirror standardRate into superRate,
|
|
181
|
+
* which is not a real second tier).
|
|
182
|
+
*/
|
|
183
|
+
superCover?: {
|
|
184
|
+
label: string;
|
|
185
|
+
dailyRate: number;
|
|
186
|
+
totalRate: number;
|
|
187
|
+
/** Excess and per-km price for this cover, when they differ from the standard tier. */
|
|
188
|
+
liability?: number;
|
|
189
|
+
excessPerKm?: number;
|
|
190
|
+
deposit?: number;
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
/** Raw WheelSys option on a rate — money still in cents until extras merge. */
|
|
194
|
+
interface QuoteExtraOption {
|
|
195
|
+
code: string;
|
|
196
|
+
name?: string;
|
|
197
|
+
rate: number;
|
|
198
|
+
inclusive?: boolean;
|
|
199
|
+
mandatory?: boolean;
|
|
200
|
+
}
|
|
201
|
+
/** Origin + adapter snapshots from the availability API listing.metadata. */
|
|
202
|
+
interface CarMetadata {
|
|
203
|
+
supplierId: string;
|
|
204
|
+
/** True supplier API record(s) for this vehicle group. */
|
|
205
|
+
origin: Record<string, unknown>[];
|
|
206
|
+
/** Intermediate adapter vehicle shape(s) before ZAR / catalogue enrichment. */
|
|
207
|
+
adapter: Record<string, unknown>[];
|
|
208
|
+
}
|
|
209
|
+
interface Car {
|
|
210
|
+
id: string;
|
|
211
|
+
/** Display make when the supplier model string splits cleanly; otherwise empty. */
|
|
212
|
+
make: string;
|
|
213
|
+
model: string;
|
|
214
|
+
/** Vehicle group / ACRISS class shown as a secondary label (e.g. "A", "MDMR"). */
|
|
215
|
+
trim: string;
|
|
216
|
+
category: string;
|
|
217
|
+
/** Categories this listing's cars belong to. An extra limited to one category is offered only when it matches. */
|
|
218
|
+
categories?: string[];
|
|
219
|
+
seats: number;
|
|
220
|
+
doors: number;
|
|
221
|
+
/** Daily rate in Rand — selected package (defaults to first rate). */
|
|
222
|
+
dailyRate: number;
|
|
223
|
+
/** Full quoted total for the rental window, in Rand. */
|
|
224
|
+
totalRate: number;
|
|
225
|
+
/** Selected rate package's pre-discount daily/total rate - see RatePackage.wasDailyRate. */
|
|
226
|
+
wasDailyRate?: number;
|
|
227
|
+
wasTotalRate?: number;
|
|
228
|
+
/** Security deposit required (ZAR). */
|
|
229
|
+
deposit: number;
|
|
230
|
+
/** Excess / waiver liability (ZAR). */
|
|
231
|
+
liability: number;
|
|
232
|
+
/** Drop-off/one-way fee (ZAR) - see RatePackage.dropOffFee's docblock. */
|
|
233
|
+
dropOffFee: number;
|
|
234
|
+
currency: string;
|
|
235
|
+
kmPerDay: number;
|
|
236
|
+
/** Price of each kilometre over the free allowance, in Rand. Follows the selected cover. */
|
|
237
|
+
excessPerKm?: number;
|
|
238
|
+
image: string;
|
|
239
|
+
featured: boolean;
|
|
240
|
+
location: {
|
|
241
|
+
hub: string;
|
|
242
|
+
city: string;
|
|
243
|
+
};
|
|
244
|
+
insuranceIncluded: boolean;
|
|
245
|
+
/** Provided by the API when free km/day is unlimited (≥ 9999). */
|
|
246
|
+
unlimitedMileage: boolean;
|
|
247
|
+
available: boolean;
|
|
248
|
+
supplier: {
|
|
249
|
+
id?: string;
|
|
250
|
+
name: string;
|
|
251
|
+
logoUrl?: string;
|
|
252
|
+
};
|
|
253
|
+
/** ACRISS / supplier vehicle code — needed later for booking. */
|
|
254
|
+
code?: string;
|
|
255
|
+
/** Selected rate package CDP (updates when the user picks a km package). */
|
|
256
|
+
cdpCode?: string;
|
|
257
|
+
/** Selected rate package's discount-badge flag - see RatePackage.isDiscounted. */
|
|
258
|
+
isDiscounted?: boolean;
|
|
259
|
+
/**
|
|
260
|
+
* Selected rate package's supplier rate identifiers - same "follows the
|
|
261
|
+
* chosen km package" behaviour as `cdpCode` above, and for the same
|
|
262
|
+
* reason: the booking has to be made at the rate the customer was shown,
|
|
263
|
+
* not at whichever package happened to be listed first (see
|
|
264
|
+
* RatePackage.rateNo, and withPackage() in CarCard/helpers.ts).
|
|
265
|
+
*/
|
|
266
|
+
rateNo?: string;
|
|
267
|
+
rateSrNo?: string;
|
|
268
|
+
/** Selected rate package's price quote - see RatePackage.quoteRef. */
|
|
269
|
+
quoteRef?: string;
|
|
270
|
+
/** Selected rate package's coverage tier label (updates with the coverage
|
|
271
|
+
* toggle) - see RatePackage.ratePackageLabel. */
|
|
272
|
+
ratePackageLabel: string;
|
|
273
|
+
carGroup?: string;
|
|
274
|
+
luggage?: number;
|
|
275
|
+
pickUpBranch?: string;
|
|
276
|
+
returnBranch?: string;
|
|
277
|
+
rentalDays?: number;
|
|
278
|
+
/** All rate/km packages for this vehicle group. */
|
|
279
|
+
packages: RatePackage[];
|
|
280
|
+
/**
|
|
281
|
+
* Price-quote reference(s) from the availability response - WheelSys
|
|
282
|
+
* returns one per rate and sends it back as QUOTEREF at booking time.
|
|
283
|
+
* Booking uses the first; a supplier that doesn't quote has none.
|
|
284
|
+
*/
|
|
285
|
+
quoteIds?: string[];
|
|
286
|
+
/** Origin supplier payloads + adapter snapshots from the API. */
|
|
287
|
+
metadata?: CarMetadata;
|
|
288
|
+
/** Optional — only set when the supplier actually returns them. */
|
|
289
|
+
transmission?: string;
|
|
290
|
+
fuelType?: string;
|
|
291
|
+
year?: number;
|
|
292
|
+
condition?: 'New' | 'Used';
|
|
293
|
+
rating?: number;
|
|
294
|
+
reviewCount?: number;
|
|
295
|
+
instantBook?: boolean;
|
|
296
|
+
availableFrom?: string;
|
|
297
|
+
photoCredit?: string;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* The add-on shape the booking wizard's first step renders. Populated live,
|
|
302
|
+
* per car/supplier, by lib/queries/extras.queries.ts (which calls the real
|
|
303
|
+
* adapter - apps/api/src/handlers/suppliers/extras.ts - via the WordPress
|
|
304
|
+
* plugin).
|
|
305
|
+
* There is no static/placeholder list here: a supplier with nothing to
|
|
306
|
+
* offer (or whose adapter doesn't implement getExtras yet) simply has no
|
|
307
|
+
* extras, rather than falling back to invented ones.
|
|
308
|
+
*
|
|
309
|
+
* Prices are in the same currency as the vehicle's daily rate (ZAR).
|
|
310
|
+
*
|
|
311
|
+
* Billing mirrors carhire's `serviceType` / `priceType`:
|
|
312
|
+
* - Per Day → `perDay` (× rental days × quantity)
|
|
313
|
+
* - Per Unit → `onceOff` (× quantity; Quant=true on Sani)
|
|
314
|
+
* - Per Rental → `onceOff` (× 1; Quant=false on Sani)
|
|
315
|
+
* - Per Trip / Per Kilometer / WAIVERS & EXTRAS → `onceOff`
|
|
316
|
+
*/
|
|
317
|
+
/** Charge basis labels shown on the card — same set carhire's ExtraOptionItem uses. */
|
|
318
|
+
type ExtraServiceType = 'Per Unit' | 'Per Rental' | 'Per Day' | 'Per Trip' | 'Per Kilometer' | 'WAIVERS & EXTRAS';
|
|
319
|
+
interface Extra {
|
|
320
|
+
/** Supplier extra code, sent verbatim in the booking payload. */
|
|
321
|
+
code: string;
|
|
322
|
+
name: string;
|
|
323
|
+
/** Optional longer blurb; charge basis lives on `serviceType`. */
|
|
324
|
+
description?: string;
|
|
325
|
+
/**
|
|
326
|
+
* How the supplier bills this extra (Per Unit / Per Rental / Per Day / …).
|
|
327
|
+
* Drives the badge and whether `perDay` or `onceOff` is set.
|
|
328
|
+
*/
|
|
329
|
+
serviceType: ExtraServiceType;
|
|
330
|
+
/** Charged for every rental day. Mutually exclusive with `onceOff`. */
|
|
331
|
+
perDay?: number;
|
|
332
|
+
/** Charged once for the rental (× quantity for Per Unit). */
|
|
333
|
+
onceOff?: number;
|
|
334
|
+
/** Above 1, the card gets a quantity stepper (Per Unit). */
|
|
335
|
+
maxQuantity: number;
|
|
336
|
+
icon: 'shield' | 'tyre' | 'child' | 'driver' | 'gps' | 'wifi' | 'delivery' | 'document';
|
|
337
|
+
/**
|
|
338
|
+
* The supplier's own group for this add-on, when its API sends one (Bluu's
|
|
339
|
+
* ProductType: Waivers, Additional services, Extended services). The
|
|
340
|
+
* wizard lists add-ons under these groups, as the supplier does.
|
|
341
|
+
*/
|
|
342
|
+
group?: string;
|
|
343
|
+
/** Surfaced first, with a "Popular" chip. Set client-side via isPopularExtra. */
|
|
344
|
+
recommended?: boolean;
|
|
345
|
+
/**
|
|
346
|
+
* True when `perDay`/`onceOff` is a placeholder, not a real price - e.g.
|
|
347
|
+
* Bluu's extras-listing endpoint never carries pricing at all (see
|
|
348
|
+
* BluuAdapter.parseExtrasResponse's docblock), so every Bluu extra starts
|
|
349
|
+
* this way until BookingWizard's setQuantity live-quotes it. Lets the UI
|
|
350
|
+
* show "priced once selected" instead of a misleading R0,00.
|
|
351
|
+
*/
|
|
352
|
+
priceUnknown?: boolean;
|
|
353
|
+
}
|
|
354
|
+
/** Selected add-ons, keyed by code. Absent or 0 means not selected. */
|
|
355
|
+
type ExtraSelection = Record<string, number>;
|
|
356
|
+
declare function isPopularExtra(code: string, name: string): boolean;
|
|
357
|
+
/** Map a supplier/raw serviceType string onto the fixed ExtraServiceType set. */
|
|
358
|
+
declare function normalizeServiceType(raw: string | undefined | null): ExtraServiceType;
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* The search criteria - one shape shared by the form that collects them, the
|
|
362
|
+
* URL that carries them between the two shortcodes, and the summary bar that
|
|
363
|
+
* echoes them back on the results page.
|
|
364
|
+
*
|
|
365
|
+
* `SAME_AS_PICKUP` is a sentinel rather than an empty string because Radix
|
|
366
|
+
* Select can't use "" as an item value. It's stripped when building the
|
|
367
|
+
* query, so it never reaches the URL.
|
|
368
|
+
*/
|
|
369
|
+
declare const SAME_AS_PICKUP = "same";
|
|
370
|
+
/** Pick-up defaults here rather than to "any location" - OR Tambo is the
|
|
371
|
+
* highest-traffic branch, so a search opened with no location picked yet
|
|
372
|
+
* still returns a useful result set instead of the whole (unfilterable)
|
|
373
|
+
* fleet. Must match a real `Branches.name` row exactly - see
|
|
374
|
+
* SearchController.php's ajax_public_branches(). */
|
|
375
|
+
declare const DEFAULT_PICKUP_LOCATION = "OR Tambo International Airport";
|
|
376
|
+
interface SearchCriteria {
|
|
377
|
+
pickupLocation: string;
|
|
378
|
+
dropoffLocation: string;
|
|
379
|
+
pickupDate: string;
|
|
380
|
+
dropoffDate: string;
|
|
381
|
+
pickupTime: string;
|
|
382
|
+
dropoffTime: string;
|
|
383
|
+
coupon: string;
|
|
384
|
+
/**
|
|
385
|
+
* Country of residence, same distinction carhire.co.za's own search form
|
|
386
|
+
* makes - some suppliers (e.g. Bluu, see AvailabilityParams.isInternational)
|
|
387
|
+
* quote different rates/terms for a foreign renter.
|
|
388
|
+
*/
|
|
389
|
+
residency: 'ZA' | 'INT';
|
|
390
|
+
/**
|
|
391
|
+
* Adapter identifier to search (e.g. "hertz"). Only set for amend: a
|
|
392
|
+
* normal search fans out to every subscribed supplier.
|
|
393
|
+
*/
|
|
394
|
+
supplier?: string;
|
|
395
|
+
/**
|
|
396
|
+
* The driver's age, when it is outside the usual 25–70 band. Young (and
|
|
397
|
+
* some older) drivers pay a fee or are refused, so suppliers price it.
|
|
398
|
+
* Left out for the usual band, so those searches stay exactly as before.
|
|
399
|
+
*/
|
|
400
|
+
driverAge?: number;
|
|
401
|
+
}
|
|
402
|
+
/** The driver-age choices the card search style offers. `age` is what is sent (the youngest age in the band); none means the usual band. */
|
|
403
|
+
declare const DRIVER_AGE_BANDS: ReadonlyArray<{
|
|
404
|
+
label: string;
|
|
405
|
+
age?: number;
|
|
406
|
+
}>;
|
|
407
|
+
declare const DEFAULT_CRITERIA: SearchCriteria;
|
|
408
|
+
/** 30-minute slots across a plausible counter day. */
|
|
409
|
+
declare const TIME_SLOTS: string[];
|
|
410
|
+
declare function criteriaToQuery(criteria: SearchCriteria): string;
|
|
411
|
+
declare function criteriaFromParams(search: string): SearchCriteria;
|
|
412
|
+
/**
|
|
413
|
+
* Whole days in the rental window, or 0 without one. A rental "day" is a
|
|
414
|
+
* billing unit, so a same-day return still counts as one.
|
|
415
|
+
*/
|
|
416
|
+
declare function rentalDays(criteria: SearchCriteria): number;
|
|
417
|
+
/** Short label for a local-date ISO string, e.g. "24 Aug". */
|
|
418
|
+
declare function formatDateLabel(iso: string): string;
|
|
419
|
+
/**
|
|
420
|
+
* True when the criteria carry a complete trip the server can search: real
|
|
421
|
+
* pick-up and return dates (return not before pick-up) and real times. A
|
|
422
|
+
* link into the results page without dates (for example "Find a car at
|
|
423
|
+
* Sandton") is not a failed search; the page asks for the dates instead.
|
|
424
|
+
*/
|
|
425
|
+
declare function hasValidTrip(criteria: SearchCriteria): boolean;
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Maps the availability search response onto the `Car` shape the results grid
|
|
429
|
+
* renders. The API normalizer owns money/km/image cleaning — this only flattens
|
|
430
|
+
* offers → fleets → Car and copies fields.
|
|
431
|
+
*/
|
|
432
|
+
|
|
433
|
+
interface RawRateOption {
|
|
434
|
+
cdpCode?: string;
|
|
435
|
+
standardRate: number;
|
|
436
|
+
/** Supplier's higher-cover tier total (e.g. Europcar's SuperCover) - see
|
|
437
|
+
* rate.resolver.ts. Most suppliers mirror standardRate into this, which
|
|
438
|
+
* toPackage() treats as "no real second tier" rather than a choice. */
|
|
439
|
+
superRate?: number;
|
|
440
|
+
dailyRate?: number;
|
|
441
|
+
kmPerDay?: number;
|
|
442
|
+
rentalDays?: number;
|
|
443
|
+
unlimitedMileage?: boolean;
|
|
444
|
+
superDeposit?: number;
|
|
445
|
+
liability?: number;
|
|
446
|
+
/** Extra-kilometre price in Rand. Suppliers send standardPricePerKm; own fleet sends standardExcessRatePerKm. */
|
|
447
|
+
standardPricePerKm?: number;
|
|
448
|
+
standardExcessRatePerKm?: number;
|
|
449
|
+
superPricePerKm?: number;
|
|
450
|
+
superExcessRatePerKm?: number;
|
|
451
|
+
/** Own fleet: excess and deposit for the higher cover. */
|
|
452
|
+
superExcess?: number;
|
|
453
|
+
superCoverDeposit?: number;
|
|
454
|
+
/** Drop-off/one-way fee (ZAR) - set only when pick-up and return branches
|
|
455
|
+
* differ (see rate.resolver.ts/aggregator.ts on the API side). */
|
|
456
|
+
dropOffFee?: number;
|
|
457
|
+
/** Supplier rate identifiers - needed to BOOK this rate, see RatePackage. */
|
|
458
|
+
rateNo?: string | number;
|
|
459
|
+
rateSrNo?: string | number;
|
|
460
|
+
/** The supplier's price quote for this rate (SaniSixt), sent back when booking it. */
|
|
461
|
+
quoteRef?: string;
|
|
462
|
+
/** Amount (ZAR, off standardRate) this rate beat a pricier same-km-tier
|
|
463
|
+
* competitor by - see aggregator.ts's dedupeCheapestPerKm(). */
|
|
464
|
+
discount?: number;
|
|
465
|
+
/** Own fleet: false when this plan's km allowance differs from its CDP. */
|
|
466
|
+
kmSelectable?: boolean;
|
|
467
|
+
/** Own fleet: the CDP km allowance behind a blocked option. 0 means unlimited. */
|
|
468
|
+
cdpKmAllowance?: number | null;
|
|
469
|
+
options?: Record<string, unknown>[];
|
|
470
|
+
}
|
|
471
|
+
interface RawSupplier {
|
|
472
|
+
id?: string;
|
|
473
|
+
name?: string;
|
|
474
|
+
logoUrl?: string;
|
|
475
|
+
}
|
|
476
|
+
interface RawListingMetadata {
|
|
477
|
+
supplierId?: string;
|
|
478
|
+
origin?: Record<string, unknown>[];
|
|
479
|
+
adapter?: Record<string, unknown>[];
|
|
480
|
+
}
|
|
481
|
+
interface RawFleetListing {
|
|
482
|
+
seat?: number;
|
|
483
|
+
door?: number;
|
|
484
|
+
code?: string;
|
|
485
|
+
carGroup: string;
|
|
486
|
+
carGroupInt?: string | number;
|
|
487
|
+
model: string;
|
|
488
|
+
carImage?: string;
|
|
489
|
+
category?: string;
|
|
490
|
+
/** Every category the cars in this listing belong to. Own fleet can have more than one. */
|
|
491
|
+
categories?: string[];
|
|
492
|
+
transmission?: string;
|
|
493
|
+
fuel?: string;
|
|
494
|
+
luggage?: number;
|
|
495
|
+
rates: RawRateOption[];
|
|
496
|
+
/** WheelSys price-quote references, one per rate (see Car.quoteIds). */
|
|
497
|
+
quoteId?: string[] | string;
|
|
498
|
+
pickUpBranch?: string;
|
|
499
|
+
returnBranch?: string;
|
|
500
|
+
supplier?: RawSupplier;
|
|
501
|
+
termsAndConditions?: string;
|
|
502
|
+
metadata?: RawListingMetadata;
|
|
503
|
+
}
|
|
504
|
+
interface RawOffer {
|
|
505
|
+
supplier?: string | RawSupplier;
|
|
506
|
+
available: boolean;
|
|
507
|
+
fleets: RawFleetListing[] | null;
|
|
508
|
+
pickBranch?: string | null;
|
|
509
|
+
returnBranch?: string | null;
|
|
510
|
+
cdpCode?: string | null;
|
|
511
|
+
/** CDP codes this search should badge as discounted - worked out by the core's search.availability action. */
|
|
512
|
+
discountCodes?: string[];
|
|
513
|
+
message?: string;
|
|
514
|
+
metadata?: {
|
|
515
|
+
supplierId?: string;
|
|
516
|
+
rentalDays?: number;
|
|
517
|
+
originResponse?: string;
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
/** How one source (a supplier, or the site's own cars) answered a search. */
|
|
521
|
+
interface SourceNotice {
|
|
522
|
+
source: string;
|
|
523
|
+
supplierName?: string;
|
|
524
|
+
/** The supplier's logo (from search_sources), when the site has one. */
|
|
525
|
+
logoUrl?: string;
|
|
526
|
+
status: string;
|
|
527
|
+
/** How many cars this source answered with (for status "ok"). */
|
|
528
|
+
count?: number;
|
|
529
|
+
/** A short reason for customers when this source has no cars to show (from the core). */
|
|
530
|
+
customerMessage?: string;
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* Why the typed coupon's special rate is not shown to the signed-in customer
|
|
534
|
+
* (the site sends who is searching when its getCustomer knows): they used it
|
|
535
|
+
* as often as one customer may (COUPON_CUSTOMER_LIMIT), or it must be claimed
|
|
536
|
+
* first (COUPON_NOT_CLAIMED). `message` is written for customers.
|
|
537
|
+
*/
|
|
538
|
+
interface CouponNotice {
|
|
539
|
+
code: 'COUPON_CUSTOMER_LIMIT' | 'COUPON_NOT_CLAIMED' | (string & {});
|
|
540
|
+
message: string;
|
|
541
|
+
/** The code that was typed. */
|
|
542
|
+
couponCode: string;
|
|
543
|
+
}
|
|
544
|
+
interface OffersResult {
|
|
545
|
+
offers: RawOffer[];
|
|
546
|
+
sources?: SourceNotice[];
|
|
547
|
+
/** Set when the typed coupon's special rate was left out for this customer. */
|
|
548
|
+
couponNotice?: CouponNotice;
|
|
549
|
+
}
|
|
550
|
+
/** The reasons to show customers, one per source, for the sources that have no cars. */
|
|
551
|
+
declare function sourceNotices(result: OffersResult): string[];
|
|
552
|
+
interface MapOffersOptions {
|
|
553
|
+
pickupLabel?: string;
|
|
554
|
+
}
|
|
555
|
+
declare function isOffersResult(value: unknown): value is OffersResult;
|
|
556
|
+
/** Normalize supplier codes (M/A) and words onto filter-friendly labels. */
|
|
557
|
+
declare function normalizeTransmission(value: string | undefined): string | undefined;
|
|
558
|
+
declare function mapOffersToCars(offers: RawOffer[], options?: MapOffersOptions): Car[];
|
|
559
|
+
|
|
560
|
+
/** Every field of `criteria` feeds the search, so the whole object is the
|
|
561
|
+
* cache key - two identical searches (e.g. the same trip re-opened within
|
|
562
|
+
* the 10-minute staleTime) hit the same cache entry and skip the round trip. */
|
|
563
|
+
declare function availabilityQueryKey(criteria: SearchCriteria): readonly ["availability", SearchCriteria];
|
|
564
|
+
/** How one source stands while a search runs: still asking, or answered. */
|
|
565
|
+
interface SourceProgress extends SourceNotice {
|
|
566
|
+
/** True until this source has answered (or failed). */
|
|
567
|
+
pending?: boolean;
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* Searches every source for the trip.
|
|
571
|
+
*
|
|
572
|
+
* It first asks the site who to search (fleetbridge_search_sources), then
|
|
573
|
+
* searches each source on its own, all at the same time. Each time a
|
|
574
|
+
* source answers, `onProgress` gets the whole list again, so the page can
|
|
575
|
+
* tick that source off while the others are still being asked. The answer
|
|
576
|
+
* comes once every source has answered, with all their cars together, in
|
|
577
|
+
* the same shape one big search gives. `onProgress` also gets the offers
|
|
578
|
+
* found so far.
|
|
579
|
+
*
|
|
580
|
+
* A search for one supplier only (criteria.supplier, used when changing a
|
|
581
|
+
* booking), or a site whose plugin has no fleetbridge_search_sources yet,
|
|
582
|
+
* makes one request for everything, as before.
|
|
583
|
+
*/
|
|
584
|
+
declare function searchAvailability(criteria: SearchCriteria,
|
|
585
|
+
/**
|
|
586
|
+
* Called each time a source answers. `offers` is every offer so far (a new
|
|
587
|
+
* array each time), so an app can show cars while the search runs:
|
|
588
|
+
* `mapOffersToCars(offers)`.
|
|
589
|
+
*/
|
|
590
|
+
onProgress?: (sources: SourceProgress[], offers: RawOffer[]) => void): Promise<unknown>;
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* A car's rate packages (km per day, and the coverage tier on top).
|
|
594
|
+
*
|
|
595
|
+
* A search answers with one Car per vehicle, plus its packages
|
|
596
|
+
* (Car.packages). Picking a package, or SuperCover on it, gives the Car the
|
|
597
|
+
* customer books: withPackage() puts that package's prices, cover and rate
|
|
598
|
+
* references on the car, so the booking is made at the rate that was shown.
|
|
599
|
+
*/
|
|
600
|
+
|
|
601
|
+
/** A stable key for a package, e.g. for a tab or a list item. */
|
|
602
|
+
declare function packageKey(pkg: RatePackage): string;
|
|
603
|
+
/** Which of a package's coverage tiers is priced/booked - see
|
|
604
|
+
* RatePackage.superCover's docblock for what makes a tier "real". */
|
|
605
|
+
type CoverageTier = 'standard' | 'super';
|
|
606
|
+
declare function withPackage(car: Car, pkg: RatePackage, tier?: CoverageTier): Car;
|
|
607
|
+
|
|
608
|
+
/**
|
|
609
|
+
* Shared transport for every `*.queries.ts` file: all of them talk to
|
|
610
|
+
* FleetBridge the same way - send an action + fields through the transport
|
|
611
|
+
* the host set on FleetBridgeProvider (see transport.ts) and read back `{ success, data }` /
|
|
612
|
+
* `{ success: false, data: { message } }`.
|
|
613
|
+
*
|
|
614
|
+
* Before this, `extras.queries.ts` and `booking.queries.ts` each duplicated
|
|
615
|
+
* that POST-and-parse dance with slightly different error copy and no
|
|
616
|
+
* shared logging. Subclassing this gets every query the same "site not
|
|
617
|
+
* connected" / "couldn't reach the site" messages and the same
|
|
618
|
+
* `console.log`/`console.error` shape, so a network tab or console filtered
|
|
619
|
+
* on "[FleetBridge]" reads consistently across every query.
|
|
620
|
+
*/
|
|
621
|
+
|
|
622
|
+
declare abstract class BaseQuery {
|
|
623
|
+
/**
|
|
624
|
+
* Sends `action` + `fields` through the transport, which normalizes
|
|
625
|
+
* every possible outcome - unconfigured site, network failure, non-2xx
|
|
626
|
+
* response, `{success: false}` - into one `QueryResult`, so subclasses
|
|
627
|
+
* never branch on `response.ok` vs `payload.success` vs a thrown error
|
|
628
|
+
* differently from each other.
|
|
629
|
+
*/
|
|
630
|
+
protected post<T>(action: string, fields?: Record<string, string>): Promise<QueryResult<T>>;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
/**
|
|
634
|
+
* The pick-up and drop-off places customers can choose from: one entry per
|
|
635
|
+
* branch name across every supplier the site has (public_branches), grouped
|
|
636
|
+
* by region. A native app uses it for its location picker; @fleetbridge/ui's
|
|
637
|
+
* own picker reads the same list.
|
|
638
|
+
*/
|
|
639
|
+
|
|
640
|
+
/** One place to pick up or drop off. */
|
|
641
|
+
interface BranchLocation {
|
|
642
|
+
/** The name customers see and search sends, for example "Cape Town International Airport". */
|
|
643
|
+
name: string;
|
|
644
|
+
/** The region it is listed under (the branch's grouping, else its country code). */
|
|
645
|
+
region: string;
|
|
646
|
+
isAirportBranch: boolean;
|
|
647
|
+
isInternational: boolean;
|
|
648
|
+
/** The street address, when the site has one. */
|
|
649
|
+
address?: string;
|
|
650
|
+
}
|
|
651
|
+
declare class BranchQueries extends BaseQuery {
|
|
652
|
+
/** Every place, ordered by region then name. A failure keeps the site's message and status. */
|
|
653
|
+
list(): Promise<QueryResult<BranchLocation[]>>;
|
|
654
|
+
}
|
|
655
|
+
declare const branchQueries: BranchQueries;
|
|
656
|
+
/** TanStack Query key for the branch list. */
|
|
657
|
+
declare const branchesQueryKey: readonly ["branches"];
|
|
658
|
+
|
|
659
|
+
/**
|
|
660
|
+
* The suppliers the site searches (search_sources): every connection that is
|
|
661
|
+
* switched on and has a login, with its name and logo. Apps use it to show the
|
|
662
|
+
* live list of suppliers, including ones with no cars for a given search.
|
|
663
|
+
*/
|
|
664
|
+
|
|
665
|
+
/** One supplier the site searches. `source` is its adapter name ("europcar", "bluu"…), sent as `supplier` to search only it. */
|
|
666
|
+
interface SupplierSource {
|
|
667
|
+
source: string;
|
|
668
|
+
supplierName: string;
|
|
669
|
+
logoUrl?: string;
|
|
670
|
+
}
|
|
671
|
+
declare class SourceQueries extends BaseQuery {
|
|
672
|
+
/** The live list, in the site's order. A failure keeps the site's message and status. */
|
|
673
|
+
list(): Promise<QueryResult<SupplierSource[]>>;
|
|
674
|
+
}
|
|
675
|
+
declare const sourceQueries: SourceQueries;
|
|
676
|
+
/** TanStack Query key for the supplier list. */
|
|
677
|
+
declare const sourcesQueryKey: readonly ["sources"];
|
|
678
|
+
|
|
679
|
+
/**
|
|
680
|
+
* The site's cache version (cache_version on createPublicHandler): a short
|
|
681
|
+
* hash that changes whenever the branch list, the supplier list or the
|
|
682
|
+
* site's own "clear app caches" stamp changes.
|
|
683
|
+
*
|
|
684
|
+
* An app stores the version next to what it caches (locations, sources…),
|
|
685
|
+
* asks again now and then, and drops its copies when the answer differs.
|
|
686
|
+
* A failed call says nothing about the cache: keep what you have.
|
|
687
|
+
*/
|
|
688
|
+
|
|
689
|
+
/** What cache_version answers. */
|
|
690
|
+
interface CacheVersion {
|
|
691
|
+
/** Compare it, never parse it. */
|
|
692
|
+
version: string;
|
|
693
|
+
/** When the site worked it out (ISO 8601). */
|
|
694
|
+
generatedAt: string;
|
|
695
|
+
}
|
|
696
|
+
declare class CacheQueries extends BaseQuery {
|
|
697
|
+
/** The current cache version. A failure (offline, old site without the action) keeps the site's message and status. */
|
|
698
|
+
version(): Promise<QueryResult<CacheVersion>>;
|
|
699
|
+
}
|
|
700
|
+
declare const cacheQueries: CacheQueries;
|
|
701
|
+
/** TanStack Query key for the cache version. */
|
|
702
|
+
declare const cacheVersionQueryKey: readonly ["cache-version"];
|
|
703
|
+
|
|
704
|
+
/**
|
|
705
|
+
* A supplier name fit to show: an all-capitals string in title case, with
|
|
706
|
+
* known short codes (GPS, USB, CDW, SCDW, TLW …) kept in capitals.
|
|
707
|
+
*
|
|
708
|
+
* displayName('TYRE AND WINDSCREEN COVER') → 'Tyre and Windscreen Cover'
|
|
709
|
+
* displayName('MIFI DATA ON THE GO') → 'MiFi Data on the Go'
|
|
710
|
+
* displayName('GPS UNIT') → 'GPS Unit'
|
|
711
|
+
* displayName('Child seat') → 'Child seat' (left alone)
|
|
712
|
+
*/
|
|
713
|
+
declare function displayName(value: string | null | undefined): string;
|
|
714
|
+
/** The car's name as the booking shows it ("Toyota Vitz or Similar"). */
|
|
715
|
+
declare function carDisplayName(car: {
|
|
716
|
+
make?: string | null;
|
|
717
|
+
model?: string | null;
|
|
718
|
+
}): string;
|
|
719
|
+
|
|
720
|
+
/**
|
|
721
|
+
* Filtering, sorting and formatting for the results shortcode — kept out of
|
|
722
|
+
* the components so the whole filter model is readable in one place.
|
|
723
|
+
*/
|
|
724
|
+
|
|
725
|
+
interface Filters {
|
|
726
|
+
query: string;
|
|
727
|
+
makes: string[];
|
|
728
|
+
models: string[];
|
|
729
|
+
/** Body class (SMALL / MEDIUM / LARGE / PREMIUM) from supplier specs — not group codes. */
|
|
730
|
+
categories: string[];
|
|
731
|
+
fuels: string[];
|
|
732
|
+
suppliers: string[];
|
|
733
|
+
transmission: 'any' | 'Manual' | 'Automatic';
|
|
734
|
+
condition: 'any' | 'New' | 'Used';
|
|
735
|
+
seats: number | null;
|
|
736
|
+
luggage: number | null;
|
|
737
|
+
priceRange: [number, number];
|
|
738
|
+
yearRange: [number, number];
|
|
739
|
+
location: string;
|
|
740
|
+
availableOnly: boolean;
|
|
741
|
+
instantBook: boolean;
|
|
742
|
+
insuranceIncluded: boolean;
|
|
743
|
+
/**
|
|
744
|
+
* Free kilometres per day: null is any, a number keeps cars with at least
|
|
745
|
+
* that many km per day (unlimited counts as more than any number), and
|
|
746
|
+
* "unlimited" keeps only cars with unlimited km.
|
|
747
|
+
*/
|
|
748
|
+
mileage: MileageFilter;
|
|
749
|
+
sort: SortOption;
|
|
750
|
+
}
|
|
751
|
+
type MileageFilter = number | 'unlimited' | null;
|
|
752
|
+
type SortOption = 'recommended' | 'price-asc' | 'price-desc' | 'rating-desc' | 'year-desc';
|
|
753
|
+
declare const SORT_OPTIONS: {
|
|
754
|
+
value: SortOption;
|
|
755
|
+
label: string;
|
|
756
|
+
}[];
|
|
757
|
+
declare const TRANSMISSIONS: readonly ["Manual", "Automatic"];
|
|
758
|
+
declare const FUEL_TYPES: readonly ["Petrol", "Diesel", "Electric", "Hybrid"];
|
|
759
|
+
declare const CONDITIONS: readonly ["New", "Used"];
|
|
760
|
+
/** Open defaults until a search result set can seed real bounds. */
|
|
761
|
+
declare const DEFAULT_PRICE_BOUNDS: [number, number];
|
|
762
|
+
declare const DEFAULT_YEAR_BOUNDS: [number, number];
|
|
763
|
+
declare const DEFAULT_SEAT_OPTIONS: number[];
|
|
764
|
+
declare const DEFAULT_FILTERS: Filters;
|
|
765
|
+
declare function uniqueSorted(values: string[]): string[];
|
|
766
|
+
declare function seatOptionsFromCars(cars: Car[]): number[];
|
|
767
|
+
declare function luggageOptionsFromCars(cars: Car[]): number[];
|
|
768
|
+
/**
|
|
769
|
+
* The km-per-day choices for the filter, from the cars in the results: each
|
|
770
|
+
* allowance a car has (for example 100 and 200), then "unlimited" when a car
|
|
771
|
+
* has unlimited km.
|
|
772
|
+
*/
|
|
773
|
+
declare function mileageOptionsFromCars(cars: Car[]): Array<number | 'unlimited'>;
|
|
774
|
+
/** The words for one km choice, for example "200+ km" or "Unlimited". */
|
|
775
|
+
declare function mileageLabel(mileage: number | 'unlimited'): string;
|
|
776
|
+
declare function priceBoundsFromCars(cars: Car[]): [number, number];
|
|
777
|
+
declare function yearBoundsFromCars(cars: Car[]): [number, number] | null;
|
|
778
|
+
declare function formatZAR(amount: number): string;
|
|
779
|
+
declare function pluralize(count: number, word: string): string;
|
|
780
|
+
declare function filterCars(cars: Car[], filters: Filters): Car[];
|
|
781
|
+
declare function sortCars(cars: Car[], sort: SortOption): Car[];
|
|
782
|
+
type FacetKey = 'categories' | 'makes' | 'fuels' | 'seats' | 'transmission' | 'condition';
|
|
783
|
+
type FacetCounts = Record<string, number>;
|
|
784
|
+
declare function facetCounts(cars: Car[], filters: Filters, key: FacetKey): FacetCounts;
|
|
785
|
+
declare function locationCounts(cars: Car[], filters: Filters): FacetCounts;
|
|
786
|
+
interface ActiveChip {
|
|
787
|
+
id: string;
|
|
788
|
+
label: string;
|
|
789
|
+
clear: Partial<Filters>;
|
|
790
|
+
}
|
|
791
|
+
declare function activeChips(filters: Filters, bounds?: {
|
|
792
|
+
price: [number, number];
|
|
793
|
+
year: [number, number] | null;
|
|
794
|
+
}): ActiveChip[];
|
|
795
|
+
declare function priceHistogram(cars: Car[], bounds?: [number, number], buckets?: number): number[];
|
|
796
|
+
/**
|
|
797
|
+
* Deep-link filter params only (`?category=SUV`). Search location lives in
|
|
798
|
+
* criteria (`?location=`), not here — applying it as a city facet against
|
|
799
|
+
* branch codes silently emptied every real result set.
|
|
800
|
+
*/
|
|
801
|
+
declare function filtersFromSearchParams(search: string): Partial<Filters>;
|
|
802
|
+
|
|
803
|
+
/**
|
|
804
|
+
* Extras (add-ons) for the booking wizard's "Add what you need" step.
|
|
805
|
+
*
|
|
806
|
+
* Sourced from FleetBridge's own synced catalogue - `fleetbridge_get_extras`
|
|
807
|
+
* is a pure local read of this WordPress site's own `Extras` table (see
|
|
808
|
+
* Admin\ExtrasController / ActionController::extras() on
|
|
809
|
+
* the PHP side), not a live per-search call to the supplier. Two of the four
|
|
810
|
+
* supplier adapters (Thermeon/Hertz, WheelSys/SaniSixt) don't reliably return
|
|
811
|
+
* priced, request-scoped extras from their own APIs, so FleetBridge holds a
|
|
812
|
+
* catalogue synced from carhire.co.za (packages/database/seeds/extras.ts)
|
|
813
|
+
* the same way Branches are, and every account's tenant DB gets a copy of
|
|
814
|
+
* whichever suppliers it's subscribed to (see tenant-extras.ts).
|
|
815
|
+
*
|
|
816
|
+
* SaniSixt still merges catalogue rows with pricing already sitting on the
|
|
817
|
+
* fetched rate (`car.packages[].options`, WheelSix's per-rate Options -
|
|
818
|
+
* `!inclusive && rate > 0`, carhire's `getSaniExtras`) since that carries the
|
|
819
|
+
* actual per-vehicle-group price the plain catalogue doesn't. Every other
|
|
820
|
+
* supplier prices straight off the catalogue row.
|
|
821
|
+
*
|
|
822
|
+
* Resolves to `null` rather than `[]` when there's nothing to show, so the
|
|
823
|
+
* wizard can skip the add-ons step instead of rendering it empty.
|
|
824
|
+
*/
|
|
825
|
+
|
|
826
|
+
/**
|
|
827
|
+
* The groups a supplier's API puts its add-ons in, by the code it sends.
|
|
828
|
+
* Bluu's GetAdditionalProductDetails returns a ProductType with each product
|
|
829
|
+
* (it arrives here as `serviceType`): WAI waivers, ADC and ADH additional
|
|
830
|
+
* services (equipment, drivers, child seats, young-driver surcharge), EXS
|
|
831
|
+
* extended services (cross-border, delivery, collection). The order here is
|
|
832
|
+
* the order the groups are shown in, as on Bluu's own booking page.
|
|
833
|
+
*/
|
|
834
|
+
declare const SUPPLIER_GROUPS: Record<string, string>;
|
|
835
|
+
/** TanStack Query key for a car's extras list - see BookingWizard's extrasQuery. */
|
|
836
|
+
declare function extrasQueryKey(car: Car): readonly ["extras", string, string];
|
|
837
|
+
declare class ExtrasQueries extends BaseQuery {
|
|
838
|
+
/**
|
|
839
|
+
* The adapter response has no icon field, so the closest keyword in the
|
|
840
|
+
* name/type stands in for one of the fixed set the wizard already renders.
|
|
841
|
+
* Order matters: more specific terms are checked before the generic ones
|
|
842
|
+
* they could also match (e.g. "child" before "driver").
|
|
843
|
+
*/
|
|
844
|
+
private inferIcon;
|
|
845
|
+
/** Quote Options for the CDP package the user picked (falls back to first). */
|
|
846
|
+
private quoteOptions;
|
|
847
|
+
/**
|
|
848
|
+
* Build an Extra with the right charge field for its serviceType.
|
|
849
|
+
* Only "Per Day" multiplies by rental days — everything else is once-off
|
|
850
|
+
* × quantity, matching carhire BookingSummary (`price * quantity`).
|
|
851
|
+
*/
|
|
852
|
+
private toExtra;
|
|
853
|
+
/**
|
|
854
|
+
* Carhire `getSaniExtras`: keep catalogue rows that also appear on the
|
|
855
|
+
* quote as optional (not inclusive) paid extras, priced in ZAR. The
|
|
856
|
+
* catalogue supplies name/description/serviceType; the quote's Options
|
|
857
|
+
* supply the actual per-vehicle-group price the plain catalogue can't.
|
|
858
|
+
*/
|
|
859
|
+
private mergeSaniCatalogue;
|
|
860
|
+
private mapCatalogueRow;
|
|
861
|
+
/**
|
|
862
|
+
* Bluu-specific overrides applied to every extra from its live catalogue:
|
|
863
|
+
*
|
|
864
|
+
* - `priceUnknown: true` on all of them - GetAdditionalProductDetails
|
|
865
|
+
* never carries a real price (see BluuAdapter.parseExtrasResponse's
|
|
866
|
+
* docblock), so every entry starts at a placeholder 0 until
|
|
867
|
+
* BookingWizard's setQuantity live-quotes it. The UI shows "priced once
|
|
868
|
+
* selected" instead of a misleading R0,00 for these (see ExtraCard).
|
|
869
|
+
* - Additional Driver Waiver gets `serviceType: 'Per Unit'` / a real
|
|
870
|
+
* `maxQuantity` - Bluu's own extras endpoint has no field distinguishing
|
|
871
|
+
* "one of these" from "one per driver", so it maps to a single on/off
|
|
872
|
+
* toggle by default (see mapCatalogueRow). It's confirmed genuinely
|
|
873
|
+
* per-driver: GetQuote needs the count in a separate top-level
|
|
874
|
+
* AdditionalDrivers field (BCR Interface Spec 2.16, GetQuote request,
|
|
875
|
+
* p.25-26; see BluuAdapter.getEstimation), which BookingWizard derives
|
|
876
|
+
* from this extra's selected quantity. Matched by name (no stable code
|
|
877
|
+
* is documented) the same way isPopularExtra() matches known extras
|
|
878
|
+
* elsewhere.
|
|
879
|
+
*/
|
|
880
|
+
private applyBluuGrouping;
|
|
881
|
+
/** The car's add-ons, or null when there are none to show or they could not be loaded. See extrasResult() to tell those two apart. */
|
|
882
|
+
extras(car: Car): Promise<Extra[] | null>;
|
|
883
|
+
/**
|
|
884
|
+
* Like extras(), but a failure (the site could not be reached, or refused)
|
|
885
|
+
* comes back as `{ ok: false }` instead of looking like "no add-ons".
|
|
886
|
+
* `extras` is null when the car has none.
|
|
887
|
+
*/
|
|
888
|
+
extrasResult(car: Car): Promise<ExtrasResult>;
|
|
889
|
+
private mapExtras;
|
|
890
|
+
}
|
|
891
|
+
/** extrasResult()'s answer: the add-ons (null when none), or why they could not be loaded. */
|
|
892
|
+
type ExtrasResult = {
|
|
893
|
+
ok: true;
|
|
894
|
+
extras: Extra[] | null;
|
|
895
|
+
} | {
|
|
896
|
+
ok: false;
|
|
897
|
+
error: string;
|
|
898
|
+
status?: number;
|
|
899
|
+
};
|
|
900
|
+
declare const extrasQueries: ExtrasQueries;
|
|
901
|
+
|
|
902
|
+
/**
|
|
903
|
+
* Live price estimate (deposit + a real price per requested extra) - see
|
|
904
|
+
* ActionController::estimation() on the PHP side (the core's suppliers.estimation action).
|
|
905
|
+
*
|
|
906
|
+
* Only meaningful for suppliers whose extras-listing/availability responses
|
|
907
|
+
* never carry a real price at all - currently just Bluu (see
|
|
908
|
+
* extras.queries.ts's docblock): a live GetQuote is the only Bluu operation
|
|
909
|
+
* that returns a deposit or per-extra pricing (BluuAdapter.getEstimation).
|
|
910
|
+
*/
|
|
911
|
+
|
|
912
|
+
interface QuoteExtraRequest {
|
|
913
|
+
code: string;
|
|
914
|
+
/** Required - Bluu echoes back its own canonical description on every
|
|
915
|
+
* quote line, never the code sent, so this is the only field the adapter
|
|
916
|
+
* can reliably match a returned line against (see BluuAdapter.getEstimation). */
|
|
917
|
+
name: string;
|
|
918
|
+
quantity: number;
|
|
919
|
+
}
|
|
920
|
+
interface LiveQuote {
|
|
921
|
+
totalPrice: number | null;
|
|
922
|
+
deposit: number | null;
|
|
923
|
+
/** One-way/drop-off fee - Europcar/Tempest only (see
|
|
924
|
+
* AdapterCapabilities.oneWayFee); an expense line item on this same
|
|
925
|
+
* estimate, not a separate call. Bluu's own one-way fee never sets this -
|
|
926
|
+
* see one-way.queries.ts. */
|
|
927
|
+
dropOffFee: number | null;
|
|
928
|
+
/** Per-extra price, keyed by code - only entries the supplier actually priced. */
|
|
929
|
+
breakdown: Record<string, number>;
|
|
930
|
+
quoteRef: string | null;
|
|
931
|
+
/** Set instead of the above when the quote failed outright - e.g. a real
|
|
932
|
+
* supplier-side rule ("Collection is not available at branch selected"),
|
|
933
|
+
* not just a name-match miss on one extra. */
|
|
934
|
+
error?: string;
|
|
935
|
+
}
|
|
936
|
+
/**
|
|
937
|
+
* Shared TanStack Query key for a Bluu deposit-only quote (empty `extras`),
|
|
938
|
+
* so ResultsPage's per-listing batch and BookingWizard's own deposit fetch
|
|
939
|
+
* for the SAME car+search window hit the same cache entry - opening the
|
|
940
|
+
* wizard for a car already priced in the results list is instant, no
|
|
941
|
+
* second SOAP round trip.
|
|
942
|
+
*/
|
|
943
|
+
declare function bluuDepositQueryKey(car: Car, criteria: SearchCriteria): readonly ["bluu-deposit", string, string, string, string, string];
|
|
944
|
+
/**
|
|
945
|
+
* Same shared-cache reasoning as bluuDepositQueryKey, for Europcar/Tempest's
|
|
946
|
+
* one-way/drop-off fee - a different call for a different reason (see
|
|
947
|
+
* ResultsPage's europcarOneWayCars docblock), so it gets its own key rather
|
|
948
|
+
* than colliding with the Bluu-deposit cache entry.
|
|
949
|
+
*/
|
|
950
|
+
declare function estimationQueryKey(car: Car, criteria: SearchCriteria): readonly ["estimation", string, string, string, string, string];
|
|
951
|
+
declare class EstimationQueries extends BaseQuery {
|
|
952
|
+
quote(car: Car, criteria: SearchCriteria, extras: QuoteExtraRequest[]): Promise<LiveQuote | null>;
|
|
953
|
+
}
|
|
954
|
+
declare const estimationQueries: EstimationQueries;
|
|
955
|
+
|
|
956
|
+
/**
|
|
957
|
+
* Live one-way/drop-off fee for a listing - see
|
|
958
|
+
* ActionController::one_way_fee() on the PHP side (the core's suppliers.oneWayFee action).
|
|
959
|
+
*
|
|
960
|
+
* Only meaningful for suppliers whose availability response never carries a
|
|
961
|
+
* real one-way fee at all - currently just Bluu (see
|
|
962
|
+
* AdapterCapabilities.oneWayFee): a live GetOneWayFee is the only Bluu
|
|
963
|
+
* operation that returns one (BluuAdapter.getOneWayFee), and it's a
|
|
964
|
+
* separate call from both availability and getEstimation.
|
|
965
|
+
*/
|
|
966
|
+
|
|
967
|
+
interface OneWayFee {
|
|
968
|
+
fee: number | null;
|
|
969
|
+
allowed: boolean | null;
|
|
970
|
+
error?: string;
|
|
971
|
+
}
|
|
972
|
+
/**
|
|
973
|
+
* Shared TanStack Query key, same reasoning as bluuDepositQueryKey - a
|
|
974
|
+
* search's whole result set shares one pickup/return branch pair, so
|
|
975
|
+
* car.id + the rental window is enough to key on.
|
|
976
|
+
*/
|
|
977
|
+
declare function oneWayFeeQueryKey(car: Car, criteria: SearchCriteria): readonly ["bluu-one-way-fee", string, string, string, string, string];
|
|
978
|
+
declare class OneWayFeeQueries extends BaseQuery {
|
|
979
|
+
check(car: Car, criteria: SearchCriteria): Promise<OneWayFee | null>;
|
|
980
|
+
}
|
|
981
|
+
declare const oneWayFeeQueries: OneWayFeeQueries;
|
|
982
|
+
|
|
983
|
+
/**
|
|
984
|
+
* What the booking wizard collects and what it costs: driver validation and
|
|
985
|
+
* the rental/add-ons quote. Submission (posting the finished request to
|
|
986
|
+
* WordPress) lives in lib/queries/booking.queries.ts.
|
|
987
|
+
*/
|
|
988
|
+
|
|
989
|
+
declare const TITLES: readonly ["Mr", "Ms", "Mrs", "Dr", "Prof"];
|
|
990
|
+
interface Driver {
|
|
991
|
+
title: string;
|
|
992
|
+
firstName: string;
|
|
993
|
+
lastName: string;
|
|
994
|
+
email: string;
|
|
995
|
+
phone: string;
|
|
996
|
+
licenceNumber: string;
|
|
997
|
+
notes: string;
|
|
998
|
+
/** Defaults to 'South Africa' - drives the phone dial-code prefix and the
|
|
999
|
+
* ID-number field's label ("SA ID number" vs "Passport number"). */
|
|
1000
|
+
country: string;
|
|
1001
|
+
/** SA ID number or passport number, label driven by `country` above. */
|
|
1002
|
+
idNumber: string;
|
|
1003
|
+
crossingBorder: boolean;
|
|
1004
|
+
streetAddress: string;
|
|
1005
|
+
city: string;
|
|
1006
|
+
suburb: string;
|
|
1007
|
+
province: string;
|
|
1008
|
+
postalCode: string;
|
|
1009
|
+
/** Optional second recipient for the booking confirmation. */
|
|
1010
|
+
additionalEmail: string;
|
|
1011
|
+
/**
|
|
1012
|
+
* The phone number's dial code, for example "+44", when it differs from
|
|
1013
|
+
* the country of residence's. Left out, the country's dial code is used.
|
|
1014
|
+
*/
|
|
1015
|
+
dialCode?: string;
|
|
1016
|
+
}
|
|
1017
|
+
declare const EMPTY_DRIVER: Driver;
|
|
1018
|
+
type DriverErrors = Partial<Record<keyof Driver, string>>;
|
|
1019
|
+
/** "email address and phone number" from a set of validation errors. */
|
|
1020
|
+
declare function describeDriverErrors(errors: DriverErrors): string;
|
|
1021
|
+
/**
|
|
1022
|
+
* Field-level validation. Mirrors customerDetailsSchema in
|
|
1023
|
+
* packages/adapters/src/schemas/booking.ts so a request that passes here has a
|
|
1024
|
+
* chance of passing the API later - the server still validates independently.
|
|
1025
|
+
*/
|
|
1026
|
+
declare function validateDriver(driver: Driver): DriverErrors;
|
|
1027
|
+
interface QuoteLine {
|
|
1028
|
+
id: string;
|
|
1029
|
+
label: string;
|
|
1030
|
+
/** Sub-label: how the amount was arrived at. */
|
|
1031
|
+
detail?: string;
|
|
1032
|
+
amount: number;
|
|
1033
|
+
}
|
|
1034
|
+
interface QuoteNote {
|
|
1035
|
+
label: string;
|
|
1036
|
+
value: string;
|
|
1037
|
+
}
|
|
1038
|
+
interface Quote {
|
|
1039
|
+
days: number;
|
|
1040
|
+
lines: QuoteLine[];
|
|
1041
|
+
/** Things that will change the price but that this bundle can't put a number on. */
|
|
1042
|
+
notes: QuoteNote[];
|
|
1043
|
+
extrasTotal: number;
|
|
1044
|
+
total: number;
|
|
1045
|
+
/** Refundable card hold, not a charge - see PriceSummary's "Funds needed on card". */
|
|
1046
|
+
deposit: number;
|
|
1047
|
+
/** What the driver owes if the car is damaged. Not added to the rental price. */
|
|
1048
|
+
excess: number;
|
|
1049
|
+
}
|
|
1050
|
+
/**
|
|
1051
|
+
* The estimate shown in the wizard: the vehicle for the rental window, plus any
|
|
1052
|
+
* add-ons.
|
|
1053
|
+
*
|
|
1054
|
+
* No invented taxes or service fees. Everything this bundle can't price - a
|
|
1055
|
+
* one-way fee, a coupon's discount, excluded insurance, whatever the supplier
|
|
1056
|
+
* levies - is listed as a note rather than a number, because a made-up total
|
|
1057
|
+
* is worse than an admitted gap.
|
|
1058
|
+
*
|
|
1059
|
+
* `extras` is whichever list is actually on offer for this car - live
|
|
1060
|
+
* per-supplier extras when available (see lib/queries/extras.queries.ts),
|
|
1061
|
+
* empty otherwise - never a static placeholder, or a selection made against
|
|
1062
|
+
* live extras would price against the wrong codes.
|
|
1063
|
+
*
|
|
1064
|
+
* `liveDeposit` overrides `car.deposit` when a supplier needed a separate
|
|
1065
|
+
* live quote to learn its real deposit (currently just Bluu, whose
|
|
1066
|
+
* availability response always reports 0 - see
|
|
1067
|
+
* lib/queries/estimation.queries.ts). `undefined` means "no live quote was
|
|
1068
|
+
* fetched for this car"; falls back to `car.deposit`.
|
|
1069
|
+
*
|
|
1070
|
+
* `liveDropOffFee` is the same idea for the one-way/drop-off fee - see
|
|
1071
|
+
* AdapterCapabilities.oneWayFee and BookingWizard's own
|
|
1072
|
+
* bluuOneWayQuery/europcarOneWayQuery. Falls back to `car.dropOffFee`
|
|
1073
|
+
* (already patched by ResultsPage's own batch, when that resolved before
|
|
1074
|
+
* the wizard opened).
|
|
1075
|
+
*/
|
|
1076
|
+
declare function quoteFor(car: Car, criteria: SearchCriteria, days: number, selection: ExtraSelection, extras: Extra[], liveDeposit?: number | null, liveDropOffFee?: number | null): Quote;
|
|
1077
|
+
/**
|
|
1078
|
+
* What one of an add-on costs for the whole rental: a per-day add-on times
|
|
1079
|
+
* the days (at least one), anything else its once-off price.
|
|
1080
|
+
*/
|
|
1081
|
+
declare function extraUnitPrice(extra: Pick<Extra, 'perDay' | 'onceOff'>, days: number): number;
|
|
1082
|
+
/** True when the car is returned at another branch than it is picked up from. */
|
|
1083
|
+
declare function isOneWay(car: Pick<Car, 'pickUpBranch' | 'returnBranch'>): boolean;
|
|
1084
|
+
/** `[{ code, quantity }]` - the shape the supplier booking payload expects. */
|
|
1085
|
+
declare function selectedExtras(selection: ExtraSelection, extras: Extra[]): {
|
|
1086
|
+
code: string;
|
|
1087
|
+
quantity: number;
|
|
1088
|
+
}[];
|
|
1089
|
+
|
|
1090
|
+
/**
|
|
1091
|
+
* Country list for the driver-details step's nationality/dial-code picker.
|
|
1092
|
+
* Name + ISO code + dial code + flag emoji - the same shape carhire's own
|
|
1093
|
+
* booking form uses, so a phone field can prefix the right code and an
|
|
1094
|
+
* ID-number field can swap its label for "Passport number" once the driver
|
|
1095
|
+
* isn't booking from South Africa.
|
|
1096
|
+
*/
|
|
1097
|
+
interface Country {
|
|
1098
|
+
name: string;
|
|
1099
|
+
code: string;
|
|
1100
|
+
dialCode: string;
|
|
1101
|
+
flag: string;
|
|
1102
|
+
}
|
|
1103
|
+
declare const COUNTRIES: Country[];
|
|
1104
|
+
declare function countryByName(name: string): Country | undefined;
|
|
1105
|
+
/** Pre-built for SearchCombobox's `groups` prop - one ungrouped, flag-labelled list. */
|
|
1106
|
+
declare const COUNTRY_GROUPS: {
|
|
1107
|
+
options: {
|
|
1108
|
+
value: string;
|
|
1109
|
+
label: string;
|
|
1110
|
+
}[];
|
|
1111
|
+
}[];
|
|
1112
|
+
|
|
1113
|
+
/**
|
|
1114
|
+
* Paying online for one of the site's own cars.
|
|
1115
|
+
*
|
|
1116
|
+
* The site's own cars can be paid for online (Paystack, Stitch or PayFast)
|
|
1117
|
+
* or at the branch, depending on the payment methods staff set up in the
|
|
1118
|
+
* admin (Fleets, Payment methods). This file talks to the WordPress plugin's
|
|
1119
|
+
* three public endpoints for that (Controllers\ActionController):
|
|
1120
|
+
*
|
|
1121
|
+
* - methods(): the ways a customer may pay at a pick-up branch. An empty
|
|
1122
|
+
* list means the booking wizard shows no payment step.
|
|
1123
|
+
* - start(): tries the payment again for a booking that waits for one,
|
|
1124
|
+
* and gives back the payment page's address.
|
|
1125
|
+
* - verify(): asks how the payment went when the customer comes back from
|
|
1126
|
+
* the payment page. Once it is paid, the booking is confirmed.
|
|
1127
|
+
*
|
|
1128
|
+
* Payment cards are never typed into this site. The customer pays on the
|
|
1129
|
+
* payment company's own page, and the keys for that company never reach the
|
|
1130
|
+
* browser.
|
|
1131
|
+
*
|
|
1132
|
+
* Nothing here reads the page's address or the browser's storage: the
|
|
1133
|
+
* address the payment page sends the customer back to is a parameter of
|
|
1134
|
+
* start(). @fleetbridge/ui keeps the browser helpers (the current page as the
|
|
1135
|
+
* return address, remembering the choice in sessionStorage); a native app
|
|
1136
|
+
* passes its own deep link or web return page.
|
|
1137
|
+
*/
|
|
1138
|
+
|
|
1139
|
+
/** The name of the address bar setting the customer comes back with (?fb_payment=...). */
|
|
1140
|
+
declare const PAYMENT_RETURN_PARAM = "fb_payment";
|
|
1141
|
+
type PaymentKind = 'PAYSTACK' | 'STITCH' | 'PAYFAST' | 'PAY_AT_BRANCH';
|
|
1142
|
+
interface PaymentMethodOption {
|
|
1143
|
+
id: string;
|
|
1144
|
+
name: string;
|
|
1145
|
+
kind: PaymentKind;
|
|
1146
|
+
/** A note staff wrote for customers, for example "Visa and Mastercard only". */
|
|
1147
|
+
instructions: string;
|
|
1148
|
+
/** Whether this method may pay only the deposit instead of the whole amount. */
|
|
1149
|
+
usableForDeposit: boolean;
|
|
1150
|
+
/** Paid online now, on the payment company's page (not at the branch). */
|
|
1151
|
+
online: boolean;
|
|
1152
|
+
/** The payment company's logo staff uploaded, or '' for none (a plain icon is shown). */
|
|
1153
|
+
logoUrl?: string;
|
|
1154
|
+
}
|
|
1155
|
+
type PaymentPurpose = 'FULL' | 'DEPOSIT';
|
|
1156
|
+
/** How the payment went, after the customer came back. */
|
|
1157
|
+
interface PaymentCheck {
|
|
1158
|
+
/** The booking's status: CONFIRMED once paid, PAYMENT_PENDING while waiting. */
|
|
1159
|
+
status: string;
|
|
1160
|
+
/** The payment's status: PENDING, SUCCEEDED, FAILED … */
|
|
1161
|
+
paymentStatus: string;
|
|
1162
|
+
/** confirmed, waiting, failed, paid_needs_attention or already_settled. */
|
|
1163
|
+
outcome: string;
|
|
1164
|
+
supplier: string;
|
|
1165
|
+
/** Only once the booking is confirmed. */
|
|
1166
|
+
reservationId?: string;
|
|
1167
|
+
bookingPin?: string;
|
|
1168
|
+
reference?: string;
|
|
1169
|
+
}
|
|
1170
|
+
/** The friendly name of each payment company, for labels. */
|
|
1171
|
+
declare const PAYMENT_KIND_LABEL: Record<PaymentKind, string>;
|
|
1172
|
+
declare class PaymentQueries extends BaseQuery {
|
|
1173
|
+
methods(branchCode: string): Promise<PaymentMethodOption[]>;
|
|
1174
|
+
/**
|
|
1175
|
+
* Opens the payment page again for a booking that waits for payment.
|
|
1176
|
+
* `returnUrl` is where the payment page sends the customer back to, with
|
|
1177
|
+
* `?fb_payment=<token>` (PAYMENT_RETURN_PARAM) added.
|
|
1178
|
+
*/
|
|
1179
|
+
start(paymentToken: string, methodId: string, purpose: PaymentPurpose, returnUrl: string): Promise<{
|
|
1180
|
+
ok: true;
|
|
1181
|
+
redirectUrl: string;
|
|
1182
|
+
} | {
|
|
1183
|
+
ok: false;
|
|
1184
|
+
error: string;
|
|
1185
|
+
}>;
|
|
1186
|
+
verify(paymentToken: string): Promise<{
|
|
1187
|
+
ok: true;
|
|
1188
|
+
check: PaymentCheck;
|
|
1189
|
+
} | {
|
|
1190
|
+
ok: false;
|
|
1191
|
+
error: string;
|
|
1192
|
+
}>;
|
|
1193
|
+
}
|
|
1194
|
+
declare const paymentQueries: PaymentQueries;
|
|
1195
|
+
|
|
1196
|
+
/**
|
|
1197
|
+
* Submits the booking wizard's booking to WordPress, which makes the real
|
|
1198
|
+
* reservation with the supplier.
|
|
1199
|
+
*
|
|
1200
|
+
* The call still goes through admin-ajax rather than straight to
|
|
1201
|
+
* FleetBridge, and for the original reason: creating a reservation needs the
|
|
1202
|
+
* account's API key plus the supplier's own credentials in the request body
|
|
1203
|
+
* (see apps/api/src/handlers/suppliers/booking.ts), and neither may ever
|
|
1204
|
+
* live in front-end JavaScript. What changed is what the PHP handler does
|
|
1205
|
+
* with the payload - it used to record an enquiry and fire an action for a
|
|
1206
|
+
* site to forward itself; it now records the attempt in the tenant
|
|
1207
|
+
* `Bookings` table and books it (see Frontend\BookingController).
|
|
1208
|
+
*
|
|
1209
|
+
* So the fields below carry everything the reservation needs and nothing the
|
|
1210
|
+
* browser could be trusted to decide: the supplier's adapter identifier and
|
|
1211
|
+
* pre-resolved branch codes, the vehicle group, and the rate/quote/CDP
|
|
1212
|
+
* references from the search - all values FleetBridge itself produced. The
|
|
1213
|
+
* handler re-resolves credentials and the active CDP code server-side.
|
|
1214
|
+
*/
|
|
1215
|
+
|
|
1216
|
+
interface BookingRequest {
|
|
1217
|
+
car: Car;
|
|
1218
|
+
criteria: SearchCriteria;
|
|
1219
|
+
driver: Driver;
|
|
1220
|
+
selection: ExtraSelection;
|
|
1221
|
+
/** Whichever catalogue `selection`'s codes were chosen from - live or static. */
|
|
1222
|
+
extras: Extra[];
|
|
1223
|
+
days: number;
|
|
1224
|
+
total: number;
|
|
1225
|
+
/**
|
|
1226
|
+
* The resolved one-way drop-off fee, if any - `quoteFor`'s own
|
|
1227
|
+
* `liveDropOffFee ?? car.dropOffFee` (see BookingWizard, which already
|
|
1228
|
+
* computed this for the price breakdown the customer sees). Persisted on
|
|
1229
|
+
* BookingRate, not folded into `extras` - see that field's own note in
|
|
1230
|
+
* `bookingRequestFields` below.
|
|
1231
|
+
*/
|
|
1232
|
+
dropOffFee?: number | null;
|
|
1233
|
+
/** `quoteFor`'s refundable deposit (Quote.deposit) - PriceSummary's "Funds
|
|
1234
|
+
* needed on card", persisted on BookingRate alongside the drop-off fee. */
|
|
1235
|
+
deposit?: number | null;
|
|
1236
|
+
/** The published terms version shown on the review step, when this supplier has one. */
|
|
1237
|
+
terms?: {
|
|
1238
|
+
id: string;
|
|
1239
|
+
version: number;
|
|
1240
|
+
} | null;
|
|
1241
|
+
/** How the customer pays, for the site's own cars (see payment.queries.ts). */
|
|
1242
|
+
payment?: {
|
|
1243
|
+
methodId: string;
|
|
1244
|
+
purpose: PaymentPurpose;
|
|
1245
|
+
/**
|
|
1246
|
+
* Where the payment page sends the customer back to. When left out, the
|
|
1247
|
+
* `paymentReturnUrl` option of bookingRequestFields / createBookingQueries
|
|
1248
|
+
* supplies it (@fleetbridge/ui passes the current page).
|
|
1249
|
+
*/
|
|
1250
|
+
returnUrl?: string;
|
|
1251
|
+
} | null;
|
|
1252
|
+
}
|
|
1253
|
+
/** Options for bookingRequestFields(), and for the query objects that call it. */
|
|
1254
|
+
interface BookingFieldOptions {
|
|
1255
|
+
/**
|
|
1256
|
+
* Gives the payment return address for a request whose `payment` has no
|
|
1257
|
+
* `returnUrl` of its own. Called only when the request has a payment.
|
|
1258
|
+
*/
|
|
1259
|
+
paymentReturnUrl?: () => string;
|
|
1260
|
+
}
|
|
1261
|
+
/**
|
|
1262
|
+
* Callbacks for a booking or quote request, called just before it is sent.
|
|
1263
|
+
* Optional, and a no-op when left out. @fleetbridge/ui uses them to dispatch
|
|
1264
|
+
* the `fleetbridge:booking-requested` / `fleetbridge:quote-requested` window
|
|
1265
|
+
* events. A callback that throws does not stop the request.
|
|
1266
|
+
*/
|
|
1267
|
+
interface BookingHooks extends BookingFieldOptions {
|
|
1268
|
+
onBookingRequested?: (request: BookingRequest) => void;
|
|
1269
|
+
onQuoteRequested?: (request: BookingRequest) => void;
|
|
1270
|
+
}
|
|
1271
|
+
/**
|
|
1272
|
+
* A booking of the site's own cars that is paid online. It is not confirmed
|
|
1273
|
+
* yet: the customer goes to the payment page first (redirectUrl). When the
|
|
1274
|
+
* page could not be opened, paymentError says why, and the token lets the
|
|
1275
|
+
* customer try again.
|
|
1276
|
+
*/
|
|
1277
|
+
interface PendingPayment {
|
|
1278
|
+
token: string;
|
|
1279
|
+
redirectUrl?: string;
|
|
1280
|
+
error?: string;
|
|
1281
|
+
}
|
|
1282
|
+
/** A confirmed reservation, as the confirmation step shows it. */
|
|
1283
|
+
interface ConfirmedBooking {
|
|
1284
|
+
/**
|
|
1285
|
+
* The supplier's booking number - the only id THEY know this booking by,
|
|
1286
|
+
* and so the one the customer quotes at the desk.
|
|
1287
|
+
*/
|
|
1288
|
+
reservationId: string;
|
|
1289
|
+
/**
|
|
1290
|
+
* FleetBridge's own PIN for the booking. Paired with the booking number
|
|
1291
|
+
* it finds the booking on FleetBridge's side (the admin Bookings
|
|
1292
|
+
* tab searches on it); the supplier has no idea what it is.
|
|
1293
|
+
*/
|
|
1294
|
+
bookingPin: string;
|
|
1295
|
+
supplier: string;
|
|
1296
|
+
/**
|
|
1297
|
+
* Tenant / FleetBridge booking reference (`fb-booking-{uuid}`), generated
|
|
1298
|
+
* before the supplier was called. Deliberately NOT displayed to customers.
|
|
1299
|
+
*/
|
|
1300
|
+
reference: string;
|
|
1301
|
+
/**
|
|
1302
|
+
* The tenant Customer row this booking was recorded against (see
|
|
1303
|
+
* BookingController's upsert_customer call). Used to remember "this
|
|
1304
|
+
* device belongs to this customer" for a return visit - see
|
|
1305
|
+
* store/customerStore.ts.
|
|
1306
|
+
*/
|
|
1307
|
+
customerId?: string;
|
|
1308
|
+
/** Set when the booking still has to be paid online. The booking number arrives once it is paid. */
|
|
1309
|
+
payment?: PendingPayment;
|
|
1310
|
+
}
|
|
1311
|
+
type BookingResult = ({
|
|
1312
|
+
ok: true;
|
|
1313
|
+
} & ConfirmedBooking) | {
|
|
1314
|
+
ok: false;
|
|
1315
|
+
error: string;
|
|
1316
|
+
/**
|
|
1317
|
+
* Present when the attempt was recorded before it failed - the normal
|
|
1318
|
+
* case, since the row is written before the supplier is called. Worth
|
|
1319
|
+
* showing: a failed attempt has no reservation number, so this is the
|
|
1320
|
+
* only handle on it, including when the reservation did in fact get
|
|
1321
|
+
* created upstream.
|
|
1322
|
+
*/
|
|
1323
|
+
bookingPin?: string;
|
|
1324
|
+
};
|
|
1325
|
+
/**
|
|
1326
|
+
* "Request a quote" never makes a reservation - see Tenant\Quote's own
|
|
1327
|
+
* docblock (WordPress plugin) for why the request is emailed rather than
|
|
1328
|
+
* booked immediately. Deliberately not `BookingResult`: there is no
|
|
1329
|
+
* reservation number/PIN/supplier to show on success, only confirmation
|
|
1330
|
+
* that the email went out.
|
|
1331
|
+
*/
|
|
1332
|
+
type QuoteRequestResult = {
|
|
1333
|
+
ok: true;
|
|
1334
|
+
message?: string;
|
|
1335
|
+
} | {
|
|
1336
|
+
ok: false;
|
|
1337
|
+
error: string;
|
|
1338
|
+
};
|
|
1339
|
+
/** Form fields both create (`fleetbridge_booking_request`) and amend
|
|
1340
|
+
* (`fleetbridge_amend_my_booking`) post. Amend adds reservationNumber + PIN
|
|
1341
|
+
* on top. */
|
|
1342
|
+
declare function bookingRequestFields(request: BookingRequest, options?: BookingFieldOptions): Record<string, string>;
|
|
1343
|
+
declare class BookingQueries extends BaseQuery {
|
|
1344
|
+
private readonly hooks;
|
|
1345
|
+
constructor(hooks?: BookingHooks);
|
|
1346
|
+
/**
|
|
1347
|
+
* Posts the booking to the host site. Calls `onBookingRequested` first,
|
|
1348
|
+
* either way (@fleetbridge/ui turns it into the
|
|
1349
|
+
* `fleetbridge:booking-requested` window event, so a theme that would
|
|
1350
|
+
* rather handle bookings itself can listen instead).
|
|
1351
|
+
*/
|
|
1352
|
+
submitBooking(request: BookingRequest): Promise<BookingResult>;
|
|
1353
|
+
/**
|
|
1354
|
+
* Posts a "Request a quote" - same fields as `submitBooking()` (it's the
|
|
1355
|
+
* same wizard, just ending here instead of at "Confirm booking"), but
|
|
1356
|
+
* WordPress records it as a Quote and emails it rather than calling the
|
|
1357
|
+
* supplier - see Tenant\Quote's own docblock. Calls `onQuoteRequested`
|
|
1358
|
+
* first (in @fleetbridge/ui, the `fleetbridge:quote-requested` window
|
|
1359
|
+
* event, the quote-mode counterpart of `fleetbridge:booking-requested`).
|
|
1360
|
+
*/
|
|
1361
|
+
requestQuote(request: BookingRequest): Promise<QuoteRequestResult>;
|
|
1362
|
+
/** The terms version this supplier's customers agree to now. Null when none is published, or when they could not be loaded (see supplierTermsResult()). */
|
|
1363
|
+
supplierTerms(identifier: string): Promise<SupplierTerms | null>;
|
|
1364
|
+
/** Like supplierTerms(), but a failure comes back as `{ ok: false }` instead of looking like "no terms". */
|
|
1365
|
+
supplierTermsResult(identifier: string): Promise<SupplierTermsResult>;
|
|
1366
|
+
}
|
|
1367
|
+
/** A supplier's published terms. */
|
|
1368
|
+
interface SupplierTerms {
|
|
1369
|
+
id: string;
|
|
1370
|
+
version: number;
|
|
1371
|
+
html: string;
|
|
1372
|
+
}
|
|
1373
|
+
/** supplierTermsResult()'s answer: the terms (null when none is published), or why they could not be loaded. */
|
|
1374
|
+
type SupplierTermsResult = {
|
|
1375
|
+
ok: true;
|
|
1376
|
+
terms: SupplierTerms | null;
|
|
1377
|
+
} | {
|
|
1378
|
+
ok: false;
|
|
1379
|
+
error: string;
|
|
1380
|
+
status?: number;
|
|
1381
|
+
};
|
|
1382
|
+
/** Booking queries with your own hooks (see BookingHooks). */
|
|
1383
|
+
declare function createBookingQueries(hooks?: BookingHooks): BookingQueries;
|
|
1384
|
+
/** Booking queries without hooks. */
|
|
1385
|
+
declare const bookingQueries: BookingQueries;
|
|
1386
|
+
|
|
1387
|
+
type ManagedBookingStatus = 'PENDING'
|
|
1388
|
+
/** Booked, waiting for the online payment. */
|
|
1389
|
+
| 'PAYMENT_PENDING'
|
|
1390
|
+
/** The supplier did not confirm it. */
|
|
1391
|
+
| 'FAILED' | 'CONFIRMED' | 'PICKED_UP' | 'RETURNED' | 'CANCELLED' | 'RECONCILED' | 'NO_SHOW';
|
|
1392
|
+
/** One selected add-on, as `BookingExtra` rows come back formatted. */
|
|
1393
|
+
interface ManagedBookingExtra {
|
|
1394
|
+
code: string;
|
|
1395
|
+
name: string;
|
|
1396
|
+
quantity: number;
|
|
1397
|
+
unitPrice: number | null;
|
|
1398
|
+
currency: string;
|
|
1399
|
+
}
|
|
1400
|
+
interface ManagedBookingVehicle {
|
|
1401
|
+
group: string | null;
|
|
1402
|
+
name: string | null;
|
|
1403
|
+
image: string | null;
|
|
1404
|
+
supplierLogo: string | null;
|
|
1405
|
+
seats: number | null;
|
|
1406
|
+
doors: number | null;
|
|
1407
|
+
transmission: string | null;
|
|
1408
|
+
fuelType: string | null;
|
|
1409
|
+
insuranceIncluded: boolean | null;
|
|
1410
|
+
ratePackageLabel: string | null;
|
|
1411
|
+
unlimitedMileage?: boolean | null;
|
|
1412
|
+
kmPerDay?: number | null;
|
|
1413
|
+
}
|
|
1414
|
+
interface ManagedBookingCustomer {
|
|
1415
|
+
name: string | null;
|
|
1416
|
+
firstName?: string | null;
|
|
1417
|
+
lastName?: string | null;
|
|
1418
|
+
title?: string | null;
|
|
1419
|
+
email: string | null;
|
|
1420
|
+
additionalEmail?: string | null;
|
|
1421
|
+
phone: string | null;
|
|
1422
|
+
dialCode?: string | null;
|
|
1423
|
+
idNumber?: string | null;
|
|
1424
|
+
idType?: string | null;
|
|
1425
|
+
licenseNumber?: string | null;
|
|
1426
|
+
country?: string | null;
|
|
1427
|
+
streetAddress?: string | null;
|
|
1428
|
+
suburb?: string | null;
|
|
1429
|
+
city?: string | null;
|
|
1430
|
+
province?: string | null;
|
|
1431
|
+
postalCode?: string | null;
|
|
1432
|
+
}
|
|
1433
|
+
/** How a booking was priced, as the site stored it. Amounts in rands. */
|
|
1434
|
+
interface ManagedBookingRate {
|
|
1435
|
+
/** The vehicle line only. */
|
|
1436
|
+
amount?: number | null;
|
|
1437
|
+
dailyRate?: number | null;
|
|
1438
|
+
days?: number | null;
|
|
1439
|
+
ratePackageLabel?: string | null;
|
|
1440
|
+
extrasTotal?: number | null;
|
|
1441
|
+
dropOffFee?: number | null;
|
|
1442
|
+
deposit?: number | null;
|
|
1443
|
+
total?: number | null;
|
|
1444
|
+
currency?: string | null;
|
|
1445
|
+
}
|
|
1446
|
+
/**
|
|
1447
|
+
* Matches ActionController::booking_view()'s shape -
|
|
1448
|
+
* that method redacts BookingStore::format_row()'s output down to this
|
|
1449
|
+
* (stripping only a handful of internal-only keys) rather than re-listing
|
|
1450
|
+
* every field, so this type is the same "whatever format_row() returns,
|
|
1451
|
+
* minus a short deny-list" contract, not a hand-picked subset.
|
|
1452
|
+
*/
|
|
1453
|
+
interface ManagedBooking {
|
|
1454
|
+
supplierRef: string | null;
|
|
1455
|
+
status: ManagedBookingStatus;
|
|
1456
|
+
supplierStatus: string | null;
|
|
1457
|
+
failureReason: string | null;
|
|
1458
|
+
supplierName: string | null;
|
|
1459
|
+
vehicle: ManagedBookingVehicle;
|
|
1460
|
+
pickupLocation: string | null;
|
|
1461
|
+
dropoffLocation: string | null;
|
|
1462
|
+
pickupDate: string | null;
|
|
1463
|
+
dropoffDate: string | null;
|
|
1464
|
+
rentalDays: number | null;
|
|
1465
|
+
extras: ManagedBookingExtra[];
|
|
1466
|
+
totalPrice: number;
|
|
1467
|
+
currency: string;
|
|
1468
|
+
/** The priced parts of the booking (the site's BookingRate row), when it has one. */
|
|
1469
|
+
rate?: ManagedBookingRate | null;
|
|
1470
|
+
customer: ManagedBookingCustomer;
|
|
1471
|
+
cdpCode: string | null;
|
|
1472
|
+
quoteRef: string | null;
|
|
1473
|
+
rateId: string | null;
|
|
1474
|
+
/** Adapter identifier ("hertz", "bluu", …) — amend re-search is locked to this supplier. */
|
|
1475
|
+
supplierIdentifier: string | null;
|
|
1476
|
+
crossBorder: boolean;
|
|
1477
|
+
notes: string | null;
|
|
1478
|
+
source: string | null;
|
|
1479
|
+
cancelledAt: string | null;
|
|
1480
|
+
cancellationReason: string | null;
|
|
1481
|
+
createdAt: string | null;
|
|
1482
|
+
/** Both gate on `status === 'CONFIRMED'` server-side - see customer_view(). */
|
|
1483
|
+
canCancel: boolean;
|
|
1484
|
+
canAmend: boolean;
|
|
1485
|
+
}
|
|
1486
|
+
interface QuotedQuote {
|
|
1487
|
+
quoteRef: string;
|
|
1488
|
+
status: 'PENDING' | 'CONFIRMED' | 'EXPIRED' | 'CANCELLED';
|
|
1489
|
+
expiresAt: string | null;
|
|
1490
|
+
supplierName: string | null;
|
|
1491
|
+
vehicle: ManagedBookingVehicle;
|
|
1492
|
+
pickupLocation: string | null;
|
|
1493
|
+
dropoffLocation: string | null;
|
|
1494
|
+
pickupDate: string | null;
|
|
1495
|
+
dropoffDate: string | null;
|
|
1496
|
+
rentalDays: number | null;
|
|
1497
|
+
extras: ManagedBookingExtra[];
|
|
1498
|
+
priceBreakdown: {
|
|
1499
|
+
label: string;
|
|
1500
|
+
amount: number;
|
|
1501
|
+
}[];
|
|
1502
|
+
totalPrice: number;
|
|
1503
|
+
currency: string;
|
|
1504
|
+
deposit: number | null;
|
|
1505
|
+
customer: ManagedBookingCustomer;
|
|
1506
|
+
notes: string | null;
|
|
1507
|
+
crossBorder?: boolean;
|
|
1508
|
+
}
|
|
1509
|
+
/** The flat shape `ajax_confirm_quote()` returns on success - the same
|
|
1510
|
+
* create-booking result shape a fresh booking gets, not a full `ManagedBooking`
|
|
1511
|
+
* (that needs a follow-up `lookup()` call - see ManageBooking's own confirm-quote effect). */
|
|
1512
|
+
interface ConfirmedQuoteBooking {
|
|
1513
|
+
reference: string;
|
|
1514
|
+
reservationId: string;
|
|
1515
|
+
bookingPin: string;
|
|
1516
|
+
supplier: string;
|
|
1517
|
+
status: string;
|
|
1518
|
+
customerId?: string;
|
|
1519
|
+
}
|
|
1520
|
+
declare class BookingManagementQueries extends BaseQuery {
|
|
1521
|
+
private readonly options;
|
|
1522
|
+
/** `options.paymentReturnUrl` feeds amend()'s booking fields (see bookingRequestFields). */
|
|
1523
|
+
constructor(options?: BookingFieldOptions);
|
|
1524
|
+
lookup(reservationNumber: string, bookingPin: string): Promise<QueryResult<{
|
|
1525
|
+
booking: ManagedBooking;
|
|
1526
|
+
}>>;
|
|
1527
|
+
cancel(reservationNumber: string, bookingPin: string, reason: string): Promise<QueryResult<{
|
|
1528
|
+
booking: ManagedBooking;
|
|
1529
|
+
}>>;
|
|
1530
|
+
/**
|
|
1531
|
+
* Load a pending quote for review. The email link calls this first; Book
|
|
1532
|
+
* on that screen then calls `confirmQuote()`.
|
|
1533
|
+
*/
|
|
1534
|
+
lookupQuote(token: string): Promise<QueryResult<{
|
|
1535
|
+
quote: QuotedQuote;
|
|
1536
|
+
}>>;
|
|
1537
|
+
/**
|
|
1538
|
+
* Turns a pending Quote into a real reservation after the customer has
|
|
1539
|
+
* reviewed it and clicked Book. The caller still needs its own `lookup()`
|
|
1540
|
+
* afterwards for the full `ManagedBooking` shape the rest of this drawer
|
|
1541
|
+
* expects.
|
|
1542
|
+
*/
|
|
1543
|
+
confirmQuote(token: string): Promise<QueryResult<ConfirmedQuoteBooking>>;
|
|
1544
|
+
/**
|
|
1545
|
+
* Re-search submit: same payload as a new booking, plus the reservation
|
|
1546
|
+
* number + PIN that prove ownership. If the supplier doesn't support
|
|
1547
|
+
* amending online (AdapterCapabilities.amendBooking), this fails with a
|
|
1548
|
+
* plain message rather than a structured code.
|
|
1549
|
+
*/
|
|
1550
|
+
amend(reservationNumber: string, bookingPin: string, request: BookingRequest): Promise<(BookingResult & {
|
|
1551
|
+
booking?: ManagedBooking;
|
|
1552
|
+
})>;
|
|
1553
|
+
}
|
|
1554
|
+
/** Booking-management queries with your own options (see BookingFieldOptions). */
|
|
1555
|
+
declare function createBookingManagementQueries(options?: BookingFieldOptions): BookingManagementQueries;
|
|
1556
|
+
declare const bookingManagementQueries: BookingManagementQueries;
|
|
1557
|
+
|
|
1558
|
+
/** A coupon a customer claimed, with the coupon as it stands now. */
|
|
1559
|
+
interface AppCoupon {
|
|
1560
|
+
/** The coupon's id (not the claim's). */
|
|
1561
|
+
id: string;
|
|
1562
|
+
/** What the customer types, for example "APP20". */
|
|
1563
|
+
code: string;
|
|
1564
|
+
description: string | null;
|
|
1565
|
+
/** "PERCENTAGE" or "FIXED_AMOUNT". */
|
|
1566
|
+
discountType: string;
|
|
1567
|
+
/** A percent (0 to 100) or an amount in rands. */
|
|
1568
|
+
discountValue: number;
|
|
1569
|
+
/** ISO time the coupon starts working. */
|
|
1570
|
+
startDate: string | null;
|
|
1571
|
+
/** ISO time it stops working. Null means no end. */
|
|
1572
|
+
endDate: string | null;
|
|
1573
|
+
/** Null means no limit. */
|
|
1574
|
+
usageLimit: number | null;
|
|
1575
|
+
/** Bookings that use it, by every customer (cancelled ones give their use back). Claims do not count. */
|
|
1576
|
+
usageCount: number;
|
|
1577
|
+
/** Bookings this customer made with it that still count. */
|
|
1578
|
+
usesByCustomer: number;
|
|
1579
|
+
/** How many bookings one customer may make with it. Null means no per-customer limit. */
|
|
1580
|
+
perCustomerLimit: number | null;
|
|
1581
|
+
/**
|
|
1582
|
+
* How many more bookings this customer may make with it (the per-customer
|
|
1583
|
+
* and the overall limit together). Null means unlimited; 0 means they
|
|
1584
|
+
* cannot use it again.
|
|
1585
|
+
*/
|
|
1586
|
+
remainingForCustomer: number | null;
|
|
1587
|
+
/** "Must be claimed first": only customers who claimed it can book with it. */
|
|
1588
|
+
requireClaim: boolean;
|
|
1589
|
+
/** The supplier it is for, as its adapter name, for example "europcar" or "own-fleet". Null when unknown. */
|
|
1590
|
+
supplierIdentifier: string | null;
|
|
1591
|
+
/** The supplier's name customers know, for example "Europcar". Null when unknown. */
|
|
1592
|
+
supplierName: string | null;
|
|
1593
|
+
/** True when it unlocks a supplier's special (CDP) rate, rather than only taking money off. */
|
|
1594
|
+
unlocksSpecialRate: boolean;
|
|
1595
|
+
/** False when staff switched it off. */
|
|
1596
|
+
isActive: boolean;
|
|
1597
|
+
/** Whether it could be used when the site answered. couponUsable() checks again against a given time. */
|
|
1598
|
+
isLive: boolean;
|
|
1599
|
+
/** Where it works ("web", "app", "whatsapp"). Empty means everywhere. */
|
|
1600
|
+
channels: string[];
|
|
1601
|
+
/** The channel it was claimed from. */
|
|
1602
|
+
channel: string;
|
|
1603
|
+
/** Why the customer got it, for example "appDownload" or "referral". */
|
|
1604
|
+
claimType: string | null;
|
|
1605
|
+
/** ISO time it was claimed. */
|
|
1606
|
+
claimedAt: string;
|
|
1607
|
+
}
|
|
1608
|
+
/**
|
|
1609
|
+
* Why a booking or search with a coupon was refused (the site's `code`).
|
|
1610
|
+
* The message that comes with it is written for the customer.
|
|
1611
|
+
*/
|
|
1612
|
+
type CouponBookingProblem =
|
|
1613
|
+
/** It ended, has not started or was switched off. */
|
|
1614
|
+
'COUPON_EXPIRED'
|
|
1615
|
+
/** It does not work on this channel. */
|
|
1616
|
+
| 'COUPON_WRONG_CHANNEL'
|
|
1617
|
+
/** A special rate that needs a coupon was booked without a valid one. */
|
|
1618
|
+
| 'COUPON_REQUIRED'
|
|
1619
|
+
/** It has been used as often as it may be. */
|
|
1620
|
+
| 'COUPON_LIMIT_REACHED'
|
|
1621
|
+
/** This customer has used it as often as one customer may ("You've already used this coupon."). */
|
|
1622
|
+
| 'COUPON_CUSTOMER_LIMIT'
|
|
1623
|
+
/** It must be claimed first, and this customer has not. */
|
|
1624
|
+
| 'COUPON_NOT_CLAIMED';
|
|
1625
|
+
/** Why a claim failed, when the site said. */
|
|
1626
|
+
type CouponClaimProblem =
|
|
1627
|
+
/** No coupon has that code. */
|
|
1628
|
+
'COUPON_NOT_FOUND'
|
|
1629
|
+
/** It ended, has not started, was switched off or is used up. */
|
|
1630
|
+
| 'COUPON_EXPIRED'
|
|
1631
|
+
/** It does not work on this channel. */
|
|
1632
|
+
| 'COUPON_WRONG_CHANNEL'
|
|
1633
|
+
/** This customer already has it. */
|
|
1634
|
+
| 'COUPON_ALREADY_CLAIMED'
|
|
1635
|
+
/** Nobody is signed in. */
|
|
1636
|
+
| 'SIGN_IN_REQUIRED';
|
|
1637
|
+
type CouponClaimResult = {
|
|
1638
|
+
ok: true;
|
|
1639
|
+
coupon: AppCoupon;
|
|
1640
|
+
} | {
|
|
1641
|
+
ok: false;
|
|
1642
|
+
/** Written for the customer. */
|
|
1643
|
+
error: string;
|
|
1644
|
+
/** The site's own reason, when it gave one. */
|
|
1645
|
+
code?: CouponClaimProblem | string;
|
|
1646
|
+
/** HTTP status: 401 not signed in, 403 wrong channel, 404 no such code, 409 already claimed, 410 or 422 expired. 0 when the site could not be reached. */
|
|
1647
|
+
status?: number;
|
|
1648
|
+
};
|
|
1649
|
+
type MyCouponsResult = {
|
|
1650
|
+
ok: true;
|
|
1651
|
+
coupons: AppCoupon[];
|
|
1652
|
+
} | {
|
|
1653
|
+
ok: false;
|
|
1654
|
+
error: string;
|
|
1655
|
+
status?: number;
|
|
1656
|
+
};
|
|
1657
|
+
declare class CouponQueries extends BaseQuery {
|
|
1658
|
+
/**
|
|
1659
|
+
* Claims the coupon with this code for the signed-in customer.
|
|
1660
|
+
* `claimType` says why they get it, free text (for example "appDownload").
|
|
1661
|
+
*/
|
|
1662
|
+
claim(code: string, claimType?: string): Promise<CouponClaimResult>;
|
|
1663
|
+
/** The signed-in customer's claimed coupons, newest first. */
|
|
1664
|
+
mine(): Promise<MyCouponsResult>;
|
|
1665
|
+
}
|
|
1666
|
+
declare const couponQueries: CouponQueries;
|
|
1667
|
+
/** TanStack Query key for the signed-in customer's coupons. */
|
|
1668
|
+
declare const myCouponsQueryKey: readonly ["coupons", "mine"];
|
|
1669
|
+
/**
|
|
1670
|
+
* Whether the customer can use this coupon on `channel` at `now`: switched
|
|
1671
|
+
* on, started, not ended, not used up (overall, or by this customer:
|
|
1672
|
+
* remainingForCustomer 0), and allowed on the channel. The same rules the
|
|
1673
|
+
* core applies to trip.promoCode. (A coupon with requireClaim is only in the
|
|
1674
|
+
* customer's list once claimed, so that rule is met.)
|
|
1675
|
+
*/
|
|
1676
|
+
declare function couponUsable(coupon: Pick<AppCoupon, 'isActive' | 'startDate' | 'endDate' | 'usageLimit' | 'usageCount' | 'channels'> & Partial<Pick<AppCoupon, 'remainingForCustomer'>>, channel: CouponChannel | null, now?: Date): boolean;
|
|
1677
|
+
/** Where a coupon works, for a label: "Everywhere", "App only", "Website and app", "Website, app and WhatsApp". */
|
|
1678
|
+
declare function channelsLabel(channels: readonly string[]): string;
|
|
1679
|
+
/** "20% off" or "R100,00 off". */
|
|
1680
|
+
declare function discountLabel(coupon: Pick<AppCoupon, 'discountType' | 'discountValue'>): string;
|
|
1681
|
+
/**
|
|
1682
|
+
* What a coupon gives, in a few words for a card or a chip:
|
|
1683
|
+
* - "Special rate with Europcar" for a coupon that unlocks a supplier's
|
|
1684
|
+
* special (CDP) rate
|
|
1685
|
+
* - "15% off" or "R150 off" otherwise, for example on the site's own fleet
|
|
1686
|
+
* (an own-fleet coupon with an amount says the amount even when it is
|
|
1687
|
+
* linked to a CDP code)
|
|
1688
|
+
*/
|
|
1689
|
+
declare function couponLabel(coupon: Pick<AppCoupon, 'discountType' | 'discountValue' | 'unlocksSpecialRate' | 'supplierName' | 'supplierIdentifier'>): string;
|
|
1690
|
+
|
|
1691
|
+
export { type ActiveChip, type AppCoupon, BaseQuery, type BookingFieldOptions, type BookingHooks, BookingManagementQueries, BookingQueries, type BookingRequest, type BookingResult, type BranchLocation, BranchQueries, CHANNEL_HEADER, CONDITIONS, COUNTRIES, COUNTRY_GROUPS, COUPON_CHANNELS, CacheQueries, type CacheVersion, type Car, type CarMetadata, type ConfirmedBooking, type ConfirmedQuoteBooking, type Country, type CouponBookingProblem, type CouponChannel, type CouponClaimProblem, type CouponClaimResult, type CouponNotice, CouponQueries, type CoverageTier, DEFAULT_CRITERIA, DEFAULT_FILTERS, DEFAULT_PICKUP_LOCATION, DEFAULT_PRICE_BOUNDS, DEFAULT_SEAT_OPTIONS, DEFAULT_YEAR_BOUNDS, DRIVER_AGE_BANDS, type Driver, type DriverErrors, EMPTY_DRIVER, type Extra, type ExtraSelection, type ExtraServiceType, type ExtrasResult, FUEL_TYPES, type FacetCounts, type FacetKey, type Filters, type FleetBridgeTransport, type HttpTransportOptions, type LiveQuote, type ManagedBooking, type ManagedBookingCustomer, type ManagedBookingExtra, type ManagedBookingRate, type ManagedBookingStatus, type ManagedBookingVehicle, type MapOffersOptions, type MileageFilter, type MyCouponsResult, type OffersResult, type OneWayFee, PAYMENT_KIND_LABEL, PAYMENT_RETURN_PARAM, PUBLIC_ACTIONS, type PaymentCheck, type PaymentKind, type PaymentMethodOption, type PaymentPurpose, PaymentQueries, type PendingPayment, type PublicAction, type QueryResult, type Quote, type QuoteExtraOption, type QuoteExtraRequest, type QuoteLine, type QuoteNote, type QuoteRequestResult, type QuotedQuote, type RatePackage, type RawOffer, SAME_AS_PICKUP, SORT_OPTIONS, SUPPLIER_GROUPS, type SearchCriteria, type SortOption, type SourceNotice, type SourceProgress, SourceQueries, type SupplierSource, type SupplierTerms, type SupplierTermsResult, TIME_SLOTS, TITLES, TRANSMISSIONS, type TransportCredentials, activeChips, availabilityQueryKey, bluuDepositQueryKey, bookingManagementQueries, bookingQueries, bookingRequestFields, branchQueries, branchesQueryKey, cacheQueries, cacheVersionQueryKey, carDisplayName, channelsLabel, countryByName, couponLabel, couponQueries, couponUsable, createBookingManagementQueries, createBookingQueries, criteriaFromParams, criteriaToQuery, describeDriverErrors, discountLabel, displayName, estimationQueries, estimationQueryKey, extraUnitPrice, extrasQueries, extrasQueryKey, facetCounts, filterCars, filtersFromSearchParams, formatDateLabel, formatZAR, getTransport, hasValidTrip, httpTransport, isCouponChannel, isOffersResult, isOneWay, isPopularExtra, locationCounts, luggageOptionsFromCars, mapOffersToCars, mileageLabel, mileageOptionsFromCars, myCouponsQueryKey, normalizeServiceType, normalizeTransmission, oneWayFeeQueries, oneWayFeeQueryKey, packageKey, paymentQueries, pluralize, priceBoundsFromCars, priceHistogram, quoteFor, rentalDays, searchAvailability, seatOptionsFromCars, selectedExtras, setTransport, shortAction, sortCars, sourceNotices, sourceQueries, sourcesQueryKey, uniqueSorted, validateDriver, withPackage, wordpressTransport, yearBoundsFromCars };
|