@open-tender/utils 0.0.7 → 0.0.9

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.
@@ -1,4 +1,4 @@
1
- import { UnpreparedOrderData, Money, Order, Tender, CheckoutConfig, OrderCart, SoldOut, MenuCategories, Address, MenuItem, CartItem, ServiceType, OrderType, CustomerRevenueCenter, OrderItem, OrderItemImage, Cart, Favorites, Orders, CartItemGroups, Customer, MenuItems, CartItemOption, SimpleCartItem, GuestItem, CartOwner, GuestData } from '@open-tender/types';
1
+ import { UnpreparedOrderData, Money, Order, Tender, CheckoutConfig, OrderCart, SoldOut, MenuCategories, Address, MenuItem, CartItem, ServiceType, OrderType, CustomerRevenueCenter, OrderItem, OrderItemImage, Cart, Favorites, Orders, CartItemGroups, Customer, MenuItems, CartItemOption, GuestItem, CartOwner, GuestData } from '@open-tender/types';
2
2
  export declare const displayPrice: (price: string) => string;
3
3
  export declare const makeDisplayPrice: (item: MenuItem) => string | null;
4
4
  export declare const addCommas: (x: number, d: number) => string;
@@ -94,7 +94,7 @@ export declare const calcPrices: (item: Partial<CartItem>) => {
94
94
  isDefault?: number | boolean | undefined;
95
95
  isSoldOut?: boolean | undefined;
96
96
  };
