@qaiddev/quests-embed 1.6.1 → 1.7.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/README.md CHANGED
@@ -252,7 +252,7 @@ For programmatic embedding — e.g. launching a quest from another widget — th
252
252
 
253
253
  | Option | Type | Default | Description |
254
254
  |--------|------|---------|-------------|
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. |
255
+ | `metadata` | `Record<string, unknown>` or a `Promise` of one | — | 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. A promise lets you open the quest before you have the ids: the form shows at once and only the create-response call waits for it. Check `QaidQuests.supports.asyncMetadata` first if you load the widget at runtime. |
256
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
 
package/dist/embed.d.ts CHANGED
@@ -10,6 +10,13 @@ import type { Answers, Questionnaire, QuestsConfig } from "./types";
10
10
  */
11
11
  export declare function randomId(): string;
12
12
  export declare class QaidQuests {
13
+ /**
14
+ * What this build accepts, for hosts that load it at runtime and may get
15
+ * an older copy. asyncMetadata: `metadata` may be a promise.
16
+ */
17
+ static readonly supports: {
18
+ readonly asyncMetadata: true;
19
+ };
13
20
  private config;
14
21
  private questionnaire;
15
22
  private inlineQuestionnaire;
@@ -473,6 +473,11 @@ function Le() {
473
473
  }
474
474
  const Oe = '<svg width="14" height="14" viewBox="0 0 14 14" aria-hidden="true"><path d="M2 2l10 10M12 2L2 12" stroke="currentColor" stroke-width="2" stroke-linecap="round" fill="none"/></svg>', Pe = '<svg width="24" height="24" viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12l4 4L19 7" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" fill="none"/></svg>';
475
475
  class ze {
476
+ /**
477
+ * What this build accepts, for hosts that load it at runtime and may get
478
+ * an older copy. asyncMetadata: `metadata` may be a promise.
479
+ */
480
+ static supports = { asyncMetadata: !0 };
476
481
  config;
477
482
  questionnaire = null;
478
483
  inlineQuestionnaire;
@@ -978,8 +983,14 @@ ${s}
978
983
  }), this.createPromise;
979
984
  }
980
985
  async createResponse() {
986
+ let e;
987
+ try {
988
+ e = await this.metadata;
989
+ } catch {
990
+ e = void 0;
991
+ }
981
992
  try {
982
- const e = await fetch(this.config.endpoint, {
993
+ const i = await fetch(this.config.endpoint, {
983
994
  method: "POST",
984
995
  headers: this.jsonHeaders(),
985
996
  body: JSON.stringify({
@@ -988,19 +999,19 @@ ${s}
988
999
  pageUrl: window.location.href,
989
1000
  visitorId: this.visitorId,
990
1001
  userAgent: navigator.userAgent,
991
- metadata: this.metadata
1002
+ metadata: e
992
1003
  })
993
1004
  });
994
- if (!e.ok) {
1005
+ if (!i.ok) {
995
1006
  console.error(
996
- `[quests-embed] failed to create response (${e.status})`
1007
+ `[quests-embed] failed to create response (${i.status})`
997
1008
  );
998
1009
  return;
999
1010
  }
1000
- const i = await e.json();
1001
- i && i.id !== null && i.id !== void 0 ? this.responseId = i.id : console.error("[quests-embed] create response returned no id");
1002
- } catch (e) {
1003
- console.error("[quests-embed] failed to create response:", e);
1011
+ const a = await i.json();
1012
+ a && a.id !== null && a.id !== void 0 ? this.responseId = a.id : console.error("[quests-embed] create response returned no id");
1013
+ } catch (i) {
1014
+ console.error("[quests-embed] failed to create response:", i);
1004
1015
  }
1005
1016
  }
1006
1017
  async submit() {