@wix/himalaya-cli 0.1839.0 → 0.1841.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/browser-plane/assets.json +5 -5
- package/dist/browser-plane/preview-deferred/{12b7dd1ca5ed350a30ed6a0085a4c31f30b46688e3795c425f145dfdd3830b31.bin → 36607933425d69130908d7a1dc25b580c1c0257cfa3d59194aa107b907a1d4a3.bin} +1 -1
- package/dist/browser-plane/sw.js +10 -10
- package/dist/cli.mjs +224 -103
- package/dist/preview-assets.generated.bin +0 -0
- package/package.json +2 -2
- package/templates/brandy/dev/index.ts +3 -0
- package/templates/brandy/tier5-src/himi-brandy-base44-account/index.ts +85 -14
|
@@ -60,6 +60,57 @@ interface AccountState {
|
|
|
60
60
|
hideConfirmDelete: boolean;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
/** What the user is typing as a secret. The screen's fields show these keys (`valuePath`), so a saved
|
|
64
|
+
* value would come back on the next launch, filled in and ready to submit again: never written to the
|
|
65
|
+
* device (`notPersisted`), never restored from an older build's snapshot (`notHydrated`). */
|
|
66
|
+
const SECRET_KEYS = ["password", "code"] as const;
|
|
67
|
+
type SecretKey = typeof SECRET_KEYS[number];
|
|
68
|
+
|
|
69
|
+
/** A host saves worker state through `__snapshotForPersistence`, which honours `notPersisted`. A
|
|
70
|
+
* binary built before it (Brandy and Himi Player shipped the Base44 capability first) saves the
|
|
71
|
+
* whole state, so there the secrets never enter state: they are held here, the fields stay at ""
|
|
72
|
+
* (a field takes the worker's value only when it changes, so typing is untouched), and those
|
|
73
|
+
* binaries keep the old uncleared fields rather than writing a password to the device. */
|
|
74
|
+
const FILTERS_PERSISTENCE =
|
|
75
|
+
typeof (globalThis as { himalaya?: { __snapshotForPersistence?: unknown } }).himalaya?.__snapshotForPersistence === "function";
|
|
76
|
+
const held: Record<SecretKey, string> = { password: "", code: "" };
|
|
77
|
+
/** Bumped on every edit and every send of a secret, so a clear that waited for a call can tell
|
|
78
|
+
* whether the user typed again in the meantime. */
|
|
79
|
+
const generation: Record<SecretKey, number> = { password: 0, code: 0 };
|
|
80
|
+
|
|
81
|
+
/** The typed secret, wherever this host keeps it. */
|
|
82
|
+
const secret = (s: AccountState, key: SecretKey): string => (FILTERS_PERSISTENCE ? s[key] : held[key]);
|
|
83
|
+
|
|
84
|
+
/** Record a typed secret: in state where the host filters it from the snapshot, else held here. */
|
|
85
|
+
function typed(s: AccountState, key: SecretKey, value: string): AccountState {
|
|
86
|
+
generation[key] += 1;
|
|
87
|
+
if (FILTERS_PERSISTENCE) return { ...s, [key]: value };
|
|
88
|
+
held[key] = value;
|
|
89
|
+
return s;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Forget a secret once it is sent, and empty its field. Where the secret was held outside state the
|
|
93
|
+
* field's value is already "", so writing "" again would not reach the field and the typed dots would
|
|
94
|
+
* stay: there it steps through a non-secret " " now and back to "" once the call settles
|
|
95
|
+
* (`clearAfter`), so the field sees a change and ends empty. */
|
|
96
|
+
function spent(s: AccountState, key: SecretKey): AccountState {
|
|
97
|
+
held[key] = "";
|
|
98
|
+
generation[key] += 1;
|
|
99
|
+
return { ...s, [key]: FILTERS_PERSISTENCE ? "" : " " };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Chain after a call that spent `key` (take it right after `spent`): empties the field `spent` left
|
|
103
|
+
* at " ". Run when the call settles, like `_signedIn` / `_failed`, never as the reducer returns: a
|
|
104
|
+
* host may not have stored that reducer's state yet, and a follow-up action then would act on the
|
|
105
|
+
* state before it. Skipped when the user typed again meanwhile: the field shows that new text and
|
|
106
|
+
* `held` has it, and the " " left in state is not secret and reaches no field (it did not change). */
|
|
107
|
+
function clearAfter(key: SecretKey): () => void {
|
|
108
|
+
const sent = generation[key];
|
|
109
|
+
return () => {
|
|
110
|
+
if (!FILTERS_PERSISTENCE && generation[key] === sent) acct._clearField(key);
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
63
114
|
const describe = (e: unknown): string =>
|
|
64
115
|
isBase44Error(e) ? (e.message || e.code) : e instanceof Error ? e.message : String(e);
|
|
65
116
|
|
|
@@ -110,6 +161,7 @@ const acct = defineService<AccountState, {
|
|
|
110
161
|
_failed: (s: AccountState, error?: string) => AccountState;
|
|
111
162
|
_failedRegister: (s: AccountState, message?: string) => AccountState;
|
|
112
163
|
_methods: (s: AccountState, password?: boolean, providers?: string[]) => AccountState;
|
|
164
|
+
_clearField: (s: AccountState, key?: string) => AccountState;
|
|
113
165
|
}>("himiBase44Account", {
|
|
114
166
|
state: derive({
|
|
115
167
|
signedIn: false,
|
|
@@ -138,6 +190,8 @@ const acct = defineService<AccountState, {
|
|
|
138
190
|
hideDelete: true,
|
|
139
191
|
hideConfirmDelete: true,
|
|
140
192
|
}),
|
|
193
|
+
notPersisted: [...SECRET_KEYS],
|
|
194
|
+
notHydrated: [...SECRET_KEYS],
|
|
141
195
|
actions: {
|
|
142
196
|
open: (s, p) => {
|
|
143
197
|
auth.status()
|
|
@@ -152,16 +206,19 @@ const acct = defineService<AccountState, {
|
|
|
152
206
|
},
|
|
153
207
|
|
|
154
208
|
setEmail: (s, p) => ({ ...s, email: String(p?.value ?? "") }),
|
|
155
|
-
setPassword: (s, p) => (
|
|
156
|
-
setCode: (s, p) => (
|
|
209
|
+
setPassword: (s, p) => typed(s, "password", String(p?.value ?? "")),
|
|
210
|
+
setCode: (s, p) => typed(s, "code", String(p?.value ?? "")),
|
|
157
211
|
usePassword: (s) => derive({ ...s, mode: "signIn", message: "" }),
|
|
158
212
|
|
|
159
213
|
signIn: (s) => {
|
|
160
|
-
|
|
161
|
-
|
|
214
|
+
const password = secret(s, "password");
|
|
215
|
+
if (!s.email || !password) return { ...s, error: "", message: "Enter your email and password." };
|
|
216
|
+
const next = spent(s, "password");
|
|
217
|
+
auth.loginViaEmailPassword(s.email, password)
|
|
162
218
|
.then(({ user }) => acct._signedIn(String(user?.email ?? s.email), "Signed in."))
|
|
163
|
-
.catch((e) => acct._failed(describe(e)))
|
|
164
|
-
|
|
219
|
+
.catch((e) => acct._failed(describe(e)))
|
|
220
|
+
.then(clearAfter("password"));
|
|
221
|
+
return { ...next, busy: true, error: "", message: "Signing in…" };
|
|
165
222
|
},
|
|
166
223
|
|
|
167
224
|
signInWith: (s, p) => {
|
|
@@ -177,20 +234,26 @@ const acct = defineService<AccountState, {
|
|
|
177
234
|
},
|
|
178
235
|
|
|
179
236
|
register: (s) => {
|
|
180
|
-
|
|
181
|
-
|
|
237
|
+
const password = secret(s, "password");
|
|
238
|
+
if (!s.email || !password) return { ...s, error: "", message: "Enter an email and a password to create an account." };
|
|
239
|
+
const next = spent(s, "password");
|
|
240
|
+
auth.register(s.email, password)
|
|
182
241
|
.then(() => acct._done("Check your email for a code to finish creating your account."))
|
|
183
242
|
// Back to the password form: the code form hides the fields a retry needs.
|
|
184
|
-
.catch((e) => acct._failedRegister(describe(e)))
|
|
185
|
-
|
|
243
|
+
.catch((e) => acct._failedRegister(describe(e)))
|
|
244
|
+
.then(clearAfter("password"));
|
|
245
|
+
return derive({ ...next, mode: "code", busy: true, error: "", message: "Creating your account…" });
|
|
186
246
|
},
|
|
187
247
|
|
|
188
248
|
verifyCode: (s) => {
|
|
189
|
-
|
|
190
|
-
|
|
249
|
+
const code = secret(s, "code");
|
|
250
|
+
if (!s.email || !code) return { ...s, error: "", message: "Enter your email and the code." };
|
|
251
|
+
const next = spent(s, "code");
|
|
252
|
+
auth.verifyOtp(s.email, code)
|
|
191
253
|
.then(({ user }) => acct._signedIn(String(user?.email ?? s.email), "Signed in."))
|
|
192
|
-
.catch((e) => acct._failed(describe(e)))
|
|
193
|
-
|
|
254
|
+
.catch((e) => acct._failed(describe(e)))
|
|
255
|
+
.then(clearAfter("code"));
|
|
256
|
+
return { ...next, busy: true, error: "", message: "Checking the code…" };
|
|
194
257
|
},
|
|
195
258
|
|
|
196
259
|
resetPassword: (s) => {
|
|
@@ -235,8 +298,16 @@ const acct = defineService<AccountState, {
|
|
|
235
298
|
// (Base44 still accepts it for users who set one) rather than an empty card.
|
|
236
299
|
return derive({ ...s, passwordEnabled: password !== false || list.length === 0, providers: list });
|
|
237
300
|
},
|
|
301
|
+
_clearField: (s, key) => ((SECRET_KEYS as readonly string[]).includes(String(key)) ? { ...s, [String(key)]: "" } : s),
|
|
238
302
|
_failedRegister: (s, error) => derive({ ...s, busy: false, mode: "signIn", message: "", error: String(error ?? "") }),
|
|
239
303
|
},
|
|
240
304
|
});
|
|
241
305
|
|
|
306
|
+
// A runtime that predates `notHydrated` has already laid the snapshot over the state: clear the
|
|
307
|
+
// secrets in place before any action runs (on those runtimes getState() IS the stored state).
|
|
308
|
+
if ((globalThis as { himalaya?: { hydrationOptOut?: unknown } }).himalaya?.hydrationOptOut !== true) {
|
|
309
|
+
const live = (acct as { getState?: () => AccountState | undefined }).getState?.();
|
|
310
|
+
if (live && typeof live === "object") for (const key of SECRET_KEYS) live[key] = "";
|
|
311
|
+
}
|
|
312
|
+
|
|
242
313
|
export default acct;
|