@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.cjs
CHANGED
|
@@ -14424,11 +14424,10 @@ const DISCARD_REQUEST_COPY = Object.freeze({
|
|
|
14424
14424
|
});
|
|
14425
14425
|
|
|
14426
14426
|
/**
|
|
14427
|
-
* What the emailed-code step of
|
|
14428
|
-
*
|
|
14429
|
-
*
|
|
14430
|
-
*
|
|
14431
|
-
* the portal and on a company's own site.
|
|
14427
|
+
* What the emailed-code step of the SDK support form's sign-in says: the
|
|
14428
|
+
* refusal of a code that is wrong, spent or expired (Core's PIN_INVALID), and
|
|
14429
|
+
* the note once a new code is sent. Neither names who sent the email, so both
|
|
14430
|
+
* read right on any site the form runs on.
|
|
14432
14431
|
*/
|
|
14433
14432
|
const HELP_DESK_CODE_STEP_COPY = Object.freeze({
|
|
14434
14433
|
codeRefused: 'That code is wrong or has expired. Check the newest email, or send a new code.',
|
|
@@ -18153,7 +18152,7 @@ class HelpDeskClient {
|
|
|
18153
18152
|
// the `federated` mark and the `federated` assurance together, never one without the other.
|
|
18154
18153
|
const customer = result?.customer;
|
|
18155
18154
|
const nativeIdentity = customer?.federated === true ? customer.assurance === 'federated' : customer?.assurance === 'identity';
|
|
18156
|
-
if (!validToken(result?.token) || !nativeIdentity || !/^hdwip_[A-Za-z0-9_-]{43}$/.test(result.identity_grant?.token)) {
|
|
18155
|
+
if (!validToken(result?.token) || !Number.isFinite(result.expires_at) || !nativeIdentity || !/^hdwip_[A-Za-z0-9_-]{43}$/.test(result.identity_grant?.token)) {
|
|
18157
18156
|
throw new SparkVaultError('The help desk returned an invalid support identity.', 'HELP_DESK_INVALID_RESPONSE');
|
|
18158
18157
|
}
|
|
18159
18158
|
this.issuedSessions.set(result, result.token);
|
|
@@ -18165,6 +18164,16 @@ class HelpDeskClient {
|
|
|
18165
18164
|
this.websiteAccountSuppressed = true;
|
|
18166
18165
|
return this.releaseSession(false);
|
|
18167
18166
|
}
|
|
18167
|
+
/**
|
|
18168
|
+
* Sign the customer out of support in this browser: revoke the session, one
|
|
18169
|
+
* a provider lent included, and keep the website's identity from signing
|
|
18170
|
+
* them back in until `useWebsiteAccount`. The session is gone here before
|
|
18171
|
+
* the revocation is answered; the host website's own sign-in is untouched.
|
|
18172
|
+
*/
|
|
18173
|
+
signOutSupport() {
|
|
18174
|
+
this.websiteAccountSuppressed = true;
|
|
18175
|
+
return this.releaseSession(true);
|
|
18176
|
+
}
|
|
18168
18177
|
/** The only operation that resumes the website's configured identity provider after an explicit switch. */
|
|
18169
18178
|
async useWebsiteAccount() {
|
|
18170
18179
|
await this.releaseSession(false);
|
|
@@ -19263,7 +19272,7 @@ function carriesFiles(event) {
|
|
|
19263
19272
|
* refusals as a picked one; the drop target shows only over the composer. A
|
|
19264
19273
|
* paste or drag of text alone stays the browser's. A file brought over the
|
|
19265
19274
|
* form is never the browser's to open in place of the unsent request: on the
|
|
19266
|
-
*
|
|
19275
|
+
* sign-in step, or while the form takes no files, it is refused outright,
|
|
19267
19276
|
* and a desk that takes no files says so when the file is dropped.
|
|
19268
19277
|
*/
|
|
19269
19278
|
function createComposer(options) {
|
|
@@ -19575,6 +19584,11 @@ function postingName(customer) {
|
|
|
19575
19584
|
return words[0];
|
|
19576
19585
|
return `${words[0]} ${Array.from(words[words.length - 1])[0]}.`;
|
|
19577
19586
|
}
|
|
19587
|
+
/** The account row's words for the customer a widget form posts as: "Posting as Alex M.", one full stop either way. */
|
|
19588
|
+
function postingAsText(customer) {
|
|
19589
|
+
const shown = postingName(customer);
|
|
19590
|
+
return `Posting as ${shown}${shown.endsWith('.') ? '' : '.'}`;
|
|
19591
|
+
}
|
|
19578
19592
|
function focusAtEnd(field, focusOptions) {
|
|
19579
19593
|
field.focus(focusOptions);
|
|
19580
19594
|
// An email field has no caret to place.
|
|
@@ -19590,6 +19604,12 @@ function textButton(text, action) {
|
|
|
19590
19604
|
button.addEventListener('click', action);
|
|
19591
19605
|
return button;
|
|
19592
19606
|
}
|
|
19607
|
+
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.';
|
|
19608
|
+
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.';
|
|
19609
|
+
const SIGNING_IN_COPY = 'Finish signing in using the secure window.';
|
|
19610
|
+
const SWITCHING_COPY = 'Choose an account in the secure window.';
|
|
19611
|
+
const SIGNED_OUT_COPY = 'You’re signed out of support. What you wrote is still here.';
|
|
19612
|
+
const FILES_AGAIN_COPY = 'Choose your files again before sending.';
|
|
19593
19613
|
const SIGN_IN_CANCELLED_COPY = 'Sign-in was cancelled. Your request is still here and hasn’t been sent.';
|
|
19594
19614
|
const RECOVER_STATUS_COPY = 'Sign in again to recover your saved request.';
|
|
19595
19615
|
const RECOVER_WEBSITE_COPY = 'Sign in to your website account again to recover your saved request.';
|
|
@@ -19660,7 +19680,9 @@ function companySignInUrl(value) {
|
|
|
19660
19680
|
*
|
|
19661
19681
|
* The request is a summary and optional details, in a composer that also
|
|
19662
19682
|
* takes files. A signed-out widget customer writes it as step 1 of 2; step 2
|
|
19663
|
-
* asks
|
|
19683
|
+
* asks nothing, and its one button signs them in, in the native sign-in
|
|
19684
|
+
* window, and sends it. A signed-in one can switch account or sign out
|
|
19685
|
+
* beside the request.
|
|
19664
19686
|
*/
|
|
19665
19687
|
function mountHelpDeskForm(client, options) {
|
|
19666
19688
|
const target = resolveTarget(options.target);
|
|
@@ -19755,9 +19777,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
19755
19777
|
const email = field('Email address', 'email');
|
|
19756
19778
|
const code = field('Email code', 'code');
|
|
19757
19779
|
const name = field('Your name', 'display_name');
|
|
19758
|
-
const
|
|
19759
|
-
const lastName = field('Last name (optional)', 'family_name');
|
|
19760
|
-
const fields = [subject, description, email, code, name, firstName, lastName];
|
|
19780
|
+
const fields = [subject, description, email, code, name];
|
|
19761
19781
|
// The support wizard's issue the form was last filled from, which either
|
|
19762
19782
|
// field may hold; undefined for a form filled from the host's subject and body.
|
|
19763
19783
|
let filledFrom = options.issue;
|
|
@@ -19772,10 +19792,6 @@ function mountHelpDeskForm(client, options) {
|
|
|
19772
19792
|
code.input.inputMode = 'numeric';
|
|
19773
19793
|
code.input.autocomplete = 'one-time-code';
|
|
19774
19794
|
name.input.autocomplete = 'name';
|
|
19775
|
-
firstName.input.autocomplete = 'given-name';
|
|
19776
|
-
lastName.input.autocomplete = 'family-name';
|
|
19777
|
-
firstName.input.maxLength = 100;
|
|
19778
|
-
lastName.input.maxLength = 100;
|
|
19779
19795
|
const codeHint = document.createElement('p');
|
|
19780
19796
|
codeHint.id = `${code.input.id}-hint`;
|
|
19781
19797
|
codeHint.className = 'svhd-hint';
|
|
@@ -19828,16 +19844,16 @@ function mountHelpDeskForm(client, options) {
|
|
|
19828
19844
|
description.wrapper.insertBefore(composer.frame, description.error);
|
|
19829
19845
|
description.wrapper.insertBefore(composer.notice, description.error);
|
|
19830
19846
|
details.append(subject.wrapper, description.wrapper);
|
|
19847
|
+
// What the form asks itself: a missing name, and an emailed code's sign-in,
|
|
19848
|
+
// which the widget leaves to the secure window.
|
|
19831
19849
|
const auth = document.createElement('fieldset');
|
|
19832
19850
|
auth.className = 'svhd-auth';
|
|
19833
19851
|
auth.hidden = true;
|
|
19834
|
-
auth.append(code.wrapper, name.wrapper);
|
|
19852
|
+
auth.append(email.wrapper, code.wrapper, name.wrapper);
|
|
19835
19853
|
const widgetAccount = document.createElement('div');
|
|
19836
19854
|
widgetAccount.className = 'svhd-widget-account';
|
|
19837
19855
|
let widgetCustomer = widget?.customer ?? null;
|
|
19838
|
-
|
|
19839
|
-
const asksName = client.desk.auth_mode !== 'identity';
|
|
19840
|
-
const reply = widget ? stepHead(`${prefix}-reply-heading`, asksName ? 'Who should we reply to?' : 'Sign in to send your request', 'Step 2 of 2') : null;
|
|
19856
|
+
const signInStep = widget ? stepHead(`${prefix}-signin-heading`, 'Sign in to send your request', 'Step 2 of 2') : null;
|
|
19841
19857
|
const identity = widget ? stepContainer('identity') : null;
|
|
19842
19858
|
const recap = document.createElement('div');
|
|
19843
19859
|
recap.className = 'svhd-recap';
|
|
@@ -19847,11 +19863,13 @@ function mountHelpDeskForm(client, options) {
|
|
|
19847
19863
|
enterStep('details'); });
|
|
19848
19864
|
editRequest.setAttribute('aria-label', 'Edit your request');
|
|
19849
19865
|
const noteText = document.createTextNode('');
|
|
19850
|
-
|
|
19851
|
-
|
|
19852
|
-
|
|
19866
|
+
// What the sign-in step's button does, named on that button while the step shows.
|
|
19867
|
+
const signInHelp = document.createElement('p');
|
|
19868
|
+
signInHelp.id = `${prefix}-signin-help`;
|
|
19869
|
+
signInHelp.className = 'svhd-hint';
|
|
19870
|
+
signInHelp.textContent = SIGN_IN_HELP_COPY;
|
|
19853
19871
|
const live = createLiveRegion('svhd-live');
|
|
19854
|
-
if (identity &&
|
|
19872
|
+
if (identity && signInStep) {
|
|
19855
19873
|
form.classList.add('svhd-widget-form');
|
|
19856
19874
|
details.append(widgetAccount);
|
|
19857
19875
|
identity.hidden = true;
|
|
@@ -19866,22 +19884,8 @@ function mountHelpDeskForm(client, options) {
|
|
|
19866
19884
|
recapLabel.textContent = 'Your request';
|
|
19867
19885
|
recapRequest.append(recapLabel, recapText);
|
|
19868
19886
|
recap.append(recapRequest, editRequest);
|
|
19869
|
-
|
|
19870
|
-
helper.id = `${email.input.id}-help`;
|
|
19871
|
-
helper.className = 'svhd-hint';
|
|
19872
|
-
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.';
|
|
19873
|
-
email.input.setAttribute('aria-describedby', helper.id);
|
|
19874
|
-
identity.append(reply.head, note, recap);
|
|
19875
|
-
if (asksName) {
|
|
19876
|
-
const names = document.createElement('div');
|
|
19877
|
-
names.className = 'svhd-widget-names';
|
|
19878
|
-
names.append(firstName.wrapper, lastName.wrapper);
|
|
19879
|
-
identity.append(names);
|
|
19880
|
-
}
|
|
19881
|
-
identity.append(email.wrapper, helper);
|
|
19887
|
+
identity.append(signInStep.head, note, recap, signInHelp);
|
|
19882
19888
|
}
|
|
19883
|
-
else
|
|
19884
|
-
auth.prepend(email.wrapper);
|
|
19885
19889
|
const status = document.createElement('p');
|
|
19886
19890
|
status.className = 'svhd-status';
|
|
19887
19891
|
status.setAttribute('role', 'status');
|
|
@@ -19973,6 +19977,8 @@ function mountHelpDeskForm(client, options) {
|
|
|
19973
19977
|
let recovery = null;
|
|
19974
19978
|
// The website gave no account back when asked for the hidden request's customer.
|
|
19975
19979
|
let websiteSignedOut = false;
|
|
19980
|
+
// The form is held while the secure window chooses another account: no send is under way.
|
|
19981
|
+
let switchingAccount = false;
|
|
19976
19982
|
function persistDraft() {
|
|
19977
19983
|
if (!options.persist || completed || destroyed)
|
|
19978
19984
|
return;
|
|
@@ -20027,9 +20033,15 @@ function mountHelpDeskForm(client, options) {
|
|
|
20027
20033
|
: 'Your saved request was restored. Review it before sending.');
|
|
20028
20034
|
return true;
|
|
20029
20035
|
}
|
|
20036
|
+
/**
|
|
20037
|
+
* The unsent text an account change carries on to the next form, and
|
|
20038
|
+
* whether the composer held files then, which stay behind. None while a
|
|
20039
|
+
* send is under way, unanswered or done: an account change must not turn an
|
|
20040
|
+
* uncertain send into a fresh request.
|
|
20041
|
+
*/
|
|
20030
20042
|
function safeComposition() {
|
|
20031
|
-
|
|
20032
|
-
|
|
20043
|
+
return pending || uncertainSubmission !== null || completed ? null
|
|
20044
|
+
: { subject: subject.input.value, body: description.input.value, hadFiles: attachments?.hasEntries === true };
|
|
20033
20045
|
}
|
|
20034
20046
|
/** What the send button reads while nothing is in flight. */
|
|
20035
20047
|
function idleLabel() {
|
|
@@ -20039,14 +20051,17 @@ function mountHelpDeskForm(client, options) {
|
|
|
20039
20051
|
return 'Verify and send request';
|
|
20040
20052
|
if (recovery === 'external_sso' && widget)
|
|
20041
20053
|
return 'Use website account';
|
|
20042
|
-
if (recovery !== null
|
|
20054
|
+
if (recovery !== null)
|
|
20043
20055
|
return 'Sign in to recover request';
|
|
20044
|
-
|
|
20056
|
+
if (widget && !widgetCustomer)
|
|
20057
|
+
return step === 'identity' ? 'Sign in and send' : 'Continue';
|
|
20058
|
+
return 'Send request';
|
|
20045
20059
|
}
|
|
20046
20060
|
/**
|
|
20047
20061
|
* The signed-in widget customer writes and sends in one step, posting as
|
|
20048
|
-
* the account named under it
|
|
20049
|
-
*
|
|
20062
|
+
* the account named under it, beside Switch account and, but for a website
|
|
20063
|
+
* account's session, which the website ends, Sign out; a signed-out one
|
|
20064
|
+
* writes the request as step 1 of 2. Either way the form shows the request.
|
|
20050
20065
|
*/
|
|
20051
20066
|
function renderWidgetIdentity() {
|
|
20052
20067
|
if (!widget)
|
|
@@ -20061,12 +20076,14 @@ function mountHelpDeskForm(client, options) {
|
|
|
20061
20076
|
if (widgetCustomer) {
|
|
20062
20077
|
const postingAs = document.createElement('p');
|
|
20063
20078
|
postingAs.className = 'svhd-posting-as';
|
|
20064
|
-
|
|
20065
|
-
|
|
20066
|
-
|
|
20067
|
-
|
|
20068
|
-
|
|
20069
|
-
|
|
20079
|
+
// Switch account opens the sign-in window in this click: nothing may await before it.
|
|
20080
|
+
const switchButton = textButton('Switch account', () => { if (free())
|
|
20081
|
+
void switchAccount(switchButton); });
|
|
20082
|
+
postingAs.append(`${postingAsText(widgetCustomer)} `, switchButton);
|
|
20083
|
+
if (widgetCustomer.assurance !== 'external_sso') {
|
|
20084
|
+
postingAs.append(' ', textButton('Sign out', () => { if (free())
|
|
20085
|
+
widget.signOut(safeComposition()); }));
|
|
20086
|
+
}
|
|
20070
20087
|
widgetAccount.append(postingAs);
|
|
20071
20088
|
}
|
|
20072
20089
|
if (widget.useWebsiteAccount && widget.offerWebsiteAccount) {
|
|
@@ -20081,7 +20098,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20081
20098
|
* The actions and notes for where the request is. While the form hides a
|
|
20082
20099
|
* previous customer's saved request (`recovery`), nothing shows of it, nor
|
|
20083
20100
|
* says it was not sent, since it may be a send whose answer was lost: the
|
|
20084
|
-
* request step's status line says how to get it back and the
|
|
20101
|
+
* request step's status line says how to get it back and the sign-in
|
|
20085
20102
|
* step's note alone speaks there, Start a new request leaves it, and the
|
|
20086
20103
|
* account row is away. A website-account customer's request comes back only
|
|
20087
20104
|
* through that account, so Use website account is its one way on when the
|
|
@@ -20093,7 +20110,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20093
20110
|
startNew.hidden = recovery === null;
|
|
20094
20111
|
widgetAccount.hidden = recovery !== null || widgetAccount.childElementCount === 0;
|
|
20095
20112
|
recap.hidden = recovery !== null;
|
|
20096
|
-
noteText.data = recovery === 'identity' || recovery === 'email_pin' ? RECOVER_NOTE_COPY :
|
|
20113
|
+
noteText.data = recovery === 'identity' || recovery === 'email_pin' ? RECOVER_NOTE_COPY : UNSENT_NOTE_COPY;
|
|
20097
20114
|
if (recovery !== null)
|
|
20098
20115
|
message(step === 'identity' ? '' : recoveryStatus());
|
|
20099
20116
|
}
|
|
@@ -20118,15 +20135,19 @@ function mountHelpDeskForm(client, options) {
|
|
|
20118
20135
|
controller.focusEntry();
|
|
20119
20136
|
}
|
|
20120
20137
|
}
|
|
20121
|
-
/** Show one step, the request or
|
|
20138
|
+
/** Show one step, the request or its sign-in, without moving focus. */
|
|
20122
20139
|
function setStep(next) {
|
|
20123
20140
|
const changed = next !== step;
|
|
20124
20141
|
step = next;
|
|
20125
20142
|
details.hidden = next !== 'details';
|
|
20126
20143
|
if (identity)
|
|
20127
20144
|
identity.hidden = next !== 'identity';
|
|
20128
|
-
if (next === 'identity')
|
|
20145
|
+
if (next === 'identity') {
|
|
20129
20146
|
recapText.textContent = subject.input.value.trim();
|
|
20147
|
+
send.setAttribute('aria-describedby', signInHelp.id);
|
|
20148
|
+
}
|
|
20149
|
+
else
|
|
20150
|
+
send.removeAttribute('aria-describedby');
|
|
20130
20151
|
renderActions();
|
|
20131
20152
|
syncLeaveGuard();
|
|
20132
20153
|
if (changed)
|
|
@@ -20134,9 +20155,11 @@ function mountHelpDeskForm(client, options) {
|
|
|
20134
20155
|
}
|
|
20135
20156
|
/** The customer moves between the steps: the new step's heading takes focus and its place is announced. */
|
|
20136
20157
|
function enterStep(next) {
|
|
20158
|
+
// A notice speaks of the step being left; a hidden saved request's status is the next step's to set again.
|
|
20159
|
+
message('');
|
|
20137
20160
|
setStep(next);
|
|
20138
20161
|
live.announce(next === 'identity' ? 'Step 2 of 2' : 'Step 1 of 2');
|
|
20139
|
-
(next === 'identity' &&
|
|
20162
|
+
(next === 'identity' && signInStep ? signInStep.heading : heading).focus();
|
|
20140
20163
|
}
|
|
20141
20164
|
// An inline wizard, on any host page that gives a `target`, asks before that
|
|
20142
20165
|
// page unloads while the request holds unsent work: leaving would lose it.
|
|
@@ -20194,7 +20217,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20194
20217
|
* in place of anything written.
|
|
20195
20218
|
*/
|
|
20196
20219
|
function disable(disabled) {
|
|
20197
|
-
for (const input of [subject.input, description.input, email.input, code.input, name.input,
|
|
20220
|
+
for (const input of [subject.input, description.input, email.input, code.input, name.input, send, cancel, changeEmail, editRequest, startNew])
|
|
20198
20221
|
input.disabled = disabled;
|
|
20199
20222
|
const held = uncertainSubmission !== null || recovery !== null;
|
|
20200
20223
|
subject.input.readOnly = held;
|
|
@@ -20231,10 +20254,8 @@ function mountHelpDeskForm(client, options) {
|
|
|
20231
20254
|
? 'We may already have received this request. Closing now loses the way to check it.'
|
|
20232
20255
|
: DISCARD_REQUEST_COPY.note;
|
|
20233
20256
|
}
|
|
20234
|
-
/** The field
|
|
20257
|
+
/** The field the request step asks for: the code, name or email the form asks for itself, else the summary. */
|
|
20235
20258
|
function stepField() {
|
|
20236
|
-
if (step === 'identity')
|
|
20237
|
-
return (asksName ? firstName : email).input;
|
|
20238
20259
|
const asked = auth.hidden ? undefined : [code, name, email].find((entry) => !entry.wrapper.hidden);
|
|
20239
20260
|
return (asked ?? subject).input;
|
|
20240
20261
|
}
|
|
@@ -20242,7 +20263,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20242
20263
|
// A press on the modal's backdrop leaves focus on the page body, and
|
|
20243
20264
|
// Keep editing must never hand focus back outside the dialog.
|
|
20244
20265
|
const active = document.activeElement;
|
|
20245
|
-
confirmReturn = active instanceof HTMLElement && shell.container.contains(active) ? active : stepField();
|
|
20266
|
+
confirmReturn = active instanceof HTMLElement && shell.container.contains(active) ? active : step === 'identity' ? send : stepField();
|
|
20246
20267
|
renderConfirmNote();
|
|
20247
20268
|
actions.hidden = true;
|
|
20248
20269
|
confirm.hidden = false;
|
|
@@ -20275,7 +20296,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20275
20296
|
}
|
|
20276
20297
|
/**
|
|
20277
20298
|
* Whether closing now would lose something: a send under way or
|
|
20278
|
-
* unanswered, a code step, a request moved on to
|
|
20299
|
+
* unanswered, a code step, a request moved on to its sign-in step, or
|
|
20279
20300
|
* text and files of the customer's own. The silent company sign-in the
|
|
20280
20301
|
* form runs as it opens (`authenticating`) is no work of the customer's.
|
|
20281
20302
|
*/
|
|
@@ -20377,11 +20398,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20377
20398
|
code.wrapper.hidden = true;
|
|
20378
20399
|
name.wrapper.hidden = true;
|
|
20379
20400
|
auth.hidden = true;
|
|
20380
|
-
|
|
20381
|
-
firstName.input.value = '';
|
|
20382
|
-
lastName.input.value = '';
|
|
20383
|
-
renderWidgetIdentity();
|
|
20384
|
-
}
|
|
20401
|
+
renderWidgetIdentity();
|
|
20385
20402
|
hosted.hidden = true;
|
|
20386
20403
|
draftId = null;
|
|
20387
20404
|
draftPromise = null;
|
|
@@ -20449,6 +20466,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20449
20466
|
restoredFiles = false;
|
|
20450
20467
|
generation += 1;
|
|
20451
20468
|
pending = false;
|
|
20469
|
+
switchingAccount = false;
|
|
20452
20470
|
sessionKnown = false;
|
|
20453
20471
|
if (options.widgetIdentity)
|
|
20454
20472
|
widgetCustomer = null;
|
|
@@ -20568,25 +20586,16 @@ function mountHelpDeskForm(client, options) {
|
|
|
20568
20586
|
}
|
|
20569
20587
|
let widgetSignIn;
|
|
20570
20588
|
if (widget && !widgetCustomer) {
|
|
20571
|
-
// The request is written;
|
|
20589
|
+
// The request is written; signing in to send it is the next step, and
|
|
20572
20590
|
// nothing reaches the network before it.
|
|
20573
20591
|
if (step === 'details') {
|
|
20574
20592
|
enterStep('identity');
|
|
20575
20593
|
return;
|
|
20576
20594
|
}
|
|
20577
|
-
const givenName = asksName ? firstName.input.value.trim() : '';
|
|
20578
|
-
const familyName = asksName ? lastName.input.value.trim() : '';
|
|
20579
|
-
const emailAddress = email.input.value.trim();
|
|
20580
|
-
const invalid = asksName && !givenName ? firstName : !email.input.validity.valid || !emailAddress ? email : null;
|
|
20581
|
-
if (invalid) {
|
|
20582
|
-
setFieldError(invalid, invalid === email ? 'Enter your email address.' : 'Enter your first name.');
|
|
20583
|
-
invalid.input.focus();
|
|
20584
|
-
return;
|
|
20585
|
-
}
|
|
20586
20595
|
// Invoke in the original submit gesture, before any awaited token read:
|
|
20587
20596
|
// the Identity adapter can open its native window without a popup block.
|
|
20588
20597
|
try {
|
|
20589
|
-
widgetSignIn = widget.signIn(
|
|
20598
|
+
widgetSignIn = widget.signIn();
|
|
20590
20599
|
}
|
|
20591
20600
|
catch (failure) {
|
|
20592
20601
|
const error = failure instanceof Error ? failure : new Error('Sign-in could not be opened.');
|
|
@@ -20609,7 +20618,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20609
20618
|
authenticating = true;
|
|
20610
20619
|
authNotification = false;
|
|
20611
20620
|
setState('authenticating');
|
|
20612
|
-
message(
|
|
20621
|
+
message(SIGNING_IN_COPY);
|
|
20613
20622
|
}
|
|
20614
20623
|
let token = await tokenFor(ownGeneration);
|
|
20615
20624
|
if (!alive(ownGeneration))
|
|
@@ -20810,7 +20819,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20810
20819
|
focusAfter = code.input;
|
|
20811
20820
|
}
|
|
20812
20821
|
else if (widgetSignIn && error instanceof SparkVaultError && error.code === 'user_cancelled') {
|
|
20813
|
-
// The request stays on
|
|
20822
|
+
// The request stays on its sign-in step, ready to sign in again;
|
|
20814
20823
|
// a hidden saved request is not here to speak of, so its note alone stays.
|
|
20815
20824
|
if (recovery === null)
|
|
20816
20825
|
message(SIGN_IN_CANCELLED_COPY);
|
|
@@ -20869,6 +20878,84 @@ function mountHelpDeskForm(client, options) {
|
|
|
20869
20878
|
}
|
|
20870
20879
|
}
|
|
20871
20880
|
}
|
|
20881
|
+
/** A request this tab saved, restored as the form mounted, which a carried composition never replaces. */
|
|
20882
|
+
function holdsSavedRequest() {
|
|
20883
|
+
return restoredDraft || restoredAnonymous;
|
|
20884
|
+
}
|
|
20885
|
+
/**
|
|
20886
|
+
* What the form says of the account change it arrives from (`arrived`), once
|
|
20887
|
+
* mounting has restored any saved request: its status line, null to leave
|
|
20888
|
+
* the one mounting set, and what a screen reader hears. A restored saved
|
|
20889
|
+
* request takes the carried text's place, so its own status stands and
|
|
20890
|
+
* nothing is said of the carried request's files.
|
|
20891
|
+
*/
|
|
20892
|
+
function arrival() {
|
|
20893
|
+
const arrived = widget?.arrived;
|
|
20894
|
+
if (!arrived)
|
|
20895
|
+
return null;
|
|
20896
|
+
const placed = !holdsSavedRequest();
|
|
20897
|
+
const files = placed && arrived.droppedFiles ? ` ${FILES_AGAIN_COPY}` : '';
|
|
20898
|
+
if (arrived.from === 'signOut')
|
|
20899
|
+
return { status: placed ? `${SIGNED_OUT_COPY}${files}` : null, announcement: `${SIGNED_OUT_COPY}${files} Step 1 of 2` };
|
|
20900
|
+
if (!widgetCustomer)
|
|
20901
|
+
return null;
|
|
20902
|
+
return { status: files ? FILES_AGAIN_COPY : null, announcement: `${postingAsText(widgetCustomer)}${files}` };
|
|
20903
|
+
}
|
|
20904
|
+
/**
|
|
20905
|
+
* Switch account: the secure window's chooser opens in the customer's
|
|
20906
|
+
* click. This customer stays signed in, the request held in view, until
|
|
20907
|
+
* another account is chosen and a form for it replaces this one. Closing
|
|
20908
|
+
* the window changes nothing; any other failure says why. Either way focus
|
|
20909
|
+
* goes back to `control`.
|
|
20910
|
+
*/
|
|
20911
|
+
async function switchAccount(control) {
|
|
20912
|
+
if (!widget)
|
|
20913
|
+
return;
|
|
20914
|
+
closeConfirm(false);
|
|
20915
|
+
let switched;
|
|
20916
|
+
try {
|
|
20917
|
+
switched = widget.switchAccount(safeComposition());
|
|
20918
|
+
}
|
|
20919
|
+
catch (failure) {
|
|
20920
|
+
const error = failure instanceof Error ? failure : new Error('Sign-in could not be opened.');
|
|
20921
|
+
message(error.message, true);
|
|
20922
|
+
notify$1(options.onError, error);
|
|
20923
|
+
return;
|
|
20924
|
+
}
|
|
20925
|
+
const ownGeneration = generation;
|
|
20926
|
+
pending = true;
|
|
20927
|
+
switchingAccount = true;
|
|
20928
|
+
disable(true);
|
|
20929
|
+
setState('authenticating');
|
|
20930
|
+
message(SWITCHING_COPY);
|
|
20931
|
+
// The status line moves the actions below it.
|
|
20932
|
+
options.onScreenChange?.();
|
|
20933
|
+
try {
|
|
20934
|
+
await switched;
|
|
20935
|
+
}
|
|
20936
|
+
catch (failure) {
|
|
20937
|
+
if (!alive(ownGeneration))
|
|
20938
|
+
return;
|
|
20939
|
+
const error = failure instanceof Error ? failure : new Error('The account could not be switched.');
|
|
20940
|
+
if (error instanceof SparkVaultError && error.code === 'user_cancelled')
|
|
20941
|
+
message('');
|
|
20942
|
+
else {
|
|
20943
|
+
message(error.message, true);
|
|
20944
|
+
notify$1(options.onError, error);
|
|
20945
|
+
}
|
|
20946
|
+
}
|
|
20947
|
+
finally {
|
|
20948
|
+
if (alive(ownGeneration)) {
|
|
20949
|
+
pending = false;
|
|
20950
|
+
switchingAccount = false;
|
|
20951
|
+
setState('editing');
|
|
20952
|
+
disable(false);
|
|
20953
|
+
options.onScreenChange?.();
|
|
20954
|
+
focusAfter = control;
|
|
20955
|
+
focusSettled();
|
|
20956
|
+
}
|
|
20957
|
+
}
|
|
20958
|
+
}
|
|
20872
20959
|
/** Take a typed, pasted or autofilled code as its digits, and send it the moment the last one lands. */
|
|
20873
20960
|
function takeCode(value) {
|
|
20874
20961
|
const digits = helpDeskPinDigits(value);
|
|
@@ -20890,26 +20977,47 @@ function mountHelpDeskForm(client, options) {
|
|
|
20890
20977
|
/** The Cancel path: remove the form, then tell the host the customer closed it. */
|
|
20891
20978
|
function dismiss() {
|
|
20892
20979
|
const discardDraft = uncertainSubmission === null;
|
|
20893
|
-
|
|
20980
|
+
if (!destroyed)
|
|
20981
|
+
teardown(!discardDraft);
|
|
20894
20982
|
if (discardDraft)
|
|
20895
20983
|
forgetDraft();
|
|
20896
20984
|
notify$1(options.onCancel, undefined);
|
|
20897
20985
|
}
|
|
20986
|
+
/** Remove the form and silence it; `save` keeps its request in this tab for the customer it shows. */
|
|
20987
|
+
function teardown(save) {
|
|
20988
|
+
if (save)
|
|
20989
|
+
persistDraft();
|
|
20990
|
+
destroyed = true;
|
|
20991
|
+
generation += 1;
|
|
20992
|
+
stopResendCountdown();
|
|
20993
|
+
attachments?.destroy(completed || uncertainSubmission !== null);
|
|
20994
|
+
composer.destroy();
|
|
20995
|
+
live.destroy();
|
|
20996
|
+
unsubscribe();
|
|
20997
|
+
form.removeEventListener('submit', onSubmit);
|
|
20998
|
+
shell.destroy();
|
|
20999
|
+
setState('destroyed');
|
|
21000
|
+
}
|
|
20898
21001
|
const controller = {
|
|
20899
21002
|
destroy() {
|
|
21003
|
+
if (!destroyed)
|
|
21004
|
+
teardown(true);
|
|
21005
|
+
},
|
|
21006
|
+
leave() {
|
|
20900
21007
|
if (destroyed)
|
|
20901
21008
|
return;
|
|
20902
|
-
|
|
20903
|
-
|
|
20904
|
-
|
|
20905
|
-
|
|
20906
|
-
|
|
20907
|
-
|
|
20908
|
-
|
|
20909
|
-
|
|
20910
|
-
|
|
20911
|
-
|
|
20912
|
-
|
|
21009
|
+
const owner = draftOwner;
|
|
21010
|
+
const sending = pending && !switchingAccount;
|
|
21011
|
+
if (!owner || sending || uncertainSubmission !== null || completed || recovery !== null) {
|
|
21012
|
+
teardown(true);
|
|
21013
|
+
return;
|
|
21014
|
+
}
|
|
21015
|
+
// The request goes on with the account change: this customer's saved copy
|
|
21016
|
+
// must not come back to them over the text as edited since, nor offer the
|
|
21017
|
+
// request a second time.
|
|
21018
|
+
teardown(false);
|
|
21019
|
+
if (options.persist)
|
|
21020
|
+
removeFormDraft(client.desk.desk_id, owner.requester_id);
|
|
20913
21021
|
},
|
|
20914
21022
|
reset() {
|
|
20915
21023
|
if (destroyed || pending || uncertainSubmission)
|
|
@@ -20925,7 +21033,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20925
21033
|
},
|
|
20926
21034
|
getState: () => state,
|
|
20927
21035
|
restoreComposition(composition) {
|
|
20928
|
-
if (destroyed ||
|
|
21036
|
+
if (destroyed || holdsSavedRequest())
|
|
20929
21037
|
return;
|
|
20930
21038
|
subject.input.value = composition.subject;
|
|
20931
21039
|
description.input.value = composition.body;
|
|
@@ -20966,10 +21074,14 @@ function mountHelpDeskForm(client, options) {
|
|
|
20966
21074
|
focusEntry(focusOptions) {
|
|
20967
21075
|
if (destroyed || form.hidden)
|
|
20968
21076
|
return false;
|
|
21077
|
+
if (step === 'identity' && signInStep) {
|
|
21078
|
+
(send.disabled ? signInStep.heading : send).focus(focusOptions);
|
|
21079
|
+
return true;
|
|
21080
|
+
}
|
|
20969
21081
|
const asked = stepField();
|
|
20970
21082
|
const entry = asked === subject.input && subject.input.value.trim() ? description.input : asked;
|
|
20971
21083
|
if (entry.disabled || entry.readOnly)
|
|
20972
|
-
|
|
21084
|
+
heading.focus(focusOptions);
|
|
20973
21085
|
else
|
|
20974
21086
|
focusAtEnd(entry, focusOptions);
|
|
20975
21087
|
return true;
|
|
@@ -21013,9 +21125,6 @@ function mountHelpDeskForm(client, options) {
|
|
|
21013
21125
|
});
|
|
21014
21126
|
send.textContent = idleLabel();
|
|
21015
21127
|
renderWidgetIdentity();
|
|
21016
|
-
// A signed-out widget customer starts on step 1 of 2 with focus in the request.
|
|
21017
|
-
if (widget && !widgetCustomer)
|
|
21018
|
-
live.announce('Step 1 of 2');
|
|
21019
21128
|
if (options.widgetIdentity?.customer) {
|
|
21020
21129
|
restoreDraft(options.widgetIdentity.customer);
|
|
21021
21130
|
disable(false);
|
|
@@ -21036,6 +21145,15 @@ function mountHelpDeskForm(client, options) {
|
|
|
21036
21145
|
restoredAnonymous = true;
|
|
21037
21146
|
}
|
|
21038
21147
|
}
|
|
21148
|
+
const arriving = arrival();
|
|
21149
|
+
if (arriving?.status)
|
|
21150
|
+
message(arriving.status);
|
|
21151
|
+
// A signed-out widget customer starts on step 1 of 2 with focus in the
|
|
21152
|
+
// request; after an account change a screen reader hears where it stands.
|
|
21153
|
+
if (arriving)
|
|
21154
|
+
live.announce(arriving.announcement);
|
|
21155
|
+
else if (widget && !widgetCustomer)
|
|
21156
|
+
live.announce('Step 1 of 2');
|
|
21039
21157
|
syncLeaveGuard();
|
|
21040
21158
|
notify$1(options.onStateChange, state);
|
|
21041
21159
|
// Native company identity starts as the form opens, never from a Connect,
|
|
@@ -23406,7 +23524,6 @@ function injectHelpDeskSupportStyles() {
|
|
|
23406
23524
|
@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}}
|
|
23407
23525
|
.svhs-panel .svhd-composer-input:focus-visible{outline:none}
|
|
23408
23526
|
.svhs-panel .svhd-composer button:focus-visible{outline-offset:-2px}
|
|
23409
|
-
.svhs-contact-target .svhd-widget-names{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:12px}
|
|
23410
23527
|
.svhs-contact-target .svhd-widget-form{display:flex;flex:1;flex-direction:column;gap:16px}
|
|
23411
23528
|
/* The request fills the panel: the details step, and in it the composer and its text, take the height the fields leave. */
|
|
23412
23529
|
.svhs-contact-target .svhd-widget-form>[data-contact-step=details]{display:flex;flex:1;flex-direction:column;gap:16px}
|
|
@@ -24757,6 +24874,13 @@ function createHelpDeskSupport(config, options) {
|
|
|
24757
24874
|
// A website-account customer's saved request the next form keeps hidden,
|
|
24758
24875
|
// asked for through the website account, which may give no account back.
|
|
24759
24876
|
let pendingRecovery = null;
|
|
24877
|
+
// The account change the next form arrives from, which it says: a Sign out
|
|
24878
|
+
// to a signed-out form, a Switch account or Use website account to the
|
|
24879
|
+
// account arrived at.
|
|
24880
|
+
let pendingArrival = null;
|
|
24881
|
+
// A chosen account's session is taking the old one's place: the host hears
|
|
24882
|
+
// the new session, never the signed-out moment between the two.
|
|
24883
|
+
let replacingSession = false;
|
|
24760
24884
|
// The issue, as written, that the held composition (the mounted form, the one
|
|
24761
24885
|
// a re-authorized form will take, or the one saved before a reload) was last
|
|
24762
24886
|
// filled from: '' for one filled from none. A form taking that composition is
|
|
@@ -24795,7 +24919,7 @@ function createHelpDeskSupport(config, options) {
|
|
|
24795
24919
|
onBack: () => {
|
|
24796
24920
|
if (destroyed || state.navigationLocked || state.identityPending)
|
|
24797
24921
|
return;
|
|
24798
|
-
// On
|
|
24922
|
+
// On the sign-in step, Back returns to the request it is for.
|
|
24799
24923
|
if (state.stage === 'contact' && !state.ticketAccessRequired && contact?.returnToRequest())
|
|
24800
24924
|
return;
|
|
24801
24925
|
// A held form shows at once while contact still checks access behind it,
|
|
@@ -24873,7 +24997,7 @@ function createHelpDeskSupport(config, options) {
|
|
|
24873
24997
|
throw new Error('Support is closed.');
|
|
24874
24998
|
client = answer;
|
|
24875
24999
|
stopSession = answer.subscribeSession((change) => {
|
|
24876
|
-
if (change.source === 'clear')
|
|
25000
|
+
if (change.source === 'clear' && !replacingSession)
|
|
24877
25001
|
notify(options.onSession, null);
|
|
24878
25002
|
});
|
|
24879
25003
|
kb = new HelpDeskKnowledgeBaseClient(config, answer.desk.desk_id);
|
|
@@ -25004,6 +25128,7 @@ function createHelpDeskSupport(config, options) {
|
|
|
25004
25128
|
requestedArticle = null;
|
|
25005
25129
|
pendingComposition = null;
|
|
25006
25130
|
pendingRecovery = null;
|
|
25131
|
+
pendingArrival = null;
|
|
25007
25132
|
feedbackSequence += 1;
|
|
25008
25133
|
sourceArticleId = undefined;
|
|
25009
25134
|
if (options.persist && client)
|
|
@@ -25169,14 +25294,19 @@ function createHelpDeskSupport(config, options) {
|
|
|
25169
25294
|
if (!client || destroyed)
|
|
25170
25295
|
return;
|
|
25171
25296
|
contactCustomer = customer;
|
|
25297
|
+
anonymous = !customer;
|
|
25172
25298
|
// A customer the website gave back sees their own saved request; none keeps it hidden.
|
|
25173
25299
|
const recovering = customer ? null : pendingRecovery;
|
|
25174
25300
|
pendingRecovery = null;
|
|
25301
|
+
// A Sign out arrives only at a signed-out form, a switch only at an account's.
|
|
25302
|
+
const arrived = pendingArrival && (pendingArrival.from === 'signOut') === !customer ? pendingArrival : null;
|
|
25303
|
+
pendingArrival = null;
|
|
25175
25304
|
let activeAttempt = null;
|
|
25176
25305
|
// A ticket carries the attempt the form opened under only while it is still
|
|
25177
25306
|
// the journey's: recovery drops it with the previous customer's question.
|
|
25178
25307
|
const formAttempt = attempt;
|
|
25179
|
-
|
|
25308
|
+
// A host that keeps the session this journey proves has no website account behind it to go back to.
|
|
25309
|
+
const bridged = !options.hostKeepsSession && Boolean(options.getSessionToken || options.getIdentityAssertion || options.identityEndpoint);
|
|
25180
25310
|
contact = mountHelpDeskForm(client, {
|
|
25181
25311
|
target: view.contactTarget,
|
|
25182
25312
|
// Filled from the issue its composition came from, so text the customer
|
|
@@ -25194,13 +25324,15 @@ function createHelpDeskSupport(config, options) {
|
|
|
25194
25324
|
},
|
|
25195
25325
|
widgetIdentity: {
|
|
25196
25326
|
customer,
|
|
25197
|
-
signIn: (
|
|
25198
|
-
switchAccount
|
|
25327
|
+
signIn: () => signIn().then((session) => { contactCustomer = session.customer; return session; }),
|
|
25328
|
+
switchAccount,
|
|
25329
|
+
signOut,
|
|
25199
25330
|
...(bridged && { useWebsiteAccount: (safe, recover) => { void useWebsiteAccount(safe, recover); } }),
|
|
25200
25331
|
offerWebsiteAccount: switchedAccount,
|
|
25201
25332
|
forgetIssue,
|
|
25202
25333
|
followIssue,
|
|
25203
25334
|
...(recovering && { recovering }),
|
|
25335
|
+
...(arrived && { arrived }),
|
|
25204
25336
|
},
|
|
25205
25337
|
onScreenChange: () => view.contactScreenChanged(),
|
|
25206
25338
|
assistanceContext: () => (attempt === formAttempt ? activeAttempt?.ticketContext() : undefined),
|
|
@@ -25314,7 +25446,6 @@ function createHelpDeskSupport(config, options) {
|
|
|
25314
25446
|
if (destroyed || ownSequence !== sequence)
|
|
25315
25447
|
return;
|
|
25316
25448
|
update({ busy: false, ticketAccessRequired: false, ticketAccessMode: undefined });
|
|
25317
|
-
anonymous = !customer;
|
|
25318
25449
|
// A composition saved before a reload goes on from the issue it was filled
|
|
25319
25450
|
// from; with none carried, the form fills itself from the issue as written.
|
|
25320
25451
|
const saved = pendingComposition === null && options.persist ? readAnonymousFormDraft(active.desk.desk_id) : null;
|
|
@@ -25378,78 +25509,120 @@ function createHelpDeskSupport(config, options) {
|
|
|
25378
25509
|
notify(options.onError, error);
|
|
25379
25510
|
}
|
|
25380
25511
|
}
|
|
25381
|
-
|
|
25382
|
-
|
|
25383
|
-
|
|
25384
|
-
|
|
25385
|
-
|
|
25386
|
-
|
|
25512
|
+
/**
|
|
25513
|
+
* Forget what the leaving customer's form led to before another account, or
|
|
25514
|
+
* none, takes its place: the form itself, the articles and the help center
|
|
25515
|
+
* access it opened. Only `composition`'s unsent text goes on to the next
|
|
25516
|
+
* form, which the leaving form's saved copy then no longer stands for
|
|
25517
|
+
* (`leave`); files and uncertain sends keep their requester boundary.
|
|
25518
|
+
*/
|
|
25519
|
+
function leaveCustomer(composition) {
|
|
25520
|
+
if (composition)
|
|
25521
|
+
contact?.leave();
|
|
25522
|
+
else
|
|
25523
|
+
contact?.destroy();
|
|
25387
25524
|
contact = null;
|
|
25525
|
+
contactCustomer = null;
|
|
25388
25526
|
cancelArticleAssets?.();
|
|
25389
25527
|
cancelArticleAssets = null;
|
|
25390
|
-
pendingComposition = composition
|
|
25528
|
+
pendingComposition = composition ? { subject: composition.subject, body: composition.body } : { subject: '', body: '' };
|
|
25391
25529
|
pendingRecovery = null;
|
|
25530
|
+
pendingArrival = null;
|
|
25392
25531
|
kb?.clearAccess();
|
|
25393
25532
|
kbConfig = null;
|
|
25394
25533
|
results = [];
|
|
25395
25534
|
requestedArticle = null;
|
|
25396
25535
|
attempt = null;
|
|
25397
25536
|
sourceArticleId = undefined;
|
|
25398
|
-
|
|
25399
|
-
|
|
25400
|
-
|
|
25401
|
-
|
|
25402
|
-
|
|
25403
|
-
|
|
25404
|
-
|
|
25405
|
-
|
|
25406
|
-
|
|
25537
|
+
}
|
|
25538
|
+
/**
|
|
25539
|
+
* Switch account from the contact form: auth.sv's chooser opens in this
|
|
25540
|
+
* gesture, the current session staying current until another account's is
|
|
25541
|
+
* redeemed. A window that closes or fails rejects, nothing changed, for the
|
|
25542
|
+
* form to say so; a redeemed session takes the old one's place.
|
|
25543
|
+
*/
|
|
25544
|
+
function switchAccount(composition) {
|
|
25545
|
+
const form = contact;
|
|
25546
|
+
const policy = client?.ticketAccessPolicy;
|
|
25547
|
+
// Open synchronously in the Switch account gesture, before anything is awaited.
|
|
25548
|
+
return signIn({ selectAccount: true, employeeCompanyId: policy?.mode === 'identity' ? policy.company_id : undefined }).then((session) => {
|
|
25549
|
+
// The form that asked has left (support destroyed or the journey reset): nothing waits on this account.
|
|
25550
|
+
if (destroyed || !client || contact !== form)
|
|
25407
25551
|
return;
|
|
25408
|
-
|
|
25552
|
+
return replaceAccount(client, session, composition);
|
|
25553
|
+
});
|
|
25554
|
+
}
|
|
25555
|
+
/**
|
|
25556
|
+
* Put a chosen account's redeemed session in the old one's place: the old
|
|
25557
|
+
* one is released as `switchSupportAccount` releases it (the website's
|
|
25558
|
+
* identity suppressed, a lent session never revoked), and a form for the new
|
|
25559
|
+
* customer takes the unsent text.
|
|
25560
|
+
*/
|
|
25561
|
+
async function replaceAccount(active, session, composition) {
|
|
25562
|
+
const ownSequence = ++sequence;
|
|
25563
|
+
leaveCustomer(composition);
|
|
25564
|
+
switchedAccount = true;
|
|
25565
|
+
pendingArrival = { from: 'switch', droppedFiles: composition?.hadFiles === true };
|
|
25566
|
+
update({ stage: 'contact', busy: true, error: undefined, results: [], article: undefined, articleUrl: undefined, kbState: undefined });
|
|
25567
|
+
// The release clears the old session at once, before its revocation is sent.
|
|
25568
|
+
replacingSession = true;
|
|
25569
|
+
const released = active.switchSupportAccount();
|
|
25570
|
+
replacingSession = false;
|
|
25571
|
+
// A refused or lost revocation leaves the chosen account in place.
|
|
25572
|
+
void released.catch((value) => notify(options.onError, failure(value)));
|
|
25573
|
+
active.setSession(session);
|
|
25574
|
+
notify(options.onSession, session);
|
|
25575
|
+
if (active.ticketAccessPolicy?.mode === 'identity') {
|
|
25576
|
+
// Without this grant, contact's access check shows the employee gate for the chosen account.
|
|
25577
|
+
try {
|
|
25409
25578
|
notify(options.onTicketAccess, await active.unlockTicketAccess({ identityGrant: session.identity_grant.token }));
|
|
25410
|
-
if (destroyed || ownSequence !== sequence)
|
|
25411
|
-
return;
|
|
25412
|
-
active.setSession(session);
|
|
25413
|
-
notify(options.onSession, session);
|
|
25414
|
-
update({ busy: false });
|
|
25415
|
-
await showContact('direct');
|
|
25416
|
-
}
|
|
25417
|
-
catch (value) {
|
|
25418
|
-
await logout.catch(() => undefined);
|
|
25419
|
-
if (destroyed || ownSequence !== sequence)
|
|
25420
|
-
return;
|
|
25421
|
-
const error = failure(value);
|
|
25422
|
-
update({ busy: false, error: error.message });
|
|
25423
|
-
if (active.hasTicketAccess) {
|
|
25424
|
-
mountContact(composition ?? { subject: '', body: '' }, null);
|
|
25425
|
-
pendingComposition = null;
|
|
25426
25579
|
}
|
|
25427
|
-
|
|
25428
|
-
|
|
25580
|
+
catch (value) {
|
|
25581
|
+
if (!destroyed && ownSequence === sequence)
|
|
25582
|
+
notify(options.onError, failure(value));
|
|
25583
|
+
}
|
|
25429
25584
|
}
|
|
25585
|
+
if (destroyed || ownSequence !== sequence)
|
|
25586
|
+
return;
|
|
25587
|
+
await showContact('direct');
|
|
25588
|
+
}
|
|
25589
|
+
/**
|
|
25590
|
+
* Sign out of support from the contact form, without a window: the session
|
|
25591
|
+
* ends at once, even one the host lent, its revocation sent behind, and a
|
|
25592
|
+
* signed-out form takes the unsent text. A website account the customer
|
|
25593
|
+
* switched away from still stands behind it (`switchedAccount` is kept).
|
|
25594
|
+
*/
|
|
25595
|
+
function signOut(composition) {
|
|
25596
|
+
if (!client || destroyed || state.navigationLocked)
|
|
25597
|
+
return;
|
|
25598
|
+
const active = client;
|
|
25599
|
+
sequence += 1;
|
|
25600
|
+
leaveCustomer(composition);
|
|
25601
|
+
pendingArrival = { from: 'signOut', droppedFiles: composition?.hadFiles === true };
|
|
25602
|
+
update({ error: undefined, results: [], article: undefined, articleUrl: undefined, kbState: undefined });
|
|
25603
|
+
// The session ends here at once, and the host hears so; a refused or lost
|
|
25604
|
+
// revocation leaves this browser signed out all the same.
|
|
25605
|
+
void active.signOutSupport().catch((value) => notify(options.onError, failure(value)));
|
|
25606
|
+
// A host that keeps the session cleans up after it as its own sign-out does.
|
|
25607
|
+
const host = options.hostKeepsSession;
|
|
25608
|
+
notify(host ? () => host.onSignOut() : undefined, undefined);
|
|
25609
|
+
void showContact('direct');
|
|
25430
25610
|
}
|
|
25431
25611
|
async function useWebsiteAccount(composition, recovering = false) {
|
|
25432
25612
|
if (!client || destroyed || state.navigationLocked)
|
|
25433
25613
|
return;
|
|
25434
25614
|
const ownSequence = ++sequence;
|
|
25435
|
-
|
|
25436
|
-
contact = null;
|
|
25437
|
-
cancelArticleAssets?.();
|
|
25438
|
-
cancelArticleAssets = null;
|
|
25439
|
-
pendingComposition = composition ?? { subject: '', body: '' };
|
|
25615
|
+
leaveCustomer(composition);
|
|
25440
25616
|
pendingRecovery = recovering ? { websiteSignedOut: true } : null;
|
|
25441
|
-
kb?.clearAccess();
|
|
25442
|
-
kbConfig = null;
|
|
25443
|
-
results = [];
|
|
25444
|
-
requestedArticle = null;
|
|
25445
|
-
attempt = null;
|
|
25446
|
-
sourceArticleId = undefined;
|
|
25447
25617
|
update({ busy: true, error: undefined, results: [], article: undefined, articleUrl: undefined, kbState: undefined });
|
|
25448
25618
|
try {
|
|
25449
25619
|
await client.useWebsiteAccount();
|
|
25450
25620
|
if (destroyed || ownSequence !== sequence)
|
|
25451
25621
|
return;
|
|
25452
25622
|
switchedAccount = false;
|
|
25623
|
+
// The website account the form arrives at says so, as a switch does; one
|
|
25624
|
+
// the website does not give back gets none (`mountContact`).
|
|
25625
|
+
pendingArrival = { from: 'switch', droppedFiles: composition?.hadFiles === true };
|
|
25453
25626
|
update({ busy: false });
|
|
25454
25627
|
await showContact('direct');
|
|
25455
25628
|
}
|
|
@@ -25462,7 +25635,7 @@ function createHelpDeskSupport(config, options) {
|
|
|
25462
25635
|
if (pendingRecovery)
|
|
25463
25636
|
pendingRecovery = { websiteSignedOut: false };
|
|
25464
25637
|
if (client.hasTicketAccess) {
|
|
25465
|
-
mountContact(
|
|
25638
|
+
mountContact(pendingComposition, null);
|
|
25466
25639
|
pendingComposition = null;
|
|
25467
25640
|
}
|
|
25468
25641
|
else
|
|
@@ -30275,7 +30448,7 @@ class SparkVault {
|
|
|
30275
30448
|
}
|
|
30276
30449
|
/** Get the SDK version */
|
|
30277
30450
|
static get version() {
|
|
30278
|
-
return '16.
|
|
30451
|
+
return '16.7.0';
|
|
30279
30452
|
}
|
|
30280
30453
|
}
|
|
30281
30454
|
if (typeof window !== 'undefined') {
|