@wix/himalaya-cli 0.1795.0 → 0.1797.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/stdlib/wix-sdk/online-programs/src/index.d.ts +6 -0
- package/dist/browser-plane/assets.json +5 -5
- package/dist/browser-plane/preview-deferred/{11bd915805d61287157c1beca36b2d642d15e8107049a7d0fed28468d2965395.bin → 04eac2ea24e0edfcc5aaa757dc5d06c6bf35c3c5ce9ccbb448b305db05715492.bin} +1 -1
- package/dist/browser-plane/sw.js +6 -6
- package/dist/cli.mjs +44 -41
- package/dist/preview-assets.generated.bin +0 -0
- package/guides/sdk-reference.json +2 -2
- 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/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
|
+
}
|