97
- export declare const makeOrderItem: (item: MenuItem, isEdit?: boolean, soldOut?: Array<SoldOut>, simpleItem?: SimpleCartItem, hasPoints?: boolean) => {
97
+ export declare const makeOrderItem: (item: MenuItem, isEdit?: boolean, soldOut?: Array<SoldOut>, simpleItem?: Partial<CartItem>, hasPoints?: boolean) => {
98
98
  groups: {
99
99
  quantity: number;
100
100
  options: {
@@ -173,8 +173,8 @@ export declare const makeOrderItem: (item: MenuItem, isEdit?: boolean, soldOut?:
173
173
  isDefault?: number | boolean | undefined;
174
174
  isSoldOut?: boolean | undefined;
175
175
  };
176
- export declare const rehydrateOrderItem: (menuItem: MenuItem, simpleCartItem: SimpleCartItem) => Partial<CartItem>;
177
- export declare const rehydrateCart: (menuItems: MenuItems, simpleCartItems: Array<SimpleCartItem>) => {
176
+ export declare const rehydrateOrderItem: (menuItem: MenuItem, simpleCartItem: Partial<CartItem>) => Partial<CartItem>;
177
+ export declare const rehydrateCart: (menuItems: MenuItems, simpleCartItems: Array<Partial<CartItem>>) => {
178
178
  cart: {
179
179
  index: number;
180
180
  id?: number | undefined;
@@ -219,7 +219,7 @@ export declare const rehydrateCart: (menuItems: MenuItems, simpleCartItems: Arra
219
219
  }[];
220
220
  cartCounts: any;
221
221
  };
222
- export declare const rehydrateCheckoutForm: (order: Order) => {
222
+ export declare const rehydrateCheckoutForm: (order: Partial<Order>) => {
223
223
  details: {
224
224
  cart_id: number | null | undefined;
225
225
  eating_utensils: boolean | undefined;
@@ -232,14 +232,14 @@ export declare const rehydrateCheckoutForm: (order: Order) => {
232
232
  address: Partial<Address>;
233
233
  surcharges: {
234
234
  id?: number | undefined;
235
- }[];
235
+ }[] | undefined;
236
236
  discounts: {
237
237
  id: number;
238
238
  ext_id?: string | null | undefined;
239
- }[];
240
- promoCodes: string[];
241
- tenders: import("@open-tender/types").OrderTender[];
242
- tip: `${number}.${number}`;
239
+ }[] | undefined;
240
+ promoCodes: string[] | undefined;
241
+ tenders: import("@open-tender/types").OrderTender[] | undefined;
242
+ tip: number | `${number}.${number}`;
243
243
  };
244
244
  export declare const makeGuestLookup: (cartGuests: Array<GuestItem>) => Partial<GuestItem & {
245
245
  [key: number]: GuestData;
@@ -357,23 +357,17 @@ const rehydrateAddress = (address) => {
357
357
  };
358
358
  };
359
359
  const rehydrateSurcharges = (surcharges) => {
360
- return surcharges
361
- .filter(i => i.is_optional)
362
- .map(i => ({ id: i.surcharge_id }));
360
+ return surcharges === null || surcharges === void 0 ? void 0 : surcharges.filter(i => i.is_optional).map(i => ({ id: i.surcharge_id }));
363
361
  };
364
362
  const rehydrateDiscounts = (discounts) => {
365
- return discounts
366
- .filter(i => !i.is_promo_code)
367
- .map(i => ({ id: i.discount_id || i.id, ext_id: i.ext_id }));
363
+ return discounts === null || discounts === void 0 ? void 0 : discounts.filter(i => !i.is_promo_code).map(i => ({ id: i.discount_id || i.id, ext_id: i.ext_id }));
368
364
  };
369
365
  const rehydratePromoCodes = (discounts) => {
370
- return discounts.filter(i => i.is_promo_code).map(i => i.name);
366
+ return discounts === null || discounts === void 0 ? void 0 : discounts.filter(i => i.is_promo_code).map(i => i.name);
371
367
  };
372
368
  const rehydrateTenders = (tenders) => {
373
369
  // const giftCards = tenders.filter((i) => i.tender_type === 'GIFT_CARD')
374
- const other = tenders
375
- // .filter((i) => i.tender_type !== 'GIFT_CARD')
376
- .map(i => {
370
+ const other = tenders === null || tenders === void 0 ? void 0 : tenders.map(i => {
377
371
  if (i.tender_type === 'CREDIT') {
378
372
  return Object.assign(Object.assign({}, i), i.credit_card);
379
373
  }
@@ -387,15 +381,16 @@ const rehydrateTenders = (tenders) => {
387
381
  return other;
388
382
  };
389
383
  const rehydrateCheckoutForm = (order) => {
384
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
390
385
  const form = {
391
- details: rehydrateDetails(order.details),
392
- customer: rehydrateCustomer(order.customer),
393
- address: rehydrateAddress(order.address),
394
- surcharges: rehydrateSurcharges(order.surcharges),
395
- discounts: rehydrateDiscounts(order.discounts),
396
- promoCodes: rehydratePromoCodes(order.discounts),
397
- tenders: rehydrateTenders(order.tenders),
398
- tip: order.totals.tip
386
+ details: rehydrateDetails((_a = order.details) !== null && _a !== void 0 ? _a : null),
387
+ customer: rehydrateCustomer((_b = order.customer) !== null && _b !== void 0 ? _b : null),
388
+ address: rehydrateAddress((_c = order.address) !== null && _c !== void 0 ? _c : null),
389
+ surcharges: rehydrateSurcharges((_d = order.surcharges) !== null && _d !== void 0 ? _d : null),
390
+ discounts: rehydrateDiscounts((_e = order.discounts) !== null && _e !== void 0 ? _e : null),
391
+ promoCodes: rehydratePromoCodes((_f = order.discounts) !== null && _f !== void 0 ? _f : null),
392
+ tenders: rehydrateTenders((_g = order.tenders) !== null && _g !== void 0 ? _g : null),
393
+ tip: (_j = (_h = order.totals) === null || _h === void 0 ? void 0 : _h.tip) !== null && _j !== void 0 ? _j : 0
399
394
  };
400
395
  return form;
401
396
  };
@@ -659,11 +654,14 @@ const makeItemLookup = (categories, itemIds) => {
659
654
  const makeGroupsLookup = (item) => {
660
655
  var _a;
661
656
  return (_a = item.groups) === null || _a === void 0 ? void 0 : _a.reduce((grpObj, i) => {
662
- const options = i.options.reduce((optObj, o) => {
657
+ var _a;
658
+ const options = (_a = i.options) === null || _a === void 0 ? void 0 : _a.reduce((optObj, o) => {
663
659
  optObj[o.id] = o;
664
660
  return optObj;
665
661
  }, {});
666
- grpObj[i.id] = Object.assign(Object.assign({}, i), { options });
662
+ if (i.id) {
663
+ grpObj[i.id] = Object.assign(Object.assign({}, i), { options });
664
+ }
667
665
  return grpObj;
668
666
  }, {});
669
667
  };
@@ -166,7 +166,7 @@ export declare const makeWeekdayIndices: (weekdays: Array<Weekday>) => Array<num
166
166
  export declare const makeOrderTimes: (orderTimes: Array<OrderTime> | null, tz: Timezone | TimezonePython) => Array<OrderTime>;
167
167
  export declare const findOrderTime: (orderTimes: Array<OrderTime> | null, tz: Timezone | TimezonePython, requestedAt: ISOString | string | null) => OrderTime;
168
168
  export declare const makeFirstTime: (settings: Partial<CustomerRevenueCenterSettings | CustomerRevenueCenter>, tz: Timezone | TimezonePython, serviceType: ServiceType, requestedAt: ISOString | string | null) => ISOString | string | null | undefined;
169
- export declare const makeFirstRequestedAt: (revenueCenter: Partial<CustomerRevenueCenter>, serviceType: ServiceType, requestedAt: ISOString | string | null) => string | null | undefined;
169
+ export declare const makeFirstRequestedAt: (revenueCenter: Partial<CustomerRevenueCenter>, serviceType: ServiceType, requestedAt?: ISOString | string | null) => string | null | undefined;
170
170
  export declare const makeFirstTimes: (revenueCenter: CustomerRevenueCenter, serviceType: ServiceType, requestedAt: ISOString) => ({
171
171
  serviceType: ServiceType;
172
172
  requestedAt: ISOString | string;
@@ -1,4 +1,4 @@
1
- import { UnpreparedOrderData, Money, Order, Tender, CheckoutConfig, OrderCart, SoldOut, MenuCategories, Address, MenuItem, CartItem, ServiceType, OrderType, CustomerRevenueCenter, OrderItem, OrderItemImage, Cart, Favorites, Orders, CartItemGroups, Customer, MenuItems, CartItemOption, SimpleCartItem, GuestItem, CartOwner, GuestData } from '@open-tender/types';
1
+ import { UnpreparedOrderData, Money, Order, Tender, CheckoutConfig, OrderCart, SoldOut, MenuCategories, Address, MenuItem, CartItem, ServiceType, OrderType, CustomerRevenueCenter, OrderItem, OrderItemImage, Cart, Favorites, Orders, CartItemGroups, Customer, MenuItems, CartItemOption, GuestItem, CartOwner, GuestData } from '@open-tender/types';
2
2
  export declare const displayPrice: (price: string) => string;
3
3
  export declare const makeDisplayPrice: (item: MenuItem) => string | null;
4
4
  export declare const addCommas: (x: number, d: number) => string;
@@ -94,7 +94,7 @@ export declare const calcPrices: (item: Partial<CartItem>) => {
94
94
  isDefault?: number | boolean | undefined;
95
95
  isSoldOut?: boolean | undefined;
96
96
  };
97
- export declare const makeOrderItem: (item: MenuItem, isEdit?: boolean, soldOut?: Array<SoldOut>, simpleItem?: SimpleCartItem, hasPoints?: boolean) => {
97
+ export declare const makeOrderItem: (item: MenuItem, isEdit?: boolean, soldOut?: Array<SoldOut>, simpleItem?: Partial<CartItem>, hasPoints?: boolean) => {
98
98
  groups: {
99
99
  quantity: number;
100
100
  options: {
@@ -173,8 +173,8 @@ export declare const makeOrderItem: (item: MenuItem, isEdit?: boolean, soldOut?:
173
173
  isDefault?: number | boolean | undefined;
174
174
  isSoldOut?: boolean | undefined;
175
175
  };
176
- export declare const rehydrateOrderItem: (menuItem: MenuItem, simpleCartItem: SimpleCartItem) => Partial<CartItem>;
177
- export declare const rehydrateCart: (menuItems: MenuItems, simpleCartItems: Array<SimpleCartItem>) => {
176
+ export declare const rehydrateOrderItem: (menuItem: MenuItem, simpleCartItem: Partial<CartItem>) => Partial<CartItem>;
177
+ export declare const rehydrateCart: (menuItems: MenuItems, simpleCartItems: Array<Partial<CartItem>>) => {
178
178
  cart: {
179
179
  index: number;
180
180
  id?: number | undefined;
@@ -219,7 +219,7 @@ export declare const rehydrateCart: (menuItems: MenuItems, simpleCartItems: Arra
219
219
  }[];
220
220
  cartCounts: any;
221
221
  };
222
- export declare const rehydrateCheckoutForm: (order: Order) => {
222
+ export declare const rehydrateCheckoutForm: (order: Partial<Order>) => {
223
223
  details: {
224
224
  cart_id: number | null | undefined;
225
225
  eating_utensils: boolean | undefined;
@@ -232,14 +232,14 @@ export declare const rehydrateCheckoutForm: (order: Order) => {
232
232
  address: Partial<Address>;
233
233
  surcharges: {
234
234
  id?: number | undefined;
235
- }[];
235
+ }[] | undefined;
236
236
  discounts: {
237
237
  id: number;
238
238
  ext_id?: string | null | undefined;
239
- }[];
240
- promoCodes: string[];
241
- tenders: import("@open-tender/types").OrderTender[];
242
- tip: `${number}.${number}`;
239
+ }[] | undefined;
240
+ promoCodes: string[] | undefined;
241
+ tenders: import("@open-tender/types").OrderTender[] | undefined;
242
+ tip: number | `${number}.${number}`;
243
243
  };
244
244
  export declare const makeGuestLookup: (cartGuests: Array<GuestItem>) => Partial<GuestItem & {
245
245
  [key: number]: GuestData;
@@ -337,23 +337,17 @@ const rehydrateAddress = (address) => {
337
337
  };
338
338
  };
339
339
  const rehydrateSurcharges = (surcharges) => {
340
- return surcharges
341
- .filter(i => i.is_optional)
342
- .map(i => ({ id: i.surcharge_id }));
340
+ return surcharges === null || surcharges === void 0 ? void 0 : surcharges.filter(i => i.is_optional).map(i => ({ id: i.surcharge_id }));
343
341
  };
344
342
  const rehydrateDiscounts = (discounts) => {
345
- return discounts
346
- .filter(i => !i.is_promo_code)
347
- .map(i => ({ id: i.discount_id || i.id, ext_id: i.ext_id }));
343
+ return discounts === null || discounts === void 0 ? void 0 : discounts.filter(i => !i.is_promo_code).map(i => ({ id: i.discount_id || i.id, ext_id: i.ext_id }));
348
344
  };
349
345
  const rehydratePromoCodes = (discounts) => {
350
- return discounts.filter(i => i.is_promo_code).map(i => i.name);
346
+ return discounts === null || discounts === void 0 ? void 0 : discounts.filter(i => i.is_promo_code).map(i => i.name);
351
347
  };
352
348
  const rehydrateTenders = (tenders) => {
353
349
  // const giftCards = tenders.filter((i) => i.tender_type === 'GIFT_CARD')
354
- const other = tenders
355
- // .filter((i) => i.tender_type !== 'GIFT_CARD')
356
- .map(i => {
350
+ const other = tenders === null || tenders === void 0 ? void 0 : tenders.map(i => {
357
351
  if (i.tender_type === 'CREDIT') {
358
352
  return Object.assign(Object.assign({}, i), i.credit_card);
359
353
  }
@@ -367,15 +361,16 @@ const rehydrateTenders = (tenders) => {
367
361
  return other;
368
362
  };
369
363
  export const rehydrateCheckoutForm = (order) => {
364
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
370
365
  const form = {
371
- details: rehydrateDetails(order.details),
372
- customer: rehydrateCustomer(order.customer),
373
- address: rehydrateAddress(order.address),
374
- surcharges: rehydrateSurcharges(order.surcharges),
375
- discounts: rehydrateDiscounts(order.discounts),
376
- promoCodes: rehydratePromoCodes(order.discounts),
377
- tenders: rehydrateTenders(order.tenders),
378
- tip: order.totals.tip
366
+ details: rehydrateDetails((_a = order.details) !== null && _a !== void 0 ? _a : null),
367
+ customer: rehydrateCustomer((_b = order.customer) !== null && _b !== void 0 ? _b : null),
368
+ address: rehydrateAddress((_c = order.address) !== null && _c !== void 0 ? _c : null),
369
+ surcharges: rehydrateSurcharges((_d = order.surcharges) !== null && _d !== void 0 ? _d : null),
370
+ discounts: rehydrateDiscounts((_e = order.discounts) !== null && _e !== void 0 ? _e : null),
371
+ promoCodes: rehydratePromoCodes((_f = order.discounts) !== null && _f !== void 0 ? _f : null),
372
+ tenders: rehydrateTenders((_g = order.tenders) !== null && _g !== void 0 ? _g : null),
373
+ tip: (_j = (_h = order.totals) === null || _h === void 0 ? void 0 : _h.tip) !== null && _j !== void 0 ? _j : 0
379
374
  };
380
375
  return form;
381
376
  };
@@ -620,11 +615,14 @@ const makeItemLookup = (categories, itemIds) => {
620
615
  const makeGroupsLookup = (item) => {
621
616
  var _a;
622
617
  return (_a = item.groups) === null || _a === void 0 ? void 0 : _a.reduce((grpObj, i) => {
623
- const options = i.options.reduce((optObj, o) => {
618
+ var _a;
619
+ const options = (_a = i.options) === null || _a === void 0 ? void 0 : _a.reduce((optObj, o) => {
624
620
  optObj[o.id] = o;
625
621
  return optObj;
626
622
  }, {});
627
- grpObj[i.id] = Object.assign(Object.assign({}, i), { options });
623
+ if (i.id) {
624
+ grpObj[i.id] = Object.assign(Object.assign({}, i), { options });
625
+ }
628
626
  return grpObj;
629
627
  }, {});
630
628
  };
@@ -166,7 +166,7 @@ export declare const makeWeekdayIndices: (weekdays: Array<Weekday>) => Array<num
166
166
  export declare const makeOrderTimes: (orderTimes: Array<OrderTime> | null, tz: Timezone | TimezonePython) => Array<OrderTime>;
167
167
  export declare const findOrderTime: (orderTimes: Array<OrderTime> | null, tz: Timezone | TimezonePython, requestedAt: ISOString | string | null) => OrderTime;
168
168
  export declare const makeFirstTime: (settings: Partial<CustomerRevenueCenterSettings | CustomerRevenueCenter>, tz: Timezone | TimezonePython, serviceType: ServiceType, requestedAt: ISOString | string | null) => ISOString | string | null | undefined;
169
- export declare const makeFirstRequestedAt: (revenueCenter: Partial<CustomerRevenueCenter>, serviceType: ServiceType, requestedAt: ISOString | string | null) => string | null | undefined;
169
+ export declare const makeFirstRequestedAt: (revenueCenter: Partial<CustomerRevenueCenter>, serviceType: ServiceType, requestedAt?: ISOString | string | null) => string | null | undefined;
170
170
  export declare const makeFirstTimes: (revenueCenter: CustomerRevenueCenter, serviceType: ServiceType, requestedAt: ISOString) => ({
171
171
  serviceType: ServiceType;
172
172
  requestedAt: ISOString | string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
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",