@wix/himalaya-cli 0.1522.0 → 0.1524.0

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.
Files changed (49) hide show
  1. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/bookings-v2/src/extensions.d.ts +18 -0
  2. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-bookings.mjs +13 -0
  3. package/dist/cli.mjs +3 -2
  4. package/package.json +2 -2
  5. package/templates/beauty-salon/dev/index.ts +862 -35
  6. package/templates/beauty-salon/tier5-src/_shared/himi-bookings.ts +69 -0
  7. package/templates/beauty-salon/tier5-src/_shared/himi-copy.ts +9 -0
  8. package/templates/beauty-salon/tier5-src/himi-booking-service/index.ts +237 -17
  9. package/templates/beauty-salon/tier5-src/himi-booking-time/index.ts +277 -55
  10. package/templates/beauty-salon/tier5-src/himi-branded-lite-cart/index.ts +4 -63
  11. package/templates/beauty-salon-owner/tier5-src/_shared/himi-copy.ts +9 -0
  12. package/templates/branded-lite/dev/index.ts +862 -35
  13. package/templates/branded-lite/tier5-src/_shared/himi-bookings.ts +69 -0
  14. package/templates/branded-lite/tier5-src/_shared/himi-copy.ts +9 -0
  15. package/templates/branded-lite/tier5-src/himi-booking-service/index.ts +237 -17
  16. package/templates/branded-lite/tier5-src/himi-booking-time/index.ts +277 -55
  17. package/templates/branded-lite/tier5-src/himi-branded-lite-cart/index.ts +4 -63
  18. package/templates/brandy/tier5-src/_shared/himi-copy.ts +9 -0
  19. package/templates/community-club/tier5-src/_shared/himi-copy.ts +9 -0
  20. package/templates/community-club-owner/tier5-src/_shared/himi-copy.ts +9 -0
  21. package/templates/events-meetups/tier5-src/_shared/himi-copy.ts +9 -0
  22. package/templates/events-meetups-owner/tier5-src/_shared/himi-copy.ts +9 -0
  23. package/templates/gym-fitness/dev/index.ts +862 -35
  24. package/templates/gym-fitness/tier5-src/_shared/himi-bookings.ts +69 -0
  25. package/templates/gym-fitness/tier5-src/_shared/himi-copy.ts +9 -0
  26. package/templates/gym-fitness/tier5-src/himi-booking-service/index.ts +237 -17
  27. package/templates/gym-fitness/tier5-src/himi-booking-time/index.ts +277 -55
  28. package/templates/gym-fitness/tier5-src/himi-branded-lite-cart/index.ts +4 -63
  29. package/templates/gym-fitness-owner/tier5-src/_shared/himi-copy.ts +9 -0
  30. package/templates/himi-chat/tier5-src/_shared/himi-copy.ts +9 -0
  31. package/templates/nonprofit-cause/tier5-src/_shared/himi-copy.ts +9 -0
  32. package/templates/nonprofit-cause-owner/tier5-src/_shared/himi-copy.ts +9 -0
  33. package/templates/owner-lite/tier5-src/_shared/himi-copy.ts +9 -0
  34. package/templates/podcast-creator/tier5-src/_shared/himi-copy.ts +9 -0
  35. package/templates/podcast-creator-owner/tier5-src/_shared/himi-copy.ts +9 -0
  36. package/templates/portfolio-creative/tier5-src/_shared/himi-copy.ts +9 -0
  37. package/templates/portfolio-creative/tier5-src/himi-branded-lite-cart/index.ts +4 -63
  38. package/templates/portfolio-creative-owner/tier5-src/_shared/himi-copy.ts +9 -0
  39. package/templates/restaurant/tier5-src/_shared/himi-copy.ts +9 -0
  40. package/templates/restaurant-owner/tier5-src/_shared/himi-copy.ts +9 -0
  41. package/templates/retail-store/tier5-src/_shared/himi-copy.ts +9 -0
  42. package/templates/retail-store/tier5-src/himi-branded-lite-cart/index.ts +4 -63
  43. package/templates/retail-store-owner/tier5-src/_shared/himi-copy.ts +9 -0
  44. package/templates/yoga-studio/dev/index.ts +857 -30
  45. package/templates/yoga-studio/tier5-src/_shared/himi-bookings.ts +69 -0
  46. package/templates/yoga-studio/tier5-src/_shared/himi-copy.ts +9 -0
  47. package/templates/yoga-studio/tier5-src/himi-booking-service/index.ts +237 -17
  48. package/templates/yoga-studio/tier5-src/himi-booking-time/index.ts +277 -55
  49. package/templates/yoga-studio-owner/tier5-src/_shared/himi-copy.ts +9 -0
