@sparkvault/sdk-js 15.13.1 → 15.14.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/index.cjs CHANGED
@@ -16566,6 +16566,7 @@ class HelpDeskClient {
16566
16566
  if (!/^hdapt_[A-Za-z0-9_-]{43}$/.test(result?.token) || !validLifetime(result.ttl_seconds))
16567
16567
  throw new SparkVaultError('The help desk returned an invalid access grant.', 'HELP_DESK_INVALID_RESPONSE');
16568
16568
  this.ticketAccess = { token: result.token, deadline: Date.now() / 1000 + result.ttl_seconds };
16569
+ return result;
16569
16570
  }
16570
16571
  /** @internal Read an installed server-proven company bearer without invoking any identity provider. */
16571
16572
  verifiedSessionTokenFor(requesterId) {
@@ -17787,6 +17788,120 @@ function createFormAttachments(client, prefix, context) {
17787
17788
  };
17788
17789
  }
17789
17790
 
17791
+ const TTL_MS = 30 * 60 * 1000;
17792
+ const storageKey = (deskId, requesterId) => isHelpDeskId(deskId) && isResourceIdOf('requester', requesterId) ? `sv-hd-draft:${deskId}:${requesterId}:new` : null;
17793
+ const validBody = (value) => typeof value === 'string' && value.length <= MAX_BODY_BYTES && new TextEncoder().encode(value).length <= MAX_BODY_BYTES;
17794
+ const validSubject = (value) => typeof value === 'string' && value.length <= MAX_SUBJECT_LEN;
17795
+ /** The question before sign-in is tab-local and contains no customer identity. */
17796
+ function clearSupportIssue(deskId) {
17797
+ try {
17798
+ if (isHelpDeskId(deskId))
17799
+ sessionStorage.removeItem(`sv-hd-issue:${deskId}`);
17800
+ }
17801
+ catch { /* Storage is optional. */ }
17802
+ }
17803
+ function readSupportDraft(deskId) {
17804
+ if (!isHelpDeskId(deskId))
17805
+ return null;
17806
+ try {
17807
+ const raw = sessionStorage.getItem(`sv-hd-issue:${deskId}`);
17808
+ if (!raw)
17809
+ return null;
17810
+ if (raw.length > MAX_BODY_BYTES * 4)
17811
+ throw new Error('Invalid issue');
17812
+ const row = JSON.parse(raw);
17813
+ if (row?.desk_id !== deskId || !validBody(row.issue) || !Number.isFinite(row.expires_at) ||
17814
+ row.expires_at <= Date.now() || row.expires_at > Date.now() + TTL_MS ||
17815
+ (row.composition !== undefined && (!validSubject(row.composition?.subject) || !validBody(row.composition?.body))))
17816
+ throw new Error('Invalid issue');
17817
+ return { issue: row.issue, ...(row.composition && { composition: { subject: row.composition.subject, body: row.composition.body } }) };
17818
+ }
17819
+ catch {
17820
+ clearSupportIssue(deskId);
17821
+ return null;
17822
+ }
17823
+ }
17824
+ function readSupportIssue(deskId) { return readSupportDraft(deskId)?.issue ?? null; }
17825
+ function readAnonymousFormDraft(deskId) { return readSupportDraft(deskId)?.composition ?? null; }
17826
+ function writeSupportDraft(deskId, issue, composition) {
17827
+ try {
17828
+ sessionStorage.setItem(`sv-hd-issue:${deskId}`, JSON.stringify({ desk_id: deskId, issue,
17829
+ ...(composition && { composition }), expires_at: Date.now() + TTL_MS }));
17830
+ }
17831
+ catch { /* The live wizard still keeps its composition in memory. */ }
17832
+ }
17833
+ function saveSupportIssue(deskId, issue) {
17834
+ if (!isHelpDeskId(deskId) || !validBody(issue))
17835
+ return;
17836
+ const composition = readAnonymousFormDraft(deskId) ?? undefined;
17837
+ if (!issue && !composition) {
17838
+ clearSupportIssue(deskId);
17839
+ return;
17840
+ }
17841
+ writeSupportDraft(deskId, issue, composition);
17842
+ }
17843
+ function saveAnonymousFormDraft(deskId, composition) {
17844
+ if (!isHelpDeskId(deskId) || !validSubject(composition.subject) || !validBody(composition.body))
17845
+ return;
17846
+ const issue = readSupportIssue(deskId) ?? '';
17847
+ if (!composition.subject && !composition.body && !issue) {
17848
+ clearSupportIssue(deskId);
17849
+ return;
17850
+ }
17851
+ writeSupportDraft(deskId, issue, { subject: composition.subject, body: composition.body });
17852
+ }
17853
+ function removeFormDraft(deskId, requesterId) {
17854
+ const key = storageKey(deskId, requesterId);
17855
+ try {
17856
+ if (key)
17857
+ sessionStorage.removeItem(key);
17858
+ }
17859
+ catch { /* Storage is optional. */ }
17860
+ }
17861
+ function readFormDraft(deskId, requesterId) {
17862
+ const key = storageKey(deskId, requesterId);
17863
+ if (!key)
17864
+ return null;
17865
+ try {
17866
+ const raw = sessionStorage.getItem(key);
17867
+ if (!raw)
17868
+ return null;
17869
+ if (raw.length > MAX_BODY_BYTES * 4)
17870
+ throw new Error('Invalid draft');
17871
+ const row = JSON.parse(raw);
17872
+ const sent = row?.uncertain;
17873
+ if (row?.version !== 1 || row.desk_id !== deskId || row.requester_id !== requesterId || row.kind !== 'new' ||
17874
+ !Number.isFinite(row.expires_at) || row.expires_at <= Date.now() || row.expires_at > Date.now() + TTL_MS ||
17875
+ !validSubject(row.subject) || !validBody(row.body) || (row.ticket_id !== null && !isResourceIdOf('ticket', row.ticket_id)) ||
17876
+ (sent !== null && (!isResourceIdOf('ticket', sent?.ticket_id) || !validSubject(sent.subject) || !validBody(sent.body) ||
17877
+ !Array.isArray(sent.attachments) || sent.attachments.length > MAX_ATTACHMENTS_PER_MESSAGE || sent.attachments.some((id) => !isResourceIdOf('attachment', id)))))
17878
+ throw new Error('Invalid draft');
17879
+ return { subject: row.subject, body: row.body, ticketId: row.ticket_id, hadFiles: row.had_files === true,
17880
+ uncertain: sent ? { ticketId: sent.ticket_id, subject: sent.subject, body: sent.body, attachments: [...sent.attachments] } : null };
17881
+ }
17882
+ catch {
17883
+ removeFormDraft(deskId, requesterId);
17884
+ return null;
17885
+ }
17886
+ }
17887
+ function saveFormDraft(deskId, requesterId, value) {
17888
+ const key = storageKey(deskId, requesterId);
17889
+ if (!key || !validSubject(value.subject) || !validBody(value.body))
17890
+ return;
17891
+ try {
17892
+ if (!value.subject && !value.body && !value.ticketId && !value.uncertain) {
17893
+ sessionStorage.removeItem(key);
17894
+ return;
17895
+ }
17896
+ const sent = value.uncertain;
17897
+ sessionStorage.setItem(key, JSON.stringify({ version: 1, desk_id: deskId, requester_id: requesterId, kind: 'new',
17898
+ expires_at: Date.now() + TTL_MS, subject: value.subject, body: value.body, ticket_id: value.ticketId,
17899
+ uncertain: sent ? { ticket_id: sent.ticketId, subject: sent.subject, body: sent.body, attachments: sent.attachments } : null,
17900
+ had_files: value.hadFiles }));
17901
+ }
17902
+ catch { /* Storage is optional; the live form keeps its composition. */ }
17903
+ }
17904
+
17790
17905
  let formSequence = 0;
