@sparkvault/sdk-js 16.5.1 → 16.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 +17 -8
- package/dist/index.cjs +324 -151
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +61 -16
- package/dist/index.mjs +324 -151
- package/dist/index.mjs.map +1 -1
- package/dist/products/help-desk/client.d.ts +7 -0
- package/dist/products/help-desk/form-composer.d.ts +1 -1
- package/dist/products/help-desk/form-types.d.ts +45 -15
- package/dist/products/help-desk/form.d.ts +16 -6
- package/dist/products/help-desk/support-types.d.ts +8 -0
- package/dist/sparkvault.js +1 -1
- package/dist/sparkvault.js.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -14420,11 +14420,10 @@ const DISCARD_REQUEST_COPY = Object.freeze({
|
|
|
14420
14420
|
});
|
|
14421
14421
|
|
|
14422
14422
|
/**
|
|
14423
|
-
* What the emailed-code step of
|
|
14424
|
-
*
|
|
14425
|
-
*
|
|
14426
|
-
*
|
|
14427
|
-
* the portal and on a company's own site.
|
|
14423
|
+
* What the emailed-code step of the SDK support form's sign-in says: the
|
|
14424
|
+
* refusal of a code that is wrong, spent or expired (Core's PIN_INVALID), and
|
|
14425
|
+
* the note once a new code is sent. Neither names who sent the email, so both
|
|
14426
|
+
* read right on any site the form runs on.
|
|
14428
14427
|
*/
|
|
14429
14428
|
const HELP_DESK_CODE_STEP_COPY = Object.freeze({
|
|
14430
14429
|
codeRefused: 'That code is wrong or has expired. Check the newest email, or send a new code.',
|
|
@@ -18149,7 +18148,7 @@ class HelpDeskClient {
|
|
|
18149
18148
|
// the `federated` mark and the `federated` assurance together, never one without the other.
|
|
18150
18149
|
const customer = result?.customer;
|
|
18151
18150
|
const nativeIdentity = customer?.federated === true ? customer.assurance === 'federated' : customer?.assurance === 'identity';
|
|
18152
|
-
if (!validToken(result?.token) || !nativeIdentity || !/^hdwip_[A-Za-z0-9_-]{43}$/.test(result.identity_grant?.token)) {
|
|
18151
|
+
if (!validToken(result?.token) || !Number.isFinite(result.expires_at) || !nativeIdentity || !/^hdwip_[A-Za-z0-9_-]{43}$/.test(result.identity_grant?.token)) {
|
|
18153
18152
|
throw new SparkVaultError('The help desk returned an invalid support identity.', 'HELP_DESK_INVALID_RESPONSE');
|
|
18154
18153
|
}
|
|
18155
18154
|
this.issuedSessions.set(result, result.token);
|
|
@@ -18161,6 +18160,16 @@ class HelpDeskClient {
|
|
|
18161
18160
|
this.websiteAccountSuppressed = true;
|
|
18162
18161
|
return this.releaseSession(false);
|
|
18163
18162
|
}
|
|
18163
|
+
/**
|
|
18164
|
+
* Sign the customer out of support in this browser: revoke the session, one
|
|
18165
|
+
* a provider lent included, and keep the website's identity from signing
|
|
18166
|
+
* them back in until `useWebsiteAccount`. The session is gone here before
|
|
18167
|
+
* the revocation is answered; the host website's own sign-in is untouched.
|
|
18168
|
+
*/
|
|
18169
|
+
signOutSupport() {
|
|
18170
|
+
this.websiteAccountSuppressed = true;
|
|
18171
|
+
return this.releaseSession(true);
|
|
18172
|
+
}
|
|
18164
18173
|
/** The only operation that resumes the website's configured identity provider after an explicit switch. */
|
|
18165
18174
|
async useWebsiteAccount() {
|
|
18166
18175
|
await this.releaseSession(false);
|
|
@@ -19259,7 +19268,7 @@ function carriesFiles(event) {
|
|
|
19259
19268
|
* refusals as a picked one; the drop target shows only over the composer. A
|
|
19260
19269
|
* paste or drag of text alone stays the browser's. A file brought over the
|
|
19261
19270
|
* form is never the browser's to open in place of the unsent request: on the
|
|
19262
|
-
*
|
|
19271
|
+
* sign-in step, or while the form takes no files, it is refused outright,
|
|
19263
19272
|
* and a desk that takes no files says so when the file is dropped.
|
|
19264
19273
|
*/
|
|
19265
19274
|
function createComposer(options) {
|
|
@@ -19571,6 +19580,11 @@ function postingName(customer) {
|
|
|
19571
19580
|
return words[0];
|
|
19572
19581
|
return `${words[0]} ${Array.from(words[words.length - 1])[0]}.`;
|
|
19573
19582
|
}
|
|
19583
|
+
/** The account row's words for the customer a widget form posts as: "Posting as Alex M.", one full stop either way. */
|
|
19584
|
+
function postingAsText(customer) {
|
|
19585
|
+
const shown = postingName(customer);
|
|
19586
|
+
return `Posting as ${shown}${shown.endsWith('.') ? '' : '.'}`;
|
|
19587
|
+
}
|
|
19574
19588
|
function focusAtEnd(field, focusOptions) {
|
|
19575
19589
|
field.focus(focusOptions);
|
|
19576
19590
|
// An email field has no caret to place.
|
|
@@ -19586,6 +19600,12 @@ function textButton(text, action) {
|
|
|
19586
19600
|
button.addEventListener('click', action);
|
|
19587
19601
|
return button;
|
|
19588
19602
|
}
|
|
19603
|
+
const UNSENT_NOTE_COPY = 'Your request hasn’t been sent yet. Sign in so we know who to reply to, then we’ll send it.';
|
|
19604
|
+
const SIGN_IN_HELP_COPY = 'A secure window opens. Sign in with your email, or continue with an account you’re already signed in to.';
|
|
19605
|
+
const SIGNING_IN_COPY = 'Finish signing in using the secure window.';
|
|
19606
|
+
const SWITCHING_COPY = 'Choose an account in the secure window.';
|
|
19607
|
+
const SIGNED_OUT_COPY = 'You’re signed out of support. What you wrote is still here.';
|
|
19608
|
+
const FILES_AGAIN_COPY = 'Choose your files again before sending.';
|
|
19589
19609
|
const SIGN_IN_CANCELLED_COPY = 'Sign-in was cancelled. Your request is still here and hasn’t been sent.';
|
|
19590
19610
|
const RECOVER_STATUS_COPY = 'Sign in again to recover your saved request.';
|
|
19591
19611
|
const RECOVER_WEBSITE_COPY = 'Sign in to your website account again to recover your saved request.';
|
|
@@ -19656,7 +19676,9 @@ function companySignInUrl(value) {
|
|
|
19656
19676
|
*
|
|
19657
19677
|
* The request is a summary and optional details, in a composer that also
|
|
19658
19678
|
* takes files. A signed-out widget customer writes it as step 1 of 2; step 2
|
|
19659
|
-
* asks
|
|
19679
|
+
* asks nothing, and its one button signs them in, in the native sign-in
|
|
19680
|
+
* window, and sends it. A signed-in one can switch account or sign out
|
|
19681
|
+
* beside the request.
|
|
19660
19682
|
*/
|
|
19661
19683
|
function mountHelpDeskForm(client, options) {
|
|
19662
19684
|
const target = resolveTarget(options.target);
|
|
@@ -19751,9 +19773,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
19751
19773
|
const email = field('Email address', 'email');
|
|
19752
19774
|
const code = field('Email code', 'code');
|
|
19753
19775
|
const name = field('Your name', 'display_name');
|
|
19754
|
-
const
|
|
19755
|
-
const lastName = field('Last name (optional)', 'family_name');
|
|
19756
|
-
const fields = [subject, description, email, code, name, firstName, lastName];
|
|
19776
|
+
const fields = [subject, description, email, code, name];
|
|
19757
19777
|
// The support wizard's issue the form was last filled from, which either
|
|
19758
19778
|
// field may hold; undefined for a form filled from the host's subject and body.
|
|
19759
19779
|
let filledFrom = options.issue;
|
|
@@ -19768,10 +19788,6 @@ function mountHelpDeskForm(client, options) {
|
|
|
19768
19788
|
code.input.inputMode = 'numeric';
|
|
19769
19789
|
code.input.autocomplete = 'one-time-code';
|
|
19770
19790
|
name.input.autocomplete = 'name';
|
|
19771
|
-
firstName.input.autocomplete = 'given-name';
|
|
19772
|
-
lastName.input.autocomplete = 'family-name';
|
|
19773
|
-
firstName.input.maxLength = 100;
|
|
19774
|
-
lastName.input.maxLength = 100;
|
|
19775
19791
|
const codeHint = document.createElement('p');
|
|
19776
19792
|
codeHint.id = `${code.input.id}-hint`;
|
|
19777
19793
|
codeHint.className = 'svhd-hint';
|
|
@@ -19824,16 +19840,16 @@ function mountHelpDeskForm(client, options) {
|
|
|
19824
19840
|
description.wrapper.insertBefore(composer.frame, description.error);
|
|
19825
19841
|
description.wrapper.insertBefore(composer.notice, description.error);
|
|
19826
19842
|
details.append(subject.wrapper, description.wrapper);
|
|
19843
|
+
// What the form asks itself: a missing name, and an emailed code's sign-in,
|
|
19844
|
+
// which the widget leaves to the secure window.
|
|
19827
19845
|
const auth = document.createElement('fieldset');
|
|
19828
19846
|
auth.className = 'svhd-auth';
|
|
19829
19847
|
auth.hidden = true;
|
|
19830
|
-
auth.append(code.wrapper, name.wrapper);
|
|
19848
|
+
auth.append(email.wrapper, code.wrapper, name.wrapper);
|
|
19831
19849
|
const widgetAccount = document.createElement('div');
|
|
19832
19850
|
widgetAccount.className = 'svhd-widget-account';
|
|
19833
19851
|
let widgetCustomer = widget?.customer ?? null;
|
|
19834
|
-
|
|
19835
|
-
const asksName = client.desk.auth_mode !== 'identity';
|
|
19836
|
-
const reply = widget ? stepHead(`${prefix}-reply-heading`, asksName ? 'Who should we reply to?' : 'Sign in to send your request', 'Step 2 of 2') : null;
|
|
19852
|
+
const signInStep = widget ? stepHead(`${prefix}-signin-heading`, 'Sign in to send your request', 'Step 2 of 2') : null;
|
|
19837
19853
|
const identity = widget ? stepContainer('identity') : null;
|
|
19838
19854
|
const recap = document.createElement('div');
|
|
19839
19855
|
recap.className = 'svhd-recap';
|
|
@@ -19843,11 +19859,13 @@ function mountHelpDeskForm(client, options) {
|
|
|
19843
19859
|
enterStep('details'); });
|
|
19844
19860
|
editRequest.setAttribute('aria-label', 'Edit your request');
|
|
19845
19861
|
const noteText = document.createTextNode('');
|
|
19846
|
-
|
|
19847
|
-
|
|
19848
|
-
|
|
19862
|
+
// What the sign-in step's button does, named on that button while the step shows.
|
|
19863
|
+
const signInHelp = document.createElement('p');
|
|
19864
|
+
signInHelp.id = `${prefix}-signin-help`;
|
|
19865
|
+
signInHelp.className = 'svhd-hint';
|
|
19866
|
+
signInHelp.textContent = SIGN_IN_HELP_COPY;
|
|
19849
19867
|
const live = createLiveRegion('svhd-live');
|
|
19850
|
-
if (identity &&
|
|
19868
|
+
if (identity && signInStep) {
|
|
19851
19869
|
form.classList.add('svhd-widget-form');
|
|
19852
19870
|
details.append(widgetAccount);
|
|
19853
19871
|
identity.hidden = true;
|
|
@@ -19862,22 +19880,8 @@ function mountHelpDeskForm(client, options) {
|
|
|
19862
19880
|
recapLabel.textContent = 'Your request';
|
|
19863
19881
|
recapRequest.append(recapLabel, recapText);
|
|
19864
19882
|
recap.append(recapRequest, editRequest);
|
|
19865
|
-
|
|
19866
|
-
helper.id = `${email.input.id}-help`;
|
|
19867
|
-
helper.className = 'svhd-hint';
|
|
19868
|
-
helper.textContent = asksName ? 'We’ll email you a code to confirm it’s you.' : 'You’ll confirm it’s you in a secure SparkVault window.';
|
|
19869
|
-
email.input.setAttribute('aria-describedby', helper.id);
|
|
19870
|
-
identity.append(reply.head, note, recap);
|
|
19871
|
-
if (asksName) {
|
|
19872
|
-
const names = document.createElement('div');
|
|
19873
|
-
names.className = 'svhd-widget-names';
|
|
19874
|
-
names.append(firstName.wrapper, lastName.wrapper);
|
|
19875
|
-
identity.append(names);
|
|
19876
|
-
}
|
|
19877
|
-
identity.append(email.wrapper, helper);
|
|
19883
|
+
identity.append(signInStep.head, note, recap, signInHelp);
|
|
19878
19884
|
}
|
|
19879
|
-
else
|
|
19880
|
-
auth.prepend(email.wrapper);
|
|
19881
19885
|
const status = document.createElement('p');
|
|
19882
19886
|
status.className = 'svhd-status';
|
|
19883
19887
|
status.setAttribute('role', 'status');
|
|
@@ -19969,6 +19973,8 @@ function mountHelpDeskForm(client, options) {
|
|
|
19969
19973
|
let recovery = null;
|
|
19970
19974
|
// The website gave no account back when asked for the hidden request's customer.
|
|
19971
19975
|
let websiteSignedOut = false;
|
|
19976
|
+
// The form is held while the secure window chooses another account: no send is under way.
|
|
19977
|
+
let switchingAccount = false;
|
|
19972
19978
|
function persistDraft() {
|
|
19973
19979
|
if (!options.persist || completed || destroyed)
|
|
19974
19980
|
return;
|
|
@@ -20023,9 +20029,15 @@ function mountHelpDeskForm(client, options) {
|
|
|
20023
20029
|
: 'Your saved request was restored. Review it before sending.');
|
|
20024
20030
|
return true;
|
|
20025
20031
|
}
|
|
20032
|
+
/**
|
|
20033
|
+
* The unsent text an account change carries on to the next form, and
|
|
20034
|
+
* whether the composer held files then, which stay behind. None while a
|
|
20035
|
+
* send is under way, unanswered or done: an account change must not turn an
|
|
20036
|
+
* uncertain send into a fresh request.
|
|
20037
|
+
*/
|
|
20026
20038
|
function safeComposition() {
|
|
20027
|
-
|
|
20028
|
-
|
|
20039
|
+
return pending || uncertainSubmission !== null || completed ? null
|
|
20040
|
+
: { subject: subject.input.value, body: description.input.value, hadFiles: attachments?.hasEntries === true };
|
|
20029
20041
|
}
|
|
20030
20042
|
/** What the send button reads while nothing is in flight. */
|
|
20031
20043
|
function idleLabel() {
|
|
@@ -20035,14 +20047,17 @@ function mountHelpDeskForm(client, options) {
|
|
|
20035
20047
|
return 'Verify and send request';
|
|
20036
20048
|
if (recovery === 'external_sso' && widget)
|
|
20037
20049
|
return 'Use website account';
|
|
20038
|
-
if (recovery !== null
|
|
20050
|
+
if (recovery !== null)
|
|
20039
20051
|
return 'Sign in to recover request';
|
|
20040
|
-
|
|
20052
|
+
if (widget && !widgetCustomer)
|
|
20053
|
+
return step === 'identity' ? 'Sign in and send' : 'Continue';
|
|
20054
|
+
return 'Send request';
|
|
20041
20055
|
}
|
|
20042
20056
|
/**
|
|
20043
20057
|
* The signed-in widget customer writes and sends in one step, posting as
|
|
20044
|
-
* the account named under it
|
|
20045
|
-
*
|
|
20058
|
+
* the account named under it, beside Switch account and, but for a website
|
|
20059
|
+
* account's session, which the website ends, Sign out; a signed-out one
|
|
20060
|
+
* writes the request as step 1 of 2. Either way the form shows the request.
|
|
20046
20061
|
*/
|
|
20047
20062
|
function renderWidgetIdentity() {
|
|
20048
20063
|
if (!widget)
|
|
@@ -20057,12 +20072,14 @@ function mountHelpDeskForm(client, options) {
|
|
|
20057
20072
|
if (widgetCustomer) {
|
|
20058
20073
|
const postingAs = document.createElement('p');
|
|
20059
20074
|
postingAs.className = 'svhd-posting-as';
|
|
20060
|
-
|
|
20061
|
-
|
|
20062
|
-
|
|
20063
|
-
|
|
20064
|
-
|
|
20065
|
-
|
|
20075
|
+
// Switch account opens the sign-in window in this click: nothing may await before it.
|
|
20076
|
+
const switchButton = textButton('Switch account', () => { if (free())
|
|
20077
|
+
void switchAccount(switchButton); });
|
|
20078
|
+
postingAs.append(`${postingAsText(widgetCustomer)} `, switchButton);
|
|
20079
|
+
if (widgetCustomer.assurance !== 'external_sso') {
|
|
20080
|
+
postingAs.append(' ', textButton('Sign out', () => { if (free())
|
|
20081
|
+
widget.signOut(safeComposition()); }));
|
|
20082
|
+
}
|
|
20066
20083
|
widgetAccount.append(postingAs);
|
|
20067
20084
|
}
|
|
20068
20085
|
if (widget.useWebsiteAccount && widget.offerWebsiteAccount) {
|
|
@@ -20077,7 +20094,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20077
20094
|
* The actions and notes for where the request is. While the form hides a
|
|
20078
20095
|
* previous customer's saved request (`recovery`), nothing shows of it, nor
|
|
20079
20096
|
* says it was not sent, since it may be a send whose answer was lost: the
|
|
20080
|
-
* request step's status line says how to get it back and the
|
|
20097
|
+
* request step's status line says how to get it back and the sign-in
|
|
20081
20098
|
* step's note alone speaks there, Start a new request leaves it, and the
|
|
20082
20099
|
* account row is away. A website-account customer's request comes back only
|
|
20083
20100
|
* through that account, so Use website account is its one way on when the
|
|
@@ -20089,7 +20106,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20089
20106
|
startNew.hidden = recovery === null;
|
|
20090
20107
|
widgetAccount.hidden = recovery !== null || widgetAccount.childElementCount === 0;
|
|
20091
20108
|
recap.hidden = recovery !== null;
|
|
20092
|
-
noteText.data = recovery === 'identity' || recovery === 'email_pin' ? RECOVER_NOTE_COPY :
|
|
20109
|
+
noteText.data = recovery === 'identity' || recovery === 'email_pin' ? RECOVER_NOTE_COPY : UNSENT_NOTE_COPY;
|
|
20093
20110
|
if (recovery !== null)
|
|
20094
20111
|
message(step === 'identity' ? '' : recoveryStatus());
|
|
20095
20112
|
}
|
|
@@ -20114,15 +20131,19 @@ function mountHelpDeskForm(client, options) {
|
|
|
20114
20131
|
controller.focusEntry();
|
|
20115
20132
|
}
|
|
20116
20133
|
}
|
|
20117
|
-
/** Show one step, the request or
|
|
20134
|
+
/** Show one step, the request or its sign-in, without moving focus. */
|
|
20118
20135
|
function setStep(next) {
|
|
20119
20136
|
const changed = next !== step;
|
|
20120
20137
|
step = next;
|
|
20121
20138
|
details.hidden = next !== 'details';
|
|
20122
20139
|
if (identity)
|
|
20123
20140
|
identity.hidden = next !== 'identity';
|
|
20124
|
-
if (next === 'identity')
|
|
20141
|
+
if (next === 'identity') {
|
|
20125
20142
|
recapText.textContent = subject.input.value.trim();
|
|
20143
|
+
send.setAttribute('aria-describedby', signInHelp.id);
|
|
20144
|
+
}
|
|
20145
|
+
else
|
|
20146
|
+
send.removeAttribute('aria-describedby');
|
|
20126
20147
|
renderActions();
|
|
20127
20148
|
syncLeaveGuard();
|
|
20128
20149
|
if (changed)
|
|
@@ -20130,9 +20151,11 @@ function mountHelpDeskForm(client, options) {
|
|
|
20130
20151
|
}
|
|
20131
20152
|
/** The customer moves between the steps: the new step's heading takes focus and its place is announced. */
|
|
20132
20153
|
function enterStep(next) {
|
|
20154
|
+
// A notice speaks of the step being left; a hidden saved request's status is the next step's to set again.
|
|
20155
|
+
message('');
|
|
20133
20156
|
setStep(next);
|
|
20134
20157
|
live.announce(next === 'identity' ? 'Step 2 of 2' : 'Step 1 of 2');
|
|
20135
|
-
(next === 'identity' &&
|
|
20158
|
+
(next === 'identity' && signInStep ? signInStep.heading : heading).focus();
|
|
20136
20159
|
}
|
|
20137
20160
|
// An inline wizard, on any host page that gives a `target`, asks before that
|
|
20138
20161
|
// page unloads while the request holds unsent work: leaving would lose it.
|
|
@@ -20190,7 +20213,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20190
20213
|
* in place of anything written.
|
|
20191
20214
|
*/
|
|
20192
20215
|
function disable(disabled) {
|
|
20193
|
-
for (const input of [subject.input, description.input, email.input, code.input, name.input,
|
|
20216
|
+
for (const input of [subject.input, description.input, email.input, code.input, name.input, send, cancel, changeEmail, editRequest, startNew])
|
|
20194
20217
|
input.disabled = disabled;
|
|
20195
20218
|
const held = uncertainSubmission !== null || recovery !== null;
|
|
20196
20219
|
subject.input.readOnly = held;
|
|
@@ -20227,10 +20250,8 @@ function mountHelpDeskForm(client, options) {
|
|
|
20227
20250
|
? 'We may already have received this request. Closing now loses the way to check it.'
|
|
20228
20251
|
: DISCARD_REQUEST_COPY.note;
|
|
20229
20252
|
}
|
|
20230
|
-
/** The field
|
|
20253
|
+
/** The field the request step asks for: the code, name or email the form asks for itself, else the summary. */
|
|
20231
20254
|
function stepField() {
|
|
20232
|
-
if (step === 'identity')
|
|
20233
|
-
return (asksName ? firstName : email).input;
|
|
20234
20255
|
const asked = auth.hidden ? undefined : [code, name, email].find((entry) => !entry.wrapper.hidden);
|
|
20235
20256
|
return (asked ?? subject).input;
|
|
20236
20257
|
}
|
|
@@ -20238,7 +20259,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20238
20259
|
// A press on the modal's backdrop leaves focus on the page body, and
|
|
20239
20260
|
// Keep editing must never hand focus back outside the dialog.
|
|
20240
20261
|
const active = document.activeElement;
|
|
20241
|
-
confirmReturn = active instanceof HTMLElement && shell.container.contains(active) ? active : stepField();
|
|
20262
|
+
confirmReturn = active instanceof HTMLElement && shell.container.contains(active) ? active : step === 'identity' ? send : stepField();
|
|
20242
20263
|
renderConfirmNote();
|
|
20243
20264
|
actions.hidden = true;
|
|
20244
20265
|
confirm.hidden = false;
|
|
@@ -20271,7 +20292,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20271
20292
|
}
|
|
20272
20293
|
/**
|
|
20273
20294
|
* Whether closing now would lose something: a send under way or
|
|
20274
|
-
* unanswered, a code step, a request moved on to
|
|
20295
|
+
* unanswered, a code step, a request moved on to its sign-in step, or
|
|
20275
20296
|
* text and files of the customer's own. The silent company sign-in the
|
|
20276
20297
|
* form runs as it opens (`authenticating`) is no work of the customer's.
|
|
20277
20298
|
*/
|
|
@@ -20373,11 +20394,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20373
20394
|
code.wrapper.hidden = true;
|
|
20374
20395
|
name.wrapper.hidden = true;
|
|
20375
20396
|
auth.hidden = true;
|
|
20376
|
-
|
|
20377
|
-
firstName.input.value = '';
|
|
20378
|
-
lastName.input.value = '';
|
|
20379
|
-
renderWidgetIdentity();
|
|
20380
|
-
}
|
|
20397
|
+
renderWidgetIdentity();
|
|
20381
20398
|
hosted.hidden = true;
|
|
20382
20399
|
draftId = null;
|
|
20383
20400
|
draftPromise = null;
|
|
@@ -20445,6 +20462,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20445
20462
|
restoredFiles = false;
|
|
20446
20463
|
generation += 1;
|
|
20447
20464
|
pending = false;
|
|
20465
|
+
switchingAccount = false;
|
|
20448
20466
|
sessionKnown = false;
|
|
20449
20467
|
if (options.widgetIdentity)
|
|
20450
20468
|
widgetCustomer = null;
|
|
@@ -20564,25 +20582,16 @@ function mountHelpDeskForm(client, options) {
|
|
|
20564
20582
|
}
|
|
20565
20583
|
let widgetSignIn;
|
|
20566
20584
|
if (widget && !widgetCustomer) {
|
|
20567
|
-
// The request is written;
|
|
20585
|
+
// The request is written; signing in to send it is the next step, and
|
|
20568
20586
|
// nothing reaches the network before it.
|
|
20569
20587
|
if (step === 'details') {
|
|
20570
20588
|
enterStep('identity');
|
|
20571
20589
|
return;
|
|
20572
20590
|
}
|
|
20573
|
-
const givenName = asksName ? firstName.input.value.trim() : '';
|
|
20574
|
-
const familyName = asksName ? lastName.input.value.trim() : '';
|
|
20575
|
-
const emailAddress = email.input.value.trim();
|
|
20576
|
-
const invalid = asksName && !givenName ? firstName : !email.input.validity.valid || !emailAddress ? email : null;
|
|
20577
|
-
if (invalid) {
|
|
20578
|
-
setFieldError(invalid, invalid === email ? 'Enter your email address.' : 'Enter your first name.');
|
|
20579
|
-
invalid.input.focus();
|
|
20580
|
-
return;
|
|
20581
|
-
}
|
|
20582
20591
|
// Invoke in the original submit gesture, before any awaited token read:
|
|
20583
20592
|
// the Identity adapter can open its native window without a popup block.
|
|
20584
20593
|
try {
|
|
20585
|
-
widgetSignIn = widget.signIn(
|
|
20594
|
+
widgetSignIn = widget.signIn();
|
|
20586
20595
|
}
|
|
20587
20596
|
catch (failure) {
|
|
20588
20597
|
const error = failure instanceof Error ? failure : new Error('Sign-in could not be opened.');
|
|
@@ -20605,7 +20614,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20605
20614
|
authenticating = true;
|
|
20606
20615
|
authNotification = false;
|
|
20607
20616
|
setState('authenticating');
|
|
20608
|
-
message(
|
|
20617
|
+
message(SIGNING_IN_COPY);
|
|
20609
20618
|
}
|
|
20610
20619
|
let token = await tokenFor(ownGeneration);
|
|
20611
20620
|
if (!alive(ownGeneration))
|
|
@@ -20806,7 +20815,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20806
20815
|
focusAfter = code.input;
|
|
20807
20816
|
}
|
|
20808
20817
|
else if (widgetSignIn && error instanceof SparkVaultError && error.code === 'user_cancelled') {
|
|
20809
|
-
// The request stays on
|
|
20818
|
+
// The request stays on its sign-in step, ready to sign in again;
|
|
20810
20819
|
// a hidden saved request is not here to speak of, so its note alone stays.
|
|
20811
20820
|
if (recovery === null)
|
|
20812
20821
|
message(SIGN_IN_CANCELLED_COPY);
|
|
@@ -20865,6 +20874,84 @@ function mountHelpDeskForm(client, options) {
|
|
|
20865
20874
|
}
|
|
20866
20875
|
}
|
|
20867
20876
|
}
|
|
20877
|
+
/** A request this tab saved, restored as the form mounted, which a carried composition never replaces. */
|
|
20878
|
+
function holdsSavedRequest() {
|
|
20879
|
+
return restoredDraft || restoredAnonymous;
|
|
20880
|
+
}
|
|
20881
|
+
/**
|
|
20882
|
+
* What the form says of the account change it arrives from (`arrived`), once
|
|
20883
|
+
* mounting has restored any saved request: its status line, null to leave
|
|
20884
|
+
* the one mounting set, and what a screen reader hears. A restored saved
|
|
20885
|
+
* request takes the carried text's place, so its own status stands and
|
|
20886
|
+
* nothing is said of the carried request's files.
|
|
20887
|
+
*/
|
|
20888
|
+
function arrival() {
|
|
20889
|
+
const arrived = widget?.arrived;
|
|
20890
|
+
if (!arrived)
|
|
20891
|
+
return null;
|
|
20892
|
+
const placed = !holdsSavedRequest();
|
|
20893
|
+
const files = placed && arrived.droppedFiles ? ` ${FILES_AGAIN_COPY}` : '';
|
|
20894
|
+
if (arrived.from === 'signOut')
|
|
20895
|
+
return { status: placed ? `${SIGNED_OUT_COPY}${files}` : null, announcement: `${SIGNED_OUT_COPY}${files} Step 1 of 2` };
|
|
20896
|
+
if (!widgetCustomer)
|
|
20897
|
+
return null;
|
|
20898
|
+
return { status: files ? FILES_AGAIN_COPY : null, announcement: `${postingAsText(widgetCustomer)}${files}` };
|
|
20899
|
+
}
|
|
20900
|
+
/**
|
|
20901
|
+
* Switch account: the secure window's chooser opens in the customer's
|
|
20902
|
+
* click. This customer stays signed in, the request held in view, until
|
|
20903
|
+
* another account is chosen and a form for it replaces this one. Closing
|
|
20904
|
+
* the window changes nothing; any other failure says why. Either way focus
|
|
20905
|
+
* goes back to `control`.
|
|
20906
|
+
*/
|
|
20907
|
+
async function switchAccount(control) {
|
|
20908
|
+
if (!widget)
|
|
20909
|
+
return;
|
|
20910
|
+
closeConfirm(false);
|
|
20911
|
+
let switched;
|
|
20912
|
+
try {
|
|
20913
|
+
switched = widget.switchAccount(safeComposition());
|
|
20914
|
+
}
|
|
20915
|
+
catch (failure) {
|
|
20916
|
+
const error = failure instanceof Error ? failure : new Error('Sign-in could not be opened.');
|
|
20917
|
+
message(error.message, true);
|
|
20918
|
+
notify$1(options.onError, error);
|
|
20919
|
+
return;
|
|
20920
|
+
}
|
|
20921
|
+
const ownGeneration = generation;
|
|
20922
|
+
pending = true;
|
|
20923
|
+
switchingAccount = true;
|
|
20924
|
+
disable(true);
|
|
20925
|
+
setState('authenticating');
|
|
20926
|
+
message(SWITCHING_COPY);
|
|
20927
|
+
// The status line moves the actions below it.
|
|
20928
|
+
options.onScreenChange?.();
|
|
20929
|
+
try {
|
|
20930
|
+
await switched;
|
|
20931
|
+
}
|
|
20932
|
+
catch (failure) {
|
|
20933
|
+
if (!alive(ownGeneration))
|
|
20934
|
+
return;
|
|
20935
|
+
const error = failure instanceof Error ? failure : new Error('The account could not be switched.');
|
|
20936
|
+
if (error instanceof SparkVaultError && error.code === 'user_cancelled')
|
|
20937
|
+
message('');
|
|
20938
|
+
else {
|
|
20939
|
+
message(error.message, true);
|
|
20940
|
+
notify$1(options.onError, error);
|
|
20941
|
+
}
|
|
20942
|
+
}
|
|
20943
|
+
finally {
|
|
20944
|
+
if (alive(ownGeneration)) {
|
|
20945
|
+
pending = false;
|
|
20946
|
+
switchingAccount = false;
|
|
20947
|
+
setState('editing');
|
|
20948
|
+
disable(false);
|
|
20949
|
+
options.onScreenChange?.();
|
|
20950
|
+
focusAfter = control;
|
|
20951
|
+
focusSettled();
|
|
20952
|
+
}
|
|
20953
|
+
}
|
|
20954
|
+
}
|
|
20868
20955
|
/** Take a typed, pasted or autofilled code as its digits, and send it the moment the last one lands. */
|
|
20869
20956
|
function takeCode(value) {
|
|
20870
20957
|
const digits = helpDeskPinDigits(value);
|
|
@@ -20886,26 +20973,47 @@ function mountHelpDeskForm(client, options) {
|
|
|
20886
20973
|
/** The Cancel path: remove the form, then tell the host the customer closed it. */
|
|
20887
20974
|
function dismiss() {
|
|
20888
20975
|
const discardDraft = uncertainSubmission === null;
|
|
20889
|
-
|
|
20976
|
+
if (!destroyed)
|
|
20977
|
+
teardown(!discardDraft);
|
|
20890
20978
|
if (discardDraft)
|
|
20891
20979
|
forgetDraft();
|
|
20892
20980
|
notify$1(options.onCancel, undefined);
|
|
20893
20981
|
}
|
|
20982
|
+
/** Remove the form and silence it; `save` keeps its request in this tab for the customer it shows. */
|
|
20983
|
+
function teardown(save) {
|
|
20984
|
+
if (save)
|
|
20985
|
+
persistDraft();
|
|
20986
|
+
destroyed = true;
|
|
20987
|
+
generation += 1;
|
|
20988
|
+
stopResendCountdown();
|
|
20989
|
+
attachments?.destroy(completed || uncertainSubmission !== null);
|
|
20990
|
+
composer.destroy();
|
|
20991
|
+
live.destroy();
|
|
20992
|
+
unsubscribe();
|
|
20993
|
+
form.removeEventListener('submit', onSubmit);
|
|
20994
|
+
shell.destroy();
|
|
20995
|
+
setState('destroyed');
|
|
20996
|
+
}
|
|
20894
20997
|
const controller = {
|
|
20895
20998
|
destroy() {
|
|
20999
|
+
if (!destroyed)
|
|
21000
|
+
teardown(true);
|
|
21001
|
+
},
|
|
21002
|
+
leave() {
|
|
20896
21003
|
if (destroyed)
|
|
20897
21004
|
return;
|
|
20898
|
-
|
|
20899
|
-
|
|
20900
|
-
|
|
20901
|
-
|
|
20902
|
-
|
|
20903
|
-
|
|
20904
|
-
|
|
20905
|
-
|
|
20906
|
-
|
|
20907
|
-
|
|
20908
|
-
|
|
21005
|
+
const owner = draftOwner;
|
|
21006
|
+
const sending = pending && !switchingAccount;
|
|
21007
|
+
if (!owner || sending || uncertainSubmission !== null || completed || recovery !== null) {
|
|
21008
|
+
teardown(true);
|
|
21009
|
+
return;
|
|
21010
|
+
}
|
|
21011
|
+
// The request goes on with the account change: this customer's saved copy
|
|
21012
|
+
// must not come back to them over the text as edited since, nor offer the
|
|
21013
|
+
// request a second time.
|
|
21014
|
+
teardown(false);
|
|
21015
|
+
if (options.persist)
|
|
21016
|
+
removeFormDraft(client.desk.desk_id, owner.requester_id);
|
|
20909
21017
|
},
|
|
20910
21018
|
reset() {
|
|
20911
21019
|
if (destroyed || pending || uncertainSubmission)
|
|
@@ -20921,7 +21029,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20921
21029
|
},
|
|
20922
21030
|
getState: () => state,
|
|
20923
21031
|
restoreComposition(composition) {
|
|
20924
|
-
if (destroyed ||
|
|
21032
|
+
if (destroyed || holdsSavedRequest())
|
|
20925
21033
|
return;
|
|
20926
21034
|
subject.input.value = composition.subject;
|
|
20927
21035
|
description.input.value = composition.body;
|
|
@@ -20962,10 +21070,14 @@ function mountHelpDeskForm(client, options) {
|
|
|
20962
21070
|
focusEntry(focusOptions) {
|
|
20963
21071
|
if (destroyed || form.hidden)
|
|
20964
21072
|
return false;
|
|
21073
|
+
if (step === 'identity' && signInStep) {
|
|
21074
|
+
(send.disabled ? signInStep.heading : send).focus(focusOptions);
|
|
21075
|
+
return true;
|
|
21076
|
+
}
|
|
20965
21077
|
const asked = stepField();
|
|
20966
21078
|
const entry = asked === subject.input && subject.input.value.trim() ? description.input : asked;
|
|
20967
21079
|
if (entry.disabled || entry.readOnly)
|
|
20968
|
-
|
|
21080
|
+
heading.focus(focusOptions);
|
|
20969
21081
|
else
|
|
20970
21082
|
focusAtEnd(entry, focusOptions);
|
|
20971
21083
|
return true;
|
|
@@ -21009,9 +21121,6 @@ function mountHelpDeskForm(client, options) {
|
|
|
21009
21121
|
});
|
|
21010
21122
|
send.textContent = idleLabel();
|
|
21011
21123
|
renderWidgetIdentity();
|
|
21012
|
-
// A signed-out widget customer starts on step 1 of 2 with focus in the request.
|
|
21013
|
-
if (widget && !widgetCustomer)
|
|
21014
|
-
live.announce('Step 1 of 2');
|
|
21015
21124
|
if (options.widgetIdentity?.customer) {
|
|
21016
21125
|
restoreDraft(options.widgetIdentity.customer);
|
|
21017
21126
|
disable(false);
|
|
@@ -21032,6 +21141,15 @@ function mountHelpDeskForm(client, options) {
|
|
|
21032
21141
|
restoredAnonymous = true;
|
|
21033
21142
|
}
|
|
21034
21143
|
}
|
|
21144
|
+
const arriving = arrival();
|
|
21145
|
+
if (arriving?.status)
|
|
21146
|
+
message(arriving.status);
|
|
21147
|
+
// A signed-out widget customer starts on step 1 of 2 with focus in the
|
|
21148
|
+
// request; after an account change a screen reader hears where it stands.
|
|
21149
|
+
if (arriving)
|
|
21150
|
+
live.announce(arriving.announcement);
|
|
21151
|
+
else if (widget && !widgetCustomer)
|
|
21152
|
+
live.announce('Step 1 of 2');
|
|
21035
21153
|
syncLeaveGuard();
|
|
21036
21154
|
notify$1(options.onStateChange, state);
|
|
21037
21155
|
// Native company identity starts as the form opens, never from a Connect,
|
|
@@ -23402,7 +23520,6 @@ function injectHelpDeskSupportStyles() {
|
|
|
23402
23520
|
@supports not selector(:has(*)){.svhs-contact-target .svhd-composer:focus-within{outline:2px solid var(--hd-focus,var(--hd-accent-ink,${DS.action}));outline-offset:3px}}
|
|
23403
23521
|
.svhs-panel .svhd-composer-input:focus-visible{outline:none}
|
|
23404
23522
|
.svhs-panel .svhd-composer button:focus-visible{outline-offset:-2px}
|
|
23405
|
-
.svhs-contact-target .svhd-widget-names{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:12px}
|
|
23406
23523
|
.svhs-contact-target .svhd-widget-form{display:flex;flex:1;flex-direction:column;gap:16px}
|
|
23407
23524
|
/* The request fills the panel: the details step, and in it the composer and its text, take the height the fields leave. */
|
|
23408
23525
|
.svhs-contact-target .svhd-widget-form>[data-contact-step=details]{display:flex;flex:1;flex-direction:column;gap:16px}
|
|
@@ -24753,6 +24870,13 @@ function createHelpDeskSupport(config, options) {
|
|
|
24753
24870
|
// A website-account customer's saved request the next form keeps hidden,
|
|
24754
24871
|
// asked for through the website account, which may give no account back.
|
|
24755
24872
|
let pendingRecovery = null;
|
|
24873
|
+
// The account change the next form arrives from, which it says: a Sign out
|
|
24874
|
+
// to a signed-out form, a Switch account or Use website account to the
|
|
24875
|
+
// account arrived at.
|
|
24876
|
+
let pendingArrival = null;
|
|
24877
|
+
// A chosen account's session is taking the old one's place: the host hears
|
|
24878
|
+
// the new session, never the signed-out moment between the two.
|
|
24879
|
+
let replacingSession = false;
|
|
24756
24880
|
// The issue, as written, that the held composition (the mounted form, the one
|
|
24757
24881
|
// a re-authorized form will take, or the one saved before a reload) was last
|
|
24758
24882
|
// filled from: '' for one filled from none. A form taking that composition is
|
|
@@ -24791,7 +24915,7 @@ function createHelpDeskSupport(config, options) {
|
|
|
24791
24915
|
onBack: () => {
|
|
24792
24916
|
if (destroyed || state.navigationLocked || state.identityPending)
|
|
24793
24917
|
return;
|
|
24794
|
-
// On
|
|
24918
|
+
// On the sign-in step, Back returns to the request it is for.
|
|
24795
24919
|
if (state.stage === 'contact' && !state.ticketAccessRequired && contact?.returnToRequest())
|
|
24796
24920
|
return;
|
|
24797
24921
|
// A held form shows at once while contact still checks access behind it,
|
|
@@ -24869,7 +24993,7 @@ function createHelpDeskSupport(config, options) {
|
|
|
24869
24993
|
throw new Error('Support is closed.');
|
|
24870
24994
|
client = answer;
|
|
24871
24995
|
stopSession = answer.subscribeSession((change) => {
|
|
24872
|
-
if (change.source === 'clear')
|
|
24996
|
+
if (change.source === 'clear' && !replacingSession)
|
|
24873
24997
|
notify(options.onSession, null);
|
|
24874
24998
|
});
|
|
24875
24999
|
kb = new HelpDeskKnowledgeBaseClient(config, answer.desk.desk_id);
|
|
@@ -25000,6 +25124,7 @@ function createHelpDeskSupport(config, options) {
|
|
|
25000
25124
|
requestedArticle = null;
|
|
25001
25125
|
pendingComposition = null;
|
|
25002
25126
|
pendingRecovery = null;
|
|
25127
|
+
pendingArrival = null;
|
|
25003
25128
|
feedbackSequence += 1;
|
|
25004
25129
|
sourceArticleId = undefined;
|
|
25005
25130
|
if (options.persist && client)
|
|
@@ -25165,14 +25290,19 @@ function createHelpDeskSupport(config, options) {
|
|
|
25165
25290
|
if (!client || destroyed)
|
|
25166
25291
|
return;
|
|
25167
25292
|
contactCustomer = customer;
|
|
25293
|
+
anonymous = !customer;
|
|
25168
25294
|
// A customer the website gave back sees their own saved request; none keeps it hidden.
|
|
25169
25295
|
const recovering = customer ? null : pendingRecovery;
|
|
25170
25296
|
pendingRecovery = null;
|
|
25297
|
+
// A Sign out arrives only at a signed-out form, a switch only at an account's.
|
|
25298
|
+
const arrived = pendingArrival && (pendingArrival.from === 'signOut') === !customer ? pendingArrival : null;
|
|
25299
|
+
pendingArrival = null;
|
|
25171
25300
|
let activeAttempt = null;
|
|
25172
25301
|
// A ticket carries the attempt the form opened under only while it is still
|
|
25173
25302
|
// the journey's: recovery drops it with the previous customer's question.
|
|
25174
25303
|
const formAttempt = attempt;
|
|
25175
|
-
|
|
25304
|
+
// A host that keeps the session this journey proves has no website account behind it to go back to.
|
|
25305
|
+
const bridged = !options.hostKeepsSession && Boolean(options.getSessionToken || options.getIdentityAssertion || options.identityEndpoint);
|
|
25176
25306
|
contact = mountHelpDeskForm(client, {
|
|
25177
25307
|
target: view.contactTarget,
|
|
25178
25308
|
// Filled from the issue its composition came from, so text the customer
|
|
@@ -25190,13 +25320,15 @@ function createHelpDeskSupport(config, options) {
|
|
|
25190
25320
|
},
|
|
25191
25321
|
widgetIdentity: {
|
|
25192
25322
|
customer,
|
|
25193
|
-
signIn: (
|
|
25194
|
-
switchAccount
|
|
25323
|
+
signIn: () => signIn().then((session) => { contactCustomer = session.customer; return session; }),
|
|
25324
|
+
switchAccount,
|
|
25325
|
+
signOut,
|
|
25195
25326
|
...(bridged && { useWebsiteAccount: (safe, recover) => { void useWebsiteAccount(safe, recover); } }),
|
|
25196
25327
|
offerWebsiteAccount: switchedAccount,
|
|
25197
25328
|
forgetIssue,
|
|
25198
25329
|
followIssue,
|
|
25199
25330
|
...(recovering && { recovering }),
|
|
25331
|
+
...(arrived && { arrived }),
|
|
25200
25332
|
},
|
|
25201
25333
|
onScreenChange: () => view.contactScreenChanged(),
|
|
25202
25334
|
assistanceContext: () => (attempt === formAttempt ? activeAttempt?.ticketContext() : undefined),
|
|
@@ -25310,7 +25442,6 @@ function createHelpDeskSupport(config, options) {
|
|
|
25310
25442
|
if (destroyed || ownSequence !== sequence)
|
|
25311
25443
|
return;
|
|
25312
25444
|
update({ busy: false, ticketAccessRequired: false, ticketAccessMode: undefined });
|
|
25313
|
-
anonymous = !customer;
|
|
25314
25445
|
// A composition saved before a reload goes on from the issue it was filled
|
|
25315
25446
|
// from; with none carried, the form fills itself from the issue as written.
|
|
25316
25447
|
const saved = pendingComposition === null && options.persist ? readAnonymousFormDraft(active.desk.desk_id) : null;
|
|
@@ -25374,78 +25505,120 @@ function createHelpDeskSupport(config, options) {
|
|
|
25374
25505
|
notify(options.onError, error);
|
|
25375
25506
|
}
|
|
25376
25507
|
}
|
|
25377
|
-
|
|
25378
|
-
|
|
25379
|
-
|
|
25380
|
-
|
|
25381
|
-
|
|
25382
|
-
|
|
25508
|
+
/**
|
|
25509
|
+
* Forget what the leaving customer's form led to before another account, or
|
|
25510
|
+
* none, takes its place: the form itself, the articles and the help center
|
|
25511
|
+
* access it opened. Only `composition`'s unsent text goes on to the next
|
|
25512
|
+
* form, which the leaving form's saved copy then no longer stands for
|
|
25513
|
+
* (`leave`); files and uncertain sends keep their requester boundary.
|
|
25514
|
+
*/
|
|
25515
|
+
function leaveCustomer(composition) {
|
|
25516
|
+
if (composition)
|
|
25517
|
+
contact?.leave();
|
|
25518
|
+
else
|
|
25519
|
+
contact?.destroy();
|
|
25383
25520
|
contact = null;
|
|
25521
|
+
contactCustomer = null;
|
|
25384
25522
|
cancelArticleAssets?.();
|
|
25385
25523
|
cancelArticleAssets = null;
|
|
25386
|
-
pendingComposition = composition
|
|
25524
|
+
pendingComposition = composition ? { subject: composition.subject, body: composition.body } : { subject: '', body: '' };
|
|
25387
25525
|
pendingRecovery = null;
|
|
25526
|
+
pendingArrival = null;
|
|
25388
25527
|
kb?.clearAccess();
|
|
25389
25528
|
kbConfig = null;
|
|
25390
25529
|
results = [];
|
|
25391
25530
|
requestedArticle = null;
|
|
25392
25531
|
attempt = null;
|
|
25393
25532
|
sourceArticleId = undefined;
|
|
25394
|
-
|
|
25395
|
-
|
|
25396
|
-
|
|
25397
|
-
|
|
25398
|
-
|
|
25399
|
-
|
|
25400
|
-
|
|
25401
|
-
|
|
25402
|
-
|
|
25533
|
+
}
|
|
25534
|
+
/**
|
|
25535
|
+
* Switch account from the contact form: auth.sv's chooser opens in this
|
|
25536
|
+
* gesture, the current session staying current until another account's is
|
|
25537
|
+
* redeemed. A window that closes or fails rejects, nothing changed, for the
|
|
25538
|
+
* form to say so; a redeemed session takes the old one's place.
|
|
25539
|
+
*/
|
|
25540
|
+
function switchAccount(composition) {
|
|
25541
|
+
const form = contact;
|
|
25542
|
+
const policy = client?.ticketAccessPolicy;
|
|
25543
|
+
// Open synchronously in the Switch account gesture, before anything is awaited.
|
|
25544
|
+
return signIn({ selectAccount: true, employeeCompanyId: policy?.mode === 'identity' ? policy.company_id : undefined }).then((session) => {
|
|
25545
|
+
// The form that asked has left (support destroyed or the journey reset): nothing waits on this account.
|
|
25546
|
+
if (destroyed || !client || contact !== form)
|
|
25403
25547
|
return;
|
|
25404
|
-
|
|
25548
|
+
return replaceAccount(client, session, composition);
|
|
25549
|
+
});
|
|
25550
|
+
}
|
|
25551
|
+
/**
|
|
25552
|
+
* Put a chosen account's redeemed session in the old one's place: the old
|
|
25553
|
+
* one is released as `switchSupportAccount` releases it (the website's
|
|
25554
|
+
* identity suppressed, a lent session never revoked), and a form for the new
|
|
25555
|
+
* customer takes the unsent text.
|
|
25556
|
+
*/
|
|
25557
|
+
async function replaceAccount(active, session, composition) {
|
|
25558
|
+
const ownSequence = ++sequence;
|
|
25559
|
+
leaveCustomer(composition);
|
|
25560
|
+
switchedAccount = true;
|
|
25561
|
+
pendingArrival = { from: 'switch', droppedFiles: composition?.hadFiles === true };
|
|
25562
|
+
update({ stage: 'contact', busy: true, error: undefined, results: [], article: undefined, articleUrl: undefined, kbState: undefined });
|
|
25563
|
+
// The release clears the old session at once, before its revocation is sent.
|
|
25564
|
+
replacingSession = true;
|
|
25565
|
+
const released = active.switchSupportAccount();
|
|
25566
|
+
replacingSession = false;
|
|
25567
|
+
// A refused or lost revocation leaves the chosen account in place.
|
|
25568
|
+
void released.catch((value) => notify(options.onError, failure(value)));
|
|
25569
|
+
active.setSession(session);
|
|
25570
|
+
notify(options.onSession, session);
|
|
25571
|
+
if (active.ticketAccessPolicy?.mode === 'identity') {
|
|
25572
|
+
// Without this grant, contact's access check shows the employee gate for the chosen account.
|
|
25573
|
+
try {
|
|
25405
25574
|
notify(options.onTicketAccess, await active.unlockTicketAccess({ identityGrant: session.identity_grant.token }));
|
|
25406
|
-
if (destroyed || ownSequence !== sequence)
|
|
25407
|
-
return;
|
|
25408
|
-
active.setSession(session);
|
|
25409
|
-
notify(options.onSession, session);
|
|
25410
|
-
update({ busy: false });
|
|
25411
|
-
await showContact('direct');
|
|
25412
|
-
}
|
|
25413
|
-
catch (value) {
|
|
25414
|
-
await logout.catch(() => undefined);
|
|
25415
|
-
if (destroyed || ownSequence !== sequence)
|
|
25416
|
-
return;
|
|
25417
|
-
const error = failure(value);
|
|
25418
|
-
update({ busy: false, error: error.message });
|
|
25419
|
-
if (active.hasTicketAccess) {
|
|
25420
|
-
mountContact(composition ?? { subject: '', body: '' }, null);
|
|
25421
|
-
pendingComposition = null;
|
|
25422
25575
|
}
|
|
25423
|
-
|
|
25424
|
-
|
|
25576
|
+
catch (value) {
|
|
25577
|
+
if (!destroyed && ownSequence === sequence)
|
|
25578
|
+
notify(options.onError, failure(value));
|
|
25579
|
+
}
|
|
25425
25580
|
}
|
|
25581
|
+
if (destroyed || ownSequence !== sequence)
|
|
25582
|
+
return;
|
|
25583
|
+
await showContact('direct');
|
|
25584
|
+
}
|
|
25585
|
+
/**
|
|
25586
|
+
* Sign out of support from the contact form, without a window: the session
|
|
25587
|
+
* ends at once, even one the host lent, its revocation sent behind, and a
|
|
25588
|
+
* signed-out form takes the unsent text. A website account the customer
|
|
25589
|
+
* switched away from still stands behind it (`switchedAccount` is kept).
|
|
25590
|
+
*/
|
|
25591
|
+
function signOut(composition) {
|
|
25592
|
+
if (!client || destroyed || state.navigationLocked)
|
|
25593
|
+
return;
|
|
25594
|
+
const active = client;
|
|
25595
|
+
sequence += 1;
|
|
25596
|
+
leaveCustomer(composition);
|
|
25597
|
+
pendingArrival = { from: 'signOut', droppedFiles: composition?.hadFiles === true };
|
|
25598
|
+
update({ error: undefined, results: [], article: undefined, articleUrl: undefined, kbState: undefined });
|
|
25599
|
+
// The session ends here at once, and the host hears so; a refused or lost
|
|
25600
|
+
// revocation leaves this browser signed out all the same.
|
|
25601
|
+
void active.signOutSupport().catch((value) => notify(options.onError, failure(value)));
|
|
25602
|
+
// A host that keeps the session cleans up after it as its own sign-out does.
|
|
25603
|
+
const host = options.hostKeepsSession;
|
|
25604
|
+
notify(host ? () => host.onSignOut() : undefined, undefined);
|
|
25605
|
+
void showContact('direct');
|
|
25426
25606
|
}
|
|
25427
25607
|
async function useWebsiteAccount(composition, recovering = false) {
|
|
25428
25608
|
if (!client || destroyed || state.navigationLocked)
|
|
25429
25609
|
return;
|
|
25430
25610
|
const ownSequence = ++sequence;
|
|
25431
|
-
|
|
25432
|
-
contact = null;
|
|
25433
|
-
cancelArticleAssets?.();
|
|
25434
|
-
cancelArticleAssets = null;
|
|
25435
|
-
pendingComposition = composition ?? { subject: '', body: '' };
|
|
25611
|
+
leaveCustomer(composition);
|
|
25436
25612
|
pendingRecovery = recovering ? { websiteSignedOut: true } : null;
|
|
25437
|
-
kb?.clearAccess();
|
|
25438
|
-
kbConfig = null;
|
|
25439
|
-
results = [];
|
|
25440
|
-
requestedArticle = null;
|
|
25441
|
-
attempt = null;
|
|
25442
|
-
sourceArticleId = undefined;
|
|
25443
25613
|
update({ busy: true, error: undefined, results: [], article: undefined, articleUrl: undefined, kbState: undefined });
|
|
25444
25614
|
try {
|
|
25445
25615
|
await client.useWebsiteAccount();
|
|
25446
25616
|
if (destroyed || ownSequence !== sequence)
|
|
25447
25617
|
return;
|
|
25448
25618
|
switchedAccount = false;
|
|
25619
|
+
// The website account the form arrives at says so, as a switch does; one
|
|
25620
|
+
// the website does not give back gets none (`mountContact`).
|
|
25621
|
+
pendingArrival = { from: 'switch', droppedFiles: composition?.hadFiles === true };
|
|
25449
25622
|
update({ busy: false });
|
|
25450
25623
|
await showContact('direct');
|
|
25451
25624
|
}
|
|
@@ -25458,7 +25631,7 @@ function createHelpDeskSupport(config, options) {
|
|
|
25458
25631
|
if (pendingRecovery)
|
|
25459
25632
|
pendingRecovery = { websiteSignedOut: false };
|
|
25460
25633
|
if (client.hasTicketAccess) {
|
|
25461
|
-
mountContact(
|
|
25634
|
+
mountContact(pendingComposition, null);
|
|
25462
25635
|
pendingComposition = null;
|
|
25463
25636
|
}
|
|
25464
25637
|
else
|
|
@@ -30271,7 +30444,7 @@ class SparkVault {
|
|
|
30271
30444
|
}
|
|
30272
30445
|
/** Get the SDK version */
|
|
30273
30446
|
static get version() {
|
|
30274
|
-
return '16.
|
|
30447
|
+
return '16.7.0';
|
|
30275
30448
|
}
|
|
30276
30449
|
}
|
|
30277
30450
|
if (typeof window !== 'undefined') {
|