@swift-food-services/catering-widget 0.1.0-beta.13 → 0.1.0-beta.15

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.cjs CHANGED
@@ -6169,18 +6169,19 @@ function groupItemsByRestaurant(orderItems) {
6169
6169
  }
6170
6170
  function createPricingApi(client) {
6171
6171
  return {
6172
- calculateCateringPricing: (orderItems, promoCodes, deliveryLocation) => client.requestJson(
6172
+ calculateCateringPricing: (orderItems, promoCodes, deliveryLocation, userId) => client.requestJson(
6173
6173
  "/pricing/catering-verify-cart",
6174
6174
  {
6175
6175
  method: "POST",
6176
6176
  body: JSON.stringify({
6177
6177
  orderItems,
6178
6178
  promoCodes,
6179
- ...deliveryLocation && { deliveryLocation }
6179
+ ...deliveryLocation && { deliveryLocation },
6180
+ ...userId && { userId }
6180
6181
  })
6181
6182
  }
6182
6183
  ),
6183
- calculateCateringPricingWithMealSessions: async (mealSessions, promoCodes, deliveryLocation) => {
6184
+ calculateCateringPricingWithMealSessions: async (mealSessions, promoCodes, deliveryLocation, userId) => {
6184
6185
  const mealSessionRequests = mealSessions.filter((s) => s.orderItems.length > 0).map((session, index) => ({
6185
6186
  sessionName: session.sessionName || `Session ${index + 1}`,
6186
6187
  sessionDate: session.sessionDate,
@@ -6197,7 +6198,8 @@ function createPricingApi(client) {
6197
6198
  body: JSON.stringify({
6198
6199
  mealSessions: mealSessionRequests,
6199
6200
  promoCodes,
6200
- ...deliveryLocation && { deliveryLocation }
6201
+ ...deliveryLocation && { deliveryLocation },
6202
+ ...userId && { userId }
6201
6203
  })
6202
6204
  }
6203
6205
  );
@@ -6212,13 +6214,13 @@ function createPricingApi(client) {
6212
6214
  };
6213
6215
  }
6214
6216
  },
6215
- validatePromoCode: async (promoCode, orderItems) => {
6217
+ validatePromoCode: async (promoCode, orderItems, userId) => {
6216
6218
  try {
6217
6219
  return await client.requestJson(
6218
6220
  "/promotions/validate-catering",
6219
6221
  {
6220
6222
  method: "POST",
6221
- body: JSON.stringify({ code: promoCode, orderItems })
6223
+ body: JSON.stringify({ code: promoCode, orderItems, ...userId && { userId } })
6222
6224
  }
6223
6225
  );
6224
6226
  } catch {
@@ -6228,11 +6230,11 @@ function createPricingApi(client) {
6228
6230
  };
6229
6231
  }
6230
6232
  },
6231
- validatePromoCodeWithMealSessions: async function(promoCode, mealSessions) {
6233
+ validatePromoCodeWithMealSessions: async function(promoCode, mealSessions, userId) {
6232
6234
  const allOrderItems = mealSessions.flatMap(
6233
6235
  (s) => groupItemsByRestaurant(s.orderItems)
6234
6236
  );
6235
- return this.validatePromoCode(promoCode, allOrderItems);
6237
+ return this.validatePromoCode(promoCode, allOrderItems, userId);
6236
6238
  }
6237
6239
  };
6238
6240
  }
@@ -8600,7 +8602,7 @@ async function fetchImageAsBase64(url) {
8600
8602
  return null;
8601
8603
  }
8602
8604
  }
8603
- async function transformLocalSessionsToPdfData(mealSessions, showPrices = true, deliveryFee, promoDiscount, appliedPromotions) {
8605
+ async function transformLocalSessionsToPdfData(mealSessions, showPrices = true, deliveryFee, promoDiscount, appliedPromotions, isDeliveryEstimated) {
8604
8606
  const sessions = [];
8605
8607
  let grandTotal = 0;
8606
8608
  const sortedSessions = [...mealSessions].filter((s) => s.orderItems.length > 0).sort((a, b) => {
@@ -8697,7 +8699,8 @@ async function transformLocalSessionsToPdfData(mealSessions, showPrices = true,
8697
8699
  totalPrice: totalWithDelivery - (promoDiscount || 0) - totalPromotionDiscount,
8698
8700
  promoDiscount: promoDiscount || void 0,
8699
8701
  appliedPromotions: appliedPromotions?.length ? appliedPromotions : void 0,
8700
- logoUrl: "/Logo_Circle.png"
8702
+ logoUrl: "/Logo_Circle.png",
8703
+ isDeliveryEstimated
8701
8704
  };
8702
8705
  }
8703
8706
 
@@ -9270,7 +9273,8 @@ var SessionPage = ({
9270
9273
  deliveryCharge,
9271
9274
  totalPrice,
9272
9275
  promoDiscount,
9273
- appliedPromotions
9276
+ appliedPromotions,
9277
+ isDeliveryEstimated
9274
9278
  }) => {
9275
9279
  const totalCatering = allSessions.reduce(
9276
9280
  (sum, s) => sum + (s.subtotal || 0),
@@ -9297,11 +9301,7 @@ var SessionPage = ({
9297
9301
  "Subtotal: \xA3",
9298
9302
  session.subtotal.toFixed(2)
9299
9303
  ] }),
9300
- /* @__PURE__ */ jsxRuntime.jsxs(renderer.Text, { style: styles.deliveryFeeText, children: [
9301
- "Delivery Fee:",
9302
- " ",
9303
- session.deliveryFee !== void 0 ? `\xA3${session.deliveryFee.toFixed(2)}` : "TBC"
9304
- ] })
9304
+ /* @__PURE__ */ jsxRuntime.jsx(renderer.Text, { style: styles.deliveryFeeText, children: session.deliveryFee !== void 0 ? isDeliveryEstimated ? `Estimated Delivery Fee (min): \xA3${session.deliveryFee.toFixed(2)}` : `Delivery Fee: \xA3${session.deliveryFee.toFixed(2)}` : "Delivery Fee: TBC" })
9305
9305
  ] }) }),
9306
9306
  isLastSession && showPrices && /* @__PURE__ */ jsxRuntime.jsxs(renderer.View, { style: styles.totalsContainer, wrap: false, children: [
9307
9307
  /* @__PURE__ */ jsxRuntime.jsxs(renderer.View, { style: styles.totalsBreakdown, children: [
@@ -9351,12 +9351,12 @@ var SessionPage = ({
9351
9351
  )
9352
9352
  ] }),
9353
9353
  /* @__PURE__ */ jsxRuntime.jsxs(renderer.View, { style: styles.totalsBreakdownRow, children: [
9354
- /* @__PURE__ */ jsxRuntime.jsx(renderer.Text, { style: styles.totalsBreakdownLabel, children: "Logistics / Delivery" }),
9355
- /* @__PURE__ */ jsxRuntime.jsx(renderer.Text, { style: styles.totalsBreakdownValueItalic, children: deliveryCharge !== void 0 ? `\xA3${deliveryCharge.toFixed(2)}` : "Estimated" })
9354
+ /* @__PURE__ */ jsxRuntime.jsx(renderer.Text, { style: styles.totalsBreakdownLabel, children: isDeliveryEstimated ? "Logistics / Delivery (Estimated Min.)" : "Logistics / Delivery" }),
9355
+ /* @__PURE__ */ jsxRuntime.jsx(renderer.Text, { style: styles.totalsBreakdownValueItalic, children: deliveryCharge !== void 0 ? `\xA3${deliveryCharge.toFixed(2)}` : "TBC" })
9356
9356
  ] })
9357
9357
  ] }),
9358
9358
  /* @__PURE__ */ jsxRuntime.jsxs(renderer.View, { style: styles.grandTotalContainer, children: [
9359
- /* @__PURE__ */ jsxRuntime.jsx(renderer.Text, { style: styles.grandTotalLabel, children: deliveryCharge !== void 0 ? "Grand Total" : "Estimated Grand Total" }),
9359
+ /* @__PURE__ */ jsxRuntime.jsx(renderer.Text, { style: styles.grandTotalLabel, children: deliveryCharge === void 0 ? "Estimated Grand Total" : isDeliveryEstimated ? "Estimated Grand Total (Min.)" : "Grand Total" }),
9360
9360
  /* @__PURE__ */ jsxRuntime.jsx(renderer.Text, { style: styles.grandTotalValue, children: deliveryCharge !== void 0 && totalPrice !== void 0 ? `\xA3${totalPrice.toFixed(2)}` : deliveryCharge !== void 0 ? `\xA3${(totalCatering + deliveryCharge - (promoDiscount || 0) - (appliedPromotions || []).reduce((s, p) => s + p.discountAmount, 0)).toFixed(2)}` : `\xA3${totalCatering.toFixed(2)} + TBC` })
9361
9361
  ] })
9362
9362
  ] }),
@@ -9389,7 +9389,8 @@ var CateringMenuPdf = ({
9389
9389
  deliveryCharge,
9390
9390
  totalPrice,
9391
9391
  promoDiscount,
9392
- appliedPromotions
9392
+ appliedPromotions,
9393
+ isDeliveryEstimated
9393
9394
  }) => {
9394
9395
  const groupedByDay = groupSessionsByDate(sessions);
9395
9396
  const allSessionsFlat = groupedByDay.flatMap(
@@ -9414,7 +9415,8 @@ var CateringMenuPdf = ({
9414
9415
  deliveryCharge,
9415
9416
  totalPrice,
9416
9417
  promoDiscount,
9417
- appliedPromotions
9418
+ appliedPromotions,
9419
+ isDeliveryEstimated
9418
9420
  },
9419
9421
  item.key
9420
9422
  ))
@@ -16014,12 +16016,25 @@ function CheckoutScreen() {
16014
16016
  pricingSessionIndex++;
16015
16017
  }
16016
16018
  });
