@qaiddev/quests-embed 1.5.0 → 1.5.3
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/README.md +12 -6
- package/dist/embed.d.ts +24 -0
- package/dist/index.d.ts +1 -1
- package/dist/qaid-quests.js +308 -206
- package/dist/qaid-quests.js.map +1 -1
- package/dist/qaid-quests.umd.cjs +3 -3
- package/dist/qaid-quests.umd.cjs.map +1 -1
- package/dist/types.d.ts +20 -6
- package/dist/visibility.d.ts +16 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -78,8 +78,8 @@ For complex configurations or inline questionnaires, use a separate JSON config
|
|
|
78
78
|
2. A response record is created on your server (`POST` to `endpoint`)
|
|
79
79
|
3. Questions render one at a time with a progress bar and Back/Next navigation
|
|
80
80
|
4. Answers autosave as the user moves between steps (`PATCH` per question). Text and currency fields debounce by `saveDebounceMs` (default 500ms)
|
|
81
|
-
5. On the final step,
|
|
82
|
-
6. A "thank you" screen appears
|
|
81
|
+
5. On the final step, the answers to the questions still visible are submitted in a single batch (`POST` to `{endpoint}/{id}/submit`). An answer to a question that `visibleIf` has since hidden is left out, and cleared on the server with a `PATCH` of `null`
|
|
82
|
+
6. A "thank you" screen appears once the server accepts the submit. If the create or the submit fails (a network error or a non-2xx reply), the embed shows "Couldn't send your answers" with a **Try again** button instead; the answers are kept, and Try again re-creates the response first if it has to
|
|
83
83
|
|
|
84
84
|
If `container` is set, the form renders inline inside that element. If not, it opens as a centered modal with a backdrop.
|
|
85
85
|
|
|
@@ -242,7 +242,7 @@ We offer a Free Plan that hosts both the endpoint and a dashboard for managing y
|
|
|
242
242
|
|
|
243
243
|
| Option | Type | Default | Description |
|
|
244
244
|
|--------|------|---------|-------------|
|
|
245
|
-
| `autoAdvance` | `boolean` | `false` | Advance automatically on
|
|
245
|
+
| `autoAdvance` | `boolean` | `false` | Advance automatically when an option is picked on a single-choice multiple-choice question. No other type auto-advances (multi-select, text, currency, range and date wait for Next / Enter) |
|
|
246
246
|
| `saveDebounceMs` | `number` | `500` | Debounce in ms for autosave on text/currency/range |
|
|
247
247
|
| `autoFocus` | `boolean` | `true` | Auto-focus the input on each step. Set `false` in preview/embedded contexts that shouldn't steal focus |
|
|
248
248
|
|
|
@@ -253,7 +253,7 @@ For programmatic embedding — e.g. launching a quest from another widget — th
|
|
|
253
253
|
| Option | Type | Default | Description |
|
|
254
254
|
|--------|------|---------|-------------|
|
|
255
255
|
| `metadata` | `Record<string, unknown>` | — | Extra key/value pairs sent verbatim in the create-response `POST` body. The server decides which keys it persists; unknown keys are ignored. Used, for example, by `@qaiddev/thumbs-embed` to pass `{ feedbackId }` so the QAid backend joins the quest answers to the feedback record. |
|
|
256
|
-
| `onComplete` | `(answers) => void` | — | Called once when the quest is completed and
|
|
256
|
+
| `onComplete` | `(answers) => void` | — | Called once when the quest is completed and the server accepted the submit (just after the thank-you screen renders), with a copy of the submitted answers — answers to questions hidden by `visibleIf` are left out. Not called while the submit is failing. Fires in both modal and inline modes. |
|
|
257
257
|
| `onClose` | `() => void` | — | Called once when the embed is torn down — visitor close, host `destroy()`, or teardown after completion. Lets a host that launched the quest drop its reference. |
|
|
258
258
|
|
|
259
259
|
```typescript
|
|
@@ -422,8 +422,14 @@ Your endpoint should return `{ "id": "..." }` (string or number). The form is us
|
|
|
422
422
|
```
|
|
423
423
|
|
|
424
424
|
`value` is `string | number | string[] | null` depending on the question type.
|
|
425
|
-
|
|
426
|
-
|
|
425
|
+
Just before submitting, the embed sends `"value": null` for every answered
|
|
426
|
+
question that `visibleIf` has since hidden, so a server that stores answers
|
|
427
|
+
from these PATCHes drops them too.
|
|
428
|
+
|
|
429
|
+
**3. Submit** — `POST {endpoint}/{id}/submit`. `answers` holds only the
|
|
430
|
+
questions visible at submit time. Reply with a 2xx; anything else (or a
|
|
431
|
+
network error) shows the visitor a retry screen instead of the thank-you
|
|
432
|
+
screen:
|
|
427
433
|
|
|
428
434
|
```json
|
|
429
435
|
{
|
package/dist/embed.d.ts
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import type { Answers, Questionnaire, QuestsConfig } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* A random v4 UUID.
|
|
4
|
+
*
|
|
5
|
+
* `crypto.randomUUID` exists only in secure contexts (HTTPS and localhost). On
|
|
6
|
+
* a plain http:// page it is undefined, and calling it threw while mounting, so
|
|
7
|
+
* the quest never appeared. `crypto.getRandomValues` has no such restriction;
|
|
8
|
+
* `Math.random` covers a runtime with no `crypto` at all. The id only groups
|
|
9
|
+
* one browser's responses, so it needs to be unique, not secret.
|
|
10
|
+
*/
|
|
11
|
+
export declare function randomId(): string;
|
|
2
12
|
export declare class QaidQuests {
|
|
3
13
|
private config;
|
|
4
14
|
private questionnaire;
|
|
@@ -14,6 +24,10 @@ export declare class QaidQuests {
|
|
|
14
24
|
private answers;
|
|
15
25
|
private responseId;
|
|
16
26
|
private visitorId;
|
|
27
|
+
private createPromise;
|
|
28
|
+
private createPending;
|
|
29
|
+
private droppedSaves;
|
|
30
|
+
private submitting;
|
|
17
31
|
private pendingSaveTimer;
|
|
18
32
|
private pendingSaveQuestionId;
|
|
19
33
|
private pendingSaveValue;
|
|
@@ -72,6 +86,13 @@ export declare class QaidQuests {
|
|
|
72
86
|
private renderHeader;
|
|
73
87
|
private renderStep;
|
|
74
88
|
private renderDone;
|
|
89
|
+
/**
|
|
90
|
+
* Shown instead of the thank-you screen when the response could not be
|
|
91
|
+
* created or the submit was refused. The answers stay in memory, so
|
|
92
|
+
* "Try again" re-runs the whole submit (re-creating the response first
|
|
93
|
+
* if needed) without the visitor re-entering anything.
|
|
94
|
+
*/
|
|
95
|
+
private renderSubmitError;
|
|
75
96
|
private advance;
|
|
76
97
|
private back;
|
|
77
98
|
private recomputeVisible;
|
|
@@ -79,8 +100,11 @@ export declare class QaidQuests {
|
|
|
79
100
|
private flushPendingSave;
|
|
80
101
|
private saveAnswer;
|
|
81
102
|
private doSave;
|
|
103
|
+
private patchAnswer;
|
|
104
|
+
private startCreate;
|
|
82
105
|
private createResponse;
|
|
83
106
|
private submit;
|
|
107
|
+
private trySubmit;
|
|
84
108
|
private jsonHeaders;
|
|
85
109
|
private showSaving;
|
|
86
110
|
private handleKeyDown;
|
package/dist/index.d.ts
CHANGED
|
@@ -32,5 +32,5 @@
|
|
|
32
32
|
*/
|
|
33
33
|
import { QaidQuests } from "./embed";
|
|
34
34
|
export { QaidQuests };
|
|
35
|
-
export { getVisibleQuestions, evaluateRule } from "./visibility";
|
|
35
|
+
export { getVisibleQuestions, getVisibleAnswers, evaluateRule, } from "./visibility";
|
|
36
36
|
export type { QuestsConfig, ResolvedQuestsConfig, Questionnaire, Question, TextQuestion, CurrencyQuestion, RangeQuestion, DateQuestion, MultipleChoiceQuestion, MultipleChoiceOption, Answers, AnswerValue, VisibilityRule, CreateResponsePayload, CreateResponseResult, UpdateAnswerPayload, SubmitPayload, } from "./types";
|