@perdieminc/time-slots 0.0.1 → 0.0.3
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 +9 -8
- package/lib/constants.d.ts +37 -0
- package/lib/constants.d.ts.map +1 -0
- package/lib/constants.js +37 -0
- package/lib/constants.js.map +1 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +41 -0
- package/lib/index.js.map +1 -0
- package/lib/schedule/available-dates.d.ts +3 -0
- package/lib/schedule/available-dates.d.ts.map +1 -0
- package/lib/schedule/available-dates.js +84 -0
- package/lib/schedule/available-dates.js.map +1 -0
- package/lib/schedule/generate.d.ts +3 -0
- package/lib/schedule/generate.d.ts.map +1 -0
- package/lib/schedule/generate.js +155 -0
- package/lib/schedule/generate.js.map +1 -0
- package/lib/schedule/get-schedules.d.ts +3 -0
- package/lib/schedule/get-schedules.d.ts.map +1 -0
- package/lib/schedule/get-schedules.js +182 -0
- package/lib/schedule/get-schedules.js.map +1 -0
- package/lib/schedule/location.d.ts +3 -0
- package/lib/schedule/location.d.ts.map +1 -0
- package/lib/schedule/location.js +38 -0
- package/lib/schedule/location.js.map +1 -0
- package/lib/types/index.d.ts +7 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +3 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types.d.ts +24 -0
- package/lib/types.js +2 -0
- package/lib/utils/business-hours.d.ts +6 -0
- package/lib/utils/business-hours.d.ts.map +1 -0
- package/lib/utils/business-hours.js +82 -0
- package/lib/utils/business-hours.js.map +1 -0
- package/lib/utils/catering.d.ts +9 -0
- package/lib/utils/catering.d.ts.map +1 -0
- package/lib/utils/catering.js +56 -0
- package/lib/utils/catering.js.map +1 -0
- package/lib/utils/date.d.ts +15 -0
- package/lib/utils/date.d.ts.map +1 -0
- package/lib/utils/date.js +109 -0
- package/lib/utils/date.js.map +1 -0
- package/lib/utils/schedule-filter.d.ts +8 -0
- package/lib/utils/schedule-filter.d.ts.map +1 -0
- package/lib/utils/schedule-filter.js +95 -0
- package/lib/utils/schedule-filter.js.map +1 -0
- package/lib/utils/store-hours.d.ts +14 -0
- package/lib/utils/store-hours.d.ts.map +1 -0
- package/lib/utils/store-hours.js +120 -0
- package/lib/utils/store-hours.js.map +1 -0
- package/lib/utils/time.d.ts +12 -0
- package/lib/utils/time.d.ts.map +1 -0
- package/lib/utils/time.js +30 -0
- package/lib/utils/time.js.map +1 -0
- package/lib/utils.d.ts +8 -0
- package/lib/utils.js +18 -0
- package/package.json +8 -7
- package/src/constants.ts +0 -45
- package/src/index.ts +0 -23
- package/src/schedule/available-dates.ts +0 -129
- package/src/schedule/generate.ts +0 -276
- package/src/schedule/get-schedules.ts +0 -264
- package/src/schedule/location.ts +0 -58
- package/src/types/business-hours.d.ts +0 -32
- package/src/types/common.d.ts +0 -5
- package/src/types/get-schedules.d.ts +0 -122
- package/src/types/index.ts +0 -34
- package/src/types/location.d.ts +0 -25
- package/src/types/schedule-filter.d.ts +0 -27
- package/src/types/schedule.d.ts +0 -83
- package/src/types/timezone-support.d.ts +0 -31
- package/src/utils/business-hours.ts +0 -120
- package/src/utils/catering.ts +0 -85
- package/src/utils/date.ts +0 -163
- package/src/utils/schedule-filter.ts +0 -140
- package/src/utils/store-hours.ts +0 -223
- package/src/utils/time.ts +0 -38
package/README.md
CHANGED
|
@@ -40,7 +40,7 @@ Builds the schedule for the current location and fulfillment preference.
|
|
|
40
40
|
| `locations` | List of locations (with `location_id`, `timezone`, and business hours). |
|
|
41
41
|
| `cartItems` | Cart items (used for pre-sale, weekly pre-sale, catering prep time, and category-based filtering). |
|
|
42
42
|
| `fulfillmentPreference` | `"PICKUP"` \| `"DELIVERY"` \| `"CURBSIDE"`. |
|
|
43
|
-
| `prepTimeSettings` | Prep time in minutes, per-weekday overrides, gap, busy times,
|
|
43
|
+
| `prepTimeSettings` | Prep time in minutes, per-weekday overrides, gap, busy times, **fulfillAtBusinessDayStart** (when true, prep is by day; when false, by minutes), and optional delivery buffer. |
|
|
44
44
|
| `currentLocation` | The location to generate the schedule for. |
|
|
45
45
|
| `isCateringFlow` | If `true`, prep time is derived from cart catering config. |
|
|
46
46
|
| `platform` | `"web"` \| `"ios"` \| `"android"` for timezone handling (default `"web"`). |
|
|
@@ -52,7 +52,7 @@ Builds the schedule for the current location and fulfillment preference.
|
|
|
52
52
|
### Types and constants
|
|
53
53
|
|
|
54
54
|
- **Fulfillment:** `FULFILLMENT_TYPES`, `FulfillmentType`, `FulfillmentSchedule`, `DaySchedule`.
|
|
55
|
-
- **Prep time:** `PrepTimeBehaviour` (first shift / every shift / roll), `DEFAULT_PREP_TIME_IN_MINUTES`, `DEFAULT_GAP_IN_MINUTES`, `PrepTimeSettings`, `PrepTimeCadence` (minute / hour / day).
|
|
55
|
+
- **Prep time:** `PrepTimeBehaviour` (first shift / every shift / roll), `DEFAULT_PREP_TIME_IN_MINUTES`, `DEFAULT_GAP_IN_MINUTES`, `MINUTES_PER_DAY`, `PrepTimeSettings`, `PrepTimeCadence` (minute / hour / day).
|
|
56
56
|
- **Store / cart:** `StoreConfig`, `PreSaleConfig`, `WeeklyPreSaleConfig`, `CartItem`, `PrepTimeSettings`, `CateringPrepTimeResult`.
|
|
57
57
|
- **Location / hours:** `LocationLike`, `BusinessHour`, `BusinessHoursOverrideInput` / `Output`, `getLocationsBusinessHoursOverrides`, `getOpeningClosingTime`.
|
|
58
58
|
- **Platform:** `PLATFORM` (web, ios, android).
|
|
@@ -71,14 +71,15 @@ Internal schedule generation uses **`getNextAvailableDates`**-style logic (timez
|
|
|
71
71
|
|
|
72
72
|
## Prep time (high level)
|
|
73
73
|
|
|
74
|
-
Prep time
|
|
74
|
+
Prep time is either **by minutes** or **by day** (e.g. in dashboard, when prep is set to “day”, it is treated as day-based).
|
|
75
75
|
|
|
76
|
-
- **
|
|
77
|
-
- **
|
|
76
|
+
- **By day:** First slot is at **business start** (opening) on the next open day(s). Number of days is derived from `prepTimeInMinutes` (e.g. 1440 min = 1 day).
|
|
77
|
+
- **By minutes:** First slot = order time + prep minutes, within store hours.
|
|
78
|
+
- **Per weekday:** different prep minutes per day via `weekDayPrepTimes` (when not using day-based prep).
|
|
78
79
|
- **Catering:** when `isCateringFlow` is true, cadence and frequency are derived from cart items via `getCateringPrepTimeConfig`.
|
|
79
80
|
- **Delivery:** optional `estimatedDeliveryMinutes` added to weekday prep times for delivery.
|
|
80
81
|
|
|
81
|
-
|
|
82
|
+
QA-friendly test cases (Given / When / Expected) are in [docs/TEST-CASES.md](docs/TEST-CASES.md).
|
|
82
83
|
|
|
83
84
|
## Scripts
|
|
84
85
|
|
|
@@ -96,5 +97,5 @@ MIT © Per Diem Subscriptions Inc.
|
|
|
96
97
|
|
|
97
98
|
## Repository
|
|
98
99
|
|
|
99
|
-
- **Homepage:** [
|
|
100
|
-
- **Issues:** [
|
|
100
|
+
- **Homepage:** [time-slots](https://github.com/PerDiemInc/time-slots#readme)
|
|
101
|
+
- **Issues:** [time-slots/issues](https://github.com/PerDiemInc/time-slots/issues)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fulfillment types for pickup, delivery, curbside.
|
|
3
|
+
*/
|
|
4
|
+
export declare const FULFILLMENT_TYPES: {
|
|
5
|
+
readonly PICKUP: "PICKUP";
|
|
6
|
+
readonly DELIVERY: "DELIVERY";
|
|
7
|
+
readonly CURBSIDE: "CURBSIDE";
|
|
8
|
+
};
|
|
9
|
+
export declare const DEFAULT_TIMEZONE = "America/New_York";
|
|
10
|
+
export type FulfillmentType = (typeof FULFILLMENT_TYPES)[keyof typeof FULFILLMENT_TYPES];
|
|
11
|
+
export declare const DEFAULT_GAP_IN_MINUTES = 15;
|
|
12
|
+
export declare const DEFAULT_PREP_TIME_IN_MINUTES = 5;
|
|
13
|
+
export declare const MINUTES_PER_DAY = 1440;
|
|
14
|
+
/**
|
|
15
|
+
* Prep time behaviour when computing first available slot.
|
|
16
|
+
*/
|
|
17
|
+
export declare const PrepTimeBehaviour: Readonly<{
|
|
18
|
+
FIRST_SHIFT: 0;
|
|
19
|
+
EVERY_SHIFT: 1;
|
|
20
|
+
ROLL_FROM_FIRST_SHIFT: 2;
|
|
21
|
+
}>;
|
|
22
|
+
export type PrepTimeBehaviourType = (typeof PrepTimeBehaviour)[keyof typeof PrepTimeBehaviour];
|
|
23
|
+
export declare const PREP_TIME_CADENCE: {
|
|
24
|
+
readonly MINUTE: "minute";
|
|
25
|
+
readonly DAY: "day";
|
|
26
|
+
readonly HOUR: "hour";
|
|
27
|
+
};
|
|
28
|
+
export type PrepTimeCadence = (typeof PREP_TIME_CADENCE)[keyof typeof PREP_TIME_CADENCE];
|
|
29
|
+
/**
|
|
30
|
+
* Platform for timezone handling (web uses @date-fns/tz; ios/android use timezone-support).
|
|
31
|
+
*/
|
|
32
|
+
export declare const PLATFORM: {
|
|
33
|
+
readonly WEB: "web";
|
|
34
|
+
readonly IOS: "ios";
|
|
35
|
+
readonly ANDROID: "android";
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,iBAAiB;;;;CAIpB,CAAC;AAEX,eAAO,MAAM,gBAAgB,qBAAqB,CAAC;AACnD,MAAM,MAAM,eAAe,GAC1B,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,OAAO,iBAAiB,CAAC,CAAC;AAE5D,eAAO,MAAM,sBAAsB,KAAK,CAAC;AACzC,eAAO,MAAM,4BAA4B,IAAI,CAAC;AAC9C,eAAO,MAAM,eAAe,OAAO,CAAC;AACpC;;GAEG;AACH,eAAO,MAAM,iBAAiB;;;;EAI5B,CAAC;AAEH,MAAM,MAAM,qBAAqB,GAChC,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,OAAO,iBAAiB,CAAC,CAAC;AAE5D,eAAO,MAAM,iBAAiB;;;;CAIpB,CAAC;AAEX,MAAM,MAAM,eAAe,GAC1B,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,OAAO,iBAAiB,CAAC,CAAC;AAE5D;;GAEG;AACH,eAAO,MAAM,QAAQ;;;;CAIX,CAAC"}
|
package/lib/constants.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PLATFORM = exports.PREP_TIME_CADENCE = exports.PrepTimeBehaviour = exports.MINUTES_PER_DAY = exports.DEFAULT_PREP_TIME_IN_MINUTES = exports.DEFAULT_GAP_IN_MINUTES = exports.DEFAULT_TIMEZONE = exports.FULFILLMENT_TYPES = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Fulfillment types for pickup, delivery, curbside.
|
|
6
|
+
*/
|
|
7
|
+
exports.FULFILLMENT_TYPES = {
|
|
8
|
+
PICKUP: "PICKUP",
|
|
9
|
+
DELIVERY: "DELIVERY",
|
|
10
|
+
CURBSIDE: "CURBSIDE",
|
|
11
|
+
};
|
|
12
|
+
exports.DEFAULT_TIMEZONE = "America/New_York";
|
|
13
|
+
exports.DEFAULT_GAP_IN_MINUTES = 15;
|
|
14
|
+
exports.DEFAULT_PREP_TIME_IN_MINUTES = 5;
|
|
15
|
+
exports.MINUTES_PER_DAY = 1440;
|
|
16
|
+
/**
|
|
17
|
+
* Prep time behaviour when computing first available slot.
|
|
18
|
+
*/
|
|
19
|
+
exports.PrepTimeBehaviour = Object.freeze({
|
|
20
|
+
FIRST_SHIFT: 0,
|
|
21
|
+
EVERY_SHIFT: 1,
|
|
22
|
+
ROLL_FROM_FIRST_SHIFT: 2,
|
|
23
|
+
});
|
|
24
|
+
exports.PREP_TIME_CADENCE = {
|
|
25
|
+
MINUTE: "minute",
|
|
26
|
+
DAY: "day",
|
|
27
|
+
HOUR: "hour",
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Platform for timezone handling (web uses @date-fns/tz; ios/android use timezone-support).
|
|
31
|
+
*/
|
|
32
|
+
exports.PLATFORM = {
|
|
33
|
+
WEB: "web",
|
|
34
|
+
IOS: "ios",
|
|
35
|
+
ANDROID: "android",
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,iBAAiB,GAAG;IAChC,MAAM,EAAE,QAAQ;IAChB,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,UAAU;CACX,CAAC;AAEE,QAAA,gBAAgB,GAAG,kBAAkB,CAAC;AAItC,QAAA,sBAAsB,GAAG,EAAE,CAAC;AAC5B,QAAA,4BAA4B,GAAG,CAAC,CAAC;AACjC,QAAA,eAAe,GAAG,IAAI,CAAC;AACpC;;GAEG;AACU,QAAA,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC9C,WAAW,EAAE,CAAC;IACd,WAAW,EAAE,CAAC;IACd,qBAAqB,EAAE,CAAC;CACxB,CAAC,CAAC;AAKU,QAAA,iBAAiB,GAAG;IAChC,MAAM,EAAE,QAAQ;IAChB,GAAG,EAAE,KAAK;IACV,IAAI,EAAE,MAAM;CACH,CAAC;AAKX;;GAEG;AACU,QAAA,QAAQ,GAAG;IACvB,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,OAAO,EAAE,SAAS;CACT,CAAC"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type { FulfillmentType, PrepTimeBehaviourType } from "./constants";
|
|
2
|
+
export { DEFAULT_GAP_IN_MINUTES, DEFAULT_PREP_TIME_IN_MINUTES, FULFILLMENT_TYPES, PLATFORM, PrepTimeBehaviour, } from "./constants";
|
|
3
|
+
export { getSchedules } from "./schedule/get-schedules";
|
|
4
|
+
export * from "./types";
|
|
5
|
+
export type { BusinessHour, BusinessHourInput, BusinessHoursOverrideInput, BusinessHoursOverrideOutput, } from "./types/business-hours";
|
|
6
|
+
export { getLocationsBusinessHoursOverrides } from "./utils/business-hours";
|
|
7
|
+
export { getCateringPrepTimeConfig } from "./utils/catering";
|
|
8
|
+
export { getPreSalePickupDates, isTodayInTimeZone, isTomorrowInTimeZone, overrideTimeZoneOnUTC, } from "./utils/date";
|
|
9
|
+
export { filterBusyTimesFromSchedule, filterMenusFromSchedule, } from "./utils/schedule-filter";
|
|
10
|
+
export { getOpeningClosingTime } from "./utils/store-hours";
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EACN,sBAAsB,EACtB,4BAA4B,EAC5B,iBAAiB,EACjB,QAAQ,EACR,iBAAiB,GACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,cAAc,SAAS,CAAC;AACxB,YAAY,EACX,YAAY,EACZ,iBAAiB,EACjB,0BAA0B,EAC1B,2BAA2B,GAC3B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,kCAAkC,EAAE,MAAM,wBAAwB,CAAC;AAC5E,OAAO,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EACN,qBAAqB,EACrB,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,GACrB,MAAM,cAAc,CAAC;AACtB,OAAO,EACN,2BAA2B,EAC3B,uBAAuB,GACvB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.getOpeningClosingTime = exports.filterMenusFromSchedule = exports.filterBusyTimesFromSchedule = exports.overrideTimeZoneOnUTC = exports.isTomorrowInTimeZone = exports.isTodayInTimeZone = exports.getPreSalePickupDates = exports.getCateringPrepTimeConfig = exports.getLocationsBusinessHoursOverrides = exports.getSchedules = exports.PrepTimeBehaviour = exports.PLATFORM = exports.FULFILLMENT_TYPES = exports.DEFAULT_PREP_TIME_IN_MINUTES = exports.DEFAULT_GAP_IN_MINUTES = void 0;
|
|
18
|
+
var constants_1 = require("./constants");
|
|
19
|
+
Object.defineProperty(exports, "DEFAULT_GAP_IN_MINUTES", { enumerable: true, get: function () { return constants_1.DEFAULT_GAP_IN_MINUTES; } });
|
|
20
|
+
Object.defineProperty(exports, "DEFAULT_PREP_TIME_IN_MINUTES", { enumerable: true, get: function () { return constants_1.DEFAULT_PREP_TIME_IN_MINUTES; } });
|
|
21
|
+
Object.defineProperty(exports, "FULFILLMENT_TYPES", { enumerable: true, get: function () { return constants_1.FULFILLMENT_TYPES; } });
|
|
22
|
+
Object.defineProperty(exports, "PLATFORM", { enumerable: true, get: function () { return constants_1.PLATFORM; } });
|
|
23
|
+
Object.defineProperty(exports, "PrepTimeBehaviour", { enumerable: true, get: function () { return constants_1.PrepTimeBehaviour; } });
|
|
24
|
+
var get_schedules_1 = require("./schedule/get-schedules");
|
|
25
|
+
Object.defineProperty(exports, "getSchedules", { enumerable: true, get: function () { return get_schedules_1.getSchedules; } });
|
|
26
|
+
__exportStar(require("./types"), exports);
|
|
27
|
+
var business_hours_1 = require("./utils/business-hours");
|
|
28
|
+
Object.defineProperty(exports, "getLocationsBusinessHoursOverrides", { enumerable: true, get: function () { return business_hours_1.getLocationsBusinessHoursOverrides; } });
|
|
29
|
+
var catering_1 = require("./utils/catering");
|
|
30
|
+
Object.defineProperty(exports, "getCateringPrepTimeConfig", { enumerable: true, get: function () { return catering_1.getCateringPrepTimeConfig; } });
|
|
31
|
+
var date_1 = require("./utils/date");
|
|
32
|
+
Object.defineProperty(exports, "getPreSalePickupDates", { enumerable: true, get: function () { return date_1.getPreSalePickupDates; } });
|
|
33
|
+
Object.defineProperty(exports, "isTodayInTimeZone", { enumerable: true, get: function () { return date_1.isTodayInTimeZone; } });
|
|
34
|
+
Object.defineProperty(exports, "isTomorrowInTimeZone", { enumerable: true, get: function () { return date_1.isTomorrowInTimeZone; } });
|
|
35
|
+
Object.defineProperty(exports, "overrideTimeZoneOnUTC", { enumerable: true, get: function () { return date_1.overrideTimeZoneOnUTC; } });
|
|
36
|
+
var schedule_filter_1 = require("./utils/schedule-filter");
|
|
37
|
+
Object.defineProperty(exports, "filterBusyTimesFromSchedule", { enumerable: true, get: function () { return schedule_filter_1.filterBusyTimesFromSchedule; } });
|
|
38
|
+
Object.defineProperty(exports, "filterMenusFromSchedule", { enumerable: true, get: function () { return schedule_filter_1.filterMenusFromSchedule; } });
|
|
39
|
+
var store_hours_1 = require("./utils/store-hours");
|
|
40
|
+
Object.defineProperty(exports, "getOpeningClosingTime", { enumerable: true, get: function () { return store_hours_1.getOpeningClosingTime; } });
|
|
41
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AACA,yCAMqB;AALpB,mHAAA,sBAAsB,OAAA;AACtB,yHAAA,4BAA4B,OAAA;AAC5B,8GAAA,iBAAiB,OAAA;AACjB,qGAAA,QAAQ,OAAA;AACR,8GAAA,iBAAiB,OAAA;AAElB,0DAAwD;AAA/C,6GAAA,YAAY,OAAA;AACrB,0CAAwB;AAOxB,yDAA4E;AAAnE,oIAAA,kCAAkC,OAAA;AAC3C,6CAA6D;AAApD,qHAAA,yBAAyB,OAAA;AAClC,qCAKsB;AAJrB,6GAAA,qBAAqB,OAAA;AACrB,yGAAA,iBAAiB,OAAA;AACjB,4GAAA,oBAAoB,OAAA;AACpB,6GAAA,qBAAqB,OAAA;AAEtB,2DAGiC;AAFhC,8HAAA,2BAA2B,OAAA;AAC3B,0HAAA,uBAAuB,OAAA;AAExB,mDAA4D;AAAnD,oHAAA,qBAAqB,OAAA"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { GetNextAvailableDatesParams } from "../types";
|
|
2
|
+
export declare function getNextAvailableDates({ startDate, timeZone, businessHours, businessHoursOverrides, datesCount, preSaleDates, presalePickupWeekDays, endDate, isDaysCadence, platform, }: GetNextAvailableDatesParams): Date[];
|
|
3
|
+
//# sourceMappingURL=available-dates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"available-dates.d.ts","sourceRoot":"","sources":["../../src/schedule/available-dates.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,2BAA2B,EAAY,MAAM,UAAU,CAAC;AAuBtE,wBAAgB,qBAAqB,CAAC,EACrC,SAAS,EACT,QAAQ,EACR,aAAa,EACb,sBAA2B,EAC3B,UAAc,EACd,YAAiB,EACjB,qBAA0B,EAC1B,OAAc,EACd,aAAqB,EACrB,QAAuB,GACvB,EAAE,2BAA2B,GAAG,IAAI,EAAE,CAyFtC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getNextAvailableDates = getNextAvailableDates;
|
|
4
|
+
const tz_1 = require("@date-fns/tz");
|
|
5
|
+
const date_fns_1 = require("date-fns");
|
|
6
|
+
const timezone_support_1 = require("timezone-support");
|
|
7
|
+
const constants_1 = require("../constants");
|
|
8
|
+
const date_1 = require("../utils/date");
|
|
9
|
+
function getStartOfDayInZone(startDate, timeZone, platform) {
|
|
10
|
+
if (platform !== constants_1.PLATFORM.ANDROID) {
|
|
11
|
+
return (0, date_fns_1.startOfDay)(startDate, { in: (0, tz_1.tz)(timeZone) });
|
|
12
|
+
}
|
|
13
|
+
const zoned = (0, timezone_support_1.getZonedTime)(startDate, (0, timezone_support_1.findTimeZone)(timeZone));
|
|
14
|
+
return new Date((0, timezone_support_1.getUnixTime)({
|
|
15
|
+
...zoned,
|
|
16
|
+
hours: 0,
|
|
17
|
+
minutes: 0,
|
|
18
|
+
seconds: 0,
|
|
19
|
+
milliseconds: 0,
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
function getNextAvailableDates({ startDate, timeZone, businessHours, businessHoursOverrides = [], datesCount = 1, preSaleDates = [], presalePickupWeekDays = [], endDate = null, isDaysCadence = false, platform = constants_1.PLATFORM.WEB, }) {
|
|
23
|
+
const startOfDayInZone = getStartOfDayInZone(startDate, timeZone, platform);
|
|
24
|
+
const zonedStartTime = (0, timezone_support_1.getZonedTime)(startOfDayInZone, (0, timezone_support_1.findTimeZone)(timeZone));
|
|
25
|
+
const dates = [];
|
|
26
|
+
for (let date = new Date((0, timezone_support_1.getUnixTime)({
|
|
27
|
+
...zonedStartTime,
|
|
28
|
+
hours: 0,
|
|
29
|
+
minutes: 0,
|
|
30
|
+
seconds: 0,
|
|
31
|
+
milliseconds: 0,
|
|
32
|
+
})), maxRuns = 0; dates.length < datesCount && maxRuns <= 30; date = (0, date_1.addDaysInTimeZone)(date, 1, timeZone), maxRuns += 1) {
|
|
33
|
+
const lastDate = dates?.at(-1);
|
|
34
|
+
if (lastDate && (0, date_fns_1.isSameDay)(lastDate, date)) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (endDate && (0, date_fns_1.isAfter)(date, endDate)) {
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
if (date.getTime() < (0, timezone_support_1.getUnixTime)(zonedStartTime)) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
const zonedDate = (0, timezone_support_1.getZonedTime)(date, (0, timezone_support_1.findTimeZone)(timeZone));
|
|
44
|
+
const dayOfWeek = zonedDate.dayOfWeek ?? 0;
|
|
45
|
+
const todayBusinessHoursOverride = businessHoursOverrides.filter((override) => zonedDate.month === override.month && zonedDate.day === override.day);
|
|
46
|
+
const closedBusinessHoursOverride = todayBusinessHoursOverride.filter((override) => !override.startTime && !override.endTime);
|
|
47
|
+
if (closedBusinessHoursOverride.length) {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
const todayBusinessHours = businessHours.filter((bh) => bh.day === dayOfWeek);
|
|
51
|
+
// If days cadence, we dont need to skip date even if it is after the last shift end time
|
|
52
|
+
if (isDaysCadence) {
|
|
53
|
+
const lastShiftEndTime = todayBusinessHours.at(-1)?.endTime;
|
|
54
|
+
const shiftEndDate = lastShiftEndTime
|
|
55
|
+
? (0, date_1.setHmOnDate)(date, lastShiftEndTime, timeZone)
|
|
56
|
+
: null;
|
|
57
|
+
/**
|
|
58
|
+
* Skip current date if current time is after the last shift end time
|
|
59
|
+
*/
|
|
60
|
+
if (shiftEndDate && (0, date_fns_1.isAfter)(startDate, shiftEndDate)) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Skip if today is closed by location hours or by override hours
|
|
66
|
+
*/
|
|
67
|
+
if (!todayBusinessHours?.length &&
|
|
68
|
+
!todayBusinessHoursOverride.length &&
|
|
69
|
+
!endDate) {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (preSaleDates.length && presalePickupWeekDays.length) {
|
|
73
|
+
if (preSaleDates.includes(zonedDate.day) &&
|
|
74
|
+
presalePickupWeekDays.includes(dayOfWeek)) {
|
|
75
|
+
dates.push(date);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
dates.push(date);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return dates;
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=available-dates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"available-dates.js","sourceRoot":"","sources":["../../src/schedule/available-dates.ts"],"names":[],"mappings":";;AA4BA,sDAoGC;AAhID,qCAAkC;AAClC,uCAA0D;AAC1D,uDAA2E;AAE3E,4CAAwC;AAExC,wCAA+D;AAE/D,SAAS,mBAAmB,CAC3B,SAAe,EACf,QAAgB,EAChB,QAAkB;IAElB,IAAI,QAAQ,KAAK,oBAAQ,CAAC,OAAO,EAAE,CAAC;QACnC,OAAO,IAAA,qBAAU,EAAC,SAAS,EAAE,EAAE,EAAE,EAAE,IAAA,OAAE,EAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACpD,CAAC;IACD,MAAM,KAAK,GAAG,IAAA,+BAAY,EAAC,SAAS,EAAE,IAAA,+BAAY,EAAC,QAAQ,CAAC,CAAC,CAAC;IAC9D,OAAO,IAAI,IAAI,CACd,IAAA,8BAAW,EAAC;QACX,GAAG,KAAK;QACR,KAAK,EAAE,CAAC;QACR,OAAO,EAAE,CAAC;QACV,OAAO,EAAE,CAAC;QACV,YAAY,EAAE,CAAC;KACf,CAAC,CACF,CAAC;AACH,CAAC;AAED,SAAgB,qBAA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CAAC;QAED,IAAI,YAAY,CAAC,MAAM,IAAI,qBAAqB,CAAC,MAAM,EAAE,CAAC;YACzD,IACC,YAAY,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC;gBACpC,qBAAqB,CAAC,QAAQ,CAAC,SAAS,CAAC,EACxC,CAAC;gBACF,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAClB,CAAC;QACF,CAAC;aAAM,CAAC;YACP,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAClB,CAAC;IACF,CAAC;IAED,OAAO,KAAK,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { DaySchedule, GenerateScheduleParams } from "../types";
|
|
2
|
+
export declare function generateSchedule({ currentDate, prepTimeBehaviour, weekDayPrepTimes, timeZone, dates, businessHours, businessHoursOverrides, preSaleHoursOverride, gapInMinutes, prepTimeCadence, }: GenerateScheduleParams): DaySchedule[];
|
|
3
|
+
//# sourceMappingURL=generate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../src/schedule/generate.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAGX,WAAW,EACX,sBAAsB,EACtB,MAAM,UAAU,CAAC;AAiElB,wBAAgB,gBAAgB,CAAC,EAChC,WAAwB,EACxB,iBAA2D,EAC3D,gBAAqB,EACrB,QAAQ,EACR,KAAU,EACV,aAAkB,EAClB,sBAA2B,EAC3B,oBAAoB,EACpB,YAAiB,EACjB,eAAsB,GACtB,EAAE,sBAAsB,GAAG,WAAW,EAAE,CAmLxC"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateSchedule = generateSchedule;
|
|
4
|
+
const date_fns_1 = require("date-fns");
|
|
5
|
+
const timezone_support_1 = require("timezone-support");
|
|
6
|
+
const constants_1 = require("../constants");
|
|
7
|
+
const date_1 = require("../utils/date");
|
|
8
|
+
function getSelectedBusinessHours({ businessHours = [], businessHoursOverrides = [], date, timeZone, preSaleHoursOverride, }) {
|
|
9
|
+
if (!date || !timeZone) {
|
|
10
|
+
return [[], (0, timezone_support_1.getZonedTime)(new Date(), (0, timezone_support_1.findTimeZone)(timeZone ?? "UTC"))];
|
|
11
|
+
}
|
|
12
|
+
const zonedDate = (0, timezone_support_1.getZonedTime)(date, (0, timezone_support_1.findTimeZone)(timeZone));
|
|
13
|
+
const dayOfWeek = zonedDate.dayOfWeek ?? 0;
|
|
14
|
+
const dayBusinessHours = businessHours?.filter((bh) => bh.day === dayOfWeek);
|
|
15
|
+
const businessHoursOverride = businessHoursOverrides?.filter((override) => zonedDate.month === override.month && zonedDate.day === override.day);
|
|
16
|
+
const selectedBusinessHours = preSaleHoursOverride
|
|
17
|
+
? preSaleHoursOverride.map((o) => ({
|
|
18
|
+
day: dayOfWeek,
|
|
19
|
+
startTime: o.startTime,
|
|
20
|
+
endTime: o.endTime,
|
|
21
|
+
}))
|
|
22
|
+
: businessHoursOverride.length
|
|
23
|
+
? businessHoursOverride.map((o) => ({
|
|
24
|
+
day: dayOfWeek,
|
|
25
|
+
startTime: o.startTime ?? "00:00",
|
|
26
|
+
endTime: o.endTime ?? "23:59",
|
|
27
|
+
}))
|
|
28
|
+
: (dayBusinessHours ?? []);
|
|
29
|
+
return [selectedBusinessHours, zonedDate];
|
|
30
|
+
}
|
|
31
|
+
// ── Public API ──────────────────────────────────────────────────────────────
|
|
32
|
+
function generateSchedule({ currentDate = new Date(), prepTimeBehaviour = constants_1.PrepTimeBehaviour.ROLL_FROM_FIRST_SHIFT, weekDayPrepTimes = {}, timeZone, dates = [], businessHours = [], businessHoursOverrides = [], preSaleHoursOverride, gapInMinutes = 15, prepTimeCadence = null, }) {
|
|
33
|
+
const isMinutesCadence = prepTimeCadence === constants_1.PREP_TIME_CADENCE.MINUTE;
|
|
34
|
+
let shiftStartDateWithPrepTime = null;
|
|
35
|
+
return dates
|
|
36
|
+
.map((date, index) => {
|
|
37
|
+
const lastDate = dates?.[index - 1];
|
|
38
|
+
const [selectedBusinessHours, zonedDate] = getSelectedBusinessHours({
|
|
39
|
+
businessHours,
|
|
40
|
+
businessHoursOverrides,
|
|
41
|
+
date,
|
|
42
|
+
timeZone,
|
|
43
|
+
preSaleHoursOverride,
|
|
44
|
+
});
|
|
45
|
+
const [prevSelectedBusinessHours] = getSelectedBusinessHours({
|
|
46
|
+
businessHours,
|
|
47
|
+
businessHoursOverrides,
|
|
48
|
+
date: lastDate,
|
|
49
|
+
timeZone,
|
|
50
|
+
preSaleHoursOverride,
|
|
51
|
+
});
|
|
52
|
+
const weekDayPrepTime = weekDayPrepTimes[zonedDate.dayOfWeek] ?? constants_1.DEFAULT_PREP_TIME_IN_MINUTES;
|
|
53
|
+
const storeTimes = {
|
|
54
|
+
openingTime: null,
|
|
55
|
+
closingTime: null,
|
|
56
|
+
remainingShifts: 0,
|
|
57
|
+
totalShifts: 0,
|
|
58
|
+
};
|
|
59
|
+
let isPrevDayMidnightTransition = false;
|
|
60
|
+
const slots = selectedBusinessHours
|
|
61
|
+
.flatMap((businessHour, i) => {
|
|
62
|
+
const startDate = (0, date_1.setHmOnDate)(date, businessHour.startTime, timeZone);
|
|
63
|
+
const shiftStartDate = isMinutesCadence && shiftStartDateWithPrepTime
|
|
64
|
+
? (0, date_fns_1.max)([shiftStartDateWithPrepTime, startDate])
|
|
65
|
+
: startDate;
|
|
66
|
+
const shiftEndDate = (0, date_1.setHmOnDate)(date, businessHour.endTime, timeZone);
|
|
67
|
+
if (i === 0) {
|
|
68
|
+
storeTimes.openingTime = shiftStartDate;
|
|
69
|
+
}
|
|
70
|
+
if (i === selectedBusinessHours.length - 1) {
|
|
71
|
+
storeTimes.closingTime = shiftEndDate;
|
|
72
|
+
}
|
|
73
|
+
if (!(0, date_fns_1.isBefore)(shiftStartDate, shiftEndDate)) {
|
|
74
|
+
if (isMinutesCadence) {
|
|
75
|
+
shiftStartDateWithPrepTime = null;
|
|
76
|
+
}
|
|
77
|
+
return [];
|
|
78
|
+
}
|
|
79
|
+
storeTimes.totalShifts += 1;
|
|
80
|
+
const fixedSlots = (0, date_fns_1.eachMinuteOfInterval)({ start: shiftStartDate, end: shiftEndDate }, { step: gapInMinutes });
|
|
81
|
+
if ((0, date_1.isTodayInTimeZone)(date, timeZone)) {
|
|
82
|
+
const openingTime = storeTimes.openingTime ?? new Date(0);
|
|
83
|
+
const baseDate = currentDate instanceof Date ? currentDate : new Date(currentDate);
|
|
84
|
+
const currentDateWithPrepTime = (0, date_fns_1.addMinutes)(new Date(Math.max(baseDate.getTime(), openingTime.getTime())), Math.max(constants_1.DEFAULT_PREP_TIME_IN_MINUTES, weekDayPrepTime));
|
|
85
|
+
if ((0, date_fns_1.isAfter)(currentDateWithPrepTime, shiftEndDate)) {
|
|
86
|
+
// If the prep time cadence is minutes, we need to set the shift start date with the prep time
|
|
87
|
+
if (isMinutesCadence) {
|
|
88
|
+
shiftStartDateWithPrepTime = currentDateWithPrepTime;
|
|
89
|
+
}
|
|
90
|
+
return [];
|
|
91
|
+
}
|
|
92
|
+
if ((0, date_fns_1.isBefore)(currentDateWithPrepTime, shiftStartDate)) {
|
|
93
|
+
storeTimes.remainingShifts += 1;
|
|
94
|
+
if (prepTimeBehaviour ===
|
|
95
|
+
constants_1.PrepTimeBehaviour.EVERY_SHIFT) {
|
|
96
|
+
const shiftStartDateWithPrepTime = (0, date_fns_1.addMinutes)(shiftStartDate, weekDayPrepTime);
|
|
97
|
+
const slotDates = fixedSlots.filter((d) => (0, date_fns_1.isAfter)(d, shiftStartDateWithPrepTime));
|
|
98
|
+
slotDates.unshift(shiftStartDateWithPrepTime);
|
|
99
|
+
return slotDates;
|
|
100
|
+
}
|
|
101
|
+
return fixedSlots;
|
|
102
|
+
}
|
|
103
|
+
const slotDates = fixedSlots.filter((d) => (0, date_fns_1.isAfter)(d, currentDateWithPrepTime));
|
|
104
|
+
slotDates.unshift(currentDateWithPrepTime);
|
|
105
|
+
storeTimes.remainingShifts += 1;
|
|
106
|
+
return slotDates;
|
|
107
|
+
}
|
|
108
|
+
if (prepTimeBehaviour === constants_1.PrepTimeBehaviour.FIRST_SHIFT && i !== 0) {
|
|
109
|
+
storeTimes.remainingShifts += 1;
|
|
110
|
+
return fixedSlots;
|
|
111
|
+
}
|
|
112
|
+
const allowZeroPrepTimeForMidnightShift = (0, date_1.isZeroPrepTimeForMidnightShift)({
|
|
113
|
+
prevDayBusinessHours: prevSelectedBusinessHours,
|
|
114
|
+
businessHour,
|
|
115
|
+
});
|
|
116
|
+
const prepTimeSlot = (0, date_fns_1.addMinutes)(prepTimeBehaviour === constants_1.PrepTimeBehaviour.ROLL_FROM_FIRST_SHIFT &&
|
|
117
|
+
!isPrevDayMidnightTransition &&
|
|
118
|
+
storeTimes.openingTime
|
|
119
|
+
? storeTimes.openingTime
|
|
120
|
+
: shiftStartDate, allowZeroPrepTimeForMidnightShift ? 0 : weekDayPrepTime);
|
|
121
|
+
isPrevDayMidnightTransition = allowZeroPrepTimeForMidnightShift;
|
|
122
|
+
if (prepTimeSlot > shiftEndDate) {
|
|
123
|
+
if (isMinutesCadence) {
|
|
124
|
+
shiftStartDateWithPrepTime = prepTimeSlot;
|
|
125
|
+
}
|
|
126
|
+
shiftStartDateWithPrepTime = prepTimeSlot;
|
|
127
|
+
return [];
|
|
128
|
+
}
|
|
129
|
+
if (prepTimeSlot < shiftStartDate) {
|
|
130
|
+
storeTimes.remainingShifts += 1;
|
|
131
|
+
return fixedSlots;
|
|
132
|
+
}
|
|
133
|
+
const slotDates = fixedSlots.filter((d) => (0, date_fns_1.isAfter)(d, prepTimeSlot));
|
|
134
|
+
slotDates.unshift(prepTimeSlot);
|
|
135
|
+
storeTimes.remainingShifts += 1;
|
|
136
|
+
shiftStartDateWithPrepTime = null; //reset the shift start date with prep time
|
|
137
|
+
return slotDates;
|
|
138
|
+
})
|
|
139
|
+
.sort(date_fns_1.compareAsc);
|
|
140
|
+
const currentDateMs = currentDate instanceof Date ? currentDate.getTime() : currentDate;
|
|
141
|
+
const availableSlots = slots.filter((d) => d.getTime() >= currentDateMs);
|
|
142
|
+
return {
|
|
143
|
+
date,
|
|
144
|
+
originalStoreOpeningTime: storeTimes.openingTime,
|
|
145
|
+
originalStoreClosingTime: storeTimes.closingTime,
|
|
146
|
+
remainingShifts: storeTimes.remainingShifts,
|
|
147
|
+
openingTime: slots[0],
|
|
148
|
+
closingTime: slots[slots.length - 1],
|
|
149
|
+
firstAvailableSlot: availableSlots[0],
|
|
150
|
+
slots: availableSlots,
|
|
151
|
+
};
|
|
152
|
+
})
|
|
153
|
+
.filter((a) => a.slots.length);
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=generate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../src/schedule/generate.ts"],"names":[],"mappings":";;AAqFA,4CA8LC;AAnRD,uCAOkB;AAClB,uDAA8D;AAE9D,4CAIsB;AAOtB,wCAIuB;AAiBvB,SAAS,wBAAwB,CAAC,EACjC,aAAa,GAAG,EAAE,EAClB,sBAAsB,GAAG,EAAE,EAC3B,IAAI,EACJ,QAAQ,EACR,oBAAoB,GACY;IAIhC,IAAI,CAAC,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;QACxB,OAAO,CAAC,EAAE,EAAE,IAAA,+BAAY,EAAC,IAAI,IAAI,EAAE,EAAE,IAAA,+BAAY,EAAC,QAAQ,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC;IACxE,CAAC;IAED,MAAM,SAAS,GAAG,IAAA,+BAAY,EAAC,IAAI,EAAE,IAAA,+BAAY,EAAC,QAAQ,CAAC,CAAC,CAAC;IAC7D,MAAM,SAAS,GAAG,SAAS,CAAC,SAAS,IAAI,CAAC,CAAC;IAE3C,MAAM,gBAAgB,GAAG,aAAa,EAAE,MAAM,CAAC,CAAC,EAAE,EAAE,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,CAAC;YACrB,WAAW,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;YACpC,kBAAkB,EAAE,cAAc,CAAC,CAAC,CAAC;YACrC,KAAK,EAAE,cAAc;SACrB,CAAC;IACH,CAAC,CAAC;SACD,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { GetSchedulesParams, GetSchedulesResult } from "../types";
|
|
2
|
+
export declare function getSchedules({ store, locations, cartItems, fulfillmentPreference, prepTimeSettings, currentLocation, isCateringFlow, platform, }: GetSchedulesParams): GetSchedulesResult;
|
|
3
|
+
//# sourceMappingURL=get-schedules.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-schedules.d.ts","sourceRoot":"","sources":["../../src/schedule/get-schedules.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAGX,kBAAkB,EAClB,kBAAkB,EAGlB,MAAM,UAAU,CAAC;AA6JlB,wBAAgB,YAAY,CAAC,EAC5B,KAAK,EACL,SAAS,EACT,SAAS,EACT,qBAAqB,EACrB,gBAAgB,EAChB,eAAe,EACf,cAAsB,EACtB,QAAuB,GACvB,EAAE,kBAAkB,GAAG,kBAAkB,CA4GzC"}
|