16019
+ const nonEmptySessionCount = pricingSessionIndex;
16020
+ const anyPerSessionFee = Array.from(
16021
+ deliveryFeeByLocalIndex.values()
16022
+ ).some((v) => typeof v === "number");
16023
+ if (!anyPerSessionFee && nonEmptySessionCount > 0 && typeof pricing?.deliveryFee === "number") {
16024
+ const perSession = pricing.deliveryFee / nonEmptySessionCount;
16025
+ deliveryFeeByLocalIndex.forEach((_, localIndex) => {
16026
+ deliveryFeeByLocalIndex.set(localIndex, perSession);
16027
+ });
16028
+ }
16017
16029
  const sessionsForPreview = mealSessions.map(
16018
16030
  (session, index) => ({
16019
16031
  sessionName: session.sessionName,
16020
16032
  sessionDate: session.sessionDate,
16021
16033
  eventTime: session.eventTime,
16022
- deliveryFee: hasDeliveryQuote ? deliveryFeeByLocalIndex.get(index) : void 0,
16034
+ // Always forward the per-session fee. When `hasDeliveryQuote` is
16035
+ // false this is the API's minimum estimate; the PDF labels it as
16036
+ // estimated via the `isDeliveryEstimated` flag below.
16037
+ deliveryFee: deliveryFeeByLocalIndex.get(index),
16023
16038
  orderItems: session.orderItems.map((orderItem) => ({
16024
16039
  item: {
16025
16040
  id: orderItem.item.id,
@@ -16062,7 +16077,8 @@ function CheckoutScreen() {
16062
16077
  withPrices,
16063
16078
  pricing?.deliveryFee || void 0,
16064
16079
  pricing?.promoDiscount || void 0,
16065
- pdfAppliedPromotions.length > 0 ? pdfAppliedPromotions : void 0
16080
+ pdfAppliedPromotions.length > 0 ? pdfAppliedPromotions : void 0,
16081
+ !hasDeliveryQuote
16066
16082
  );
16067
16083
  const blob = await renderer.pdf(
16068
16084
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -16074,7 +16090,8 @@ function CheckoutScreen() {
16074
16090
  promoDiscount: pdfData.promoDiscount,
16075
16091
  appliedPromotions: pdfData.appliedPromotions,
16076
16092
  totalPrice: pricing?.total ?? pdfData.totalPrice,
16077
- logoUrl: pdfData.logoUrl
16093
+ logoUrl: pdfData.logoUrl,
16094
+ isDeliveryEstimated: pdfData.isDeliveryEstimated
16078
16095
  }
16079
16096
  )
16080
16097
  ).toBlob();
@@ -18372,12 +18389,25 @@ function CateringOrderBuilder() {
18372
18389
  pricingSessionIndex++;
18373
18390
  }
18374
18391
  });
18392
+ const nonEmptySessionCount = pricingSessionIndex;
18393
+ const anyPerSessionFee = Array.from(
18394
+ deliveryFeeByLocalIndex.values()
18395
+ ).some((v) => typeof v === "number");
18396
+ if (!anyPerSessionFee && nonEmptySessionCount > 0 && typeof pricing?.deliveryFee === "number") {
18397
+ const perSession = pricing.deliveryFee / nonEmptySessionCount;
18398
+ deliveryFeeByLocalIndex.forEach((_, localIndex) => {
18399
+ deliveryFeeByLocalIndex.set(localIndex, perSession);
18400
+ });
18401
+ }
18375
18402
  const sessionsForPreview = mealSessions.map(
18376
18403
  (session, index) => ({
18377
18404
  sessionName: session.sessionName,
18378
18405
  sessionDate: session.sessionDate,
18379
18406
  eventTime: session.eventTime,
18380
- deliveryFee: hasDeliveryQuote ? deliveryFeeByLocalIndex.get(index) : void 0,
18407
+ // Always forward the per-session fee. When `hasDeliveryQuote` is
18408
+ // false this is the API's minimum estimate; the PDF labels it as
18409
+ // estimated via the `isDeliveryEstimated` flag below.
18410
+ deliveryFee: deliveryFeeByLocalIndex.get(index),
18381
18411
  orderItems: session.orderItems.map((orderItem) => ({
18382
18412
  item: {
18383
18413
  id: orderItem.item.id,
@@ -18413,7 +18443,8 @@ function CateringOrderBuilder() {
18413
18443
  withPrices,
18414
18444
  pricing?.deliveryFee || void 0,
18415
18445
  pricing?.promoDiscount || void 0,
18416
- pdfAppliedPromotions.length > 0 ? pdfAppliedPromotions : void 0
18446
+ pdfAppliedPromotions.length > 0 ? pdfAppliedPromotions : void 0,
18447
+ !hasDeliveryQuote
18417
18448
  );
18418
18449
  const blob = await renderer.pdf(
18419
18450
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -18425,7 +18456,8 @@ function CateringOrderBuilder() {
18425
18456
  totalPrice: pricing?.total ?? pdfData.totalPrice,
18426
18457
  promoDiscount: pdfData.promoDiscount,
18427
18458
  appliedPromotions: pdfData.appliedPromotions,
18428
- logoUrl: pdfData.logoUrl
18459
+ logoUrl: pdfData.logoUrl,
18460
+ isDeliveryEstimated: pdfData.isDeliveryEstimated
18429
18461
  }
18430
18462
  )
18431
18463
  ).toBlob();