17791
17906
  /** An absent or server-side answer cannot establish that the write was refused. */
17792
17907
  function unknownSubmissionOutcome(error) {
@@ -18044,6 +18159,58 @@ function mountHelpDeskForm(client, options) {
18044
18159
  let resendTimer = null;
18045
18160
  let confirmReturn = null;
18046
18161
  let done = null;
18162
+ let draftRequester = null;
18163
+ let restoredDraft = false;
18164
+ let restoredAnonymous = false;
18165
+ let restoredFiles = false;
18166
+ let savedDraftNeedsSignIn = false;
18167
+ function persistDraft() {
18168
+ if (!options.persist || completed || destroyed)
18169
+ return;
18170
+ if (!draftRequester) {
18171
+ if (!savedDraftNeedsSignIn)
18172
+ saveAnonymousFormDraft(client.desk.desk_id, { subject: subject.input.value, body: description.input.value });
18173
+ return;
18174
+ }
18175
+ saveFormDraft(client.desk.desk_id, draftRequester, {
18176
+ subject: subject.input.value, body: description.input.value, ticketId: draftId,
18177
+ uncertain: uncertainSubmission, hadFiles: restoredFiles || attachments?.hasEntries === true,
18178
+ });
18179
+ }
18180
+ function forgetDraft() {
18181
+ if (draftRequester)
18182
+ removeFormDraft(client.desk.desk_id, draftRequester);
18183
+ else if (options.persist)
18184
+ clearSupportIssue(client.desk.desk_id);
18185
+ }
18186
+ /** Only /me or the verified sign-in answer can select a saved requester's draft. */
18187
+ function restoreDraft(customer) {
18188
+ if (!options.persist || draftRequester === customer.requester_id)
18189
+ return false;
18190
+ savedDraftNeedsSignIn = false;
18191
+ draftRequester = customer.requester_id;
18192
+ const saved = readFormDraft(client.desk.desk_id, draftRequester);
18193
+ clearSupportIssue(client.desk.desk_id);
18194
+ if (!saved) {
18195
+ persistDraft();
18196
+ return false;
18197
+ }
18198
+ restoredDraft = true;
18199
+ restoredFiles = saved.hadFiles && !saved.uncertain;
18200
+ subject.input.value = saved.uncertain?.subject ?? saved.subject;
18201
+ description.input.value = saved.uncertain?.body ?? saved.body;
18202
+ draftId = saved.ticketId;
18203
+ uncertainSubmission = saved.uncertain;
18204
+ subject.input.readOnly = uncertainSubmission !== null;
18205
+ description.input.readOnly = uncertainSubmission !== null;
18206
+ send.textContent = uncertainSubmission ? 'Check submission' : options.widgetIdentity ? widgetCustomer ? 'Send message' : 'Continue' : 'Send request';
18207
+ setState(uncertainSubmission ? 'uncertain' : 'editing');
18208
+ message(uncertainSubmission
18209
+ ? 'Your original request is preserved. Check submission before starting another request.'
18210
+ : restoredFiles ? 'Your text was restored. Choose your files again before sending; files are not saved in this browser.'
18211
+ : 'Your saved request was restored. Review it before sending.');
18212
+ return true;
18213
+ }
18047
18214
  function safeComposition() {
18048
18215
  // An account switch must not turn an uncertain send into a fresh request.
18049
18216
  return pending || uncertainSubmission !== null || completed ? null : { subject: subject.input.value, body: description.input.value };
@@ -18096,6 +18263,7 @@ function mountHelpDeskForm(client, options) {
18096
18263
  }
18097
18264
  function setState(next) {
18098
18265
  state = next;
18266
+ persistDraft();
18099
18267
  notify$1(options.onStateChange, next);
18100
18268
  }
18101
18269
  function message(text, isError = false) {
@@ -18307,6 +18475,8 @@ function mountHelpDeskForm(client, options) {
18307
18475
  draftId = null;
18308
18476
  draftPromise = null;
18309
18477
  uncertainSubmission = null;
18478
+ savedDraftNeedsSignIn = false;
18479
+ restoredAnonymous = false;
18310
18480
  subject.input.readOnly = false;
18311
18481
  description.input.readOnly = false;
18312
18482
  completed = false;
@@ -18351,15 +18521,28 @@ function mountHelpDeskForm(client, options) {
18351
18521
  attachments.element.hidden = true;
18352
18522
  return;
18353
18523
  }
18524
+ // Preserve the old request before hiding it. The next verified requester
18525
+ // selects only their own storage key, including after a 401 and sign-in.
18526
+ persistDraft();
18527
+ const canRecover = options.persist && draftRequester !== null && readFormDraft(client.desk.desk_id, draftRequester) !== null;
18528
+ draftRequester = null;
18529
+ restoredDraft = false;
18530
+ restoredFiles = false;
18354
18531
  generation += 1;
18355
18532
  pending = false;
18356
18533
  sessionKnown = false;
18357
18534
  if (options.widgetIdentity)
18358
18535
  widgetCustomer = null;
18359
18536
  clearComposer();
18537
+ savedDraftNeedsSignIn = Boolean(canRecover);
18360
18538
  disable(false);
18361
18539
  setState('editing');
18362
- message('Your sign-in changed. Start a new request for the current account.');
18540
+ if (savedDraftNeedsSignIn) {
18541
+ send.textContent = 'Sign in to recover request';
18542
+ message('Sign in again to recover your saved request. Its text stays private until your account is confirmed.');
18543
+ }
18544
+ else
18545
+ message('Your sign-in changed. Start a new request for the current account.');
18363
18546
  }
18364
18547
  const unsubscribe = client.subscribeSession(sessionChanged);
18365
18548
  const alive = (ownGeneration) => !destroyed && generation === ownGeneration;
@@ -18391,6 +18574,7 @@ function mountHelpDeskForm(client, options) {
18391
18574
  if (!alive(ownGeneration))
18392
18575
  throw new SparkVaultError('The help desk session changed.', 'HELP_DESK_SESSION_CHANGED', 409);
18393
18576
  draftId = draft.ticket_id;
18577
+ persistDraft();
18394
18578
  return draft.ticket_id;
18395
18579
  });
18396
18580
  draftPromise = operation;
@@ -18456,7 +18640,8 @@ function mountHelpDeskForm(client, options) {
18456
18640
  description.input.value = body;
18457
18641
  }
18458
18642
  const refused = refusal(subjectText, body);
18459
- if (refused) {
18643
+ const recoveringAfterSignIn = savedDraftNeedsSignIn;
18644
+ if (refused && !recoveringAfterSignIn) {
18460
18645
  const [entry, text] = refused;
18461
18646
  setFieldError(entry, text);
18462
18647
  entry.input.focus();
@@ -18532,6 +18717,13 @@ function mountHelpDeskForm(client, options) {
18532
18717
  renderWidgetIdentity();
18533
18718
  message('');
18534
18719
  }
18720
+ // The native result is Core's proof. Bind its draft before a later
18721
+ // profile refresh can fail and leave verified text in anonymous storage.
18722
+ const restored = Boolean(widgetSignIn && session && restoreDraft(session.customer));
18723
+ if (session)
18724
+ notify$1(options.onSession, session);
18725
+ if (restored)
18726
+ return;
18535
18727
  }
18536
18728
  if (!alive(ownGeneration))
18537
18729
  return;
@@ -18584,6 +18776,7 @@ function mountHelpDeskForm(client, options) {
18584
18776
  dropChallenge();
18585
18777
  subject.input.value = subjectText;
18586
18778
  description.input.value = body;
18779
+ notify$1(options.onSession, verified);
18587
18780
  }
18588
18781
  if (!token || !alive(ownGeneration))
18589
18782
  return;
@@ -18591,6 +18784,17 @@ function mountHelpDeskForm(client, options) {
18591
18784
  if (!alive(ownGeneration) || !(await tokenFor(ownGeneration)))
18592
18785
  return;
18593
18786
  auth.hidden = true;
18787
+ // An earlier saved request, especially an uncertain send, always wins
18788
+ // over a newly described issue. Authentication never submits it by itself.
18789
+ if (restoreDraft(customer))
18790
+ return;
18791
+ if (refused && recoveringAfterSignIn) {
18792
+ const [entry, text] = refused;
18793
+ setState('editing');
18794
+ setFieldError(entry, text);
18795
+ focusAfter = entry.input;
18796
+ return;
18797
+ }
18594
18798
  if (customer.needs_display_name) {
18595
18799
  if (client.desk.auth_mode === 'external_sso' && customer.assurance === 'external_sso')
18596
18800
  throw new SparkVaultError('Your company support profile could not be loaded.', 'HELP_DESK_EXTERNAL_PROFILE_INCOMPLETE', 503);
@@ -18628,12 +18832,14 @@ function mountHelpDeskForm(client, options) {
18628
18832
  return;
18629
18833
  uncertainSubmission = { ticketId: id, subject: subjectText, body, attachments: attachments?.attachmentIds ?? [] };
18630
18834
  }
18835
+ persistDraft();
18631
18836
  attachments?.lock(true);
18632
18837
  ticketAttempted = true;
18633
18838
  const ticket = await client.createTicket({ ...uncertainSubmission, attachments: [...uncertainSubmission.attachments], ...options.assistanceContext?.() }, { expectedSessionToken: token });
18634
18839
  if (!alive(ownGeneration) || !(await tokenFor(ownGeneration)))
18635
18840
  return;
18636
18841
  completed = true;
18842
+ forgetDraft();
18637
18843
  uncertainSubmission = null;
18638
18844
  setState('success');
18639
18845
  if (!alive(ownGeneration))
@@ -18745,13 +18951,17 @@ function mountHelpDeskForm(client, options) {
18745
18951
  };
18746
18952
  /** The Cancel path: remove the form, then tell the host the customer closed it. */
18747
18953
  function dismiss() {
18954
+ const discardDraft = uncertainSubmission === null;
18748
18955
  controller.destroy();
18956
+ if (discardDraft)
18957
+ forgetDraft();
18749
18958
  notify$1(options.onCancel, undefined);
18750
18959
  }
18751
18960
  const controller = {
18752
18961
  destroy() {
18753
18962
  if (destroyed)
18754
18963
  return;
18964
+ persistDraft();
18755
18965
  destroyed = true;
18756
18966
  generation += 1;
18757
18967
  stopResendCountdown();
@@ -18764,6 +18974,9 @@ function mountHelpDeskForm(client, options) {
18764
18974
  reset() {
18765
18975
  if (destroyed || pending || uncertainSubmission)
18766
18976
  return;
18977
+ forgetDraft();
18978
+ restoredDraft = false;
18979
+ restoredFiles = false;
18767
18980
  generation += 1;
18768
18981
  clearComposer();
18769
18982
  disable(false);
@@ -18772,13 +18985,14 @@ function mountHelpDeskForm(client, options) {
18772
18985
  },
18773
18986
  getState: () => state,
18774
18987
  restoreComposition(composition) {
18775
- if (destroyed)
18988
+ if (destroyed || restoredDraft || restoredAnonymous)
18776
18989
  return;
18777
18990
  subject.input.value = composition.subject;
18778
18991
  description.input.value = composition.body;
18992
+ persistDraft();
18779
18993
  },
18780
18994
  refill(composition) {
18781
- if (destroyed || safeComposition() === null)
18995
+ if (destroyed || restoredDraft || safeComposition() === null)
18782
18996
  return false;
18783
18997
  for (const [entry, key] of [[subject, 'subject'], [description, 'body']]) {
18784
18998
  if (!edited(entry.input, prefill[key])) {
@@ -18787,6 +19001,7 @@ function mountHelpDeskForm(client, options) {
18787
19001
  }
18788
19002
  prefill[key] = composition[key];
18789
19003
  }
19004
+ persistDraft();
18790
19005
  return true;
18791
19006
  },
18792
19007
  resumeAfterAccess() {
@@ -18826,7 +19041,25 @@ function mountHelpDeskForm(client, options) {
18826
19041
  keepEditing.addEventListener('click', () => closeConfirm(true));
18827
19042
  discard.addEventListener('click', dismiss);
18828
19043
  form.addEventListener('submit', onSubmit);
19044
+ form.addEventListener('input', persistDraft);
19045
+ form.addEventListener('change', () => {
19046
+ if (attachments?.hasEntries)
19047
+ restoredFiles = false;
19048
+ persistDraft();
19049
+ });
18829
19050
  renderWidgetIdentity();
19051
+ if (options.widgetIdentity?.customer) {
19052
+ restoreDraft(options.widgetIdentity.customer);
19053
+ disable(false);
19054
+ }
19055
+ else if (options.persist) {
19056
+ const saved = readAnonymousFormDraft(client.desk.desk_id);
19057
+ if (saved) {
19058
+ subject.input.value = saved.subject;
19059
+ description.input.value = saved.body;
19060
+ restoredAnonymous = true;
19061
+ }
19062
+ }
18830
19063
  notify$1(options.onStateChange, state);
18831
19064
  // Native company identity starts as the form opens, never from a Connect,
18832
19065
  // Allow, verification or submit gesture. Guest email is explicit desk policy.
@@ -19347,7 +19580,9 @@ class HelpDeskKnowledgeBaseClient {
19347
19580
  !['public', 'password', 'ip_allowlist', 'identity'].includes(value.access?.mode) ||
19348
19581
  (value.available && (!/^[a-f0-9]{64}$/.test(value.release_id ?? '') || !this.canonicalOrigin(value.canonical_origin))))
19349
19582
  throw invalid();
19350
- if (this.config?.release_id !== value.release_id || !value.authorized)
19583
+ // The first config initializes an empty client. Invalidating it would
19584
+ // reject another initial check still in flight for this same publication.
19585
+ if ((this.config !== null && this.config.release_id !== value.release_id) || !value.authorized)
19351
19586
  this.clearContent();
19352
19587
  this.config = value;
19353
19588
  return value;
@@ -19991,13 +20226,19 @@ function injectHelpDeskSupportStyles() {
19991
20226
  .svhs-contact-target .svhd-description{min-height:160px}
19992
20227
  .svhs-contact-target>.svhd-container{padding:24px}
19993
20228
  .svhs-contact-target .svhd-widget-form>.svhd-actions{padding-bottom:env(safe-area-inset-bottom)}
19994
- .svhs-receipt-scroll{padding-top:58px;flex:0}
20229
+ .svhs-receipt-scroll{padding-top:58px}
19995
20230
  .svhs-panel[data-stage=receipt] .svhs-bottom{border-top:0;padding-top:8px}
19996
20231
  .svhs-toast{right:18px;left:18px;bottom:calc(88px + var(--svhs-toast-offset,0px) + env(safe-area-inset-bottom));max-width:none}
19997
20232
  }
19998
20233
  @media(pointer:coarse){.svhs-icon-button{width:44px;height:44px}.svhs-back{min-height:44px}.svhs-query .svhs-text-button{min-height:44px;min-width:44px}}
19999
20234
  @media(prefers-reduced-motion:reduce){.svhs-panel,.svhs-panel *,.sv-support-launcher{transition-duration:0s!important;animation-duration:.01ms!important;animation-iteration-count:1!important;scroll-behavior:auto!important}}
20000
20235
  @media(forced-colors:active){.svhs-panel button:focus-visible,.svhs-panel a:focus-visible,.svhs-panel input:focus-visible,.svhs-panel textarea:focus-visible{outline:2px solid Highlight}.svhs-panel,.svhs-primary,.svhs-secondary{border:1px solid ButtonText}}
20236
+ .svhs-panel.svhs-page{position:static;inset:auto;z-index:auto;width:100%;height:auto;max-width:960px;max-height:none;margin:0 auto;border:1px solid ${DS.slate200};border-radius:8px;box-shadow:none;transition:none}
20237
+ .svhs-page .svhs-screen{flex:none}
20238
+ .svhs-page .svhs-scroll{flex:none;overflow:visible;overscroll-behavior:auto;scrollbar-gutter:auto}
20239
+ .svhs-page .svhs-contact-target,.svhs-page .svhs-contact-target>.svhd-container{min-height:0}
20240
+ .svhs-page .svhd-widget-form>.svhd-actions{position:static;margin:0;padding:16px 0 0}
20241
+ .svhs-page .svhd-widget-form>.svhd-actions>.svhd-secondary{display:inline-flex}
20001
20242
  `;
20002
20243
  document.head.appendChild(style);
20003
20244
  }
@@ -20219,8 +20460,9 @@ function httpUrl(value, base = window.location.href) {
20219
20460
  * so its page lock and keyboard ownership compose with the Identity dialog.
20220
20461
  */
20221
20462
  class SupportView {
20222
- constructor(actions) {
20463
+ constructor(actions, target) {
20223
20464
  this.actions = actions;
20465
+ this.target = target;
20224
20466
  this.contactTarget = element('div', 'svhs-contact-target');
20225
20467
  this.panel = element('section', 'svhs-panel');
20226
20468
  this.prefix = `svhs-${++sequence}`;
@@ -20264,11 +20506,13 @@ class SupportView {
20264
20506
  this.toastCleanups = new Set();
20265
20507
  this.destroyed = false;
20266
20508
  injectHelpDeskSupportStyles();
20267
- this.phoneHistory = actions.onBrowserBack && actions.onBrowserForward ? new SupportPhoneHistory({
20509
+ this.phoneHistory = !target && actions.onBrowserBack && actions.onBrowserForward ? new SupportPhoneHistory({
20268
20510
  onBack: () => this.actions.onBrowserBack?.(),
20269
20511
  onForward: () => this.actions.onBrowserForward?.(),
20270
20512
  }) : null;
20271
20513
  this.panel.id = `${this.prefix}-panel`;
20514
+ if (target)
20515
+ this.panel.classList.add('svhs-page');
20272
20516
  this.panel.tabIndex = -1;
20273
20517
  this.panel.hidden = true;
20274
20518
  this.panel.setAttribute('aria-labelledby', `${this.prefix}-name`);
@@ -20287,7 +20531,9 @@ class SupportView {
20287
20531
  this.external.rel = 'noopener noreferrer';
20288
20532
  this.external.append(icon('external'));
20289
20533
  const toolbarActions = element('div', 'svhs-toolbar-actions');
20290
- toolbarActions.append(this.external, this.close);
20534
+ toolbarActions.append(this.external);
20535
+ if (!target)
20536
+ toolbarActions.append(this.close);
20291
20537
  toolbar.append(this.back, this.deskName, toolbarActions);
20292
20538
  this.panel.append(toolbar);
20293
20539
  this.identityNotice.append(element('p', 'svhs-status', 'Sign-in is open in another window.'), button('svhs-text-button', 'Cancel sign-in', () => this.actions.onCancelIdentity?.()));
@@ -20348,7 +20594,9 @@ class SupportView {
20348
20594
  feedback.classList.add('svhs-feedback-scroll');
20349
20595
  feedback.append(element('p', 'svhs-copy', 'Your feedback helps us improve our help articles.'));
20350
20596
  const feedbackActions = element('div', 'svhs-feedback-actions');
20351
- feedbackActions.append(button('svhs-primary', 'Yes, that helped', () => this.actions.onAnswered()), button('svhs-secondary', 'No, contact support', () => this.actions.onContact('article_not_answered')), button('svhs-text-button', 'Not now', () => this.actions.onClose()));
20597
+ feedbackActions.append(button('svhs-primary', 'Yes, that helped', () => this.actions.onAnswered()), button('svhs-secondary', 'No, contact support', () => this.actions.onContact('article_not_answered')));
20598
+ if (!target)
20599
+ feedbackActions.append(button('svhs-text-button', 'Not now', () => this.actions.onClose()));
20352
20600
  feedback.append(feedbackActions);
20353
20601
  const contact = this.screen('contact');
20354
20602
  contact.classList.add('svhs-contact-scroll');
@@ -20372,12 +20620,16 @@ class SupportView {
20372
20620
  receipt.append(this.receiptCopy, this.receiptTicket, this.receiptMessage);
20373
20621
  this.restart = button('svhs-text-button', 'Ask another question', () => this.actions.onRestart?.());
20374
20622
  const receiptFooter = this.footer('receipt', 'svhs-receipt-actions');
20375
- receiptFooter.append(button('svhs-secondary svhs-full', 'Done', () => this.actions.onClose()), this.restart);
20623
+ if (!target)
20624
+ receiptFooter.append(button('svhs-secondary svhs-full', 'Done', () => this.actions.onClose()));
20625
+ receiptFooter.append(this.restart);
20376
20626
  this.panel.append(this.live);
20377
20627
  this.media = typeof window.matchMedia === 'function' ? window.matchMedia('(max-width:640px)') : null;
20378
- this.media?.addEventListener('change', this.onMediaChange);
20379
- window.visualViewport?.addEventListener('resize', this.onViewportChange);
20380
- window.visualViewport?.addEventListener('scroll', this.onViewportChange);
20628
+ if (!target) {
20629
+ this.media?.addEventListener('change', this.onMediaChange);
20630
+ window.visualViewport?.addEventListener('resize', this.onViewportChange);
20631
+ window.visualViewport?.addEventListener('scroll', this.onViewportChange);
20632
+ }
20381
20633
  this.onKeydown = (event) => {
20382
20634
  if (this.shell || !this.state?.visible || this.destroyed || event.defaultPrevented || event.isComposing || event.keyCode === 229)
20383
20635
  return;
@@ -20390,7 +20642,8 @@ class SupportView {
20390
20642
  event.preventDefault();
20391
20643
  this.actions.onClose();
20392
20644
  };
20393
- document.addEventListener('keydown', this.onKeydown);
20645
+ if (!target)
20646
+ document.addEventListener('keydown', this.onKeydown);
20394
20647
  }
20395
20648
  render(next) {
20396
20649
  if (this.destroyed)
@@ -20458,7 +20711,7 @@ class SupportView {
20458
20711
  this.contactTitle.parentElement.hidden = this.contactTitle.hidden && this.contactStatus.hidden && this.contactError.hidden;
20459
20712
  const target = heading ?? this.contactTarget;
20460
20713
  target.tabIndex = -1;
20461
- target.focus({ preventScroll: true });
20714
+ target.focus({ preventScroll: !this.target });
20462
20715
  }
20463
20716
  /** Hydrate only the current reader's matching authorized publication assets. */
20464
20717
  setArticleAsset(path, blobUrl) {
@@ -20884,6 +21137,13 @@ class SupportView {
20884
21137
  syncPresentation() {
20885
21138
  if (this.destroyed)
20886
21139
  return;
21140
+ if (this.target) {
21141
+ this.panel.hidden = !this.state?.visible;
21142
+ if (!this.panel.isConnected || this.panel.parentElement !== this.target)
21143
+ this.target.append(this.panel);
21144
+ this.resizeIssue();
21145
+ return;
21146
+ }
20887
21147
  this.phoneHistory?.sync(Boolean(this.state?.visible), Boolean(this.media?.matches));
20888
21148
  const active = this.panel.contains(document.activeElement) && document.activeElement instanceof HTMLElement ? document.activeElement : null;
20889
21149
  if (!this.state?.visible) {
@@ -20942,6 +21202,8 @@ class SupportView {
20942
21202
  hide() {
20943
21203
  const wasVisible = !this.panel.hidden;
20944
21204
  this.panel.hidden = true;
21205
+ if (this.target)
21206
+ return;
20945
21207
  if (this.shell) {
20946
21208
  this.panel.remove();
20947
21209
  this.shell.destroy();
@@ -20968,12 +21230,12 @@ class SupportView {
20968
21230
  if (!this.state?.visible)
20969
21231
  return;
20970
21232
  if (this.state.stage === 'issue') {
20971
- (this.media?.matches ? this.close : this.issue).focus({ preventScroll: true });
21233
+ (!this.target && this.media?.matches ? this.close : this.issue).focus({ preventScroll: !this.target });
20972
21234
  }
20973
21235
  else if (this.state.stage === 'contact')
20974
21236
  this.focusContact();
20975
21237
  else
20976
- (this.headings.get(this.state.stage) ?? this.panel).focus({ preventScroll: true });
21238
+ (this.headings.get(this.state.stage) ?? this.panel).focus({ preventScroll: !this.target });
20977
21239
  }
20978
21240
  }
20979
21241
 
@@ -21016,6 +21278,8 @@ function createHelpDeskSupport(config, options) {
21016
21278
  let requestedArticle = null;
21017
21279
  let articleRetrySearch = false;
21018
21280
  let cancelArticleAssets = null;
21281
+ let stopSession = null;
21282
+ let anonymous = false;
21019
21283
  const lifetime = new AbortController();
21020
21284
  const bindings = new Set();
21021
21285
  let state = { visible: false, stage: 'issue', deskName: 'Support', issue: '' };
@@ -21025,7 +21289,11 @@ function createHelpDeskSupport(config, options) {
21025
21289
  }
21026
21290
  const http = new HttpClient({ ...config, accessToken: undefined, getAccessToken: undefined, apiKey: undefined });
21027
21291
  const view = new SupportView({
21028
- onIssueChange: (issue) => { state.issue = issue; },
21292
+ onIssueChange: (issue) => {
21293
+ state.issue = issue;
21294
+ if (options.persist && anonymous && client)
21295
+ saveSupportIssue(client.desk.desk_id, issue);
21296
+ },
21029
21297
  onSearch: (issue) => { void search(issue); },
21030
21298
  onContact: (reason) => { void showContact(reason); },
21031
21299
  onOpenArticle: (id) => { void openArticle(id); },
@@ -21063,15 +21331,11 @@ function createHelpDeskSupport(config, options) {
21063
21331
  if (destroyed || !state.article)
21064
21332
  return;
21065
21333
  void attempt?.then((active) => active?.solved());
21066
- endJourney();
21067
- minimize();
21334
+ resetJourney(options.target !== undefined);
21068
21335
  view.showToast('We’re happy we could help.');
21069
- state = { visible: false, stage: 'issue', deskName: state.deskName, issue: '', position: state.position };
21070
- update({});
21071
21336
  },
21072
21337
  onRestart: () => {
21073
- endJourney();
21074
- update({ stage: 'issue', issue: '', results: [], article: undefined, receipt: undefined, error: undefined, busy: false });
21338
+ resetJourney(state.visible);
21075
21339
  },
21076
21340
  onRetry: () => {
21077
21341
  if (state.stage === 'contact')
@@ -21088,7 +21352,7 @@ function createHelpDeskSupport(config, options) {
21088
21352
  onCancelIdentity: () => nativeIdentity?.abort(),
21089
21353
  onBrowserBack: minimize,
21090
21354
  onBrowserForward: () => update({ visible: true }),
21091
- });
21355
+ }, options.target === undefined ? undefined : resolveTarget(options.target));
21092
21356
  const launcher = (() => {
21093
21357
  try {
21094
21358
  return options.launcher ? createSupportLauncher(typeof options.launcher === 'object' ? options.launcher : {}, () => { void open(); }) : null;
@@ -21113,6 +21377,10 @@ function createHelpDeskSupport(config, options) {
21113
21377
  if (destroyed)
21114
21378
  throw new Error('Support is closed.');
21115
21379
  client = answer;
21380
+ stopSession = answer.subscribeSession((change) => {
21381
+ if (change.source === 'clear')
21382
+ notify(options.onSession, null);
21383
+ });
21116
21384
  kb = new HelpDeskKnowledgeBaseClient(config, answer.desk.desk_id);
21117
21385
  analytics = createSupportAnalytics({
21118
21386
  deskId: answer.desk.desk_id,
@@ -21135,7 +21403,34 @@ function createHelpDeskSupport(config, options) {
21135
21403
  state.issue = input.issue;
21136
21404
  update({ visible: true });
21137
21405
  try {
21138
- await connect();
21406
+ const active = await connect();
21407
+ if (!options.persist || destroyed || state.stage !== 'issue')
21408
+ return;
21409
+ const token = await active.getSessionToken();
21410
+ if (destroyed)
21411
+ return;
21412
+ anonymous = !token;
21413
+ if (!token) {
21414
+ if (!state.issue)
21415
+ update({ issue: readSupportIssue(active.desk.desk_id) ?? '' });
21416
+ if (state.issue)
21417
+ saveSupportIssue(active.desk.desk_id, state.issue);
21418
+ if (readAnonymousFormDraft(active.desk.desk_id))
21419
+ await showContact('direct');
21420
+ }
21421
+ else if (active.hasTicketAccess) {
21422
+ const customer = await active.getMe();
21423
+ if (destroyed || state.stage !== 'issue')
21424
+ return;
21425
+ const saved = readFormDraft(active.desk.desk_id, customer.requester_id);
21426
+ const composition = readAnonymousFormDraft(active.desk.desk_id);
21427
+ if ((saved || composition) && !state.issue) {
21428
+ update({ issue: saved?.body ?? readSupportIssue(active.desk.desk_id) ?? '' });
21429
+ await showContact('direct');
21430
+ }
21431
+ else if (!state.issue)
21432
+ update({ issue: readSupportIssue(active.desk.desk_id) ?? '' });
21433
+ }
21139
21434
  }
21140
21435
  catch (value) {
21141
21436
  if (!destroyed) {
@@ -21147,7 +21442,7 @@ function createHelpDeskSupport(config, options) {
21147
21442
  }
21148
21443
  function minimize() { update({ visible: false }); }
21149
21444
  /** Forget a finished journey: its form and the files it authorized, any composition held for it, its suggestions and article. */
21150
- function endJourney() {
21445
+ function resetJourney(visible) {
21151
21446
  contact?.destroy();
21152
21447
  contact = null;
21153
21448
  contactCustomer = null;
@@ -21158,6 +21453,10 @@ function createHelpDeskSupport(config, options) {
21158
21453
  results = [];
21159
21454
  requestedArticle = null;
21160
21455
  pendingComposition = null;
21456
+ if (options.persist && client)
21457
+ clearSupportIssue(client.desk.desk_id);
21458
+ update({ visible, stage: 'issue', issue: '', results: [], article: undefined, articleUrl: undefined,
21459
+ receipt: undefined, error: undefined, busy: false, navigationLocked: false });
21161
21460
  }
21162
21461
  function signIn(input = {}) {
21163
21462
  if (!client)
@@ -21321,6 +21620,13 @@ function createHelpDeskSupport(config, options) {
21321
21620
  // wrote in an earlier form and carried here stays their own.
21322
21621
  ...composeIssue(composedFrom),
21323
21622
  attachments: options.attachments,
21623
+ persist: options.persist,
21624
+ onSession: (session) => {
21625
+ anonymous = false;
21626
+ if (options.persist)
21627
+ clearSupportIssue(client.desk.desk_id);
21628
+ notify(options.onSession, session);
21629
+ },
21324
21630
  widgetIdentity: {
21325
21631
  customer,
21326
21632
  signIn: (input) => signIn(input).then((session) => { contactCustomer = session.customer; return session; }),
@@ -21341,7 +21647,7 @@ function createHelpDeskSupport(config, options) {
21341
21647
  });
21342
21648
  });
21343
21649
  },
21344
- onCancel: () => { contact = null; minimize(); },
21650
+ onCancel: () => resetJourney(options.target !== undefined),
21345
21651
  onSuccess: (ticket) => receipt(ticket),
21346
21652
  onStateChange: (next) => update({ navigationLocked: ['authenticating', 'submitting', 'uncertain'].includes(next) }),
21347
21653
  });
@@ -21406,9 +21712,13 @@ function createHelpDeskSupport(config, options) {
21406
21712
  if (destroyed || ownSequence !== sequence)
21407
21713
  return;
21408
21714
  update({ busy: false, ticketAccessRequired: false, ticketAccessMode: undefined });
21715
+ anonymous = !customer;
21716
+ const composition = pendingComposition ?? (options.persist ? readAnonymousFormDraft(active.desk.desk_id) : null) ?? composeIssue(state.issue);
21717
+ if (customer && options.persist)
21718
+ clearSupportIssue(active.desk.desk_id);
21409
21719
  if (!pendingComposition)
21410
21720
  composedFrom = state.issue.trim();
21411
- mountContact(pendingComposition ?? composeIssue(state.issue), customer);
21721
+ mountContact(composition, customer);
21412
21722
  pendingComposition = null;
21413
21723
  }
21414
21724
  catch (value) {
@@ -21437,13 +21747,15 @@ function createHelpDeskSupport(config, options) {
21437
21747
  update({ busy: true, error: undefined });
21438
21748
  try {
21439
21749
  if (policy?.mode === 'password')
21440
- await active.unlockTicketAccess({ password });
21750
+ notify(options.onTicketAccess, await active.unlockTicketAccess({ password }));
21441
21751
  else if (identity) {
21442
21752
  const session = await identity;
21443
- await active.unlockTicketAccess({ identityGrant: session.identity_grant.token });
21753
+ notify(options.onTicketAccess, await active.unlockTicketAccess({ identityGrant: session.identity_grant.token }));
21444
21754
  const hostToken = await active.getSessionToken();
21445
- if (!hostToken)
21755
+ if (!hostToken) {
21446
21756
  active.setSession(session);
21757
+ notify(options.onSession, session);
21758
+ }
21447
21759
  }
21448
21760
  else
21449
21761
  throw new Error('Connect to an approved network, then try again.');
@@ -21486,10 +21798,11 @@ function createHelpDeskSupport(config, options) {
21486
21798
  if (destroyed || ownSequence !== sequence)
21487
21799
  return;
21488
21800
  if (active.ticketAccessPolicy?.mode === 'identity')
21489
- await active.unlockTicketAccess({ identityGrant: session.identity_grant.token });
21801
+ notify(options.onTicketAccess, await active.unlockTicketAccess({ identityGrant: session.identity_grant.token }));
21490
21802
  if (destroyed || ownSequence !== sequence)
21491
21803
  return;
21492
21804
  active.setSession(session);
21805
+ notify(options.onSession, session);
21493
21806
  update({ busy: false });
21494
21807
  await showContact('direct');
21495
21808
  }
@@ -21586,6 +21899,8 @@ function createHelpDeskSupport(config, options) {
21586
21899
  analytics?.dispose();
21587
21900
  launcher?.destroy();
21588
21901
  view.destroy();
21902
+ stopSession?.();
21903
+ stopSession = null;
21589
21904
  // Only this support client is cleared; the host site's sign-in is untouched.
21590
21905
  client?.clearTicketAccess();
21591
21906
  client?.setSession(null);
@@ -26333,7 +26648,7 @@ class SparkVault {
26333
26648
  }
26334
26649
  /** Get the SDK version */
26335
26650
  static get version() {
26336
- return '15.13.1';
26651
+ return '15.14.0';
26337
26652
  }
26338
26653
  }
26339
26654
  if (typeof window !== 'undefined') {