@@ -2,9 +2,8 @@ import { getStoreProduct } from "../_shared/himi-store.js";
2
2
  import { iapPriceCopy } from "../_shared/iap-worker.js";
3
3
  import { withIapPresentation } from "../_shared/iap-presentation.js";
4
4
  import { type IapCommerce, classifyCart } from "@himalaya/iap-checkout";
5
- import { addCouponToCurrentCart, calculateCurrentCart, createCheckoutFromCurrentCart, createOrder, getCurrentCart, removeCouponFromCurrentCart, removeLineItemsFromCurrentCart, updateLineItemsQuantity, type WixCartDetail, type WixCartLineItemDetail } from "@himalaya/wix-ecom";
5
+ import { addCouponToCurrentCart, calculateCurrentCart, createCheckoutFromCurrentCart, getCurrentCart, removeCouponFromCurrentCart, removeLineItemsFromCurrentCart, updateLineItemsQuantity, type WixCartDetail, type WixCartLineItemDetail } from "@himalaya/wix-ecom";
6
6
  import { createRedirectSession } from "@himalaya/wix-redirects";
7
- import { session as wixPlatformSession } from "@himalaya/wix-platform";
8
7
  import { payCashierOrder } from "@himalaya/checkout";
9
8
  import { hostedCheckoutOpener, isHostedWorker } from "../_shared/hosted-checkout.js";
10
9
  import { formatCurrency } from "../_shared/engine-intl.js";
@@ -14,16 +13,6 @@ import { formatCurrency } from "../_shared/engine-intl.js";
14
13
  const WIX_STORES_CATALOG_ID = "215238eb-22a5-4c36-9e7b-e7c08025e04e";
15
14
  const WIX_STORES_APP_ID = "1380b703-ce81-ff05-f115-39571d94dfcd";
16
15
 
17
- /** The site's metaSiteId for the cashier payment config. Best-effort — the native
18
- * cashier can also resolve it from the app's signed Wix session, so "" is tolerated. */
19
- async function resolveMsid(): Promise<string> {
20
- try {
21
- const st = await wixPlatformSession.signedInstanceStatus();
22
- return st.msid ?? "";
23
- } catch {
24
- return "";
25
- }
26
- }
27
16
  import { copyParam, copyTemplate, stashCopy } from "../_shared/himi-copy.js";
28
17
  import { getAll, upsert, remove as dbRemove, type DbEntity } from "@himalaya/local-db";
29
18
  import { isOfflineFailure, writeMayHaveLanded } from "../_shared/owner-load-error.js";
@@ -387,30 +376,6 @@ function couponDetails(result: unknown): { id: string; code: string } {
387
376
  return { id: coupon?.coupon?.id ?? coupon?.id ?? "", code: coupon?.coupon?.code ?? coupon?.code ?? "" };
388
377
  }
389
378
 
390
- /** The state slice a SETTLED order leaves behind: the order consumed the cart, so the
391
- * lines AND the subtotal go with it (`refresh` and the error path both clear the pair —
392
- * leaving a stale subtotal in state is the class of defect #864 fixed on the render side).
393
- *
394
- * `emptyText` is cleared deliberately: the empty card would otherwise nudge "Your cart is
395
- * empty." underneath the confirmation, which is noise at the moment of a successful
396
- * payment. The next `load` restores it.
397
- *
398
- * This used to be written inline as `{ items: [], itemCount: 0, checkoutHint: ... }`.
399
- * `itemCount` is not a field of `State` and never was — a write to nowhere, which is why
400
- * the subtotal and emptyText resets were missing. It survived because nothing typechecks
401
- * Tier-5 workers: esbuild erases types, and no tsconfig includes tier5-bundles-src.
402
- */
403
- function cartConsumedByOrder(): Pick<State, "items" | "subtotal" | "emptyText" | "checkoutHint" | "showPaidToast" | "promoCode" | "appliedCode" | "couponId" | "discount"> {
404
- return {
405
- items: [],
406
- subtotal: "",
407
- emptyText: "",
408
- checkoutHint: copyParam("cart.checkoutPaidMessage", "Order placed. Thanks!"),
409
- showPaidToast: true,
410
- promoCode: "", appliedCode: "", couponId: "", discount: "",
411
- };
412
- }
413
-
414
379
  let cartPricing: IapCommerce;
