@final-commerce/common 2.3.0 → 2.4.0-preprod.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -389,7 +389,8 @@ declare enum StripeCurrencyCode {
389
389
 
390
390
  declare enum ProductType {
391
391
  SIMPLE = "simple",
392
- VARIABLE = "variable"
392
+ VARIABLE = "variable",
393
+ BOOKING = "booking"
393
394
  }
394
395
  declare enum ProductStatus {
395
396
  ACTIVE = "active",
@@ -403,6 +404,43 @@ declare enum PaymentProcessor {
403
404
  EXTERNAL = "external"
404
405
  }
405
406
 
407
+ declare enum BookingType {
408
+ RENTAL = "rental",
409
+ APPOINTMENT = "appointment",
410
+ OVERNIGHT = "overnight",
411
+ GROUP = "group"
412
+ }
413
+ declare enum BookingRatePeriod {
414
+ SLOT = "slot",
415
+ DAY = "day",
416
+ NIGHT = "night",
417
+ WEEK = "week",
418
+ MONTH = "month"
419
+ }
420
+ declare enum BookingResourceKind {
421
+ ASSET = "asset",
422
+ ROOM = "room",
423
+ PROPERTY = "property",
424
+ SPACE = "space",
425
+ STAFF = "staff",
426
+ TABLE = "table"
427
+ }
428
+ declare enum ReservationStatus {
429
+ HELD = "held",
430
+ CONFIRMED = "confirmed",
431
+ CANCELLED = "cancelled",
432
+ EXPIRED = "expired"
433
+ }
434
+ declare enum BookingResourceStatus {
435
+ ACTIVE = "active",
436
+ INACTIVE = "inactive"
437
+ }
438
+ declare enum ResourceAvailabilityState {
439
+ AVAILABLE = "available",
440
+ FULLY_BOOKED = "fullyBooked",
441
+ NO_HOURS_IN_RANGE = "noHoursInRange"
442
+ }
443
+
406
444
  interface CurrencyConfig {
407
445
  minorUnits: number;
408
446
  symbol: string;
@@ -783,6 +821,13 @@ interface OrderLineItem {
783
821
  returnedQuantity?: number;
784
822
  [key: string]: unknown;
785
823
  }
824
+ interface OrderReservationForContext {
825
+ internalId?: string;
826
+ quantity?: number;
827
+ fulfilledQuantity?: number;
828
+ returnedQuantity?: number;
829
+ [key: string]: unknown;
830
+ }
786
831
  interface SplitPaymentPayment {
787
832
  amount?: number;
788
833
  [key: string]: unknown;
@@ -798,6 +843,7 @@ interface OrderContext {
798
843
  paymentMethods: OrderPaymentMethod[];
799
844
  refunds: OrderRefund[];
800
845
  lineItems: OrderLineItem[];
846
+ reservations: OrderReservationForContext[];
801
847
  };
802
848
  computed: {
803
849
  balance: number;
@@ -911,6 +957,7 @@ interface OrderLikeForContext {
911
957
  refunds?: OrderRefund[];
912
958
  refund?: OrderRefund[];
913
959
  lineItems?: OrderLineItem[];
960
+ reservations?: OrderReservationForContext[];
914
961
  }
915
962
  interface OrderLikeForLegacyInference extends OrderLikeForContext {
916
963
  status?: string;
@@ -1200,6 +1247,150 @@ interface ConfigUpdatedPayload {
1200
1247
  }
1201
1248
  type OrderStateEventPayload = StateTransitionCompletedPayload | StateTransitionBlockedPayload | ConfigUpdatedPayload;
1202
1249
 
1250
+ interface WeeklyHours {
1251
+ weekday: number;
1252
+ openMinute: number;
1253
+ closeMinute: number;
1254
+ }
1255
+ interface BookingRulesInput {
1256
+ ratePeriod: BookingRatePeriod | `${BookingRatePeriod}`;
1257
+ slot: {
1258
+ lengthMinutes: number;
1259
+ bufferMinutes?: number;
1260
+ minimumToRun?: number;
1261
+ minStay?: number;
1262
+ maxStay?: number;
1263
+ sharedAcrossProducts?: boolean;
1264
+ };
1265
+ window: {
1266
+ maxAdvanceDays?: number;
1267
+ minNoticeMinutes?: number;
1268
+ holdMinutes?: number;
1269
+ bookableFrom?: Date | string | null;
1270
+ bookableTo?: Date | string | null;
1271
+ };
1272
+ availability: {
1273
+ weeklyHours?: WeeklyHours[];
1274
+ offMarket?: {
1275
+ from: Date | string;
1276
+ to: Date | string;
1277
+ }[];
1278
+ arrivalDays?: number[];
1279
+ availableFrom?: Date | string | null;
1280
+ };
1281
+ checkInTime?: string | null;
1282
+ checkOutTime?: string | null;
1283
+ }
1284
+ interface BusyWindow {
1285
+ startAt: Date;
1286
+ bufferEndAt: Date;
1287
+ }
1288
+ interface GridSlot {
1289
+ startAt: Date;
1290
+ endAt: Date;
1291
+ bufferEndAt: Date;
1292
+ canStart: boolean;
1293
+ }
1294
+ declare class BookingRulesError extends Error {
1295
+ constructor(message: string);
1296
+ }
1297
+
1298
+ declare function windowEndsAt(rule: BookingRulesInput, now: Date): Date | null;
1299
+ declare function buildGrid(rule: BookingRulesInput, timeZone: string, from: Date, to: Date, now: Date, busy?: BusyWindow[]): GridSlot[];
1300
+ declare function slotsForWindow(grid: GridSlot[], startAt: Date, endAt: Date): GridSlot[];
1301
+
1302
+ interface BookingOccupancy {
1303
+ resourceId: string;
1304
+ productId: string;
1305
+ qty: number;
1306
+ startAt: Date;
1307
+ bufferEndAt: Date;
1308
+ }
1309
+ interface BookingResourceInput {
1310
+ id: string;
1311
+ name: string;
1312
+ seats?: number | null;
1313
+ timeZone: string;
1314
+ presence?: WeeklyHours[] | null;
1315
+ }
1316
+ interface ResourceAvailability {
1317
+ resourceId: string;
1318
+ name: string;
1319
+ capacity: number;
1320
+ booked: number;
1321
+ free: number;
1322
+ }
1323
+ interface AvailabilitySlot extends GridSlot {
1324
+ capacity: number;
1325
+ booked: number;
1326
+ free: number;
1327
+ resources: ResourceAvailability[];
1328
+ }
1329
+ interface ResourceInWindow {
1330
+ resourceId: string;
1331
+ name: string;
1332
+ slots: number;
1333
+ free: number;
1334
+ state: ResourceAvailabilityState;
1335
+ }
1336
+ interface AvailabilityInput {
1337
+ productId: string;
1338
+ bookingRulesId?: string;
1339
+ bookingType?: BookingType;
1340
+ rule: BookingRulesInput;
1341
+ resources: BookingResourceInput[];
1342
+ occupied: BookingOccupancy[];
1343
+ from: Date;
1344
+ to: Date;
1345
+ now: Date;
1346
+ }
1347
+ declare const withinPresence: (slot: GridSlot, timeZone: string, presence?: WeeklyHours[] | null) => boolean;
1348
+ declare function occupancyIn(occupied: BookingOccupancy[], productId: string, startAt: Date, bufferEndAt: Date, shared: boolean): {
1349
+ taken: number;
1350
+ foreignProductId?: string;
1351
+ };
1352
+ declare function buildAvailability({ productId, bookingRulesId, bookingType, rule, resources, occupied, from, to, now, }: AvailabilityInput): {
1353
+ resources: ResourceInWindow[];
1354
+ slots: AvailabilitySlot[];
1355
+ productId: string;
1356
+ bookingRulesId: string | undefined;
1357
+ bookingType: BookingType | undefined;
1358
+ ratePeriod: "slot" | "day" | "night" | "week" | "month" | BookingRatePeriod;
1359
+ minimumToRun: number | undefined;
1360
+ minStay: number | undefined;
1361
+ maxStay: number | undefined;
1362
+ bookableUntil: Date | null;
1363
+ beyondWindow: boolean;
1364
+ };
1365
+ interface ResourcePresenceRow {
1366
+ resourceId: string;
1367
+ outletId: string;
1368
+ weeklyHours?: WeeklyHours[] | null;
1369
+ }
1370
+ declare function presentAt<T extends {
1371
+ id: string;
1372
+ }>(resources: T[], rows: ResourcePresenceRow[], outletId?: string): {
1373
+ resource: T;
1374
+ presence?: WeeklyHours[] | null;
1375
+ }[];
1376
+
1377
+ declare const DEFAULT_HOLD_MINUTES = 10;
1378
+ interface PlanWindowInput {
1379
+ rule: BookingRulesInput;
1380
+ timeZone: string;
1381
+ presence?: WeeklyHours[] | null;
1382
+ startAt: Date;
1383
+ endAt: Date;
1384
+ now: Date;
1385
+ busy?: BusyWindow[];
1386
+ }
1387
+ declare function planWindow({ rule, timeZone, presence, startAt, endAt, now, busy }: PlanWindowInput): {
1388
+ slots: GridSlot[];
1389
+ endAt: Date;
1390
+ bufferEndAt: Date;
1391
+ };
1392
+ declare const holdExpiresAt: (rule: BookingRulesInput, now: Date) => Date;
1393
+
1203
1394
  declare const ADYEN_ROLLOUT_COUNTRY_CODES: Set<string>;
1204
1395
  declare function isAdyenRolloutCountry(alpha2: string): boolean;
1205
1396
 
@@ -1214,4 +1405,4 @@ declare const EUFixedRates: Record<string, CurrencyRate>;
1214
1405
  declare const OtherFixedRates: Record<string, CurrencyRate>;
1215
1406
  declare const COUNTRY_CURRENCIES: Record<string, string>;
1216
1407
 
1217
- export { ADYEN_ROLLOUT_COUNTRY_CODES, type Amount, AttributeType, type AvailableTransition, CONDITION_OPERATORS, COUNTRY_CURRENCIES, CURRENCY_CONFIG, type CartDiscountBucket, type CartFeeBucket, type CashDrawer, type CashRoundingTuple, CompanyType, type Condition, type ConditionGroup, type ConditionOperator, type ConfigUpdatedPayload, type ConfigValidationError, type ConfigValidationResult, type ConfigValidationWarning, type CrossAxisRequires, type CrossAxisRule, type CrossAxisTrigger, CurrencyCode, type CurrencyConfig, type CurrencyRate, CustomTableAvailability, CustomerPlatform, DEFAULT_CONFIG, DEFAULT_CROSS_AXIS_RULES, DEFAULT_DISPLAY_STATE_MAP, DEFAULT_RESOLVED_CONFIG, DEFAULT_UNIT_ID, type DeleteStateConfigFragmentParams, type DeleteStateConfigFragmentResponse, type DiscountsBreakdown, type DiscountsTuple, type DisplayStateResult, type DisplayStateRule, DualWriteStrategy, EUFixedRates, EUROPE, type EndOfSessionReport, ExtensionCategory, FINANCIAL_INVARIANTS, FULFILLMENT_STATES, type FailedCondition, type FeesBreakdown, FeesCustomBillingStatus, type FeesTuple, type FinancialInvariant, type FragmentParam, type FragmentValidationResult, type FulfillmentState, type FulfillmentStateDefinition, type FulfillmentTransitionPath, type GetAvailableTransitionsParams, type GetAvailableTransitionsResponse, type GetOrderDisplayStateParams, type GetOrderDisplayStateResponse, type GetOrderStateConfigParams, type GetOrderStateConfigResponse, type GetStateConfigFragmentParams, type GetStateConfigFragmentResponse, InventoryBaseActionEnum, type InventoryBaseActionType, InventorySpecificActionType, InvoiceStatus, LegacyWriteStrategy, LibraryItemType, MAX_PRECISION, type Measurable, type MeasurementBase, type MeasurementUnit, type MeasurementUnitFamily, MenuProject, type ModifiersBreakdown, type ModifiersTuple, NAFixedRates, NORTH_AMERICA, NonRevenueItemType, ORDER_STATE_ACTIONS, ORDER_STATE_EVENTS, ORDER_STATE_TOPIC, type OrderContext, type OrderLikeForContext, type OrderLikeForLegacyInference, type OrderLineItem, type OrderMutationData, type OrderPaymentMethod, OrderPlatform, type OrderRefund, type OrderStateEventPayload, type OrderStateWritable, type OrderWriteStrategy, OtherFixedRates, OwnerType, PATH_MODES, PAYMENT_STATES, POS_VALID_INITIAL_STATES, type PathMode, PaymentMethod, PaymentProcessor, type PaymentState, type PaymentStateDefinition, type PaymentTransitionPath, Platform, PreviewImageMode, PricingLevel, PricingPlanEnum, PricingRegionEnum, type ProductDiscountBucket, type ProductFeeBucket, ProductStatus, ProductType, PublicationAvailability, type PublicationConfig, PublicationStatus, REGION_MAPPING, REPORT_NEGATE_PATHS, ReceiptSendChannel, ReceiptType, type RefundsBreakdown, ResidualPaymentMethod, ResidualStatus, type ResolveTemplateResult, STATE_SCHEMA, STRIPE_SUPPORTED_COUNTRIES, SYSTEM_FAMILIES, SYSTEM_FAMILY_IDS, SYSTEM_UNITS, SYSTEM_UNIT_IDS, type SalesSummary, type SaveStateConfigFragmentParams, type SaveStateConfigFragmentResponse, type SettlementBreakdown, type SettlementBuckets, type SettlementCardSection, type SettlementCashSection, type SettlementCustomEntry, type SplitPayment, type SplitPaymentPayment, type StaffSales, type StaffSalesEntry, type StateConfig, type StateConfigFragment, type StateDefinition, type StatePair, type StateSchema, type StateTransitionBlockedPayload, type StateTransitionCompletedPayload, StationStatus, type StoredStateConfig, StripeCurrencyCode, StripeStatus, type TaxBreakdown, type TaxBreakdownRateEntry, type TaxBreakdownSection, type TaxBreakdownSubtotal, type TaxesTuple, TimePeriod, type TipEntry, type TipsBreakdown, type TipsTuple, TopMetericsSort, type TransitionBlockedBy, type TransitionConditionSet, type TransitionOrderStateParams, type TransitionOrderStateResponse, type TransitionPath, type TransitionRequest, type TransitionResult, UserTypes, addAmounts, amountToString, assertUnitSane, availableIn, baseFor, baseFulfillmentDefinitions, baseOf, basePaymentDefinitions, buildOrderContext, buildPosPresetConfig, buildResolvedConfig, calculatePercentage, canTransition, conditionSummary, convertFixedFeeToLocalCurrency, createAmount, crossAxisRuleApplies, deriveDisplayState, deriveFamilyCode, deriveUnitId, displayRuleMatchesPair, divideAmount, evaluateCondition, evaluateConditionSet, extendPrice, extendPriceFor, formatCurrency, formatInUnit, formatMinorUnitsToString, formatQuantity, fromBase, fromMinorUnits, generateMongoID, getAvailableTransitions, getCashAmountDue, getCountriesByRegion, getCurrencyConfig, getCurrentISODate, getFinancialInvariantViolations, getGoodsPortion, getLineSubtotal, getMinorUnitMultiplier, getMinorUnits, getPaymentLegTotal, getPricingRegionFromCountry, getSettlementTotal, getTotalCollected, inferStatesFromLegacyStatus, isAdyenRolloutCountry, isConditionOperator, isFulfillmentState, isPaymentState, isSupportedCurrency, isSystemFamilyCode, isValidQuantity, isWhole, mapToLegacyStatus, maxPrecisionFor, mergeFragment, multiplyAmount, normalizeMongoIdString, parseAmountToMinorUnits, parseCurrencyCode, parseStripeCurrencyCode, removeFragment, resolveFamily, resolveTemplate, resolveUnit, roundToPrecision, sameFamily, setOrderState, signReportForDisplay, stringifyMinorUnits, subtractAmounts, toBase, toMinorUnits, validateConfig, validateFragmentCompatibility, violatesFinancialInvariant };
1408
+ export { ADYEN_ROLLOUT_COUNTRY_CODES, type Amount, AttributeType, type AvailabilityInput, type AvailabilitySlot, type AvailableTransition, type BookingOccupancy, BookingRatePeriod, type BookingResourceInput, BookingResourceKind, BookingResourceStatus, BookingRulesError, type BookingRulesInput, BookingType, type BusyWindow, CONDITION_OPERATORS, COUNTRY_CURRENCIES, CURRENCY_CONFIG, type CartDiscountBucket, type CartFeeBucket, type CashDrawer, type CashRoundingTuple, CompanyType, type Condition, type ConditionGroup, type ConditionOperator, type ConfigUpdatedPayload, type ConfigValidationError, type ConfigValidationResult, type ConfigValidationWarning, type CrossAxisRequires, type CrossAxisRule, type CrossAxisTrigger, CurrencyCode, type CurrencyConfig, type CurrencyRate, CustomTableAvailability, CustomerPlatform, DEFAULT_CONFIG, DEFAULT_CROSS_AXIS_RULES, DEFAULT_DISPLAY_STATE_MAP, DEFAULT_HOLD_MINUTES, DEFAULT_RESOLVED_CONFIG, DEFAULT_UNIT_ID, type DeleteStateConfigFragmentParams, type DeleteStateConfigFragmentResponse, type DiscountsBreakdown, type DiscountsTuple, type DisplayStateResult, type DisplayStateRule, DualWriteStrategy, EUFixedRates, EUROPE, type EndOfSessionReport, ExtensionCategory, FINANCIAL_INVARIANTS, FULFILLMENT_STATES, type FailedCondition, type FeesBreakdown, FeesCustomBillingStatus, type FeesTuple, type FinancialInvariant, type FragmentParam, type FragmentValidationResult, type FulfillmentState, type FulfillmentStateDefinition, type FulfillmentTransitionPath, type GetAvailableTransitionsParams, type GetAvailableTransitionsResponse, type GetOrderDisplayStateParams, type GetOrderDisplayStateResponse, type GetOrderStateConfigParams, type GetOrderStateConfigResponse, type GetStateConfigFragmentParams, type GetStateConfigFragmentResponse, type GridSlot, InventoryBaseActionEnum, type InventoryBaseActionType, InventorySpecificActionType, InvoiceStatus, LegacyWriteStrategy, LibraryItemType, MAX_PRECISION, type Measurable, type MeasurementBase, type MeasurementUnit, type MeasurementUnitFamily, MenuProject, type ModifiersBreakdown, type ModifiersTuple, NAFixedRates, NORTH_AMERICA, NonRevenueItemType, ORDER_STATE_ACTIONS, ORDER_STATE_EVENTS, ORDER_STATE_TOPIC, type OrderContext, type OrderLikeForContext, type OrderLikeForLegacyInference, type OrderLineItem, type OrderMutationData, type OrderPaymentMethod, OrderPlatform, type OrderRefund, type OrderReservationForContext, type OrderStateEventPayload, type OrderStateWritable, type OrderWriteStrategy, OtherFixedRates, OwnerType, PATH_MODES, PAYMENT_STATES, POS_VALID_INITIAL_STATES, type PathMode, PaymentMethod, PaymentProcessor, type PaymentState, type PaymentStateDefinition, type PaymentTransitionPath, type PlanWindowInput, Platform, PreviewImageMode, PricingLevel, PricingPlanEnum, PricingRegionEnum, type ProductDiscountBucket, type ProductFeeBucket, ProductStatus, ProductType, PublicationAvailability, type PublicationConfig, PublicationStatus, REGION_MAPPING, REPORT_NEGATE_PATHS, ReceiptSendChannel, ReceiptType, type RefundsBreakdown, ReservationStatus, ResidualPaymentMethod, ResidualStatus, type ResolveTemplateResult, type ResourceAvailability, ResourceAvailabilityState, type ResourceInWindow, type ResourcePresenceRow, STATE_SCHEMA, STRIPE_SUPPORTED_COUNTRIES, SYSTEM_FAMILIES, SYSTEM_FAMILY_IDS, SYSTEM_UNITS, SYSTEM_UNIT_IDS, type SalesSummary, type SaveStateConfigFragmentParams, type SaveStateConfigFragmentResponse, type SettlementBreakdown, type SettlementBuckets, type SettlementCardSection, type SettlementCashSection, type SettlementCustomEntry, type SplitPayment, type SplitPaymentPayment, type StaffSales, type StaffSalesEntry, type StateConfig, type StateConfigFragment, type StateDefinition, type StatePair, type StateSchema, type StateTransitionBlockedPayload, type StateTransitionCompletedPayload, StationStatus, type StoredStateConfig, StripeCurrencyCode, StripeStatus, type TaxBreakdown, type TaxBreakdownRateEntry, type TaxBreakdownSection, type TaxBreakdownSubtotal, type TaxesTuple, TimePeriod, type TipEntry, type TipsBreakdown, type TipsTuple, TopMetericsSort, type TransitionBlockedBy, type TransitionConditionSet, type TransitionOrderStateParams, type TransitionOrderStateResponse, type TransitionPath, type TransitionRequest, type TransitionResult, UserTypes, type WeeklyHours, addAmounts, amountToString, assertUnitSane, availableIn, baseFor, baseFulfillmentDefinitions, baseOf, basePaymentDefinitions, buildAvailability, buildGrid, buildOrderContext, buildPosPresetConfig, buildResolvedConfig, calculatePercentage, canTransition, conditionSummary, convertFixedFeeToLocalCurrency, createAmount, crossAxisRuleApplies, deriveDisplayState, deriveFamilyCode, deriveUnitId, displayRuleMatchesPair, divideAmount, evaluateCondition, evaluateConditionSet, extendPrice, extendPriceFor, formatCurrency, formatInUnit, formatMinorUnitsToString, formatQuantity, fromBase, fromMinorUnits, generateMongoID, getAvailableTransitions, getCashAmountDue, getCountriesByRegion, getCurrencyConfig, getCurrentISODate, getFinancialInvariantViolations, getGoodsPortion, getLineSubtotal, getMinorUnitMultiplier, getMinorUnits, getPaymentLegTotal, getPricingRegionFromCountry, getSettlementTotal, getTotalCollected, holdExpiresAt, inferStatesFromLegacyStatus, isAdyenRolloutCountry, isConditionOperator, isFulfillmentState, isPaymentState, isSupportedCurrency, isSystemFamilyCode, isValidQuantity, isWhole, mapToLegacyStatus, maxPrecisionFor, mergeFragment, multiplyAmount, normalizeMongoIdString, occupancyIn, parseAmountToMinorUnits, parseCurrencyCode, parseStripeCurrencyCode, planWindow, presentAt, removeFragment, resolveFamily, resolveTemplate, resolveUnit, roundToPrecision, sameFamily, setOrderState, signReportForDisplay, slotsForWindow, stringifyMinorUnits, subtractAmounts, toBase, toMinorUnits, validateConfig, validateFragmentCompatibility, violatesFinancialInvariant, windowEndsAt, withinPresence };
package/dist/index.d.ts CHANGED
@@ -389,7 +389,8 @@ declare enum StripeCurrencyCode {
389
389
 
390
390
  declare enum ProductType {
391
391
  SIMPLE = "simple",
392
- VARIABLE = "variable"
392
+ VARIABLE = "variable",
393
+ BOOKING = "booking"
393
394
  }
394
395
  declare enum ProductStatus {
395
396
  ACTIVE = "active",
@@ -403,6 +404,43 @@ declare enum PaymentProcessor {
403
404
  EXTERNAL = "external"
404
405
  }
405
406
 
407
+ declare enum BookingType {
408
+ RENTAL = "rental",
409
+ APPOINTMENT = "appointment",
410
+ OVERNIGHT = "overnight",
411
+ GROUP = "group"
412
+ }
413
+ declare enum BookingRatePeriod {
414
+ SLOT = "slot",
415
+ DAY = "day",
416
+ NIGHT = "night",
417
+ WEEK = "week",
418
+ MONTH = "month"
419
+ }
420
+ declare enum BookingResourceKind {
421
+ ASSET = "asset",
422
+ ROOM = "room",
423
+ PROPERTY = "property",
424
+ SPACE = "space",
425
+ STAFF = "staff",
426
+ TABLE = "table"
427
+ }
428
+ declare enum ReservationStatus {
429
+ HELD = "held",
430
+ CONFIRMED = "confirmed",
431
+ CANCELLED = "cancelled",
432
+ EXPIRED = "expired"
433
+ }
434
+ declare enum BookingResourceStatus {
435
+ ACTIVE = "active",
436
+ INACTIVE = "inactive"
437
+ }
438
+ declare enum ResourceAvailabilityState {
439
+ AVAILABLE = "available",
440
+ FULLY_BOOKED = "fullyBooked",
441
+ NO_HOURS_IN_RANGE = "noHoursInRange"
442
+ }
443
+
406
444
  interface CurrencyConfig {
407
445
  minorUnits: number;
408
446
  symbol: string;
@@ -783,6 +821,13 @@ interface OrderLineItem {
783
821
  returnedQuantity?: number;
784
822
  [key: string]: unknown;
785
823
  }
824
+ interface OrderReservationForContext {
825
+ internalId?: string;
826
+ quantity?: number;
827
+ fulfilledQuantity?: number;
828
+ returnedQuantity?: number;
829
+ [key: string]: unknown;
830
+ }
786
831
  interface SplitPaymentPayment {
787
832
  amount?: number;
788
833
  [key: string]: unknown;
@@ -798,6 +843,7 @@ interface OrderContext {
798
843
  paymentMethods: OrderPaymentMethod[];
799
844
  refunds: OrderRefund[];
800
845
  lineItems: OrderLineItem[];
846
+ reservations: OrderReservationForContext[];
801
847
  };
802
848
  computed: {
803
849
  balance: number;
@@ -911,6 +957,7 @@ interface OrderLikeForContext {
911
957
  refunds?: OrderRefund[];
912
958
  refund?: OrderRefund[];
913
959
  lineItems?: OrderLineItem[];
960
+ reservations?: OrderReservationForContext[];
914
961
  }
915
962
  interface OrderLikeForLegacyInference extends OrderLikeForContext {
916
963
  status?: string;
@@ -1200,6 +1247,150 @@ interface ConfigUpdatedPayload {
1200
1247
  }
1201
1248
  type OrderStateEventPayload = StateTransitionCompletedPayload | StateTransitionBlockedPayload | ConfigUpdatedPayload;
1202
1249
 
1250
+ interface WeeklyHours {
1251
+ weekday: number;
1252
+ openMinute: number;
1253
+ closeMinute: number;
1254
+ }
1255
+ interface BookingRulesInput {
1256
+ ratePeriod: BookingRatePeriod | `${BookingRatePeriod}`;
1257
+ slot: {
1258
+ lengthMinutes: number;
1259
+ bufferMinutes?: number;
1260
+ minimumToRun?: number;
1261
+ minStay?: number;
1262
+ maxStay?: number;
1263
+ sharedAcrossProducts?: boolean;
1264
+ };
1265
+ window: {
1266
+ maxAdvanceDays?: number;
1267
+ minNoticeMinutes?: number;
1268
+ holdMinutes?: number;
1269
+ bookableFrom?: Date | string | null;
1270
+ bookableTo?: Date | string | null;
1271
+ };
1272
+ availability: {
1273
+ weeklyHours?: WeeklyHours[];
1274
+ offMarket?: {
1275
+ from: Date | string;
1276
+ to: Date | string;
1277
+ }[];
1278
+ arrivalDays?: number[];
1279
+ availableFrom?: Date | string | null;
1280
+ };
1281
+ checkInTime?: string | null;
1282
+ checkOutTime?: string | null;
1283
+ }
1284
+ interface BusyWindow {
1285
+ startAt: Date;
1286
+ bufferEndAt: Date;
1287
+ }
1288
+ interface GridSlot {
1289
+ startAt: Date;
1290
+ endAt: Date;
1291
+ bufferEndAt: Date;
1292
+ canStart: boolean;
1293
+ }
1294
+ declare class BookingRulesError extends Error {
1295
+ constructor(message: string);
1296
+ }
1297
+
1298
+ declare function windowEndsAt(rule: BookingRulesInput, now: Date): Date | null;
1299
+ declare function buildGrid(rule: BookingRulesInput, timeZone: string, from: Date, to: Date, now: Date, busy?: BusyWindow[]): GridSlot[];
1300
+ declare function slotsForWindow(grid: GridSlot[], startAt: Date, endAt: Date): GridSlot[];
1301
+
1302
+ interface BookingOccupancy {
1303
+ resourceId: string;
1304
+ productId: string;
1305
+ qty: number;
1306
+ startAt: Date;
1307
+ bufferEndAt: Date;
1308
+ }
1309
+ interface BookingResourceInput {
1310
+ id: string;
1311
+ name: string;
1312
+ seats?: number | null;
1313
+ timeZone: string;
1314
+ presence?: WeeklyHours[] | null;
1315
+ }
1316
+ interface ResourceAvailability {
1317
+ resourceId: string;
1318
+ name: string;
1319
+ capacity: number;
1320
+ booked: number;
1321
+ free: number;
1322
+ }
1323
+ interface AvailabilitySlot extends GridSlot {
1324
+ capacity: number;
1325
+ booked: number;
1326
+ free: number;
1327
+ resources: ResourceAvailability[];
1328
+ }
1329
+ interface ResourceInWindow {
1330
+ resourceId: string;
1331
+ name: string;
1332
+ slots: number;
1333
+ free: number;
1334
+ state: ResourceAvailabilityState;
1335
+ }
1336
+ interface AvailabilityInput {
1337
+ productId: string;
1338
+ bookingRulesId?: string;
1339
+ bookingType?: BookingType;
1340
+ rule: BookingRulesInput;
1341
+ resources: BookingResourceInput[];
1342
+ occupied: BookingOccupancy[];
1343
+ from: Date;
1344
+ to: Date;
1345
+ now: Date;
1346
+ }
1347
+ declare const withinPresence: (slot: GridSlot, timeZone: string, presence?: WeeklyHours[] | null) => boolean;
1348
+ declare function occupancyIn(occupied: BookingOccupancy[], productId: string, startAt: Date, bufferEndAt: Date, shared: boolean): {
1349
+ taken: number;
1350
+ foreignProductId?: string;
1351
+ };
1352
+ declare function buildAvailability({ productId, bookingRulesId, bookingType, rule, resources, occupied, from, to, now, }: AvailabilityInput): {
1353
+ resources: ResourceInWindow[];
1354
+ slots: AvailabilitySlot[];
1355
+ productId: string;
1356
+ bookingRulesId: string | undefined;
1357
+ bookingType: BookingType | undefined;
1358
+ ratePeriod: "slot" | "day" | "night" | "week" | "month" | BookingRatePeriod;
1359
+ minimumToRun: number | undefined;
1360
+ minStay: number | undefined;
1361
+ maxStay: number | undefined;
1362
+ bookableUntil: Date | null;
1363
+ beyondWindow: boolean;
1364
+ };
1365
+ interface ResourcePresenceRow {
1366
+ resourceId: string;
1367
+ outletId: string;
1368
+ weeklyHours?: WeeklyHours[] | null;
1369
+ }
1370
+ declare function presentAt<T extends {
1371
+ id: string;
1372
+ }>(resources: T[], rows: ResourcePresenceRow[], outletId?: string): {
1373
+ resource: T;
1374
+ presence?: WeeklyHours[] | null;
1375
+ }[];
1376
+
1377
+ declare const DEFAULT_HOLD_MINUTES = 10;
1378
+ interface PlanWindowInput {
1379
+ rule: BookingRulesInput;
1380
+ timeZone: string;
1381
+ presence?: WeeklyHours[] | null;
1382
+ startAt: Date;
1383
+ endAt: Date;
1384
+ now: Date;
1385
+ busy?: BusyWindow[];
1386
+ }
1387
+ declare function planWindow({ rule, timeZone, presence, startAt, endAt, now, busy }: PlanWindowInput): {
1388
+ slots: GridSlot[];
1389
+ endAt: Date;
1390
+ bufferEndAt: Date;
1391
+ };
1392
+ declare const holdExpiresAt: (rule: BookingRulesInput, now: Date) => Date;
1393
+
1203
1394
  declare const ADYEN_ROLLOUT_COUNTRY_CODES: Set<string>;
1204
1395
  declare function isAdyenRolloutCountry(alpha2: string): boolean;
1205
1396
 
@@ -1214,4 +1405,4 @@ declare const EUFixedRates: Record<string, CurrencyRate>;
1214
1405
  declare const OtherFixedRates: Record<string, CurrencyRate>;
1215
1406
  declare const COUNTRY_CURRENCIES: Record<string, string>;
1216
1407
 
1217
- export { ADYEN_ROLLOUT_COUNTRY_CODES, type Amount, AttributeType, type AvailableTransition, CONDITION_OPERATORS, COUNTRY_CURRENCIES, CURRENCY_CONFIG, type CartDiscountBucket, type CartFeeBucket, type CashDrawer, type CashRoundingTuple, CompanyType, type Condition, type ConditionGroup, type ConditionOperator, type ConfigUpdatedPayload, type ConfigValidationError, type ConfigValidationResult, type ConfigValidationWarning, type CrossAxisRequires, type CrossAxisRule, type CrossAxisTrigger, CurrencyCode, type CurrencyConfig, type CurrencyRate, CustomTableAvailability, CustomerPlatform, DEFAULT_CONFIG, DEFAULT_CROSS_AXIS_RULES, DEFAULT_DISPLAY_STATE_MAP, DEFAULT_RESOLVED_CONFIG, DEFAULT_UNIT_ID, type DeleteStateConfigFragmentParams, type DeleteStateConfigFragmentResponse, type DiscountsBreakdown, type DiscountsTuple, type DisplayStateResult, type DisplayStateRule, DualWriteStrategy, EUFixedRates, EUROPE, type EndOfSessionReport, ExtensionCategory, FINANCIAL_INVARIANTS, FULFILLMENT_STATES, type FailedCondition, type FeesBreakdown, FeesCustomBillingStatus, type FeesTuple, type FinancialInvariant, type FragmentParam, type FragmentValidationResult, type FulfillmentState, type FulfillmentStateDefinition, type FulfillmentTransitionPath, type GetAvailableTransitionsParams, type GetAvailableTransitionsResponse, type GetOrderDisplayStateParams, type GetOrderDisplayStateResponse, type GetOrderStateConfigParams, type GetOrderStateConfigResponse, type GetStateConfigFragmentParams, type GetStateConfigFragmentResponse, InventoryBaseActionEnum, type InventoryBaseActionType, InventorySpecificActionType, InvoiceStatus, LegacyWriteStrategy, LibraryItemType, MAX_PRECISION, type Measurable, type MeasurementBase, type MeasurementUnit, type MeasurementUnitFamily, MenuProject, type ModifiersBreakdown, type ModifiersTuple, NAFixedRates, NORTH_AMERICA, NonRevenueItemType, ORDER_STATE_ACTIONS, ORDER_STATE_EVENTS, ORDER_STATE_TOPIC, type OrderContext, type OrderLikeForContext, type OrderLikeForLegacyInference, type OrderLineItem, type OrderMutationData, type OrderPaymentMethod, OrderPlatform, type OrderRefund, type OrderStateEventPayload, type OrderStateWritable, type OrderWriteStrategy, OtherFixedRates, OwnerType, PATH_MODES, PAYMENT_STATES, POS_VALID_INITIAL_STATES, type PathMode, PaymentMethod, PaymentProcessor, type PaymentState, type PaymentStateDefinition, type PaymentTransitionPath, Platform, PreviewImageMode, PricingLevel, PricingPlanEnum, PricingRegionEnum, type ProductDiscountBucket, type ProductFeeBucket, ProductStatus, ProductType, PublicationAvailability, type PublicationConfig, PublicationStatus, REGION_MAPPING, REPORT_NEGATE_PATHS, ReceiptSendChannel, ReceiptType, type RefundsBreakdown, ResidualPaymentMethod, ResidualStatus, type ResolveTemplateResult, STATE_SCHEMA, STRIPE_SUPPORTED_COUNTRIES, SYSTEM_FAMILIES, SYSTEM_FAMILY_IDS, SYSTEM_UNITS, SYSTEM_UNIT_IDS, type SalesSummary, type SaveStateConfigFragmentParams, type SaveStateConfigFragmentResponse, type SettlementBreakdown, type SettlementBuckets, type SettlementCardSection, type SettlementCashSection, type SettlementCustomEntry, type SplitPayment, type SplitPaymentPayment, type StaffSales, type StaffSalesEntry, type StateConfig, type StateConfigFragment, type StateDefinition, type StatePair, type StateSchema, type StateTransitionBlockedPayload, type StateTransitionCompletedPayload, StationStatus, type StoredStateConfig, StripeCurrencyCode, StripeStatus, type TaxBreakdown, type TaxBreakdownRateEntry, type TaxBreakdownSection, type TaxBreakdownSubtotal, type TaxesTuple, TimePeriod, type TipEntry, type TipsBreakdown, type TipsTuple, TopMetericsSort, type TransitionBlockedBy, type TransitionConditionSet, type TransitionOrderStateParams, type TransitionOrderStateResponse, type TransitionPath, type TransitionRequest, type TransitionResult, UserTypes, addAmounts, amountToString, assertUnitSane, availableIn, baseFor, baseFulfillmentDefinitions, baseOf, basePaymentDefinitions, buildOrderContext, buildPosPresetConfig, buildResolvedConfig, calculatePercentage, canTransition, conditionSummary, convertFixedFeeToLocalCurrency, createAmount, crossAxisRuleApplies, deriveDisplayState, deriveFamilyCode, deriveUnitId, displayRuleMatchesPair, divideAmount, evaluateCondition, evaluateConditionSet, extendPrice, extendPriceFor, formatCurrency, formatInUnit, formatMinorUnitsToString, formatQuantity, fromBase, fromMinorUnits, generateMongoID, getAvailableTransitions, getCashAmountDue, getCountriesByRegion, getCurrencyConfig, getCurrentISODate, getFinancialInvariantViolations, getGoodsPortion, getLineSubtotal, getMinorUnitMultiplier, getMinorUnits, getPaymentLegTotal, getPricingRegionFromCountry, getSettlementTotal, getTotalCollected, inferStatesFromLegacyStatus, isAdyenRolloutCountry, isConditionOperator, isFulfillmentState, isPaymentState, isSupportedCurrency, isSystemFamilyCode, isValidQuantity, isWhole, mapToLegacyStatus, maxPrecisionFor, mergeFragment, multiplyAmount, normalizeMongoIdString, parseAmountToMinorUnits, parseCurrencyCode, parseStripeCurrencyCode, removeFragment, resolveFamily, resolveTemplate, resolveUnit, roundToPrecision, sameFamily, setOrderState, signReportForDisplay, stringifyMinorUnits, subtractAmounts, toBase, toMinorUnits, validateConfig, validateFragmentCompatibility, violatesFinancialInvariant };
1408
+ export { ADYEN_ROLLOUT_COUNTRY_CODES, type Amount, AttributeType, type AvailabilityInput, type AvailabilitySlot, type AvailableTransition, type BookingOccupancy, BookingRatePeriod, type BookingResourceInput, BookingResourceKind, BookingResourceStatus, BookingRulesError, type BookingRulesInput, BookingType, type BusyWindow, CONDITION_OPERATORS, COUNTRY_CURRENCIES, CURRENCY_CONFIG, type CartDiscountBucket, type CartFeeBucket, type CashDrawer, type CashRoundingTuple, CompanyType, type Condition, type ConditionGroup, type ConditionOperator, type ConfigUpdatedPayload, type ConfigValidationError, type ConfigValidationResult, type ConfigValidationWarning, type CrossAxisRequires, type CrossAxisRule, type CrossAxisTrigger, CurrencyCode, type CurrencyConfig, type CurrencyRate, CustomTableAvailability, CustomerPlatform, DEFAULT_CONFIG, DEFAULT_CROSS_AXIS_RULES, DEFAULT_DISPLAY_STATE_MAP, DEFAULT_HOLD_MINUTES, DEFAULT_RESOLVED_CONFIG, DEFAULT_UNIT_ID, type DeleteStateConfigFragmentParams, type DeleteStateConfigFragmentResponse, type DiscountsBreakdown, type DiscountsTuple, type DisplayStateResult, type DisplayStateRule, DualWriteStrategy, EUFixedRates, EUROPE, type EndOfSessionReport, ExtensionCategory, FINANCIAL_INVARIANTS, FULFILLMENT_STATES, type FailedCondition, type FeesBreakdown, FeesCustomBillingStatus, type FeesTuple, type FinancialInvariant, type FragmentParam, type FragmentValidationResult, type FulfillmentState, type FulfillmentStateDefinition, type FulfillmentTransitionPath, type GetAvailableTransitionsParams, type GetAvailableTransitionsResponse, type GetOrderDisplayStateParams, type GetOrderDisplayStateResponse, type GetOrderStateConfigParams, type GetOrderStateConfigResponse, type GetStateConfigFragmentParams, type GetStateConfigFragmentResponse, type GridSlot, InventoryBaseActionEnum, type InventoryBaseActionType, InventorySpecificActionType, InvoiceStatus, LegacyWriteStrategy, LibraryItemType, MAX_PRECISION, type Measurable, type MeasurementBase, type MeasurementUnit, type MeasurementUnitFamily, MenuProject, type ModifiersBreakdown, type ModifiersTuple, NAFixedRates, NORTH_AMERICA, NonRevenueItemType, ORDER_STATE_ACTIONS, ORDER_STATE_EVENTS, ORDER_STATE_TOPIC, type OrderContext, type OrderLikeForContext, type OrderLikeForLegacyInference, type OrderLineItem, type OrderMutationData, type OrderPaymentMethod, OrderPlatform, type OrderRefund, type OrderReservationForContext, type OrderStateEventPayload, type OrderStateWritable, type OrderWriteStrategy, OtherFixedRates, OwnerType, PATH_MODES, PAYMENT_STATES, POS_VALID_INITIAL_STATES, type PathMode, PaymentMethod, PaymentProcessor, type PaymentState, type PaymentStateDefinition, type PaymentTransitionPath, type PlanWindowInput, Platform, PreviewImageMode, PricingLevel, PricingPlanEnum, PricingRegionEnum, type ProductDiscountBucket, type ProductFeeBucket, ProductStatus, ProductType, PublicationAvailability, type PublicationConfig, PublicationStatus, REGION_MAPPING, REPORT_NEGATE_PATHS, ReceiptSendChannel, ReceiptType, type RefundsBreakdown, ReservationStatus, ResidualPaymentMethod, ResidualStatus, type ResolveTemplateResult, type ResourceAvailability, ResourceAvailabilityState, type ResourceInWindow, type ResourcePresenceRow, STATE_SCHEMA, STRIPE_SUPPORTED_COUNTRIES, SYSTEM_FAMILIES, SYSTEM_FAMILY_IDS, SYSTEM_UNITS, SYSTEM_UNIT_IDS, type SalesSummary, type SaveStateConfigFragmentParams, type SaveStateConfigFragmentResponse, type SettlementBreakdown, type SettlementBuckets, type SettlementCardSection, type SettlementCashSection, type SettlementCustomEntry, type SplitPayment, type SplitPaymentPayment, type StaffSales, type StaffSalesEntry, type StateConfig, type StateConfigFragment, type StateDefinition, type StatePair, type StateSchema, type StateTransitionBlockedPayload, type StateTransitionCompletedPayload, StationStatus, type StoredStateConfig, StripeCurrencyCode, StripeStatus, type TaxBreakdown, type TaxBreakdownRateEntry, type TaxBreakdownSection, type TaxBreakdownSubtotal, type TaxesTuple, TimePeriod, type TipEntry, type TipsBreakdown, type TipsTuple, TopMetericsSort, type TransitionBlockedBy, type TransitionConditionSet, type TransitionOrderStateParams, type TransitionOrderStateResponse, type TransitionPath, type TransitionRequest, type TransitionResult, UserTypes, type WeeklyHours, addAmounts, amountToString, assertUnitSane, availableIn, baseFor, baseFulfillmentDefinitions, baseOf, basePaymentDefinitions, buildAvailability, buildGrid, buildOrderContext, buildPosPresetConfig, buildResolvedConfig, calculatePercentage, canTransition, conditionSummary, convertFixedFeeToLocalCurrency, createAmount, crossAxisRuleApplies, deriveDisplayState, deriveFamilyCode, deriveUnitId, displayRuleMatchesPair, divideAmount, evaluateCondition, evaluateConditionSet, extendPrice, extendPriceFor, formatCurrency, formatInUnit, formatMinorUnitsToString, formatQuantity, fromBase, fromMinorUnits, generateMongoID, getAvailableTransitions, getCashAmountDue, getCountriesByRegion, getCurrencyConfig, getCurrentISODate, getFinancialInvariantViolations, getGoodsPortion, getLineSubtotal, getMinorUnitMultiplier, getMinorUnits, getPaymentLegTotal, getPricingRegionFromCountry, getSettlementTotal, getTotalCollected, holdExpiresAt, inferStatesFromLegacyStatus, isAdyenRolloutCountry, isConditionOperator, isFulfillmentState, isPaymentState, isSupportedCurrency, isSystemFamilyCode, isValidQuantity, isWhole, mapToLegacyStatus, maxPrecisionFor, mergeFragment, multiplyAmount, normalizeMongoIdString, occupancyIn, parseAmountToMinorUnits, parseCurrencyCode, parseStripeCurrencyCode, planWindow, presentAt, removeFragment, resolveFamily, resolveTemplate, resolveUnit, roundToPrecision, sameFamily, setOrderState, signReportForDisplay, slotsForWindow, stringifyMinorUnits, subtractAmounts, toBase, toMinorUnits, validateConfig, validateFragmentCompatibility, violatesFinancialInvariant, windowEndsAt, withinPresence };