@wix/himalaya-cli 0.1796.0 → 0.1798.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/sdk/base44/src/index.d.ts +14 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/sdk-types/src/capabilities.generated.d.ts +1 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/online-programs/src/index.d.ts +6 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/audio-record.mjs +1 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/base44.mjs +6 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/calendar.mjs +1 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/calls.mjs +1 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/contacts.mjs +1 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/location.mjs +1 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/motion.mjs +1 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/photos.mjs +1 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/sdk-types.mjs +1 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/tasks.mjs +1 -1
- package/dist/browser-plane/assets.json +5 -5
- package/dist/browser-plane/preview-deferred/{04eac2ea24e0edfcc5aaa757dc5d06c6bf35c3c5ce9ccbb448b305db05715492.bin → 7838236432e18e6d8b08481d145add5e31d7bfe9573403d3365e141f749e13ff.bin} +1 -1
- package/dist/browser-plane/sw.js +6 -6
- package/dist/cli.mjs +44 -43
- package/dist/preview-assets.generated.bin +0 -0
- package/guides/sdk-reference.json +11 -4
- package/guides/web-page-sdk-reference.md +1 -1
- package/package.json +2 -2
- package/templates/beauty-salon/l10n/en.json +1 -1
- package/templates/branded-lite/dev/index.ts +483 -0
- package/templates/branded-lite/l10n/ar.json +66 -0
- package/templates/branded-lite/l10n/cs.json +66 -0
- package/templates/branded-lite/l10n/da.json +66 -0
- package/templates/branded-lite/l10n/de.json +66 -0
- package/templates/branded-lite/l10n/el.json +66 -0
- package/templates/branded-lite/l10n/en.json +8 -1
- package/templates/branded-lite/l10n/es.json +66 -0
- package/templates/branded-lite/l10n/fi.json +66 -0
- package/templates/branded-lite/l10n/fr.json +66 -0
- package/templates/branded-lite/l10n/he.json +53 -0
- package/templates/branded-lite/l10n/hu.json +66 -0
- package/templates/branded-lite/l10n/id.json +66 -0
- package/templates/branded-lite/l10n/it.json +66 -0
- package/templates/branded-lite/l10n/ja.json +66 -0
- package/templates/branded-lite/l10n/ko.json +66 -0
- package/templates/branded-lite/l10n/lt.json +66 -0
- package/templates/branded-lite/l10n/nl.json +66 -0
- package/templates/branded-lite/l10n/no.json +66 -0
- package/templates/branded-lite/l10n/pl.json +66 -0
- package/templates/branded-lite/l10n/pt.json +66 -0
- package/templates/branded-lite/l10n/ru.json +66 -0
- package/templates/branded-lite/l10n/sv.json +66 -0
- package/templates/branded-lite/l10n/th.json +66 -0
- package/templates/branded-lite/l10n/tr.json +66 -0
- package/templates/branded-lite/l10n/uk.json +66 -0
- package/templates/branded-lite/l10n/vi.json +66 -0
- package/templates/branded-lite/l10n/zh.json +66 -0
- package/templates/branded-lite/tier5-src/himi-branded-lite-program-step/index.ts +396 -14
- package/templates/branded-lite/tier5-src/himi-branded-lite-program-step/quiz.ts +114 -0
- package/templates/brandy/dev/index.ts +109 -19
- package/templates/brandy/tier5-src/himi-brandy-base44-account/index.ts +70 -15
- package/templates/community-club/l10n/en.json +1 -1
- package/templates/events-meetups/l10n/en.json +1 -1
- package/templates/gym-fitness/l10n/en.json +1 -1
- package/templates/nonprofit-cause/l10n/en.json +1 -1
- package/templates/podcast-creator/l10n/en.json +1 -1
- package/templates/portfolio-creative/l10n/en.json +1 -1
- package/templates/restaurant/l10n/en.json +1 -1
- package/templates/retail-store/l10n/en.json +1 -1
- package/templates/yoga-studio/dev/index.ts +483 -0
- package/templates/yoga-studio/l10n/ar.json +66 -0
- package/templates/yoga-studio/l10n/cs.json +66 -0
- package/templates/yoga-studio/l10n/da.json +66 -0
- package/templates/yoga-studio/l10n/de.json +66 -0
- package/templates/yoga-studio/l10n/el.json +66 -0
- package/templates/yoga-studio/l10n/en.json +8 -1
- package/templates/yoga-studio/l10n/es.json +66 -0
- package/templates/yoga-studio/l10n/fi.json +66 -0
- package/templates/yoga-studio/l10n/fr.json +66 -0
- package/templates/yoga-studio/l10n/he.json +53 -0
- package/templates/yoga-studio/l10n/hu.json +66 -0
- package/templates/yoga-studio/l10n/id.json +66 -0
- package/templates/yoga-studio/l10n/it.json +66 -0
- package/templates/yoga-studio/l10n/ja.json +66 -0
- package/templates/yoga-studio/l10n/ko.json +66 -0
- package/templates/yoga-studio/l10n/lt.json +66 -0
- package/templates/yoga-studio/l10n/nl.json +66 -0
- package/templates/yoga-studio/l10n/no.json +66 -0
- package/templates/yoga-studio/l10n/pl.json +66 -0
- package/templates/yoga-studio/l10n/pt.json +66 -0
- package/templates/yoga-studio/l10n/ru.json +66 -0
- package/templates/yoga-studio/l10n/sv.json +66 -0
- package/templates/yoga-studio/l10n/th.json +66 -0
- package/templates/yoga-studio/l10n/tr.json +66 -0
- package/templates/yoga-studio/l10n/uk.json +66 -0
- package/templates/yoga-studio/l10n/vi.json +66 -0
- package/templates/yoga-studio/l10n/zh.json +66 -0
- package/templates/yoga-studio/tier5-src/_shared/branded-form.ts +321 -0
- package/templates/yoga-studio/tier5-src/himi-branded-lite-program-step/index.ts +396 -14
- package/templates/yoga-studio/tier5-src/himi-branded-lite-program-step/quiz.ts +114 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// The quiz of a QUIZ step: what the member answers, what is sent, and what the answer said.
|
|
2
|
+
//
|
|
3
|
+
// A program quiz is a Wix Forms form in the namespace `wix.achievements.quizzes.v1.quiz`, and the
|
|
4
|
+
// quiz id (the step's `quizOptions.id`) IS the form id. GET /online-programs/v1/quizzes/{id} is
|
|
5
|
+
// app-identity only (a member gets an empty 403), but the member reads the form itself
|
|
6
|
+
// (`@himalaya/wix-forms` getForm): its questions, their options, and the quiz settings in
|
|
7
|
+
// `extendedFields.namespaces["@achievements/quizzes"].settings` — never the right answers, which the
|
|
8
|
+
// server strips. Verified on amit1, 2026-11-19.
|
|
9
|
+
//
|
|
10
|
+
// The questions are ordinary Wix Forms fields with QUIZ_* identifiers, so the shared form parser
|
|
11
|
+
// (branded-form.ts) reads them once each identifier is mapped to the plain field it is drawn as.
|
|
12
|
+
// A question the app cannot fill (a file upload, an image choice) makes the quiz "unsupported":
|
|
13
|
+
// the step then opens on the website, as before the app took quizzes.
|
|
14
|
+
// Pure: no SDK import, so a node test drives it without a worker.
|
|
15
|
+
import { localProblems, parseForm, submissionValues, type FieldValue, type FormFieldModel } from "../_shared/branded-form.js";
|
|
16
|
+
|
|
17
|
+
export interface QuizModel {
|
|
18
|
+
id: string;
|
|
19
|
+
questions: FormFieldModel[];
|
|
20
|
+
/** The percent a member needs to pass; 0 when the quiz sets none. */
|
|
21
|
+
passingGrade: number;
|
|
22
|
+
/** How many tries the quiz allows; 0 = no limit. The site counts them, the app cannot read the count. */
|
|
23
|
+
attempts: number;
|
|
24
|
+
/** A question the app cannot fill: the quiz is taken on the website. */
|
|
25
|
+
unsupported: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
type Obj = Record<string, unknown>;
|
|
29
|
+
const obj = (v: unknown): Obj => (v && typeof v === "object" && !Array.isArray(v) ? v as Obj : {});
|
|
30
|
+
const num = (v: unknown): number => (typeof v === "number" && Number.isFinite(v) && v > 0 ? v : 0);
|
|
31
|
+
|
|
32
|
+
/** The plain identifier each quiz component is drawn as. A component not listed here is unsupported. */
|
|
33
|
+
const PLAIN_IDENTIFIER: Record<string, string> = {
|
|
34
|
+
RADIO_GROUP: "RADIO_GROUP", CHECKBOX_GROUP: "CHECKBOX_GROUP", TEXT_INPUT: "TEXT_INPUT", TEXT_AREA: "TEXT_AREA", NUMBER_INPUT: "NUMBER_INPUT",
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const DRAWN_KINDS: ReadonlySet<FormFieldModel["kind"]> = new Set(["choice", "multi", "text", "area", "number"]);
|
|
38
|
+
|
|
39
|
+
/** The `<inputType>Options.componentType` of a field: RADIO_GROUP for a single choice, CHECKBOX_GROUP for a multi choice, … */
|
|
40
|
+
function componentType(field: Obj): string {
|
|
41
|
+
const input = obj(field.inputOptions);
|
|
42
|
+
const type = String(input.inputType ?? "").toLowerCase().replace(/_([a-z])/g, (_m, c: string) => c.toUpperCase());
|
|
43
|
+
return String(obj(input[`${type}Options`]).componentType ?? "");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** A quiz form (or a `{ form }` answer) → the questions in display order and the quiz settings. */
|
|
47
|
+
export function parseQuiz(raw: unknown): QuizModel {
|
|
48
|
+
const form = obj(obj(raw).form ?? raw);
|
|
49
|
+
const formFields = (Array.isArray(form.formFields) ? form.formFields : []).map((f) => {
|
|
50
|
+
const field = obj(f);
|
|
51
|
+
const identifier = String(field.identifier ?? "");
|
|
52
|
+
if (!identifier.startsWith("QUIZ_")) return field;
|
|
53
|
+
// An unknown quiz component keeps its QUIZ_ identifier, which the parser does not know: unsupported.
|
|
54
|
+
const plain = PLAIN_IDENTIFIER[componentType(field)];
|
|
55
|
+
return plain ? { ...field, identifier: plain } : field;
|
|
56
|
+
});
|
|
57
|
+
const parsed = parseForm({ ...form, formFields });
|
|
58
|
+
const questions = parsed.pages.flat().map((id) => parsed.fields[id]).filter((f): f is FormFieldModel => !!f && f.kind !== "display");
|
|
59
|
+
// The step screen draws these kinds only (a radio, a checkbox list, a text, a text area, a number);
|
|
60
|
+
// a question of any other kind could never be answered here, and every quiz question is required.
|
|
61
|
+
const drawable = questions.every((q) => DRAWN_KINDS.has(q.kind));
|
|
62
|
+
const settings = obj(obj(obj(obj(form.extendedFields).namespaces)["@achievements/quizzes"]).settings);
|
|
63
|
+
return {
|
|
64
|
+
id: String(form.id ?? ""),
|
|
65
|
+
questions,
|
|
66
|
+
passingGrade: Math.min(100, num(settings.passingGrade)),
|
|
67
|
+
attempts: Math.floor(num(settings.attempts)),
|
|
68
|
+
// parseForm also marks a form with no input field unsupported: a quiz with no question has nothing to take.
|
|
69
|
+
unsupported: parsed.unsupported || questions.length === 0 || !drawable,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** The questions not answered yet (every quiz question is required on the site). */
|
|
74
|
+
export function unansweredTargets(quiz: QuizModel, values: Record<string, FieldValue>): string[] {
|
|
75
|
+
const required = quiz.questions.map((q) => ({ ...q, required: true }));
|
|
76
|
+
return Object.keys(localProblems(required, values));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** The submission's `answers`: keyed by each question's target, `{ value }` shaped by its input type. */
|
|
80
|
+
export function quizAnswers(quiz: QuizModel, values: Record<string, FieldValue>): Record<string, { value: unknown }> {
|
|
81
|
+
return Object.fromEntries(Object.entries(submissionValues(quiz.questions, values)).map(([target, value]) => [target, { value }]));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface QuizResult {
|
|
85
|
+
passed: boolean;
|
|
86
|
+
/** The member's grade, a percent. */
|
|
87
|
+
score: number;
|
|
88
|
+
passingGrade: number;
|
|
89
|
+
/** Questions marked right, of the questions the answer marked at all; both 0 when it marks none. */
|
|
90
|
+
correct: number;
|
|
91
|
+
marked: number;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** A quiz submission or a resolved step → its result. A pass is COMPLETED (a submission answers
|
|
95
|
+
* COMPLETED, never PASSED, on amit1); FAILED is a fail; any other status (a quiz waiting for review)
|
|
96
|
+
* is not a pass. A resolved step carries `earnedScore`, a submission `earnedGrade`. */
|
|
97
|
+
export function quizResult(raw: unknown): QuizResult {
|
|
98
|
+
const r = obj(raw);
|
|
99
|
+
const status = String(r.evaluationStatus ?? r.status ?? "").toUpperCase();
|
|
100
|
+
const answers = Object.values(obj(r.answers)).map(obj).filter((a) => typeof a.correct === "boolean");
|
|
101
|
+
return {
|
|
102
|
+
passed: status === "COMPLETED",
|
|
103
|
+
score: Math.round(num(r.earnedGrade ?? r.earnedScore)),
|
|
104
|
+
passingGrade: Math.round(num(r.passingGrade)),
|
|
105
|
+
correct: answers.filter((a) => a.correct === true).length,
|
|
106
|
+
marked: answers.length,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** The 428 the site answers once the member has used every try ("Quiz submissions exceed attempts limit"). */
|
|
111
|
+
export function isAttemptsExhausted(error: unknown): boolean {
|
|
112
|
+
const text = String((error as { message?: unknown } | undefined)?.message ?? error ?? "");
|
|
113
|
+
return /attempts limit/i.test(text) || (/\b428\b/.test(text) && /attempt/i.test(text));
|
|
114
|
+
}
|
|
@@ -343,7 +343,7 @@ const NOTIFICATIONS_SEED = {
|
|
|
343
343
|
}
|
|
344
344
|
};
|
|
345
345
|
// The native Account screen of a BASE44 site (a `base44` binding in ../provisioning.json): sign in,
|
|
346
|
-
// register
|
|
346
|
+
// register (verified by an emailed code), the sign-in providers the app turned on, sign out — and Delete account when the binding names the backend
|
|
347
347
|
// function that deletes it (`base44.deleteAccountFunction`; App Store 5.1.1(v)). Signing in here
|
|
348
348
|
// signs the website's pages in too. It runs on the himi-brandy-base44-account worker in tier5-src/.
|
|
349
349
|
const BASE44_ACCOUNT = {
|
|
@@ -434,6 +434,111 @@ const BASE44_ACCOUNT = {
|
|
|
434
434
|
}
|
|
435
435
|
}
|
|
436
436
|
},
|
|
437
|
+
{
|
|
438
|
+
"id": "himi_base44_account.provider_google",
|
|
439
|
+
"body": {
|
|
440
|
+
"package": "himalaya",
|
|
441
|
+
"type": "Button",
|
|
442
|
+
"props": {
|
|
443
|
+
"title": "Continue with Google",
|
|
444
|
+
"style": "secondary",
|
|
445
|
+
"fullWidth": true,
|
|
446
|
+
"action": {
|
|
447
|
+
"actionId": "tier5.himiBase44Account.signInWith",
|
|
448
|
+
"params": {
|
|
449
|
+
"provider": "google"
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
},
|
|
454
|
+
"modifiers": {
|
|
455
|
+
"hiddenPath": "$service:himiBase44Account.hideGoogle"
|
|
456
|
+
}
|
|
457
|
+
},
|
|
458
|
+
{
|
|
459
|
+
"id": "himi_base44_account.provider_apple",
|
|
460
|
+
"body": {
|
|
461
|
+
"package": "himalaya",
|
|
462
|
+
"type": "Button",
|
|
463
|
+
"props": {
|
|
464
|
+
"title": "Continue with Apple",
|
|
465
|
+
"style": "secondary",
|
|
466
|
+
"fullWidth": true,
|
|
467
|
+
"action": {
|
|
468
|
+
"actionId": "tier5.himiBase44Account.signInWith",
|
|
469
|
+
"params": {
|
|
470
|
+
"provider": "apple"
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
},
|
|
475
|
+
"modifiers": {
|
|
476
|
+
"hiddenPath": "$service:himiBase44Account.hideApple"
|
|
477
|
+
}
|
|
478
|
+
},
|
|
479
|
+
{
|
|
480
|
+
"id": "himi_base44_account.provider_microsoft",
|
|
481
|
+
"body": {
|
|
482
|
+
"package": "himalaya",
|
|
483
|
+
"type": "Button",
|
|
484
|
+
"props": {
|
|
485
|
+
"title": "Continue with Microsoft",
|
|
486
|
+
"style": "secondary",
|
|
487
|
+
"fullWidth": true,
|
|
488
|
+
"action": {
|
|
489
|
+
"actionId": "tier5.himiBase44Account.signInWith",
|
|
490
|
+
"params": {
|
|
491
|
+
"provider": "microsoft"
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
},
|
|
496
|
+
"modifiers": {
|
|
497
|
+
"hiddenPath": "$service:himiBase44Account.hideMicrosoft"
|
|
498
|
+
}
|
|
499
|
+
},
|
|
500
|
+
{
|
|
501
|
+
"id": "himi_base44_account.provider_facebook",
|
|
502
|
+
"body": {
|
|
503
|
+
"package": "himalaya",
|
|
504
|
+
"type": "Button",
|
|
505
|
+
"props": {
|
|
506
|
+
"title": "Continue with Facebook",
|
|
507
|
+
"style": "secondary",
|
|
508
|
+
"fullWidth": true,
|
|
509
|
+
"action": {
|
|
510
|
+
"actionId": "tier5.himiBase44Account.signInWith",
|
|
511
|
+
"params": {
|
|
512
|
+
"provider": "facebook"
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
},
|
|
517
|
+
"modifiers": {
|
|
518
|
+
"hiddenPath": "$service:himiBase44Account.hideFacebook"
|
|
519
|
+
}
|
|
520
|
+
},
|
|
521
|
+
{
|
|
522
|
+
"id": "himi_base44_account.provider_sso",
|
|
523
|
+
"body": {
|
|
524
|
+
"package": "himalaya",
|
|
525
|
+
"type": "Button",
|
|
526
|
+
"props": {
|
|
527
|
+
"title": "Continue with single sign-on",
|
|
528
|
+
"style": "secondary",
|
|
529
|
+
"fullWidth": true,
|
|
530
|
+
"action": {
|
|
531
|
+
"actionId": "tier5.himiBase44Account.signInWith",
|
|
532
|
+
"params": {
|
|
533
|
+
"provider": "sso"
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
},
|
|
538
|
+
"modifiers": {
|
|
539
|
+
"hiddenPath": "$service:himiBase44Account.hideSso"
|
|
540
|
+
}
|
|
541
|
+
},
|
|
437
542
|
{
|
|
438
543
|
"id": "himi_base44_account.email",
|
|
439
544
|
"body": {
|
|
@@ -447,6 +552,9 @@ const BASE44_ACCOUNT = {
|
|
|
447
552
|
"actionId": "tier5.himiBase44Account.setEmail"
|
|
448
553
|
}
|
|
449
554
|
}
|
|
555
|
+
},
|
|
556
|
+
"modifiers": {
|
|
557
|
+
"hiddenPath": "$service:himiBase44Account.hideEmailField"
|
|
450
558
|
}
|
|
451
559
|
},
|
|
452
560
|
{
|
|
@@ -521,24 +629,6 @@ const BASE44_ACCOUNT = {
|
|
|
521
629
|
"hiddenPath": "$service:himiBase44Account.hidePasswordField"
|
|
522
630
|
}
|
|
523
631
|
},
|
|
524
|
-
{
|
|
525
|
-
"id": "himi_base44_account.send_code",
|
|
526
|
-
"body": {
|
|
527
|
-
"package": "himalaya",
|
|
528
|
-
"type": "Button",
|
|
529
|
-
"props": {
|
|
530
|
-
"title": "Email me a code instead",
|
|
531
|
-
"style": "secondary",
|
|
532
|
-
"fullWidth": true,
|
|
533
|
-
"action": {
|
|
534
|
-
"actionId": "tier5.himiBase44Account.sendCode"
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
},
|
|
538
|
-
"modifiers": {
|
|
539
|
-
"hiddenPath": "$service:himiBase44Account.hidePasswordField"
|
|
540
|
-
}
|
|
541
|
-
},
|
|
542
632
|
{
|
|
543
633
|
"id": "himi_base44_account.verify_code",
|
|
544
634
|
"body": {
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
// himi-brandy-base44-account — the native Account screen of an app whose website is a Base44 site.
|
|
2
|
-
// Sign in
|
|
3
|
-
//
|
|
2
|
+
// Sign in with the methods the Base44 app turned on (email + password, and Google / Microsoft /
|
|
3
|
+
// Facebook / Apple / SSO through the system browser), register (verified by the emailed code),
|
|
4
|
+
// reset a password, sign out, and — when the app provides the backend function — delete the account.
|
|
5
|
+
//
|
|
6
|
+
// Base44 has no passwordless email login: its `resend-otp` only re-sends the code that verifies a
|
|
7
|
+
// NEW account. So the code form appears only after Create account, never as a sign-in method.
|
|
8
|
+
//
|
|
9
|
+
// Provider buttons follow the app's public sign-in settings (`auth.providers()`), and only show
|
|
10
|
+
// where this build can finish a provider sign-in (`providerSignIn`): the provider returns to the
|
|
11
|
+
// app's own `https://<slug>.base44.app`, which opens the app only when Base44's app-link files
|
|
12
|
+
// there name this build.
|
|
4
13
|
//
|
|
5
14
|
// Signing in here is what signs the WEBSITE tabs in: the native session bridge carries the
|
|
6
15
|
// token into every Base44 WebView (the token itself never reaches this worker — login answers
|
|
@@ -20,8 +29,12 @@ interface AccountState {
|
|
|
20
29
|
email: string;
|
|
21
30
|
password: string;
|
|
22
31
|
code: string;
|
|
23
|
-
/** "signIn" | "
|
|
32
|
+
/** "signIn" | "code" — which form the card shows. "code" only follows Create account. */
|
|
24
33
|
mode: string;
|
|
34
|
+
/** The hosted providers this app turned on AND this build can complete, in Base44's order. */
|
|
35
|
+
providers: string[];
|
|
36
|
+
/** Email + password is on for this app (Base44's default). */
|
|
37
|
+
passwordEnabled: boolean;
|
|
25
38
|
/** The app's delete-account function, "" when it has none (no Delete row). */
|
|
26
39
|
deleteFunction: string;
|
|
27
40
|
confirmingDelete: boolean;
|
|
@@ -36,6 +49,13 @@ interface AccountState {
|
|
|
36
49
|
hideSignedOut: boolean;
|
|
37
50
|
hideCodeField: boolean;
|
|
38
51
|
hidePasswordField: boolean;
|
|
52
|
+
/** The email field: the password form and the verify-code step need it; a provider-only app does not. */
|
|
53
|
+
hideEmailField: boolean;
|
|
54
|
+
hideGoogle: boolean;
|
|
55
|
+
hideMicrosoft: boolean;
|
|
56
|
+
hideFacebook: boolean;
|
|
57
|
+
hideApple: boolean;
|
|
58
|
+
hideSso: boolean;
|
|
39
59
|
hideDelete: boolean;
|
|
40
60
|
hideConfirmDelete: boolean;
|
|
41
61
|
}
|
|
@@ -43,6 +63,13 @@ interface AccountState {
|
|
|
43
63
|
const describe = (e: unknown): string =>
|
|
44
64
|
isBase44Error(e) ? (e.message || e.code) : e instanceof Error ? e.message : String(e);
|
|
45
65
|
|
|
66
|
+
const hideProvider = (s: AccountState, provider: string): boolean =>
|
|
67
|
+
s.signedIn || s.mode === "code" || !s.providers.includes(provider);
|
|
68
|
+
|
|
69
|
+
const PROVIDER_LABEL: Record<string, string> = {
|
|
70
|
+
google: "Google", microsoft: "Microsoft", facebook: "Facebook", apple: "Apple", sso: "SSO",
|
|
71
|
+
};
|
|
72
|
+
|
|
46
73
|
/** Recompute the hiddenWhen flags from the state that drives them. */
|
|
47
74
|
function derive(s: AccountState): AccountState {
|
|
48
75
|
return {
|
|
@@ -50,7 +77,13 @@ function derive(s: AccountState): AccountState {
|
|
|
50
77
|
hideSignedIn: !s.signedIn,
|
|
51
78
|
hideSignedOut: s.signedIn,
|
|
52
79
|
hideCodeField: s.signedIn || s.mode !== "code",
|
|
53
|
-
hidePasswordField: s.signedIn || s.mode === "code",
|
|
80
|
+
hidePasswordField: s.signedIn || s.mode === "code" || !s.passwordEnabled,
|
|
81
|
+
hideEmailField: s.signedIn || (s.mode !== "code" && !s.passwordEnabled),
|
|
82
|
+
hideGoogle: hideProvider(s, "google"),
|
|
83
|
+
hideMicrosoft: hideProvider(s, "microsoft"),
|
|
84
|
+
hideFacebook: hideProvider(s, "facebook"),
|
|
85
|
+
hideApple: hideProvider(s, "apple"),
|
|
86
|
+
hideSso: hideProvider(s, "sso"),
|
|
54
87
|
hideDelete: !s.signedIn || !s.deleteFunction || s.confirmingDelete,
|
|
55
88
|
hideConfirmDelete: !s.signedIn || !s.deleteFunction || !s.confirmingDelete,
|
|
56
89
|
};
|
|
@@ -61,11 +94,10 @@ const acct = defineService<AccountState, {
|
|
|
61
94
|
setEmail: (s: AccountState, p?: { value?: string }) => AccountState;
|
|
62
95
|
setPassword: (s: AccountState, p?: { value?: string }) => AccountState;
|
|
63
96
|
setCode: (s: AccountState, p?: { value?: string }) => AccountState;
|
|
64
|
-
useCode: (s: AccountState) => AccountState;
|
|
65
97
|
usePassword: (s: AccountState) => AccountState;
|
|
66
98
|
signIn: (s: AccountState) => AccountState;
|
|
99
|
+
signInWith: (s: AccountState, p?: { provider?: string }) => AccountState;
|
|
67
100
|
register: (s: AccountState) => AccountState;
|
|
68
|
-
sendCode: (s: AccountState) => AccountState;
|
|
69
101
|
verifyCode: (s: AccountState) => AccountState;
|
|
70
102
|
resetPassword: (s: AccountState) => AccountState;
|
|
71
103
|
signOut: (s: AccountState) => AccountState;
|
|
@@ -77,6 +109,7 @@ const acct = defineService<AccountState, {
|
|
|
77
109
|
_done: (s: AccountState, message?: string) => AccountState;
|
|
78
110
|
_failed: (s: AccountState, error?: string) => AccountState;
|
|
79
111
|
_failedRegister: (s: AccountState, message?: string) => AccountState;
|
|
112
|
+
_methods: (s: AccountState, password?: boolean, providers?: string[]) => AccountState;
|
|
80
113
|
}>("himiBase44Account", {
|
|
81
114
|
state: derive({
|
|
82
115
|
signedIn: false,
|
|
@@ -85,6 +118,8 @@ const acct = defineService<AccountState, {
|
|
|
85
118
|
password: "",
|
|
86
119
|
code: "",
|
|
87
120
|
mode: "signIn",
|
|
121
|
+
providers: [],
|
|
122
|
+
passwordEnabled: true,
|
|
88
123
|
deleteFunction: "",
|
|
89
124
|
confirmingDelete: false,
|
|
90
125
|
busy: false,
|
|
@@ -94,6 +129,12 @@ const acct = defineService<AccountState, {
|
|
|
94
129
|
hideSignedOut: false,
|
|
95
130
|
hideCodeField: true,
|
|
96
131
|
hidePasswordField: false,
|
|
132
|
+
hideEmailField: false,
|
|
133
|
+
hideGoogle: true,
|
|
134
|
+
hideMicrosoft: true,
|
|
135
|
+
hideFacebook: true,
|
|
136
|
+
hideApple: true,
|
|
137
|
+
hideSso: true,
|
|
97
138
|
hideDelete: true,
|
|
98
139
|
hideConfirmDelete: true,
|
|
99
140
|
}),
|
|
@@ -102,13 +143,17 @@ const acct = defineService<AccountState, {
|
|
|
102
143
|
auth.status()
|
|
103
144
|
.then((st) => (st.signedIn ? acct._signedIn(String(st.user?.email ?? ""), "") : acct._signedOut("")))
|
|
104
145
|
.catch((e) => acct._failed(describe(e)));
|
|
146
|
+
// The app's sign-in settings. Unreadable (offline, an older host without the verb) keeps
|
|
147
|
+
// email + password, which every Base44 app has — never an empty card.
|
|
148
|
+
auth.providers()
|
|
149
|
+
.then((m) => acct._methods(m.password, m.providerSignIn ? m.providers : []))
|
|
150
|
+
.catch(() => undefined);
|
|
105
151
|
return derive({ ...s, deleteFunction: String(p?.deleteFunction ?? "") });
|
|
106
152
|
},
|
|
107
153
|
|
|
108
154
|
setEmail: (s, p) => ({ ...s, email: String(p?.value ?? "") }),
|
|
109
155
|
setPassword: (s, p) => ({ ...s, password: String(p?.value ?? "") }),
|
|
110
156
|
setCode: (s, p) => ({ ...s, code: String(p?.value ?? "") }),
|
|
111
|
-
useCode: (s) => derive({ ...s, mode: "code", message: "" }),
|
|
112
157
|
usePassword: (s) => derive({ ...s, mode: "signIn", message: "" }),
|
|
113
158
|
|
|
114
159
|
signIn: (s) => {
|
|
@@ -119,6 +164,18 @@ const acct = defineService<AccountState, {
|
|
|
119
164
|
return { ...s, password: "", busy: true, error: "", message: "Signing in…" };
|
|
120
165
|
},
|
|
121
166
|
|
|
167
|
+
signInWith: (s, p) => {
|
|
168
|
+
const provider = String(p?.provider ?? "");
|
|
169
|
+
if (s.busy || !s.providers.includes(provider)) return s;
|
|
170
|
+
const label = PROVIDER_LABEL[provider] ?? provider;
|
|
171
|
+
auth.loginWithProvider(provider as Parameters<typeof auth.loginWithProvider>[0])
|
|
172
|
+
.then(({ user }) => acct._signedIn(String(user?.email ?? ""), `Signed in with ${label}.`))
|
|
173
|
+
.catch((e) => (isBase44Error(e) && e.code === "cancelled"
|
|
174
|
+
? acct._done("")
|
|
175
|
+
: acct._failed(`${label} sign-in failed: ${describe(e)}`)));
|
|
176
|
+
return { ...s, busy: true, error: "", message: `Opening ${label} sign-in…` };
|
|
177
|
+
},
|
|
178
|
+
|
|
122
179
|
register: (s) => {
|
|
123
180
|
if (!s.email || !s.password) return { ...s, error: "", message: "Enter an email and a password to create an account." };
|
|
124
181
|
auth.register(s.email, s.password)
|
|
@@ -128,14 +185,6 @@ const acct = defineService<AccountState, {
|
|
|
128
185
|
return derive({ ...s, password: "", mode: "code", busy: true, error: "", message: "Creating your account…" });
|
|
129
186
|
},
|
|
130
187
|
|
|
131
|
-
sendCode: (s) => {
|
|
132
|
-
if (!s.email) return { ...s, error: "", message: "Enter your email first." };
|
|
133
|
-
auth.loginViaOtp(s.email)
|
|
134
|
-
.then(() => acct._done("We emailed you a code."))
|
|
135
|
-
.catch((e) => acct._failed(describe(e)));
|
|
136
|
-
return derive({ ...s, mode: "code", busy: true, error: "", message: "Sending a code…" });
|
|
137
|
-
},
|
|
138
|
-
|
|
139
188
|
verifyCode: (s) => {
|
|
140
189
|
if (!s.email || !s.code) return { ...s, error: "", message: "Enter your email and the code." };
|
|
141
190
|
auth.verifyOtp(s.email, s.code)
|
|
@@ -180,6 +229,12 @@ const acct = defineService<AccountState, {
|
|
|
180
229
|
derive({ ...s, error: "", signedIn: false, user: "", busy: false, confirmingDelete: false, mode: "signIn", message: String(message ?? "") }),
|
|
181
230
|
_done: (s, message) => ({ ...s, busy: false, error: "", message: String(message ?? "") }),
|
|
182
231
|
_failed: (s, error) => ({ ...s, busy: false, message: "", error: String(error ?? "") }),
|
|
232
|
+
_methods: (s, password, providers) => {
|
|
233
|
+
const list = Array.isArray(providers) ? providers.map(String) : [];
|
|
234
|
+
// A provider-only app on a build that cannot finish a provider sign-in keeps email + password
|
|
235
|
+
// (Base44 still accepts it for users who set one) rather than an empty card.
|
|
236
|
+
return derive({ ...s, passwordEnabled: password !== false || list.length === 0, providers: list });
|
|
237
|
+
},
|
|
183
238
|
_failedRegister: (s, error) => derive({ ...s, busy: false, mode: "signIn", message: "", error: String(error ?? "") }),
|
|
184
239
|
},
|
|
185
240
|
});
|