415
380
  const defineService = withIapPresentation<State>({
416
381
  onCreate: commerce => { cartPricing = commerce; },
@@ -544,13 +509,7 @@ const svc = defineService<State, {
544
509
  return derive({ ...state, checkoutHint: copyParam("cart.quantityFailedMessage", "Could not update the quantity.") });
545
510
  }
546
511
  },
547
- // Phase 2a — cart checkout collects payment IN-APP through the shared pay rail
548
- // (@wix/himalaya/checkout) instead of always bouncing to the hosted checkout:
549
- // createCheckoutFromCurrentCart → ecom.createOrder → payCashierOrder
550
- // A wallet-equipped app settles with NO navigation at all; every other app hands
551
- // off to the in-app Wix cashier (the previous behaviour), so nothing regresses.
552
- // `createOrder` returning no paymentGatewayOrderId means there is nothing to
553
- // charge (fully covered / zero total) — the order already stands.
512
+ // Physical checkout collects shipping before the site's checkout creates the order.
554
513
  checkout: async (state) => {
555
514
  let validatedLines: WixCartLineItemDetail[] = [];
556
515
  const signature = (lines: WixCartLineItemDetail[]) => JSON.stringify(lines.map(line => [line.id, line.quantity, (line as WixCartLineItemDetail & { catalogReference?: Row["catalogReference"] }).catalogReference]));
@@ -577,21 +536,11 @@ const svc = defineService<State, {
577
536
  if (!checkout.checkoutId) return derive({ ...state, checkoutHint: copyParam("cart.checkoutIdMissingMessage", "Wix did not return a checkout id.") });
578
537
  const checkoutId = checkout.checkoutId;
579
538
 
580
- // Hosted (Spaces): the site's own checkout page creates the order (RN's
581
- // route) — creating it here first fails on a site with no payment method set up, before the
582
- // member ever reaches the checkout. The host opens the checkout as the lent member.
583
539
  const hosted = isHostedWorker();
584
- const order = hosted ? { paymentGatewayOrderId: "" } : await createOrder(checkoutId);
585
- const snapshotId = order.paymentGatewayOrderId ?? "";
586
- if (!snapshotId && !hosted) {
587
- await writeCachedItems([]);
588
- return derive({ ...state, ...cartConsumedByOrder() });
589
- }
590
-
591
540
  const pay = await payCashierOrder({
592
541
  appId: WIX_STORES_APP_ID,
593
- snapshotId,
594
- msid: await resolveMsid(),
542
+ snapshotId: "",
543
+ msid: "",
595
544
  mayCharge: async () => {
596
545
  const latest = await getCurrentCart();
597
546
  if (signature(latest.lineItems ?? []) !== signature(validatedLines)) return false;
@@ -611,19 +560,11 @@ const svc = defineService<State, {
611
560
  return redirect.redirectSession?.fullUrl;
612
561
  },
613
562
  });
614
- if (pay.kind === "paid") {
615
- // Settled in place — the cart is consumed by the order.
616
- await writeCachedItems([]);
617
- return derive({ ...state, ...cartConsumedByOrder() });
618
- }
619
563
  if (pay.kind === "handoff") {
620
564
  // Do NOT clear the cart: payment completes in the cashier and the order is
621
565
  // only confirmed once it lands, so the cart must survive a bail-out.
622
566
  return derive({ ...state, checkoutHint: copyParam("cart.checkoutOpenedMessage", "Checkout opened.") });
623
567
  }
624
- if (pay.kind === "cancelled") {
625
- return derive({ ...state, checkoutHint: copyParam("cart.checkoutCancelledMessage", "Payment cancelled — your cart is still here.") });
626
- }
627
568
  return derive({ ...state, checkoutHint: copyParam("cart.checkoutFailedMessage", "Checkout could not start.") });
628
569
  } catch {
629
570
  return derive({ ...state, checkoutHint: copyParam("cart.checkoutFailedMessage", "Checkout could not start.") });
@@ -54,3 +54,12 @@ export function copyTemplate(key: string, fallback: string, values: Record<strin
54
54
  name in values ? String(values[name]) : "",
55
55
  );
56
56
  }
57
+
58
+ /** The small ICU plural form used by Bookings spot counts. The provisioned copy may
59
+ * translate both branches without adding a second key for the singular. */
60
+ export function copyPlural(key: string, fallback: string, count: number): string {
61
+ const pattern = copyParam(key, fallback);
62
+ const match = /^\{n, plural, one \{([^{}]*)\} other \{([^{}]*)\}\}$/.exec(pattern);
63
+ if (!match) return copyTemplate(key, fallback, { n: count });
64
+ return (count === 1 ? match[1] : match[2])!.replace(/#/g, String(count));
65
+ }