@wix/himalaya-cli 0.1807.0 → 0.1808.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.
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/site-shell.d.ts +62 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/core.mjs +124 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/sdui.mjs +12 -0
- package/dist/cli.mjs +14 -1
- package/package.json +2 -2
- package/templates/brandy/README.md +83 -14
- package/templates/brandy/config.ts +42 -34
- package/templates/brandy/dev/index.ts +240 -21
- package/templates/brandy/dev/member-screens.ts +2302 -0
- package/templates/brandy/himalaya.content.json +3 -0
- package/templates/brandy/himalaya.template.json +1 -1
- package/templates/brandy/provisioning.json +4 -1
- package/templates/brandy/provisioning.member.example.json +69 -7
- package/templates/brandy/tier5-src/_shared/exclusive-writes.ts +66 -0
- package/templates/brandy/tier5-src/_shared/header-badges.ts +113 -0
- package/templates/brandy/tier5-src/_shared/himi-store-saved.ts +57 -0
- package/templates/brandy/tier5-src/_shared/iap-presentation.ts +207 -0
- package/templates/brandy/tier5-src/_shared/restaurant-ordering.ts +201 -0
- package/templates/brandy/tier5-src/_shared/source-badges.ts +72 -0
- package/templates/brandy/tier5-src/himi-branded-lite-cart/index.ts +703 -0
- package/templates/brandy/tier5-src/himi-branded-lite-header-badges/index.ts +70 -0
- package/templates/brandy/tier5-src/himi-branded-lite-member-cart/flag.ts +3 -0
- package/templates/brandy/tier5-src/himi-branded-lite-member-cart/index.ts +6 -0
- package/templates/brandy/tier5-src/perks/index.ts +75 -0
- package/templates/brandy/tokens.json +5 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// The badges-only app-level worker (`navigation.navLogicBundle`) for a migrated One App: the live counts behind the
|
|
2
|
+
// header's bell, chat and cart buttons, and nothing else. It is the part of the Branded Lite app's full nav worker
|
|
3
|
+
// (`himi-branded-lite-nav`) a scaffold can use on its own: that worker also carries a push observer, hosted-site mode
|
|
4
|
+
// and a services-pin check, which a scaffold has no config for.
|
|
5
|
+
//
|
|
6
|
+
// The service is named `brandedLiteNav`, like the full worker's, so a top-bar action binds the same
|
|
7
|
+
// `$service:brandedLiteNav.<field>` path whichever worker an app names. A scaffold ships this source INERT: nothing
|
|
8
|
+
// loads it until the app's config names it (`himi one-app header-badges` writes that), so a scaffold without
|
|
9
|
+
// header badges is unchanged.
|
|
10
|
+
|
|
11
|
+
import { defineService } from "@himalaya/state";
|
|
12
|
+
import { hostSessionFromGlobal } from "@himalaya/iap";
|
|
13
|
+
import { HEADER_BADGE_KEYS, headerBadges, type HeaderBadgeActionSignatures, type HeaderBadges, type HeaderBadgeState } from "../_shared/header-badges.js";
|
|
14
|
+
|
|
15
|
+
/** `memberCartHidden` / `visitorCartHidden`: which of a site shell's two cart icons shows
|
|
16
|
+
* — the native member cart for a signed-in member, the website's cart page for anyone else. Read from
|
|
17
|
+
* the host session clock, the same identity the cart count and the cart screen follow. A host with no clock reads
|
|
18
|
+
* signed out, so it shows the website's cart. */
|
|
19
|
+
/** `memberCartBadge`: `cartBadge` for a signed-in member, null for anyone else, for a cart icon that opens a members-only
|
|
20
|
+
* cart. A visitor's own cart count is a different cart, and must not ride an icon whose tap asks them to sign in. */
|
|
21
|
+
type State = HeaderBadgeState & { memberCartHidden: boolean; visitorCartHidden: boolean; memberCartBadge: number | null };
|
|
22
|
+
const MEMBER_KEYS: ("memberCartHidden" | "visitorCartHidden" | "memberCartBadge")[] = ["memberCartHidden", "visitorCartHidden", "memberCartBadge"];
|
|
23
|
+
const session = hostSessionFromGlobal();
|
|
24
|
+
/** A web host has no session clock (the stub reads signed out): its sign-in arrives through `onIdentityChange`. */
|
|
25
|
+
let webSignedIn = false;
|
|
26
|
+
const isMember = (): boolean => session.current().kind === "member" || webSignedIn;
|
|
27
|
+
const memberFlags = () => { const member = isMember(); return { memberCartHidden: !member, visitorCartHidden: member }; };
|
|
28
|
+
|
|
29
|
+
/** Recomputed after every update, so a count or a session change both reach it. */
|
|
30
|
+
function withMemberCartBadge(s: State): State {
|
|
31
|
+
return { ...s, memberCartBadge: isMember() ? s.cartBadge : null };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// State changes await native work; overlapping actions must use the preceding result.
|
|
35
|
+
let stateQueue: Promise<State> | undefined;
|
|
36
|
+
function updateInOrder(s: State, update: (current: State) => Promise<State>): Promise<State> {
|
|
37
|
+
const previous = stateQueue ?? Promise.resolve(s);
|
|
38
|
+
const result = previous.then(update).then(withMemberCartBadge);
|
|
39
|
+
stateQueue = result.catch(() => previous);
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const badges: HeaderBadges<State> = headerBadges<State>(updateInOrder, () => svc);
|
|
44
|
+
|
|
45
|
+
const svc = defineService<State, HeaderBadgeActionSignatures<State> & {
|
|
46
|
+
syncMember: (s: State) => Promise<State>;
|
|
47
|
+
onIdentityChange: (s: State, change?: unknown) => Promise<State>;
|
|
48
|
+
}>("brandedLiteNav", {
|
|
49
|
+
// Every count unavailable until the first read lands, and no failure to report.
|
|
50
|
+
state: { notificationsBadge: null, chatBadge: null, cartBadge: null, errorText: "", memberCartBadge: null, ...memberFlags() },
|
|
51
|
+
// The counts describe THIS run (see _shared/header-badges.ts): never stored, never restored.
|
|
52
|
+
notPersisted: [...HEADER_BADGE_KEYS, ...MEMBER_KEYS],
|
|
53
|
+
notHydrated: [...HEADER_BADGE_KEYS, ...MEMBER_KEYS],
|
|
54
|
+
actions: {
|
|
55
|
+
...badges.actions,
|
|
56
|
+
syncMember: async (s) => updateInOrder(s, async (current) => ({ ...current, ...memberFlags() })),
|
|
57
|
+
// The web host's identity hook: record who is signed in BEFORE the shared piece drops and re-reads the counts,
|
|
58
|
+
// so the cart icons' visibility and the member count follow it as they follow the native clock.
|
|
59
|
+
onIdentityChange: async (s: State, change?: unknown) => {
|
|
60
|
+
webSignedIn = (change as { signedIn?: unknown } | undefined)?.signedIn === true;
|
|
61
|
+
const next = await badges.actions.onIdentityChange(s);
|
|
62
|
+
return updateInOrder(next, async (current) => ({ ...current, ...memberFlags() }));
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
export { svc };
|
|
68
|
+
|
|
69
|
+
badges.start();
|
|
70
|
+
session.subscribe(() => { void svc.syncMember(); });
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// The members-only cart a site shell serves: Branded Lite's cart worker, with
|
|
2
|
+
// the members-only flag set before it boots, so its boot load already shows the sign-in gate to a signed-out shopper
|
|
3
|
+
// instead of reading a native visitor cart (which is not the website's).
|
|
4
|
+
import "./flag.js";
|
|
5
|
+
import { svc } from "../himi-branded-lite-cart/index.js";
|
|
6
|
+
export { svc };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// tier5-src/perks/index.ts — the worker behind the sample "Perks" screen (screen id `perks` in dev/index.ts).
|
|
2
|
+
//
|
|
3
|
+
// A SAMPLE of your own native screen beside your website's pages: provisioning.json places it as a tab
|
|
4
|
+
// (`site.nativePages`), dev/index.ts builds its descriptor, and this worker owns its state. Nothing here talks to
|
|
5
|
+
// your site or needs a Wix binding, so it works in a fresh scaffold. Replace the perks with your own, or copy the
|
|
6
|
+
// pattern for any screen of yours (`himi docs tier-5-add-a-screen`):
|
|
7
|
+
//
|
|
8
|
+
// 1. the worker OWNS the list: `perks` is plain state, and the descriptor's Grid binds it with
|
|
9
|
+
// `itemsPath: "$service:perks.perks"`, each row reading `$item.<field>`;
|
|
10
|
+
// 2. every field the screen shows is a FLAT string, shaped here, never at the binding site;
|
|
11
|
+
// 3. derived fields (each row's `status`, the `summary` line) are recomputed by `derive()` in EVERY action:
|
|
12
|
+
// a worker's state is a plain object, and nothing re-runs a derived field on its own;
|
|
13
|
+
// 4. a row's tap dispatches `tier5.perks.toggle` with `{ id: "$item.id" }`, and the reducer reads that payload
|
|
14
|
+
// defensively (`p?.id`): a host calls it with no argument when an action carries no params.
|
|
15
|
+
//
|
|
16
|
+
// The state survives a relaunch of the SAME bundle (the platform keeps each worker's snapshot), so a claimed perk stays
|
|
17
|
+
// claimed. A snapshot restores only into the bundle that wrote it: ship any change to this worker (an edited CATALOG
|
|
18
|
+
// included) and the next cold start begins from `derive([])`, with the new catalog and no claims.
|
|
19
|
+
// Build it with `himi build`; `himi validate --strict` checks every `$service:perks.*` binding against this state,
|
|
20
|
+
// and `himi test` taps every row.
|
|
21
|
+
|
|
22
|
+
import { defineService } from "@himalaya/state";
|
|
23
|
+
|
|
24
|
+
/** One perk as the screen shows it. Flat strings only: the row template binds `$item.title`, never a nested path. */
|
|
25
|
+
interface PerkRow {
|
|
26
|
+
id: string;
|
|
27
|
+
title: string;
|
|
28
|
+
detail: string;
|
|
29
|
+
/** Derived: what a tap does next ("Tap to claim") or what was done ("Claimed"). */
|
|
30
|
+
status: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface PerksState {
|
|
34
|
+
/** The rows the Grid draws (`itemsPath`). Always an array, never undefined. */
|
|
35
|
+
perks: PerkRow[];
|
|
36
|
+
/** The ids the member claimed: the one piece of real state; everything else is derived from it. */
|
|
37
|
+
claimed: string[];
|
|
38
|
+
/** Derived: the line above the list. */
|
|
39
|
+
summary: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Your perks. Edit the copy, add or remove one: each needs a unique `id`. */
|
|
43
|
+
const CATALOG: ReadonlyArray<Omit<PerkRow, "status">> = [
|
|
44
|
+
{ id: "welcome", title: "Welcome offer", detail: "10% off your first order. Show this screen at checkout." },
|
|
45
|
+
{ id: "early", title: "Early access", detail: "Hear about new arrivals and events before anyone else." },
|
|
46
|
+
{ id: "birthday", title: "Birthday treat", detail: "A small gift from us in your birthday month." },
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
/** Recompute every derived field from `claimed`. Applied at the end of every action. */
|
|
50
|
+
function derive(claimed: readonly string[]): PerksState {
|
|
51
|
+
const kept = CATALOG.filter((perk) => claimed.includes(perk.id)).map((perk) => perk.id);
|
|
52
|
+
return {
|
|
53
|
+
claimed: kept,
|
|
54
|
+
perks: CATALOG.map((perk) => ({ ...perk, status: kept.includes(perk.id) ? "Claimed — tap to undo" : "Tap to claim" })),
|
|
55
|
+
summary: kept.length === 0
|
|
56
|
+
? "Claim a perk to use it on your next visit."
|
|
57
|
+
: `You've claimed ${kept.length} of ${CATALOG.length} perks.`,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const svc = defineService<PerksState, {
|
|
62
|
+
toggle: (s: PerksState, p?: { id?: unknown }) => PerksState;
|
|
63
|
+
}>("perks", {
|
|
64
|
+
state: derive([]),
|
|
65
|
+
actions: {
|
|
66
|
+
// The one action: claim a perk, or undo a claim. An unknown or missing id changes nothing.
|
|
67
|
+
toggle: (s, p) => {
|
|
68
|
+
const id = String(p?.id ?? "");
|
|
69
|
+
if (!CATALOG.some((perk) => perk.id === id)) return s;
|
|
70
|
+
return derive(s.claimed.includes(id) ? s.claimed.filter((c) => c !== id) : [...s.claimed, id]);
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
export { svc };
|