@wix/himalaya-cli 0.1852.0 → 0.1853.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/cli.mjs +95 -32
- package/guides/himi-json-output.md +8 -2
- package/guides/one-app-section-mappings.md +1 -1
- package/guides/one-app-to-himi-app.md +19 -6
- package/package.json +2 -2
- package/template-icons/bare-fashion.png +0 -0
- package/templates/bare-fashion/README.md +52 -0
- package/templates/bare-fashion/config.ts +474 -0
- package/templates/bare-fashion/dev/index.ts +16526 -0
- package/templates/bare-fashion/himalaya.content.json +70 -0
- package/templates/bare-fashion/himalaya.template.json +18 -0
- package/templates/bare-fashion/icon.png +0 -0
- package/templates/bare-fashion/platforms.json +3 -0
- package/templates/bare-fashion/tier5-src/_shared/app-locale.ts +70 -0
- package/templates/bare-fashion/tier5-src/_shared/bare-fashion-address-book.ts +116 -0
- package/templates/bare-fashion/tier5-src/_shared/bare-fashion-address-countries.ts +261 -0
- package/templates/bare-fashion/tier5-src/_shared/bare-fashion-bag-count.ts +24 -0
- package/templates/bare-fashion/tier5-src/_shared/bare-fashion-categories.ts +48 -0
- package/templates/bare-fashion/tier5-src/_shared/bare-fashion-facets.ts +265 -0
- package/templates/bare-fashion/tier5-src/_shared/bare-fashion-load-error.ts +38 -0
- package/templates/bare-fashion/tier5-src/_shared/bare-fashion-product-card.ts +136 -0
- package/templates/bare-fashion/tier5-src/_shared/bare-fashion-store-options.ts +129 -0
- package/templates/bare-fashion/tier5-src/_shared/branded-lite-hosted.ts +282 -0
- package/templates/bare-fashion/tier5-src/_shared/collection-contract.ts +228 -0
- package/templates/bare-fashion/tier5-src/_shared/collection-query.ts +201 -0
- package/templates/bare-fashion/tier5-src/_shared/collection-service.ts +429 -0
- package/templates/bare-fashion/tier5-src/_shared/engine-intl.ts +529 -0
- package/templates/bare-fashion/tier5-src/_shared/himi-account.ts +209 -0
- package/templates/bare-fashion/tier5-src/_shared/himi-copy.ts +123 -0
- package/templates/bare-fashion/tier5-src/_shared/himi-layouts.ts +142 -0
- package/templates/bare-fashion/tier5-src/_shared/himi-store-categories.ts +108 -0
- package/templates/bare-fashion/tier5-src/_shared/himi-store-saved.ts +57 -0
- package/templates/bare-fashion/tier5-src/_shared/himi-store.ts +7 -0
- package/templates/bare-fashion/tier5-src/_shared/himi-text.ts +24 -0
- package/templates/bare-fashion/tier5-src/_shared/hosted-checkout.ts +70 -0
- package/templates/bare-fashion/tier5-src/_shared/live-session.ts +172 -0
- package/templates/bare-fashion/tier5-src/_shared/local-preferences.ts +38 -0
- package/templates/bare-fashion/tier5-src/_shared/member-access.ts +63 -0
- package/templates/bare-fashion/tier5-src/_shared/member-avatar.ts +76 -0
- package/templates/bare-fashion/tier5-src/_shared/member-orders.ts +8 -0
- package/templates/bare-fashion/tier5-src/_shared/online-actions.ts +76 -0
- package/templates/bare-fashion/tier5-src/_shared/owner-load-error.ts +348 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-account/index.ts +127 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-address-form/index.ts +367 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-addresses/index.ts +202 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-appearance/index.ts +73 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-cart/index.ts +540 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-collection/index.ts +111 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-home/index.ts +241 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-nav/index.ts +56 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-order/index.ts +437 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-product/index.ts +650 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-products/index.ts +142 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-saved/index.ts +45 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-search/index.ts +199 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-shop/index.ts +79 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-sign-in/index.ts +269 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-wallet/index.ts +224 -0
- package/templates/bare-fashion/tier5-src/himi-branded-lite-info/index.ts +209 -0
- package/templates/bare-fashion/tier5-src/himi-branded-lite-orders/index.ts +327 -0
- package/templates/bare-fashion/tier5-src/wix-spaces-collections/index.ts +48 -0
- package/templates/bare-fashion/tier5-src/wix-spaces-delete-account/index.ts +59 -0
- package/templates/bare-fashion/tier5-src/wix-spaces-view-profile/index.ts +119 -0
- package/templates/bare-fashion/tokens.json +348 -0
- package/templates/beauty-salon/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/beauty-salon/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/beauty-salon-owner/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/beauty-salon-owner/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/branded-lite/recipes/upcoming-bookings.json +118 -6
- package/templates/branded-lite/tier5-src/_shared/collection-query-legacy.ts +7 -0
- package/templates/branded-lite/tier5-src/_shared/collection-query.ts +7 -0
- package/templates/branded-lite/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/branded-lite/tier5-src/_shared/events-inline-options.ts +55 -3
- package/templates/branded-lite/tier5-src/_shared/events-inline.ts +5 -3
- package/templates/branded-lite/tier5-src/_shared/upcoming-bookings-section.ts +15 -4
- package/templates/branded-lite/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/brandy/tier5-src/_shared/collection-query-legacy.ts +7 -0
- package/templates/brandy/tier5-src/_shared/collection-query.ts +7 -0
- package/templates/brandy/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/community-club/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/community-club/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/community-club/tier5-src/_shared/events-inline-options.ts +77 -0
- package/templates/community-club/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/community-club-owner/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/community-club-owner/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/conference/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/conference/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/conference/tier5-src/_shared/events-inline-options.ts +77 -0
- package/templates/conference/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/events-meetups/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/events-meetups/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/events-meetups/tier5-src/_shared/events-inline-options.ts +77 -0
- package/templates/events-meetups/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/events-meetups-owner/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/events-meetups-owner/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/fitness-gym/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/fitness-gym/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/gym-fitness/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/gym-fitness/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/gym-fitness/tier5-src/_shared/events-inline-options.ts +77 -0
- package/templates/gym-fitness/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/gym-fitness-owner/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/gym-fitness-owner/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/medical-services/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/medical-services/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/nonprofit-cause/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/nonprofit-cause/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/nonprofit-cause/tier5-src/_shared/events-inline-options.ts +77 -0
- package/templates/nonprofit-cause/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/nonprofit-cause-owner/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/nonprofit-cause-owner/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/owner-lite/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/owner-lite/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/personal-fitness-trainer/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/podcast-creator/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/podcast-creator/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/podcast-creator/tier5-src/_shared/events-inline-options.ts +77 -0
- package/templates/podcast-creator/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/podcast-creator-owner/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/podcast-creator-owner/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/portfolio-creative/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/portfolio-creative/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/portfolio-creative/tier5-src/_shared/events-inline-options.ts +77 -0
- package/templates/portfolio-creative/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/portfolio-creative-owner/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/portfolio-creative-owner/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/restaurant/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/restaurant/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/restaurant/tier5-src/_shared/events-inline-options.ts +77 -0
- package/templates/restaurant/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/restaurant-owner/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/restaurant-owner/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/retail-store/tier5-src/_shared/collection-query-legacy.ts +7 -0
- package/templates/retail-store/tier5-src/_shared/collection-query.ts +7 -0
- package/templates/retail-store/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/retail-store-owner/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/retail-store-owner/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/salon-spa/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/salon-spa/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/wholesale-store/tier5-src/_shared/collection-query-legacy.ts +7 -0
- package/templates/wholesale-store/tier5-src/_shared/collection-query.ts +7 -0
- package/templates/wholesale-store/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/yoga-studio/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/yoga-studio/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/yoga-studio/tier5-src/_shared/events-inline-options.ts +77 -0
- package/templates/yoga-studio/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/yoga-studio-owner/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/yoga-studio-owner/tier5-src/_shared/collection-service.ts +7 -1
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
// Tier-5 bundle: himi-store sign-in — the member sign-in, sign-up and password-reset form.
|
|
2
|
+
//
|
|
3
|
+
// The Account tab (himi-store-account) is a greeting and a menu. Its SIGN IN and CREATE
|
|
4
|
+
// ACCOUNT buttons open this screen with a `mode` param. A screen cannot bind to another
|
|
5
|
+
// screen's service, so the form lives in its own bundle. Both bundles read the session
|
|
6
|
+
// through `_shared/himi-account`. When a session starts, this worker leaves the screen: in
|
|
7
|
+
// place of itself to the screen the shopper asked for (`returnScreenId`, e.g. My orders),
|
|
8
|
+
// otherwise back to Account.
|
|
9
|
+
import { defineService, navigate } from "@himalaya/state";
|
|
10
|
+
import { dispatch } from "@himalaya/dispatch";
|
|
11
|
+
import { signedInEmail, strOf } from "../_shared/himi-account";
|
|
12
|
+
import { stashCopy, copyParam, copyTemplate } from "../_shared/himi-copy.js";
|
|
13
|
+
|
|
14
|
+
interface SignInRouteInput {
|
|
15
|
+
mode?: string;
|
|
16
|
+
intent?: string;
|
|
17
|
+
contextName?: string;
|
|
18
|
+
returnScreenId?: string;
|
|
19
|
+
returnId?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Open params land on `himalaya.input` (paramKeys on himi_sign_in). */
|
|
23
|
+
function routeInput(): SignInRouteInput {
|
|
24
|
+
const input = (globalThis as { himalaya?: { input?: SignInRouteInput } }).himalaya?.input;
|
|
25
|
+
return input && typeof input === "object" ? input : {};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function strField(arg: unknown, key: string): string {
|
|
29
|
+
if (!arg || typeof arg !== "object") return "";
|
|
30
|
+
const raw = (arg as Record<string, unknown>)[key];
|
|
31
|
+
return typeof raw === "string" ? raw.trim() : "";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Every open takes its params fresh — never the previous open's. A guest who backs out of
|
|
35
|
+
// "sign in to see your orders" and then taps SIGN IN must not land on My orders.
|
|
36
|
+
function routeFrom(arg: unknown): Pick<S, "authIntent" | "authContextName" | "returnScreenId" | "returnId" | "isRegistering" | "isRecovering"> {
|
|
37
|
+
const route = routeInput();
|
|
38
|
+
const mode = strField(arg, "mode") || route.mode || "";
|
|
39
|
+
return {
|
|
40
|
+
authIntent: strField(arg, "intent") || route.intent || "",
|
|
41
|
+
authContextName: strField(arg, "contextName") || route.contextName || "",
|
|
42
|
+
returnScreenId: strField(arg, "returnScreenId") || route.returnScreenId || "",
|
|
43
|
+
returnId: strField(arg, "returnId") || route.returnId || "",
|
|
44
|
+
isRegistering: mode === "register",
|
|
45
|
+
isRecovering: mode === "recovery",
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Next value of a focus token: monotonic, and never empty once requested. A counter
|
|
50
|
+
// rather than Date.now() — deterministic under test, and immune to two focus
|
|
51
|
+
// requests landing inside the same millisecond.
|
|
52
|
+
function bumpToken(t: string): string {
|
|
53
|
+
return String(Number(t || 0) + 1);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// A token may be cleared ONLY by a transition that unmounts the field it targets.
|
|
57
|
+
//
|
|
58
|
+
// A mode switch re-lays-out the form: the name fields (gated on notRegistering) go
|
|
59
|
+
// away, but Email is rendered in ALL three modes and stays mounted. Clearing
|
|
60
|
+
// `emailFocus` here would be a reset-while-mounted: Email's renderer-side "last token
|
|
61
|
+
// I acted on" survives, so the next bump would republish a value it has already seen
|
|
62
|
+
// and ignores — the Last name → Email chain would silently die after one round-trip.
|
|
63
|
+
const NO_FOCUS_MODE_SWITCH = { lastNameFocus: "" };
|
|
64
|
+
|
|
65
|
+
function authHeadline(s: S, isRegistering: boolean, isRecovering: boolean): { authTitle: string; authBody: string } {
|
|
66
|
+
if (isRecovering) {
|
|
67
|
+
return {
|
|
68
|
+
authTitle: copyParam("storeAccount.authTitleRecovery", "Reset password"),
|
|
69
|
+
authBody: copyParam("storeAccount.authBodyRecovery", "Enter your member email and we will send a reset link."),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
if (isRegistering) {
|
|
73
|
+
return {
|
|
74
|
+
authTitle: copyParam("storeAccount.authTitleRegister", "Create account"),
|
|
75
|
+
authBody: copyParam("storeAccount.authBodyRegister", "Create an account to keep your bag, your orders and your wishlist."),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
switch (s.authIntent) {
|
|
79
|
+
case "join_group":
|
|
80
|
+
return {
|
|
81
|
+
authTitle: copyParam("storeAccount.authTitleJoinGroup", "Sign in to join"),
|
|
82
|
+
authBody: s.authContextName
|
|
83
|
+
? copyTemplate("storeAccount.authBodyJoinGroupNamed", "Sign in to join {name}, then we’ll bring you back.", { name: s.authContextName })
|
|
84
|
+
: copyParam("storeAccount.authBodyJoinGroup", "Sign in to join this group, then we’ll bring you back."),
|
|
85
|
+
};
|
|
86
|
+
case "rsvp":
|
|
87
|
+
return {
|
|
88
|
+
authTitle: copyParam("storeAccount.authTitleRsvp", "Sign in to RSVP"),
|
|
89
|
+
authBody: copyParam("storeAccount.authBodyRsvp", "Sign in to RSVP, then we’ll bring you back."),
|
|
90
|
+
};
|
|
91
|
+
case "post":
|
|
92
|
+
return {
|
|
93
|
+
authTitle: copyParam("storeAccount.authTitlePost", "Sign in to post"),
|
|
94
|
+
authBody: copyParam("storeAccount.authBodyPost", "Sign in to join the conversation, then we’ll bring you back."),
|
|
95
|
+
};
|
|
96
|
+
default:
|
|
97
|
+
return {
|
|
98
|
+
authTitle: copyParam("storeAccount.authTitle", "Sign in"),
|
|
99
|
+
authBody: copyParam("storeAccount.authBody", "Sign in to keep your bag, your orders and your wishlist."),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
interface S {
|
|
105
|
+
authTitle: string;
|
|
106
|
+
authBody: string;
|
|
107
|
+
/** Mid-flow gate intent (`join_group` | `rsvp` | `post` | ""). */
|
|
108
|
+
authIntent: string;
|
|
109
|
+
authContextName: string;
|
|
110
|
+
/** Where to go once signed in. Empty: back to Account. */
|
|
111
|
+
returnScreenId: string;
|
|
112
|
+
returnId: string;
|
|
113
|
+
email: string;
|
|
114
|
+
password: string;
|
|
115
|
+
firstName: string;
|
|
116
|
+
lastName: string;
|
|
117
|
+
// Focus TOKENS (`TextFieldProps.focus_path`), not flags: the bound field focuses
|
|
118
|
+
// whenever the token becomes a new non-empty value, so a monotonic counter is the
|
|
119
|
+
// shape — a latched boolean cannot request focus a second time. Every other
|
|
120
|
+
// transition here goes through derive({...s}), which carries them, and they are
|
|
121
|
+
// deliberately never reset: re-publishing a token the renderer has already seen
|
|
122
|
+
// is ignored, which would make the Next key go dead.
|
|
123
|
+
lastNameFocus: string;
|
|
124
|
+
emailFocus: string;
|
|
125
|
+
message: string;
|
|
126
|
+
/** What `message` is: a failure ("error"), the reset-link note ("success"), or nothing (""). */
|
|
127
|
+
messageKind: "" | "error" | "success";
|
|
128
|
+
isRegistering: boolean;
|
|
129
|
+
notRegistering: boolean;
|
|
130
|
+
isRecovering: boolean;
|
|
131
|
+
notRecovering: boolean;
|
|
132
|
+
hideSignInChoices: boolean;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function derive(s: S): S {
|
|
136
|
+
const isRegistering = !!s.isRegistering;
|
|
137
|
+
const isRecovering = !!s.isRecovering;
|
|
138
|
+
const headline = authHeadline(s, isRegistering, isRecovering);
|
|
139
|
+
return {
|
|
140
|
+
...s,
|
|
141
|
+
isRegistering,
|
|
142
|
+
notRegistering: !isRegistering,
|
|
143
|
+
isRecovering,
|
|
144
|
+
notRecovering: !isRecovering,
|
|
145
|
+
hideSignInChoices: isRegistering || isRecovering,
|
|
146
|
+
authTitle: headline.authTitle,
|
|
147
|
+
authBody: headline.authBody,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function opened(s: S, arg?: unknown): S {
|
|
152
|
+
stashCopy(arg);
|
|
153
|
+
return derive({ ...s, ...routeFrom(arg), password: "", message: "", messageKind: "", ...NO_FOCUS_MODE_SWITCH });
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** A session has started: open the screen the shopper asked for, else go back to Account. */
|
|
157
|
+
function leave(s: S): S {
|
|
158
|
+
const done = derive({ ...s, password: "", message: "", messageKind: "" });
|
|
159
|
+
if (s.returnScreenId) {
|
|
160
|
+
return navigate(done, {
|
|
161
|
+
screenId: s.returnScreenId,
|
|
162
|
+
...(s.returnId ? { args: { id: s.returnId } } : {}),
|
|
163
|
+
presentation: "replace",
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
return navigate(done, { presentation: "back" });
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const svc = defineService<S, {
|
|
170
|
+
load: (s: S, arg?: unknown) => S;
|
|
171
|
+
setEmail: (s: S, arg?: unknown) => S;
|
|
172
|
+
setPassword: (s: S, arg?: unknown) => S;
|
|
173
|
+
setFirstName: (s: S, arg?: unknown) => S;
|
|
174
|
+
setLastName: (s: S, arg?: unknown) => S;
|
|
175
|
+
focusLastName: (s: S) => S;
|
|
176
|
+
focusEmail: (s: S) => S;
|
|
177
|
+
showRegister: (s: S) => S;
|
|
178
|
+
showSignIn: (s: S) => S;
|
|
179
|
+
showRecovery: (s: S) => S;
|
|
180
|
+
resetPassword: (s: S) => Promise<S>;
|
|
181
|
+
signIn: (s: S) => Promise<S>;
|
|
182
|
+
register: (s: S) => Promise<S>;
|
|
183
|
+
}>("bareFashionSignIn", {
|
|
184
|
+
state: derive({
|
|
185
|
+
authTitle: "Sign in",
|
|
186
|
+
authBody: "Sign in to keep your bag, your orders and your wishlist.",
|
|
187
|
+
authIntent: "",
|
|
188
|
+
authContextName: "",
|
|
189
|
+
returnScreenId: "",
|
|
190
|
+
returnId: "",
|
|
191
|
+
email: "",
|
|
192
|
+
password: "",
|
|
193
|
+
firstName: "",
|
|
194
|
+
lastName: "",
|
|
195
|
+
lastNameFocus: "",
|
|
196
|
+
emailFocus: "",
|
|
197
|
+
message: "", messageKind: "",
|
|
198
|
+
isRegistering: false,
|
|
199
|
+
notRegistering: true,
|
|
200
|
+
isRecovering: false,
|
|
201
|
+
notRecovering: true,
|
|
202
|
+
hideSignInChoices: false,
|
|
203
|
+
}),
|
|
204
|
+
actions: {
|
|
205
|
+
load: (s, arg) => opened(s, arg),
|
|
206
|
+
setEmail: (s, arg) => derive({ ...s, email: strOf(arg), message: "", messageKind: "" }),
|
|
207
|
+
setPassword: (s, arg) => derive({ ...s, password: strOf(arg), message: "", messageKind: "" }),
|
|
208
|
+
setFirstName: (s, arg) => derive({ ...s, firstName: strOf(arg), message: "", messageKind: "" }),
|
|
209
|
+
setLastName: (s, arg) => derive({ ...s, lastName: strOf(arg), message: "", messageKind: "" }),
|
|
210
|
+
// The register form's Next keys. Only first/last name carry one: they share a
|
|
211
|
+
// single visibility gate (notRegistering) so their target is always on screen.
|
|
212
|
+
// Email deliberately does NOT chain to password — see the comment on the
|
|
213
|
+
// descriptor: password is hidden while recovering, and submitLabel is static.
|
|
214
|
+
focusLastName: (s) => derive({ ...s, lastNameFocus: bumpToken(s.lastNameFocus) }),
|
|
215
|
+
focusEmail: (s) => derive({ ...s, emailFocus: bumpToken(s.emailFocus) }),
|
|
216
|
+
// A mode switch RE-LAYS-OUT the form, mounting and unmounting fields behind
|
|
217
|
+
// `hiddenWhen`. A re-mounted field treats its first seed as "focus me on open", so
|
|
218
|
+
// a carried-over token would drop the user into the MIDDLE of the form — leaving
|
|
219
|
+
// register and coming back would open focused on Last name, skipping First name.
|
|
220
|
+
// Only the tokens whose fields actually unmount here are cleared: see
|
|
221
|
+
// NO_FOCUS_MODE_SWITCH for why Email's is deliberately NOT among them.
|
|
222
|
+
showRegister: (s) => derive({ ...s, isRegistering: true, isRecovering: false, message: "", messageKind: "", ...NO_FOCUS_MODE_SWITCH }),
|
|
223
|
+
showSignIn: (s) => derive({ ...s, isRegistering: false, isRecovering: false, message: "", messageKind: "", ...NO_FOCUS_MODE_SWITCH }),
|
|
224
|
+
showRecovery: (s) => derive({ ...s, isRegistering: false, isRecovering: true, password: "", message: "", messageKind: "", ...NO_FOCUS_MODE_SWITCH }),
|
|
225
|
+
resetPassword: async (s) => {
|
|
226
|
+
const email = s.email.trim();
|
|
227
|
+
if (!email || !email.includes("@")) return derive({ ...s, message: copyParam("storeAccount.validationEmail", "Enter a valid email address."), messageKind: "error" });
|
|
228
|
+
try {
|
|
229
|
+
await dispatch("himi.wix.resetPassword", { email });
|
|
230
|
+
return derive({
|
|
231
|
+
...s,
|
|
232
|
+
email,
|
|
233
|
+
isRecovering: false,
|
|
234
|
+
message: copyParam("storeAccount.resetSent", "If that email is registered, a reset link is on its way."), messageKind: "success",
|
|
235
|
+
});
|
|
236
|
+
} catch {
|
|
237
|
+
return derive({ ...s, message: copyParam("storeAccount.resetFailed", "Reset email could not be sent. Try again."), messageKind: "error" });
|
|
238
|
+
}
|
|
239
|
+
},
|
|
240
|
+
signIn: async (s) => {
|
|
241
|
+
if (!s.email || !s.password) return derive({ ...s, message: copyParam("storeAccount.validationEmailPassword", "Enter your email and password."), messageKind: "error" });
|
|
242
|
+
try {
|
|
243
|
+
await dispatch("himi.wix.signInDirect", { email: s.email, password: s.password });
|
|
244
|
+
} catch {
|
|
245
|
+
return derive({ ...s, message: copyParam("storeAccount.signInFailed", "Sign in failed. Try again."), messageKind: "error" });
|
|
246
|
+
}
|
|
247
|
+
if (!(await signedInEmail())) return derive({ ...s, message: copyParam("storeAccount.signInCheckDetails", "Sign in failed. Check your details."), messageKind: "error" });
|
|
248
|
+
return leave(s);
|
|
249
|
+
},
|
|
250
|
+
register: async (s) => {
|
|
251
|
+
if (!s.email || !s.password) return derive({ ...s, message: copyParam("storeAccount.validationEmailPassword", "Enter your email and password."), messageKind: "error" });
|
|
252
|
+
try {
|
|
253
|
+
await dispatch("himi.wix.registerDirect", {
|
|
254
|
+
email: s.email,
|
|
255
|
+
password: s.password,
|
|
256
|
+
firstName: s.firstName,
|
|
257
|
+
lastName: s.lastName,
|
|
258
|
+
});
|
|
259
|
+
} catch {
|
|
260
|
+
return derive({ ...s, message: copyParam("storeAccount.registerFailed", "Account creation failed. Try another email."), messageKind: "error" });
|
|
261
|
+
}
|
|
262
|
+
if (!(await signedInEmail())) return derive({ ...s, message: copyParam("storeAccount.registerTrySignIn", "Account creation failed. Try signing in."), messageKind: "error" });
|
|
263
|
+
return leave(s);
|
|
264
|
+
},
|
|
265
|
+
},
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
svc.load();
|
|
269
|
+
export { svc };
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
// Tier-5 bundle: himi-store-wallet — My wallet, the member's saved payment methods.
|
|
2
|
+
//
|
|
3
|
+
// Same jobs as the site's My Wallet page (Wix Payments, payments-my-wallet): list the
|
|
4
|
+
// saved cards and PayPal accounts (the default first, with a Default badge), set the
|
|
5
|
+
// default, and remove one after a confirmation. Copy is the site's own wallet text.
|
|
6
|
+
// There is no "Add payment method": a card is saved at Wix checkout. The app reads only the
|
|
7
|
+
// brand, the last four digits, the holder and the expiry date — never a card number.
|
|
8
|
+
import { defineService, navigate } from "@himalaya/state";
|
|
9
|
+
import { wixCall } from "@himalaya/wix-ecom";
|
|
10
|
+
import { signedInEmail } from "../_shared/himi-account.js";
|
|
11
|
+
import { errorFlags, errorKindOf, type ErrorKind } from "../_shared/bare-fashion-load-error.js";
|
|
12
|
+
|
|
13
|
+
const BASE = "/payments/saved-payment-methods/v1/saved-payment-methods";
|
|
14
|
+
|
|
15
|
+
interface SavedPaymentMethod {
|
|
16
|
+
id?: string;
|
|
17
|
+
primary?: boolean;
|
|
18
|
+
paymentMethod?: {
|
|
19
|
+
typeId?: string;
|
|
20
|
+
paymentMethodTypeId?: string;
|
|
21
|
+
paymentMethodBrandId?: string;
|
|
22
|
+
cardInfo?: { lastFourDigits?: string; expirationMonth?: number; expirationYear?: number; cardholderName?: string; brand?: string };
|
|
23
|
+
accountInfo?: { email?: string; accountHolder?: string };
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Brand ids Wix Payments uses, to the names Wix shows. Unknown ids are title-cased. */
|
|
28
|
+
const BRANDS: Record<string, string> = {
|
|
29
|
+
visa: "Visa", mastercard: "Mastercard", amex: "American Express", americanexpress: "American Express",
|
|
30
|
+
discover: "Discover", jcb: "JCB", diners: "Diners Club", dinersclub: "Diners Club", unionpay: "UnionPay",
|
|
31
|
+
maestro: "Maestro", elo: "Elo", hipercard: "Hipercard", cartesbancaires: "Cartes Bancaires", rupay: "RuPay",
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// Remove and Set as default run in two steps on one host `_poll` (a worker has no timer),
|
|
35
|
+
// like Add to bag on the product screen. The latch lives at module scope, so a second tap
|
|
36
|
+
// or a restored state never writes twice.
|
|
37
|
+
const OP_POLL = { id: "himi-wallet-op", intervalMs: 1000, action: "bareFashionWallet.tick" };
|
|
38
|
+
let pending: { kind: "remove" | "default"; id: string } | null = null;
|
|
39
|
+
|
|
40
|
+
interface Row {
|
|
41
|
+
id: string;
|
|
42
|
+
title: string;
|
|
43
|
+
holder: string;
|
|
44
|
+
expiry: string;
|
|
45
|
+
isExpired: boolean;
|
|
46
|
+
notExpired: boolean;
|
|
47
|
+
isDefault: boolean;
|
|
48
|
+
notDefault: boolean;
|
|
49
|
+
hideSetDefault: boolean;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
interface S {
|
|
53
|
+
status: "loading" | "ready" | "error" | "signedOut";
|
|
54
|
+
rows: Row[];
|
|
55
|
+
message: string;
|
|
56
|
+
confirmId: string;
|
|
57
|
+
confirmOpen: boolean;
|
|
58
|
+
confirmText: string;
|
|
59
|
+
busy: boolean;
|
|
60
|
+
notBusy: boolean;
|
|
61
|
+
removeLabel: string;
|
|
62
|
+
hideLoading: boolean;
|
|
63
|
+
hideList: boolean;
|
|
64
|
+
hideEmpty: boolean;
|
|
65
|
+
hideError: boolean;
|
|
66
|
+
/** Why the last load failed: the error state shows the offline or the server variant. */
|
|
67
|
+
errorKind?: ErrorKind;
|
|
68
|
+
hideOfflineError?: boolean;
|
|
69
|
+
hideServerError?: boolean;
|
|
70
|
+
hideSignedOut: boolean;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function titleCase(v: string): string {
|
|
74
|
+
return v.replace(/[_-]+/g, " ").replace(/\b\w/g, (c) => c.toUpperCase());
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function brandName(pm: NonNullable<SavedPaymentMethod["paymentMethod"]>): string {
|
|
78
|
+
const raw = String(pm.paymentMethodBrandId || pm.cardInfo?.brand || "").trim();
|
|
79
|
+
const key = raw.toLowerCase().replace(/[^a-z]/g, "");
|
|
80
|
+
return BRANDS[key] ?? (raw ? titleCase(raw) : "");
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function pad2(n: number): string {
|
|
84
|
+
return n < 10 ? `0${n}` : String(n);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** One saved method → one row. `now` comes from the action, never from boot state. */
|
|
88
|
+
function toRow(m: SavedPaymentMethod, now: Date): Row | null {
|
|
89
|
+
const pm = m.paymentMethod;
|
|
90
|
+
if (!m.id || !pm) return null;
|
|
91
|
+
const isPayPal = pm.typeId === "payPal" || !!pm.accountInfo?.email;
|
|
92
|
+
const isDefault = m.primary === true;
|
|
93
|
+
let title: string;
|
|
94
|
+
let holder = "";
|
|
95
|
+
let expiry = "";
|
|
96
|
+
let isExpired = false;
|
|
97
|
+
if (isPayPal) {
|
|
98
|
+
const email = pm.accountInfo?.email ?? "";
|
|
99
|
+
title = email ? `PayPal (${email})` : "PayPal";
|
|
100
|
+
if (pm.accountInfo?.accountHolder) holder = `Account holder: ${pm.accountInfo.accountHolder}`;
|
|
101
|
+
} else {
|
|
102
|
+
const card = pm.cardInfo ?? {};
|
|
103
|
+
const name = brandName(pm) || "Credit card";
|
|
104
|
+
title = card.lastFourDigits ? `${name} (${card.lastFourDigits})` : name;
|
|
105
|
+
if (card.cardholderName) holder = `Cardholder: ${card.cardholderName}`;
|
|
106
|
+
const month = Number(card.expirationMonth);
|
|
107
|
+
const year = Number(card.expirationYear);
|
|
108
|
+
if (month >= 1 && month <= 12 && year > 0) {
|
|
109
|
+
const thisMonth = now.getMonth() + 1;
|
|
110
|
+
const thisYear = now.getFullYear();
|
|
111
|
+
isExpired = year === thisYear ? month < thisMonth : year < thisYear;
|
|
112
|
+
expiry = `Expiration date: ${pad2(month)}/${String(year).slice(-2)}${isExpired ? " (Expired)" : ""}`;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return { id: m.id, title, holder, expiry, isExpired, notExpired: !isExpired, isDefault, notDefault: !isDefault, hideSetDefault: isDefault };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function derive(s: S): S {
|
|
119
|
+
const has = s.rows.length > 0;
|
|
120
|
+
return {
|
|
121
|
+
...s,
|
|
122
|
+
confirmOpen: !!s.confirmId,
|
|
123
|
+
notBusy: !s.busy,
|
|
124
|
+
removeLabel: s.busy && !!s.confirmId ? "REMOVING…" : "REMOVE PAYMENT METHOD",
|
|
125
|
+
hideLoading: s.status !== "loading",
|
|
126
|
+
hideList: s.status !== "ready" || !has,
|
|
127
|
+
hideEmpty: s.status !== "ready" || has,
|
|
128
|
+
hideError: s.status !== "error",
|
|
129
|
+
...errorFlags(s.status, s.errorKind),
|
|
130
|
+
hideSignedOut: s.status !== "signedOut",
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async function fetchRows(s: S, message = ""): Promise<S> {
|
|
135
|
+
if (!(await signedInEmail())) return derive({ ...s, status: "signedOut", rows: [], message: "" });
|
|
136
|
+
try {
|
|
137
|
+
const res = await wixCall<{ savedPaymentMethods?: SavedPaymentMethod[] }>("GET", `${BASE}?siteMemberId=me`);
|
|
138
|
+
const now = new Date();
|
|
139
|
+
const rows = (res?.savedPaymentMethods ?? []).map((m) => toRow(m, now)).filter((r): r is Row => !!r);
|
|
140
|
+
// The site lists the default method first.
|
|
141
|
+
rows.sort((a, b) => Number(b.isDefault) - Number(a.isDefault));
|
|
142
|
+
return derive({ ...s, status: "ready", rows, message });
|
|
143
|
+
} catch (e) {
|
|
144
|
+
return derive({ ...s, status: "error", errorKind: errorKindOf(e), message: "" });
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
async function commitRemove(s: S, id: string): Promise<S> {
|
|
149
|
+
try {
|
|
150
|
+
await wixCall("DELETE", `${BASE}/${encodeURIComponent(id)}`);
|
|
151
|
+
return fetchRows(derive({ ...s, confirmId: "", busy: false }), "Payment method removed.");
|
|
152
|
+
} catch {
|
|
153
|
+
return derive({ ...s, confirmId: "", busy: false,
|
|
154
|
+
message: "We couldn't remove your payment method due to a technical issue on our side. Try again." });
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async function commitDefault(s: S, id: string): Promise<S> {
|
|
159
|
+
try {
|
|
160
|
+
// The site's client calls this with GET and falls back to POST; do the same.
|
|
161
|
+
const path = `${BASE}/${encodeURIComponent(id)}/mark-primary`;
|
|
162
|
+
try { await wixCall("GET", path); } catch { await wixCall("POST", path, { savedPaymentMethodId: id }); }
|
|
163
|
+
return fetchRows(derive({ ...s, busy: false }));
|
|
164
|
+
} catch {
|
|
165
|
+
return derive({ ...s, busy: false, message: "We couldn't save the changes to your default payment method. Try again." });
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function idOf(arg: unknown): string {
|
|
170
|
+
const id = arg && typeof arg === "object" ? (arg as { id?: unknown }).id : arg;
|
|
171
|
+
return typeof id === "string" ? id : "";
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const svc = defineService<S, {
|
|
175
|
+
load: (s: S) => Promise<S>;
|
|
176
|
+
retry: (s: S) => Promise<S>;
|
|
177
|
+
tick: (s: S) => Promise<S | undefined>;
|
|
178
|
+
askRemove: (s: S, arg?: unknown) => S;
|
|
179
|
+
cancelRemove: (s: S) => S;
|
|
180
|
+
confirmRemove: (s: S) => S | undefined;
|
|
181
|
+
setDefault: (s: S, arg?: unknown) => S | undefined;
|
|
182
|
+
signIn: (s: S) => S;
|
|
183
|
+
}>("bareFashionWallet", {
|
|
184
|
+
state: derive({
|
|
185
|
+
status: "loading", rows: [], message: "", confirmId: "", confirmOpen: false, confirmText: "",
|
|
186
|
+
busy: false, notBusy: true, removeLabel: "REMOVE PAYMENT METHOD",
|
|
187
|
+
hideLoading: false, hideList: true, hideEmpty: true, hideError: true, hideSignedOut: true,
|
|
188
|
+
}),
|
|
189
|
+
actions: {
|
|
190
|
+
load: (s) => fetchRows(s),
|
|
191
|
+
retry: (s) => fetchRows(derive({ ...s, status: "loading" })),
|
|
192
|
+
tick: async (s) => {
|
|
193
|
+
if (pending) {
|
|
194
|
+
const op = pending;
|
|
195
|
+
pending = null;
|
|
196
|
+
return op.kind === "remove" ? commitRemove(s, op.id) : commitDefault(s, op.id);
|
|
197
|
+
}
|
|
198
|
+
// A busy state with no write behind it (a torn-down worker) must not stick.
|
|
199
|
+
return s.busy ? derive({ ...s, busy: false }) : undefined;
|
|
200
|
+
},
|
|
201
|
+
askRemove: (s, arg) => {
|
|
202
|
+
const row = s.rows.find((r) => r.id === idOf(arg));
|
|
203
|
+
if (!row || s.busy) return s;
|
|
204
|
+
return derive({ ...s, message: "", confirmId: row.id,
|
|
205
|
+
confirmText: `Once removed, ${row.title} will no longer be saved for faster checkout. You can save it again at any time.` });
|
|
206
|
+
},
|
|
207
|
+
cancelRemove: (s) => (s.busy ? s : derive({ ...s, confirmId: "" })),
|
|
208
|
+
confirmRemove: (s) => {
|
|
209
|
+
if (!s.confirmId || s.busy) return undefined;
|
|
210
|
+
pending = { kind: "remove", id: s.confirmId };
|
|
211
|
+
return { ...derive({ ...s, busy: true }), _poll: { ...OP_POLL, immediate: true } } as S;
|
|
212
|
+
},
|
|
213
|
+
setDefault: (s, arg) => {
|
|
214
|
+
const id = idOf(arg);
|
|
215
|
+
if (!id || s.busy) return undefined;
|
|
216
|
+
pending = { kind: "default", id };
|
|
217
|
+
return { ...derive({ ...s, busy: true, message: "" }), _poll: { ...OP_POLL, immediate: true } } as S;
|
|
218
|
+
},
|
|
219
|
+
signIn: (s) => navigate(s, { screenId: "himi_sign_in", args: { mode: "signin", returnScreenId: "himi_wallet" } }),
|
|
220
|
+
},
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
svc.load();
|
|
224
|
+
export { svc };
|