@wix/himalaya-cli 0.1648.0 → 0.1649.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 (64) hide show
  1. package/package.json +2 -2
  2. package/template-icons/wholesale-store.png +0 -0
  3. package/templates/wholesale-store/README.md +53 -0
  4. package/templates/wholesale-store/config.ts +247 -0
  5. package/templates/wholesale-store/dev/index.ts +12194 -0
  6. package/templates/wholesale-store/himalaya.content.json +43 -0
  7. package/templates/wholesale-store/himalaya.template.json +14 -0
  8. package/templates/wholesale-store/icon.png +0 -0
  9. package/templates/wholesale-store/platforms.json +1 -0
  10. package/templates/wholesale-store/tier5-src/_shared/app-locale.ts +61 -0
  11. package/templates/wholesale-store/tier5-src/_shared/branded-lite-hosted.ts +279 -0
  12. package/templates/wholesale-store/tier5-src/_shared/business-chat-copy.ts +40 -0
  13. package/templates/wholesale-store/tier5-src/_shared/business-chat-history.ts +51 -0
  14. package/templates/wholesale-store/tier5-src/_shared/business-chat-message-model.ts +177 -0
  15. package/templates/wholesale-store/tier5-src/_shared/business-chat-model.ts +56 -0
  16. package/templates/wholesale-store/tier5-src/_shared/business-chat-presenter.ts +576 -0
  17. package/templates/wholesale-store/tier5-src/_shared/business-chat-transport.ts +148 -0
  18. package/templates/wholesale-store/tier5-src/_shared/collection-contract.ts +228 -0
  19. package/templates/wholesale-store/tier5-src/_shared/collection-query-legacy.ts +194 -0
  20. package/templates/wholesale-store/tier5-src/_shared/collection-query.ts +252 -0
  21. package/templates/wholesale-store/tier5-src/_shared/collection-service.ts +423 -0
  22. package/templates/wholesale-store/tier5-src/_shared/detail-presence.ts +51 -0
  23. package/templates/wholesale-store/tier5-src/_shared/empty-flags.ts +33 -0
  24. package/templates/wholesale-store/tier5-src/_shared/engine-intl.ts +508 -0
  25. package/templates/wholesale-store/tier5-src/_shared/exclusive-writes.ts +66 -0
  26. package/templates/wholesale-store/tier5-src/_shared/himi-account.ts +164 -0
  27. package/templates/wholesale-store/tier5-src/_shared/himi-copy.ts +89 -0
  28. package/templates/wholesale-store/tier5-src/_shared/himi-store-categories.ts +108 -0
  29. package/templates/wholesale-store/tier5-src/_shared/himi-store-collection.ts +22 -0
  30. package/templates/wholesale-store/tier5-src/_shared/himi-store-saved.ts +57 -0
  31. package/templates/wholesale-store/tier5-src/_shared/himi-store.ts +7 -0
  32. package/templates/wholesale-store/tier5-src/_shared/himi-text.ts +24 -0
  33. package/templates/wholesale-store/tier5-src/_shared/hosted-checkout.ts +70 -0
  34. package/templates/wholesale-store/tier5-src/_shared/iap-presentation.ts +207 -0
  35. package/templates/wholesale-store/tier5-src/_shared/iap-worker.ts +125 -0
  36. package/templates/wholesale-store/tier5-src/_shared/inbox-rooms.ts +68 -0
  37. package/templates/wholesale-store/tier5-src/_shared/live-session.ts +172 -0
  38. package/templates/wholesale-store/tier5-src/_shared/local-preferences.ts +38 -0
  39. package/templates/wholesale-store/tier5-src/_shared/member-access.ts +52 -0
  40. package/templates/wholesale-store/tier5-src/_shared/member-account-routes.ts +52 -0
  41. package/templates/wholesale-store/tier5-src/_shared/member-orders.ts +8 -0
  42. package/templates/wholesale-store/tier5-src/_shared/member-screen.ts +99 -0
  43. package/templates/wholesale-store/tier5-src/_shared/online-actions.ts +76 -0
  44. package/templates/wholesale-store/tier5-src/_shared/owner-editor-value.ts +164 -0
  45. package/templates/wholesale-store/tier5-src/_shared/owner-load-error.ts +348 -0
  46. package/templates/wholesale-store/tier5-src/_shared/payment-setup.ts +6 -0
  47. package/templates/wholesale-store/tier5-src/_shared/read-service.ts +255 -0
  48. package/templates/wholesale-store/tier5-src/_shared/restaurant-ordering.ts +201 -0
  49. package/templates/wholesale-store/tier5-src/_shared/rich-body.ts +78 -0
  50. package/templates/wholesale-store/tier5-src/_shared/rich-content-link.ts +34 -0
  51. package/templates/wholesale-store/tier5-src/_shared/sign-in-sheet.ts +18 -0
  52. package/templates/wholesale-store/tier5-src/_shared/store-order-presentation.ts +56 -0
  53. package/templates/wholesale-store/tier5-src/_shared/store-product-info.ts +50 -0
  54. package/templates/wholesale-store/tier5-src/business-chat/index.ts +724 -0
  55. package/templates/wholesale-store/tier5-src/himi-branded-lite-cart/index.ts +602 -0
  56. package/templates/wholesale-store/tier5-src/himi-branded-lite-order/index.ts +472 -0
  57. package/templates/wholesale-store/tier5-src/himi-branded-lite-orders/index.ts +327 -0
  58. package/templates/wholesale-store/tier5-src/himi-store-account/index.ts +998 -0
  59. package/templates/wholesale-store/tier5-src/himi-store-product/index.ts +889 -0
  60. package/templates/wholesale-store/tier5-src/himi-store-saved/index.ts +68 -0
  61. package/templates/wholesale-store/tier5-src/himi-store-shop/index.ts +150 -0
  62. package/templates/wholesale-store/tier5-src/himi-wholesale-home/index.ts +507 -0
  63. package/templates/wholesale-store/tier5-src/wix-spaces-collection-detail/index.ts +195 -0
  64. package/templates/wholesale-store/tokens.json +340 -0
