@open-tender/utils 0.0.9 → 0.0.11

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.
@@ -93,6 +93,7 @@ export declare const calcPrices: (item: Partial<CartItem>) => {
93
93
  signature?: string | undefined;
94
94
  isDefault?: number | boolean | undefined;
95
95
  isSoldOut?: boolean | undefined;
96
+ favorite?: import("@open-tender/types").Favorite | undefined;
96
97
  };
97
98
  export declare const makeOrderItem: (item: MenuItem, isEdit?: boolean, soldOut?: Array<SoldOut>, simpleItem?: Partial<CartItem>, hasPoints?: boolean) => {
98
99
  groups: {
@@ -172,6 +173,7 @@ export declare const makeOrderItem: (item: MenuItem, isEdit?: boolean, soldOut?:
172
173
  signature?: string | undefined;
173
174
  isDefault?: number | boolean | undefined;
174
175
  isSoldOut?: boolean | undefined;
176
+ favorite?: import("@open-tender/types").Favorite | undefined;
175
177
  };
176
178
  export declare const rehydrateOrderItem: (menuItem: MenuItem, simpleCartItem: Partial<CartItem>) => Partial<CartItem>;
177
179
  export declare const rehydrateCart: (menuItems: MenuItems, simpleCartItems: Array<Partial<CartItem>>) => {
@@ -216,6 +218,7 @@ export declare const rehydrateCart: (menuItems: MenuItems, simpleCartItems: Arra
216
218
  signature?: string | undefined;
217
219
  isDefault?: number | boolean | undefined;
218
220
  isSoldOut?: boolean | undefined;
221
+ favorite?: import("@open-tender/types").Favorite | undefined;
219
222
  }[];
220
223
  cartCounts: any;
221
224
  };
@@ -285,6 +288,7 @@ export declare const combineCarts: (cart: Cart, guestCart: Array<GuestItem>, car
285
288
  signature?: string | undefined;
286
289
  isDefault?: number | boolean | undefined;
287
290
  isSoldOut?: boolean | undefined;
291
+ favorite?: import("@open-tender/types").Favorite | undefined;
288
292
  } | {
289
293
  madeFor: string;
290
294
  cart_guest_id?: number | null | undefined;
@@ -321,12 +325,12 @@ export declare const decrementItem: (cart: Cart, index: number) => {
321
325
  };
322
326
  export declare const makeSimpleCart: (cart: OrderCart) => {
323
327
  id: number;
324
- quantity: number;
328
+ quantity: number | undefined;
325
329
  groups: {
326
330
  id: number | undefined;
327
331
  options: {
328
332
  id: number;
329
- quantity: number;
333
+ quantity: number | undefined;
330
334
  }[];
331
335
  }[] | undefined;
332
336
  made_for: string;
@@ -411,6 +415,7 @@ export declare const validateCart: (cart: OrderCart, categories: MenuCategories,
411
415
  signature?: string | undefined;
412
416
  isDefault?: number | boolean | undefined;
413
417
  isSoldOut?: boolean | undefined;
418
+ favorite?: import("@open-tender/types").Favorite | undefined;
414
419
  } | null)[];
415
420
  errors: {
416
421
  missingItems: OrderItem[];
@@ -672,7 +672,7 @@ const validateCart = (cart, categories, soldOut) => {
672
672
  const missingItems = [];
673
673
  const invalidItems = [];
674
674
  let newCart = cart.map(oldItem => {
675
- var _a, _b;
675
+ var _a, _b, _c, _d;
676
676
  const newItem = itemLookup[oldItem.id];
677
677
  if (!newItem || soldOut.includes(oldItem.id)) {
678
678
  missingItems.push(oldItem);
@@ -753,8 +753,8 @@ const validateCart = (cart, categories, soldOut) => {
753
753
  else {
754
754
  // check to see if this item's quantity is below the min or
755
755
  // above the max from the current menu
756
- if ((newItem.max && oldItem.quantity > newItem.max) ||
757
- (newItem.min && oldItem.quantity < newItem.min)) {
756
+ if ((newItem.max && ((_c = oldItem.quantity) !== null && _c !== void 0 ? _c : 0) > newItem.max) ||
757
+ (newItem.min && ((_d = oldItem.quantity) !== null && _d !== void 0 ? _d : 0) < newItem.min)) {
758
758
  invalidItems.push(oldItem);
759
759
  return null;
760
760
  }
@@ -34,7 +34,7 @@ export declare const cleanISOString: (date: Date) => ISOString;
34
34
  export declare const dateToIso: (date: Date, tz: Timezone | TimezonePython) => ISOString;
35
35
  export declare const adjustIso: (iso: ISOString, tz: Timezone | TimezonePython, adjustment: Duration) => ISOString;
36
36
  export declare const adjustZonedIso: (zonedIso: ISOString, tz: Timezone | TimezonePython, adjustment: Duration) => string;
37
- export declare const dateToZonedDateStr: (date: Date, tz: Timezone | TimezonePython, fmt?: string) => string;
37
+ export declare const dateToZonedDateStr: (date: Date, tz: Timezone | TimezonePython, fmt?: string, days?: number) => string;
38
38
  export declare const dateToZonedIso: (date: Date, tz: Timezone | TimezonePython) => string;
39
39
  export declare const currentLocalDate: (tz: Timezone | TimezonePython) => Date;
40
40
  export declare const currentLocalDateStr: (tz: Timezone | TimezonePython, fmt?: string) => string;
@@ -182,3 +182,4 @@ export declare const makeIntervals: (tz: Timezone | TimezonePython) => Array<Int
182
182
  orders: Array<Partial<Order>>;
183
183
  }>;
184
184
  export declare const formatTimeList: (dateStr: ISOString, tz: Timezone | TimezonePython, includeDate: boolean) => string;
185
+ export declare const makeCartDateStr: (requestedAt: string, tz: Timezone | TimezonePython, waitTime?: number | null) => string;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.time24ToDateStr = exports.time24ToDate = exports.minutesToDate = exports.setTimeForDate = exports.time24ToMinutes = exports.makeClosedWeekdays = exports.makeWeekdaysExcluded = exports.makeOppositeTimes = exports.makeEstimatedTime = exports.makeRequestedAtStr = exports.makeRequestedIso = exports.makeReadableDateStrFromIso = exports.isoToDateStrMinutes = exports.dateStrMinutesToIso = exports.formatTimeStr = exports.formatDateStr = exports.dateStrToZonedWeekday = exports.dateStrToZonedDate = exports.dateStrToDate = exports.currentLocalDateStr = exports.currentLocalDate = exports.dateToZonedIso = exports.dateToZonedDateStr = exports.adjustZonedIso = exports.adjustIso = exports.dateToIso = exports.cleanISOString = exports.isoToDateStr = exports.isoToDate = exports.tomorrowDate = exports.todayDate = exports.makeLocalDateStr = exports.zonedTimeToDateStr = exports.zonedTimeToDate = exports.makeLocalDate = exports.getUserTimezone = exports.fmtDate = exports.parseIsoToDate = exports.weekdayAndTimeToDate = exports.dateForWeekday = exports.timeLeft = exports.secondsToTime = exports.secondsLeft = exports.minutesLeft = exports.makeWeekday = exports.weekdayOptions = exports.weekdaysLower = exports.weekdaysUpper = exports.weekdays = exports.timezoneMap = void 0;
4
- exports.formatTimeList = exports.makeIntervals = exports.getLastInterval = exports.makeGroupOrderTimeStr = exports.formatTime = exports.makeGroupOrderTime = exports.getFirstTime = exports.adjustRequestedAt = exports.getNextInterval = exports.makeFirstTimes = exports.makeFirstRequestedAt = exports.makeFirstTime = exports.findOrderTime = exports.makeOrderTimes = exports.makeWeekdayIndices = exports.makeDatePickerDates = exports.makeDatePickerTimes = exports.makeDatepickerArgs = exports.makeTimes = exports.makeDates = exports.makeTimeIntervals = exports.getNextIntervalMinutes = exports.getMinutesfromDate = exports.minutesToDates = void 0;
4
+ exports.makeCartDateStr = exports.formatTimeList = exports.makeIntervals = exports.getLastInterval = exports.makeGroupOrderTimeStr = exports.formatTime = exports.makeGroupOrderTime = exports.getFirstTime = exports.adjustRequestedAt = exports.getNextInterval = exports.makeFirstTimes = exports.makeFirstRequestedAt = exports.makeFirstTime = exports.findOrderTime = exports.makeOrderTimes = exports.makeWeekdayIndices = exports.makeDatePickerDates = exports.makeDatePickerTimes = exports.makeDatepickerArgs = exports.makeTimes = exports.makeDates = exports.makeTimeIntervals = exports.getNextIntervalMinutes = exports.getMinutesfromDate = exports.minutesToDates = void 0;
5
5
  const date_fns_1 = require("date-fns");
6
6
  const date_fns_tz_1 = require("date-fns-tz");
7
7
  /* CONSTANTS */
@@ -136,8 +136,9 @@ const adjustZonedIso = (zonedIso, tz, adjustment) => {
136
136
  return dateStr;
137
137
  };
138
138
  exports.adjustZonedIso = adjustZonedIso;
139
- const dateToZonedDateStr = (date, tz, fmt = "yyyy-MM-dd'T'HH:mm:ssXXX") => {
140
- const zoned = (0, date_fns_tz_1.utcToZonedTime)(date, tz);
139
+ const dateToZonedDateStr = (date, tz, fmt = "yyyy-MM-dd'T'HH:mm:ssXXX", days = 0) => {
140
+ const adjustedDate = (0, date_fns_1.add)(date, { days: days });
141
+ const zoned = (0, date_fns_tz_1.utcToZonedTime)(adjustedDate, tz);
141
142
  return (0, date_fns_tz_1.format)(zoned, fmt, { timeZone: tz });
142
143
  };
143
144
  exports.dateToZonedDateStr = dateToZonedDateStr;
@@ -702,3 +703,21 @@ const formatTimeList = (dateStr, tz, includeDate) => {
702
703
  return (0, date_fns_tz_1.format)(date, fmt).replace('AM', 'am').replace('PM', 'pm');
703
704
  };
704
705
  exports.formatTimeList = formatTimeList;
706
+ const makeCartDateStr = (requestedAt, tz, waitTime) => {
707
+ if (requestedAt === 'asap')
708
+ return `Ready in about ${waitTime} minutes`;
709
+ const requestedDateStr = (0, exports.isoToDateStr)(requestedAt, tz, 'yyyy-MM-dd');
710
+ const now = new Date();
711
+ const today = (0, exports.dateToZonedDateStr)(now, tz, 'yyyy-MM-dd');
712
+ const tomorrow = (0, exports.dateToZonedDateStr)(now, tz, 'yyyy-MM-dd', 1);
713
+ const isToday = requestedDateStr === today;
714
+ const isTomorrow = requestedDateStr === tomorrow;
715
+ const timeStr = (0, exports.isoToDateStr)(requestedAt, tz, 'h:mma').toLowerCase();
716
+ const dateStr = (0, exports.isoToDateStr)(requestedAt, tz, 'EEE, MMM dd');
717
+ if (isToday)
718
+ return `Ready by ${timeStr}`;
719
+ if (isTomorrow)
720
+ return `Ready by ${timeStr} tomorrow`;
721
+ return `Ready by ${timeStr} on ${dateStr}`;
722
+ };
723
+ exports.makeCartDateStr = makeCartDateStr;
@@ -71,14 +71,14 @@ const makeNetOrder = (order, refunds) => {
71
71
  refunds.forEach(refund => {
72
72
  const lookup = (0, exports.makeRefundLookup)(refund);
73
73
  copy.cart.forEach((i) => {
74
- var _a, _b, _c, _d;
74
+ var _a, _b, _c, _d, _e;
75
75
  const item = lookup.cart[(_a = i.line_no) !== null && _a !== void 0 ? _a : 0];
76
76
  if (item) {
77
- i.quantity -= (_b = item.quantity) !== null && _b !== void 0 ? _b : 0;
78
- i.price_total = adjustAmount(i.price_total, (_c = item.price_total) !== null && _c !== void 0 ? _c : '0.0');
77
+ i.quantity = (_c = ((_b = i.quantity) !== null && _b !== void 0 ? _b : 0) - item.quantity) !== null && _c !== void 0 ? _c : 0;
78
+ i.price_total = adjustAmount(i.price_total, (_d = item.price_total) !== null && _d !== void 0 ? _d : '0.0');
79
79
  }
80
80
  if (i.quantity === 0) {
81
- (_d = i.groups) === null || _d === void 0 ? void 0 : _d.forEach(group => group.options.forEach(option => {
81
+ (_e = i.groups) === null || _e === void 0 ? void 0 : _e.forEach(group => group.options.forEach(option => {
82
82
  option.quantity = 0;
83
83
  option.price_total = '0.00';
84
84
  }));
@@ -93,6 +93,7 @@ export declare const calcPrices: (item: Partial<CartItem>) => {
93
93
  signature?: string | undefined;
94
94
  isDefault?: number | boolean | undefined;
95
95
  isSoldOut?: boolean | undefined;
96
+ favorite?: import("@open-tender/types").Favorite | undefined;
96
97
  };
97
98
  export declare const makeOrderItem: (item: MenuItem, isEdit?: boolean, soldOut?: Array<SoldOut>, simpleItem?: Partial<CartItem>, hasPoints?: boolean) => {
98
99
  groups: {
@@ -172,6 +173,7 @@ export declare const makeOrderItem: (item: MenuItem, isEdit?: boolean, soldOut?:
172
173
  signature?: string | undefined;
173
174
  isDefault?: number | boolean | undefined;
174
175
  isSoldOut?: boolean | undefined;
176
+ favorite?: import("@open-tender/types").Favorite | undefined;
175
177
  };
176
178
  export declare const rehydrateOrderItem: (menuItem: MenuItem, simpleCartItem: Partial<CartItem>) => Partial<CartItem>;
177
179
  export declare const rehydrateCart: (menuItems: MenuItems, simpleCartItems: Array<Partial<CartItem>>) => {
@@ -216,6 +218,7 @@ export declare const rehydrateCart: (menuItems: MenuItems, simpleCartItems: Arra
216
218
  signature?: string | undefined;
217
219
  isDefault?: number | boolean | undefined;
218
220
  isSoldOut?: boolean | undefined;
221
+ favorite?: import("@open-tender/types").Favorite | undefined;
219
222
  }[];
220
223
  cartCounts: any;
221
224
  };
@@ -285,6 +288,7 @@ export declare const combineCarts: (cart: Cart, guestCart: Array<GuestItem>, car
285
288
  signature?: string | undefined;
286
289
  isDefault?: number | boolean | undefined;
287
290
  isSoldOut?: boolean | undefined;
291
+ favorite?: import("@open-tender/types").Favorite | undefined;
288
292
  } | {
289
293
  madeFor: string;
290
294
  cart_guest_id?: number | null | undefined;
@@ -321,12 +325,12 @@ export declare const decrementItem: (cart: Cart, index: number) => {
321
325
  };
322
326
  export declare const makeSimpleCart: (cart: OrderCart) => {
323
327
  id: number;
324
- quantity: number;
328
+ quantity: number | undefined;
325
329
  groups: {
326
330
  id: number | undefined;
327
331
  options: {
328
332
  id: number;
329
- quantity: number;
333
+ quantity: number | undefined;
330
334
  }[];
331
335
  }[] | undefined;
332
336
  made_for: string;
@@ -411,6 +415,7 @@ export declare const validateCart: (cart: OrderCart, categories: MenuCategories,
411
415
  signature?: string | undefined;
412
416
  isDefault?: number | boolean | undefined;
413
417
  isSoldOut?: boolean | undefined;
418
+ favorite?: import("@open-tender/types").Favorite | undefined;
414
419
  } | null)[];
415
420
  errors: {
416
421
  missingItems: OrderItem[];
@@ -633,7 +633,7 @@ export const validateCart = (cart, categories, soldOut) => {
633
633
  const missingItems = [];
634
634
  const invalidItems = [];
635
635
  let newCart = cart.map(oldItem => {
636
- var _a, _b;
636
+ var _a, _b, _c, _d;
637
637
  const newItem = itemLookup[oldItem.id];
638
638
  if (!newItem || soldOut.includes(oldItem.id)) {
639
639
  missingItems.push(oldItem);
@@ -714,8 +714,8 @@ export const validateCart = (cart, categories, soldOut) => {
714
714
  else {
715
715
  // check to see if this item's quantity is below the min or
716
716
  // above the max from the current menu
717
- if ((newItem.max && oldItem.quantity > newItem.max) ||
718
- (newItem.min && oldItem.quantity < newItem.min)) {
717
+ if ((newItem.max && ((_c = oldItem.quantity) !== null && _c !== void 0 ? _c : 0) > newItem.max) ||
718
+ (newItem.min && ((_d = oldItem.quantity) !== null && _d !== void 0 ? _d : 0) < newItem.min)) {
719
719
  invalidItems.push(oldItem);
720
720
  return null;
721
721
  }
@@ -34,7 +34,7 @@ export declare const cleanISOString: (date: Date) => ISOString;
34
34
  export declare const dateToIso: (date: Date, tz: Timezone | TimezonePython) => ISOString;
35
35
  export declare const adjustIso: (iso: ISOString, tz: Timezone | TimezonePython, adjustment: Duration) => ISOString;
36
36
  export declare const adjustZonedIso: (zonedIso: ISOString, tz: Timezone | TimezonePython, adjustment: Duration) => string;
37
- export declare const dateToZonedDateStr: (date: Date, tz: Timezone | TimezonePython, fmt?: string) => string;
37
+ export declare const dateToZonedDateStr: (date: Date, tz: Timezone | TimezonePython, fmt?: string, days?: number) => string;
38
38
  export declare const dateToZonedIso: (date: Date, tz: Timezone | TimezonePython) => string;
39
39
  export declare const currentLocalDate: (tz: Timezone | TimezonePython) => Date;
40
40
  export declare const currentLocalDateStr: (tz: Timezone | TimezonePython, fmt?: string) => string;
@@ -182,3 +182,4 @@ export declare const makeIntervals: (tz: Timezone | TimezonePython) => Array<Int
182
182
  orders: Array<Partial<Order>>;
183
183
  }>;
184
184
  export declare const formatTimeList: (dateStr: ISOString, tz: Timezone | TimezonePython, includeDate: boolean) => string;
185
+ export declare const makeCartDateStr: (requestedAt: string, tz: Timezone | TimezonePython, waitTime?: number | null) => string;
@@ -110,8 +110,9 @@ export const adjustZonedIso = (zonedIso, tz, adjustment) => {
110
110
  const dateStr = format(zoned, "yyyy-MM-dd'T'HH:mm:ssXXX", { timeZone: tz });
111
111
  return dateStr;
112
112
  };
113
- export const dateToZonedDateStr = (date, tz, fmt = "yyyy-MM-dd'T'HH:mm:ssXXX") => {
114
- const zoned = utcToZonedTime(date, tz);
113
+ export const dateToZonedDateStr = (date, tz, fmt = "yyyy-MM-dd'T'HH:mm:ssXXX", days = 0) => {
114
+ const adjustedDate = add(date, { days: days });
115
+ const zoned = utcToZonedTime(adjustedDate, tz);
115
116
  return format(zoned, fmt, { timeZone: tz });
116
117
  };
117
118
  export const dateToZonedIso = (date, tz) => {
@@ -629,3 +630,20 @@ export const formatTimeList = (dateStr, tz, includeDate) => {
629
630
  const fmt = includeDate ? 'MMM d, h:mma' : 'h:mma';
630
631
  return format(date, fmt).replace('AM', 'am').replace('PM', 'pm');
631
632
  };
633
+ export const makeCartDateStr = (requestedAt, tz, waitTime) => {
634
+ if (requestedAt === 'asap')
635
+ return `Ready in about ${waitTime} minutes`;
636
+ const requestedDateStr = isoToDateStr(requestedAt, tz, 'yyyy-MM-dd');
637
+ const now = new Date();
638
+ const today = dateToZonedDateStr(now, tz, 'yyyy-MM-dd');
639
+ const tomorrow = dateToZonedDateStr(now, tz, 'yyyy-MM-dd', 1);
640
+ const isToday = requestedDateStr === today;
641
+ const isTomorrow = requestedDateStr === tomorrow;
642
+ const timeStr = isoToDateStr(requestedAt, tz, 'h:mma').toLowerCase();
643
+ const dateStr = isoToDateStr(requestedAt, tz, 'EEE, MMM dd');
644
+ if (isToday)
645
+ return `Ready by ${timeStr}`;
646
+ if (isTomorrow)
647
+ return `Ready by ${timeStr} tomorrow`;
648
+ return `Ready by ${timeStr} on ${dateStr}`;
649
+ };
@@ -64,14 +64,14 @@ export const makeNetOrder = (order, refunds) => {
64
64
  refunds.forEach(refund => {
65
65
  const lookup = makeRefundLookup(refund);
66
66
  copy.cart.forEach((i) => {
67
- var _a, _b, _c, _d;
67
+ var _a, _b, _c, _d, _e;
68
68
  const item = lookup.cart[(_a = i.line_no) !== null && _a !== void 0 ? _a : 0];
69
69
  if (item) {
70
- i.quantity -= (_b = item.quantity) !== null && _b !== void 0 ? _b : 0;
71
- i.price_total = adjustAmount(i.price_total, (_c = item.price_total) !== null && _c !== void 0 ? _c : '0.0');
70
+ i.quantity = (_c = ((_b = i.quantity) !== null && _b !== void 0 ? _b : 0) - item.quantity) !== null && _c !== void 0 ? _c : 0;
71
+ i.price_total = adjustAmount(i.price_total, (_d = item.price_total) !== null && _d !== void 0 ? _d : '0.0');
72
72
  }
73
73
  if (i.quantity === 0) {
74
- (_d = i.groups) === null || _d === void 0 ? void 0 : _d.forEach(group => group.options.forEach(option => {
74
+ (_e = i.groups) === null || _e === void 0 ? void 0 : _e.forEach(group => group.options.forEach(option => {
75
75
  option.quantity = 0;
76
76
  option.price_total = '0.00';
77
77
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "A library of utils for use with Open Tender applications that utilize our cloud-based Order API.",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -57,7 +57,7 @@
57
57
  "react": "^18.2.0"
58
58
  },
59
59
  "dependencies": {
60
- "@open-tender/types": "^0.0.46",
60
+ "@open-tender/types": "^0.0.62",
61
61
  "date-fns": "^2.29.3",
62
62
  "date-fns-tz": "^1.3.7",
63
63
  "react-native-responsive-screen": "^1.4.2",