@@ -0,0 +1,68 @@
1
+ import { withIapPresentation } from "../_shared/iap-presentation.js";
2
+ import { withEmptyFlags } from "../_shared/empty-flags.js";
3
+ import { readSavedProducts, removeSavedProduct, type SavedProduct } from "../_shared/himi-store-saved.js";
4
+ import { stashCopy, copyParam } from "../_shared/himi-copy.js";
5
+
6
+ interface Row extends SavedProduct {
7
+ commercePrice?: string; initial: string; noImage: boolean; hasImage: boolean; detailScreenId: string;
8
+ notOnSale: boolean; wasPriceEmpty: boolean; noSwatches: boolean; noTagRow: boolean;
9
+ swatch1: string; swatch2: string; swatch3: string; swatch4: string; swatch5: string;
10
+ noSwatch1: boolean; noSwatch2: boolean; noSwatch3: boolean; noSwatch4: boolean; noSwatch5: boolean;
11
+ }
12
+ interface S {
13
+ status: "loading" | "ready" | "error";
14
+ rows: Row[];
15
+ error: string;
16
+ emptyText: string;
17
+ isLoading: boolean;
18
+ notLoading: boolean;
19
+ notErrored: boolean;
20
+ noEmpty: boolean;
21
+ hasRows: boolean;
22
+ }
23
+ function shape(s: Pick<S, "status" | "rows" | "error">): S {
24
+ return { ...s, isLoading: s.status === "loading", notLoading: s.status !== "loading", notErrored: s.status !== "error", noEmpty: s.status !== "ready" || s.rows.length > 0, hasRows: s.rows.length > 0, emptyText: copyParam("savedProducts.empty", "Tap the heart on a product to add it to your wishlist.") };
25
+ }
26
+ function loadRows(): Row[] {
27
+ return readSavedProducts().map(row => {
28
+ const swatches = (row.swatches ?? []).filter(value => /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i.test(value)).slice(0, 5);
29
+ return { ...row, commercePrice: row.price, initial: row.name.slice(0, 1).toUpperCase(), hasImage: !!row.image, noImage: !row.image,
30
+ detailScreenId: "himi_product", notOnSale: !row.wasPrice, wasPriceEmpty: !!row.wasPrice, noSwatches: swatches.length === 0, noTagRow: !row.wasPrice && swatches.length === 0,
31
+ swatch1: swatches[0] ?? "", swatch2: swatches[1] ?? "", swatch3: swatches[2] ?? "", swatch4: swatches[3] ?? "", swatch5: swatches[4] ?? "",
32
+ noSwatch1: !swatches[0], noSwatch2: !swatches[1], noSwatch3: !swatches[2], noSwatch4: !swatches[3], noSwatch5: !swatches[4] };
33
+ });
34
+ }
35
+ function failed(s: S): S {
36
+ return shape({ ...s, status: "error", error: copyParam("savedProducts.error", "Could not update your wishlist. Try again.") });
37
+ }
38
+ const defineService = withIapPresentation<S>({
39
+ forcePriceRefreshActions: ["load", "remove"],
40
+ prefix: "savedProducts", transientKeys: ["rows"], contentActions: ["load", "remove"],
41
+ items: state => state.rows.map(row => ({ reference: { kind: "storesProduct", id: row.id }, commerceDisplayPrice: row.commercePrice ?? row.price })),
42
+ present: (state, price) => ({ ...state, rows: state.rows.map(row => {
43
+ const next = price(row.id, row.commercePrice ?? row.price);
44
+ const iapAdjusted = next !== (row.commercePrice ?? row.price);
45
+ return { ...row, price: next, wasPriceEmpty: !!row.wasPrice && !iapAdjusted, notOnSale: !row.wasPrice || iapAdjusted, noTagRow: (!row.wasPrice || iapAdjusted) && !row.swatches?.length };
46
+ }) }),
47
+ });
48
+ const svc = defineService<S, {
49
+ load: (s: S, arg?: unknown) => S;
50
+ remove: (s: S, arg?: unknown) => S;
51
+ }>("himiStoreSaved", withEmptyFlags({
52
+ state: shape({ status: "loading", rows: [], error: "" }),
53
+ actions: {
54
+ load: (s, arg) => {
55
+ stashCopy(arg);
56
+ try { return shape({ status: "ready", rows: loadRows(), error: "" }); }
57
+ catch { return failed(s); }
58
+ },
59
+ remove: (s, arg) => {
60
+ const id = typeof arg === "string" ? arg : String((arg as { id?: unknown } | undefined)?.id ?? "");
61
+ try {
62
+ removeSavedProduct(id);
63
+ return shape({ status: "ready", rows: loadRows(), error: "" });
64
+ } catch { return failed(s); }
65
+ },
66
+ },
67
+ }, { rows: "noRows" }));
68
+ export { svc };
@@ -0,0 +1,150 @@
1
+ // Tier-5 bundle: himi-store — product catalog.
2
+ import { withIapPresentation } from "../_shared/iap-presentation.js";
3
+ import { storeCollectionSaving } from "../_shared/himi-store-collection.js";
4
+ import { defineBackendCollection } from "../_shared/collection-service.js";
5
+ import { getCurrentCart } from "@himalaya/wix-ecom";
6
+ import { productImage, productPrice, searchStoreProducts, type StoreProduct } from "../_shared/himi-store.js";
7
+ import { cleanTitle, initials } from "../_shared/himi-text.js";
8
+ import { copyParam } from "../_shared/himi-copy.js";
9
+
10
+ // Response caching belongs to the shared policy-controlled Wix read bridge.
11
+ // Local database summaries are not complete, scoped product responses.
12
+
13
+ /** Live cart size (sum of line-item quantities) for the top-bar cart badge.
14
+ * Best-effort: a cart error just yields 0 (badge hidden), never fails the screen. */
15
+ async function cartItemCount(): Promise<number> {
16
+ try {
17
+ const cart = await getCurrentCart();
18
+ return (cart.lineItems ?? []).reduce((n, li) => n + (li.quantity ?? 1), 0);
19
+ } catch {
20
+ return 0;
21
+ }
22
+ }
23
+
24
+ interface Row {
25
+ id: string;
26
+ name: string;
27
+ subtitle: string;
28
+ commercePrice: string;
29
+ wasPrice: string;
30
+ image: string;
31
+ initial: string;
32
+ hasImage: boolean;
33
+ noImage: boolean;
34
+ detailScreenId: string;
35
+ }
36
+
37
+ interface S {
38
+ status: "loading" | "ready" | "error";
39
+ total?: number;
40
+ complete?: boolean;
41
+ pageError?: boolean;
42
+ loadingMore?: boolean;
43
+ fromCache?: boolean;
44
+ query: string;
45
+ all: Row[];
46
+ collection?: { items: Array<Row & { collectionSubtitle: string }> };
47
+ results: Row[];
48
+ /** RFC 0008 cursor paging — non-empty while more pages exist ("" ⇒ exhausted). */
49
+ nextCursor: string;
50
+ emptyText: string;
51
+ countLabel: string;
52
+ cartCount: number;
53
+ isLoading: boolean;
54
+ notLoading: boolean;
55
+ isErrored: boolean;
56
+ notErrored: boolean;
57
+ noEmpty: boolean;
58
+ }
59
+
60
+ function row(p: StoreProduct): Row {
61
+ const name = cleanTitle(p.name) || "Product";
62
+ const image = productImage(p);
63
+ const id = p.id ?? "";
64
+ const priceData = p.priceData as { formatted?: { discountedPrice?: string; price?: string }; discountedPrice?: string; salePrice?: string } | undefined;
65
+ const regular = productPrice(p);
66
+ const discounted = priceData?.formatted?.discountedPrice ?? priceData?.discountedPrice ?? priceData?.salePrice;
67
+ const salePrice = discounted && discounted !== (priceData?.formatted?.price ?? regular)
68
+ ? productPrice({ ...p, priceData: { ...priceData, formatted: { ...priceData?.formatted, price: discounted } } } as StoreProduct)
69
+ : "";
70
+ const originalV3 = p.compareAtPriceRange?.minValue
71
+ ? productPrice({ ...p, price: undefined, priceData: undefined, actualPriceRange: p.compareAtPriceRange })
72
+ : "";
73
+ const wasPrice = salePrice ? regular : originalV3 && originalV3 !== regular ? originalV3 : "";
74
+ return {
75
+ id,
76
+ name,
77
+ subtitle: salePrice || regular,
78
+ commercePrice: salePrice || regular,
79
+ wasPrice,
80
+ image,
81
+ initial: initials(name),
82
+ hasImage: !!image,
83
+ noImage: !image,
84
+ // WS-C — canonical param-less detail screenId; the descriptor row binds the
85
+ // separate `id` field as a first-class nav param (no more baked suffixes).
86
+ detailScreenId: "himi_product",
87
+ };
88
+ }
89
+
90
+ function derive(s: S): S {
91
+ const count = s.results.length;
92
+ return {
93
+ ...s,
94
+ isLoading: s.status === "loading",
95
+ notLoading: s.status !== "loading",
96
+ isErrored: s.status === "error",
97
+ notErrored: s.status !== "error",
98
+ noEmpty: s.status === "loading" || s.status === "error" || count > 0,
99
+ countLabel: count ? `${count} product${count === 1 ? "" : "s"} from Wix Stores` : "",
100
+ };
101
+ }
102
+
103
+ const svc = defineBackendCollection("himiStoreShop", {
104
+ readLifecycle: true,
105
+ register: withIapPresentation<S>({
106
+ prefix: "shop", transientKeys: ["all", "results", "collection"], contentActions: ["collectionDataChanged"],
107
+ items: state => state.results.map(row => ({ reference: { kind: "storesProduct", id: row.id }, commerceDisplayPrice: row.commercePrice ?? row.subtitle })),
108
+ present: (state, price) => ({ ...state, results: state.results.map(row => ({ ...row, subtitle: price(row.id) })), all: state.all.map(row => ({ ...row, subtitle: price(row.id) })),
109
+ ...(state.collection ? { collection: { ...state.collection, items: state.collection.items.map(row => ({ ...row, collectionSubtitle: price(row.id) })) } } : {}) }),
110
+ }),
111
+ state: derive({ status: "loading", query: "", all: [], results: [], nextCursor: "",
112
+ emptyText: "", countLabel: "", cartCount: 0, isLoading: true, notLoading: false,
113
+ isErrored: false, notErrored: true, noEmpty: true }),
114
+ saving: storeCollectionSaving,
115
+ source: {
116
+ cacheRead: true,
117
+ id: (item: Row) => item.id,
118
+ async fetch(criteria, cursor, readOptions) {
119
+ // Nothing saved: the empty page follows from the local selection, offline too, and no
120
+ // Wix read happens to vouch for it.
121
+ if (criteria.filter === "saved" && !criteria.savedIds.length)
122
+ return { items: [], nextCursor: "", total: 0, local: true,
123
+ metadata: { cartCount: readOptions?.cache === "only-if-cached" ? 0 : await cartItemCount(), fromCache: false } };
124
+ try {
125
+ const response = await searchStoreProducts({ query: criteria.query, sort: criteria.sort,
126
+ ...(criteria.filter === "saved" ? { ids: criteria.savedIds } : {}), limit: 50, cursor }, readOptions);
127
+ const items = (response.products ?? []).map(row);
128
+ return { items, nextCursor: response.pagingMetadata?.cursors?.next ?? "",
129
+ total: response.pagingMetadata?.total,
130
+ metadata: cursor ? undefined : { cartCount: readOptions?.cache === "only-if-cached" ? 0 : await cartItemCount(), fromCache: false } };
131
+ } catch (error) { throw error; }
132
+ },
133
+ },
134
+ apply(state, page) {
135
+
136
+ const status = page.status === "idle" ? "loading" : page.status;
137
+ return derive({ ...state, ...page.metadata, status, query: page.criteria.query,
138
+ all: page.items, results: page.items, nextCursor: page.nextCursor,
139
+ total: page.total, complete: page.complete, pageError: page.pageError,
140
+ loadingMore: page.loadingMore, fromCache: page.metadata?.fromCache === true,
141
+ emptyText: status === "error" ? copyParam("shop.errorText", "Products could not load.")
142
+ : page.criteria.query || page.criteria.filter !== "all"
143
+ ? copyParam("shop.noMatchText", "No products match this view.")
144
+ : copyParam("shop.emptyText", "No products are published yet."),
145
+ });
146
+ },
147
+ });
148
+
149
+ svc.load();
150
+ export { svc };