@sparkvault/sdk-js 15.11.8 → 15.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -818,12 +818,20 @@ interface NotifyInboxRow {
818
818
  * building a URL from the code.
819
819
  */
820
820
  pointer_url?: string;
821
+ /**
822
+ * True for a SEALED send's row, for good, whether or not its reveal still
823
+ * opens. A row is plain text, its `body` the whole message, only when
824
+ * `sealed` is false and it is not `recalled`; a sealed row's `body` is its
825
+ * sender's instructions about the reveal.
826
+ */
827
+ sealed: boolean;
821
828
  /**
822
829
  * True only when there is a secure part left to reveal — exactly when
823
- * `sparklink_code` is present. `false` does NOT mean "cleartext row": a sealed
824
- * row whose reveal no longer opens (opened, answered, expired or gone) is
825
- * unlocked too, and so is a recalled one, with nothing behind it. Branch on
826
- * `recalled` before treating an unlocked row as plain text.
830
+ * `sparklink_code` is present. `false` does NOT mean "cleartext row": a
831
+ * `sealed` row whose reveal no longer opens (opened, answered, expired or
832
+ * gone) is unlocked too, and so is a recalled one, with nothing behind it.
833
+ * Show such a sealed row as no longer available rather than its
834
+ * instructions, which describe a link that opens nothing.
827
835
  */
828
836
  locked: boolean;
829
837
  /**
package/dist/index.mjs CHANGED
@@ -13258,6 +13258,24 @@ const CUSTOMER_UPLOAD_REFUSALS = Object.freeze({
13258
13258
  UPLOADS_OFF: 'customer_uploads_off'
13259
13259
  });
13260
13260
 
13261
+ /** The longest subject, in characters. */
13262
+ const MAX_SUBJECT_LEN = 200;
13263
+
13264
+ /**
13265
+ * The largest message body, in UTF-8 bytes of its safe markup. A body's stored
13266
+ * written form can be longer, so it is read back with
13267
+ * `parseSafeMarkup(stored, { maxBytes: serializedBound(MAX_BODY_BYTES) })`
13268
+ * (@sparkvault/app-sdk/safe-markup).
13269
+ */
13270
+ const MAX_BODY_BYTES = 65536;
13271
+
13272
+ /**
13273
+ * What a customer's message over MAX_BODY_BYTES reads, word for word in the
13274
+ * portal's message editor and the SDK's support form: neither sends it, and
13275
+ * both keep every character for the customer to shorten.
13276
+ */
13277
+ const MESSAGE_TOO_LONG_COPY = 'This message is too long to send. Shorten it and try again.';
13278
+
13261
13279
  /** The most attachments one message carries. */
13262
13280
  const MAX_ATTACHMENTS_PER_MESSAGE = 20;
13263
13281
 
@@ -17136,6 +17154,23 @@ function lastExtension(name) {
17136
17154
  return shownExtension(closeUpSpaces(name));
17137
17155
  }
17138
17156
 
17157
+ /**
17158
+ * The longest prefix of `text` within `maxLength` UTF-16 units that splits no
17159
+ * character.
17160
+ *
17161
+ * @param {string} text
17162
+ * @param {number} maxLength
17163
+ * @returns {string}
17164
+ */
17165
+ function truncateToLength(text, maxLength) {
17166
+ let truncated = '';
17167
+ for (const character of text) {
17168
+ if (truncated.length + character.length > maxLength) break;
17169
+ truncated += character;
17170
+ }
17171
+ return truncated;
17172
+ }
17173
+
17139
17174
  /**
17140
17175
  * What a help-desk attachment may be named and what its first bytes may not
17141
17176
  * be: the one list of the files a ticket accepts, beside the one list of
@@ -17783,10 +17818,10 @@ function hostedUrl(host, path) {
17783
17818
  return null;
17784
17819
  }
17785
17820
  }
17786
- /** Whether a field holds text of the customer's own: anything but nothing or what the host prefilled. */
17821
+ /** Whether a field holds text of the customer's own: anything but nothing or what the form was filled with. */
17787
17822
  function edited(input, prefill) {
17788
17823
  const text = input.value.trim();
17789
- return text !== '' && text !== (prefill ?? '').trim();
17824
+ return text !== '' && text !== prefill.trim();
17790
17825
  }
17791
17826
  function companySignInUrl(value) {
17792
17827
  try {
@@ -17877,9 +17912,11 @@ function mountHelpDeskForm(client, options) {
17877
17912
  const firstName = field('First name', 'given_name');
17878
17913
  const lastName = field('Last name (optional)', 'family_name');
17879
17914
  const fields = [subject, description, email, code, name, firstName, lastName];
17880
- subject.input.maxLength = 200;
17881
- subject.input.value = options.subject ?? '';
17882
- description.input.value = options.body ?? '';
17915
+ // What the host, or the support controller, filled the form with: text the customer did not write.
17916
+ const prefill = { subject: options.subject ?? '', body: options.body ?? '' };
17917
+ subject.input.maxLength = MAX_SUBJECT_LEN;
17918
+ subject.input.value = prefill.subject;
17919
+ description.input.value = prefill.body;
17883
17920
  email.input.type = 'email';
17884
17921
  email.input.autocomplete = 'email';
17885
17922
  code.input.inputMode = 'numeric';
@@ -18166,9 +18203,23 @@ function mountHelpDeskForm(client, options) {
18166
18203
  if (completed)
18167
18204
  return false;
18168
18205
  return (pending && state !== 'authenticating') || uncertainSubmission !== null || challenge !== null
18169
- || edited(subject.input, options.subject) || edited(description.input, options.body)
18206
+ || edited(subject.input, prefill.subject) || edited(description.input, prefill.body)
18170
18207
  || attachments?.hasEntries === true;
18171
18208
  }
18209
+ /** The field a composition the ticket write would refuse is refused under, with what it reads there; null for one it takes. */
18210
+ function refusal(subjectText, body) {
18211
+ if (!subjectText)
18212
+ return [subject, 'Add a subject.'];
18213
+ if (subjectText.length > MAX_SUBJECT_LEN)
18214
+ return [subject, `Keep the subject to ${MAX_SUBJECT_LEN} characters.`];
18215
+ if (!body.trim())
18216
+ return [description, 'Describe what you need help with.'];
18217
+ // The limit counts UTF-8 bytes, so a message of fewer characters can be over it;
18218
+ // a message of more UTF-16 units than that is over it without being encoded.
18219
+ if (body.length > MAX_BODY_BYTES || new TextEncoder().encode(body).length > MAX_BODY_BYTES)
18220
+ return [description, MESSAGE_TOO_LONG_COPY];
18221
+ return null;
18222
+ }
18172
18223
  function showDone(ticket, customer) {
18173
18224
  const section = document.createElement('section');
18174
18225
  section.className = 'svhd-done';
@@ -18400,10 +18451,11 @@ function mountHelpDeskForm(client, options) {
18400
18451
  subject.input.value = subjectText;
18401
18452
  description.input.value = body;
18402
18453
  }
18403
- if (!subjectText || subjectText.length > 200 || !body.trim()) {
18404
- const refused = !subjectText || subjectText.length > 200 ? subject : description;
18405
- setFieldError(refused, !subjectText ? 'Add a subject.' : subjectText.length > 200 ? 'Keep the subject to 200 characters.' : 'Describe what you need help with.');
18406
- refused.input.focus();
18454
+ const refused = refusal(subjectText, body);
18455
+ if (refused) {
18456
+ const [entry, text] = refused;
18457
+ setFieldError(entry, text);
18458
+ entry.input.focus();
18407
18459
  return;
18408
18460
  }
18409
18461
  let widgetSignIn;
@@ -18715,7 +18767,24 @@ function mountHelpDeskForm(client, options) {
18715
18767
  setState('editing');
18716
18768
  },
18717
18769
  getState: () => state,
18718
- getComposition: safeComposition,
18770
+ restoreComposition(composition) {
18771
+ if (destroyed)
18772
+ return;
18773
+ subject.input.value = composition.subject;
18774
+ description.input.value = composition.body;
18775
+ },
18776
+ refill(composition) {
18777
+ if (destroyed || safeComposition() === null)
18778
+ return false;
18779
+ for (const [entry, key] of [[subject, 'subject'], [description, 'body']]) {
18780
+ if (!edited(entry.input, prefill[key])) {
18781
+ entry.input.value = composition[key];
18782
+ clearFieldError(entry);
18783
+ }
18784
+ prefill[key] = composition[key];
18785
+ }
18786
+ return true;
18787
+ },
18719
18788
  resumeAfterAccess() {
18720
18789
  if (!destroyed && !pending && !completed && uncertainSubmission === null)
18721
18790
  message('');
@@ -19681,6 +19750,58 @@ function createSupportLauncher(options, open) {
19681
19750
  };
19682
19751
  }
19683
19752
 
19753
+ /** A title written with a period: in "Dear Mr. Smith," that period ends no sentence. */
19754
+ const HONORIFIC = String.raw `(?:Mr|Mrs|Ms|Mx|Dr|Prof)\.`;
19755
+ /**
19756
+ * Where a sentence ends: after a period, exclamation or question mark that
19757
+ * whitespace follows. An honorific's period is matched first, whole, and left
19758
+ * as it is.
19759
+ */
19760
+ const SENTENCE_END = new RegExp(String.raw `\b${HONORIFIC}(?=\s)|([.!?])(?=\s)`, 'g');
19761
+ /** The word a greeting opens with, whole: "Hi", "Hello", "Good morning", "Morning". */
19762
+ const SALUTATION = /^(?:hi|hello|hey|hiya|howdy|greetings|dear|good\s+day|(?:good\s+)?(?:morning|afternoon|evening))(?!\p{L})/iu;
19763
+ /** The few words greetings use for whom they address. */
19764
+ const ADDRESS_WORDS = 'again|there|team|all|everyone|everybody|folks|guys|support|customer|service|sir|madam|or|and';
19765
+ /**
19766
+ * What may follow the salutation in a greeting: up to four words of address,
19767
+ * each an honorific, a name or one of the few words greetings use, in lower
19768
+ * case or capitals ("Mr. Smith", "Privacy Bee team", "there", "AGAIN", "Sir
19769
+ * or Madam"), then anything but letters and digits: punctuation, symbols and
19770
+ * emoji. The words of an issue ("Hi, I can't sign in", "Hey refund please",
19771
+ * "HELLO I CANT LOGIN") are none of these, so a sentence holding them is the
19772
+ * issue. A name is a capital and lowercase letters, again for each capital of
19773
+ * one like PayPal or McKenzie, so a word in capitals is shouted, not a name.
19774
+ * Case-sensitive, so that case tells a name: a case-insensitive \p{Lu} matches
19775
+ * every letter. A name's apostrophes and hyphens only join letters, so a word
19776
+ * of address ends in a letter or an honorific's period, and the closing run
19777
+ * never competes with it for more than that one period; that keeps the read
19778
+ * linear.
19779
+ */
19780
+ const ADDRESS = new RegExp(String.raw `^(?:[\s,/&]+(?:${HONORIFIC}|${ADDRESS_WORDS}|${ADDRESS_WORDS.toUpperCase()}|\p{Lu}\p{Ll}*(?:\p{Lu}\p{Ll}+)*(?:['\u2019-]\p{L}+)*)){0,4}[^\p{L}\p{N}]*$`, 'u');
19781
+ const TO_WHOM = /^to\s+whom\s+it\s+may\s+concern[^\p{L}\p{N}]*$/iu;
19782
+ const LETTER = /\p{L}/u;
19783
+ /** A line or sentence that only greets: "Hi there,", "Good morning team!", "Dear Sir or Madam,", "To whom it may concern:". */
19784
+ function isGreeting(sentence) {
19785
+ const salutation = SALUTATION.exec(sentence);
19786
+ return salutation ? ADDRESS.test(sentence.slice(salutation[0].length)) : TO_WHOM.test(sentence);
19787
+ }
19788
+ /**
19789
+ * The subject a support issue prefills: its first line or sentence that holds
19790
+ * a word and says more than a greeting (its first one when none does),
19791
+ * shortened at a word boundary with an ellipsis to fit MAX_SUBJECT_LEN. The
19792
+ * message carries the whole issue, so the subject only needs to name it.
19793
+ */
19794
+ function issueSubject(issue) {
19795
+ const sentences = issue.replace(SENTENCE_END, (match, end) => end ? `${end}\n` : match)
19796
+ .split('\n').map((sentence) => sentence.trim()).filter(Boolean);
19797
+ const subject = sentences.find((sentence) => LETTER.test(sentence) && !isGreeting(sentence)) ?? sentences[0] ?? '';
19798
+ if (subject.length <= MAX_SUBJECT_LEN)
19799
+ return subject;
19800
+ const kept = truncateToLength(subject, MAX_SUBJECT_LEN - 1);
19801
+ const atWord = /\s/u.test(subject.charAt(kept.length)) ? kept : kept.replace(/\s+\S*$/u, '');
19802
+ return `${atWord.trimEnd()}…`;
19803
+ }
19804
+
19684
19805
  /** The support journey's only skin. Customer content stays in the product register. */
19685
19806
  function injectHelpDeskSupportStyles() {
19686
19807
  if (document.getElementById('sparkvault-help-desk-support-styles'))
@@ -20852,6 +20973,8 @@ class SupportView {
20852
20973
  }
20853
20974
  }
20854
20975
 
20976
+ /** What contact starts from: the issue's subject and, as the message, every character of the issue. */
20977
+ function composeIssue(issue) { return { subject: issueSubject(issue), body: issue }; }
20855
20978
  function notify(callback, value) {
20856
20979
  try {
20857
20980
  void Promise.resolve(callback?.(value)).catch(() => undefined);
@@ -20873,8 +20996,15 @@ function createHelpDeskSupport(config, options) {
20873
20996
  let kbConfig = null;
20874
20997
  let contact = null;
20875
20998
  let contactCustomer = null;
20876
- let contactOpening = false;
20999
+ // The sequence of the contact opening in flight. It blocks another opening
21000
+ // only while it is the current sequence, so whatever supersedes it frees it.
21001
+ let contactOpening = null;
20877
21002
  let pendingComposition = null;
21003
+ // The issue, trimmed, that the held composition (the mounted form, or the one
21004
+ // a re-authorized form will take) was last filled from: '' for one filled from
21005
+ // none. A re-authorized form is filled from it too, so the text it carries is
21006
+ // the customer's own, or not, as it was in the form it came from.
21007
+ let composedFrom = '';
20878
21008
  let nativeIdentity = null;
20879
21009
  let switchedAccount = false;
20880
21010
  let attempt = null;
@@ -20899,10 +21029,10 @@ function createHelpDeskSupport(config, options) {
20899
21029
  onBack: () => {
20900
21030
  if (destroyed || state.navigationLocked || state.identityPending)
20901
21031
  return;
20902
- if (state.busy) {
21032
+ // A held form shows at once while contact still checks access behind it,
21033
+ // so a contact opening in flight is cancelled even when nothing is busy.
21034
+ if (state.busy || contactOpening === sequence)
20903
21035
  sequence += 1;
20904
- contactOpening = false;
20905
- }
20906
21036
  update({ busy: false });
20907
21037
  if (state.stage === 'feedback')
20908
21038
  update({ stage: 'article', error: undefined });
@@ -20929,30 +21059,14 @@ function createHelpDeskSupport(config, options) {
20929
21059
  if (destroyed || !state.article)
20930
21060
  return;
20931
21061
  void attempt?.then((active) => active?.solved());
20932
- contact?.destroy();
20933
- contact = null;
20934
- contactCustomer = null;
20935
- cancelArticleAssets?.();
20936
- cancelArticleAssets = null;
21062
+ endJourney();
20937
21063
  minimize();
20938
21064
  view.showToast('We’re happy we could help.');
20939
- sequence += 1;
20940
- attempt = null;
20941
- results = [];
20942
21065
  state = { visible: false, stage: 'issue', deskName: state.deskName, issue: '', position: state.position };
20943
21066
  update({});
20944
21067
  },
20945
21068
  onRestart: () => {
20946
- contact?.destroy();
20947
- contact = null;
20948
- contactCustomer = null;
20949
- cancelArticleAssets?.();
20950
- cancelArticleAssets = null;
20951
- sequence += 1;
20952
- attempt = null;
20953
- results = [];
20954
- requestedArticle = null;
20955
- pendingComposition = null;
21069
+ endJourney();
20956
21070
  update({ stage: 'issue', issue: '', results: [], article: undefined, receipt: undefined, error: undefined, busy: false });
20957
21071
  },
20958
21072
  onRetry: () => {
@@ -21014,7 +21128,7 @@ function createHelpDeskSupport(config, options) {
21014
21128
  if (destroyed)
21015
21129
  return;
21016
21130
  if (state.stage === 'issue' && !state.issue && input.issue)
21017
- state.issue = input.issue.slice(0, 12000);
21131
+ state.issue = input.issue;
21018
21132
  update({ visible: true });
21019
21133
  try {
21020
21134
  await connect();
@@ -21028,6 +21142,19 @@ function createHelpDeskSupport(config, options) {
21028
21142
  }
21029
21143
  }
21030
21144
  function minimize() { update({ visible: false }); }
21145
+ /** Forget a finished journey: its form and the files it authorized, any composition held for it, its suggestions and article. */
21146
+ function endJourney() {
21147
+ contact?.destroy();
21148
+ contact = null;
21149
+ contactCustomer = null;
21150
+ cancelArticleAssets?.();
21151
+ cancelArticleAssets = null;
21152
+ sequence += 1;
21153
+ attempt = null;
21154
+ results = [];
21155
+ requestedArticle = null;
21156
+ pendingComposition = null;
21157
+ }
21031
21158
  function signIn(input = {}) {
21032
21159
  if (!client)
21033
21160
  return Promise.reject(new Error('Support is still loading. Please try again.'));
@@ -21060,7 +21187,7 @@ function createHelpDeskSupport(config, options) {
21060
21187
  if (destroyed || !issue.trim())
21061
21188
  return;
21062
21189
  const ownSequence = ++sequence;
21063
- update({ stage: 'results', issue: issue.slice(0, 12000), busy: true, error: undefined, results: [], article: undefined, kbState: undefined });
21190
+ update({ stage: 'results', issue, busy: true, error: undefined, results: [], article: undefined, kbState: undefined });
21064
21191
  results = [];
21065
21192
  try {
21066
21193
  const active = await connect();
@@ -21186,7 +21313,9 @@ function createHelpDeskSupport(config, options) {
21186
21313
  let activeAttempt = null;
21187
21314
  contact = mountHelpDeskForm(client, {
21188
21315
  target: view.contactTarget,
21189
- ...composition,
21316
+ // Filled with the issue its composition came from, so text the customer
21317
+ // wrote in an earlier form and carried here stays their own.
21318
+ ...composeIssue(composedFrom),
21190
21319
  attachments: options.attachments,
21191
21320
  widgetIdentity: {
21192
21321
  customer,
@@ -21212,6 +21341,9 @@ function createHelpDeskSupport(config, options) {
21212
21341
  onSuccess: (ticket) => receipt(ticket),
21213
21342
  onStateChange: (next) => update({ navigationLocked: ['authenticating', 'submitting', 'uncertain'].includes(next) }),
21214
21343
  });
21344
+ contact.restoreComposition(composition);
21345
+ // A composition carried across re-authorization was filled from the issue as it read then.
21346
+ followIssue();
21215
21347
  const activeForm = contact;
21216
21348
  void attempt?.then((active) => {
21217
21349
  // Keep the mutable callback small: an analytics response arriving late
@@ -21221,9 +21353,23 @@ function createHelpDeskSupport(config, options) {
21221
21353
  });
21222
21354
  view.focusContact();
21223
21355
  }
21356
+ /**
21357
+ * Bring the mounted form to the issue as the customer last wrote it: an issue
21358
+ * rewritten since the form was filled fills each field they have not written
21359
+ * in, and text they wrote in the form stays theirs (`refill`). An unchanged
21360
+ * or emptied issue says nothing new.
21361
+ */
21362
+ function followIssue() {
21363
+ const issue = state.issue.trim();
21364
+ if (!contact || !issue || issue === composedFrom)
21365
+ return;
21366
+ if (contact.refill(composeIssue(state.issue)))
21367
+ composedFrom = issue;
21368
+ }
21224
21369
  async function showContact(reason) {
21225
- if (destroyed || contactOpening)
21370
+ if (destroyed || contactOpening === sequence)
21226
21371
  return;
21372
+ followIssue();
21227
21373
  cancelArticleAssets?.();
21228
21374
  cancelArticleAssets = null;
21229
21375
  if (reason === 'direct' && state.kbState === 'unavailable' && !attempt) {
@@ -21232,8 +21378,8 @@ function createHelpDeskSupport(config, options) {
21232
21378
  if (reason !== 'direct')
21233
21379
  void attempt?.then((active) => active?.contactRequested(reason));
21234
21380
  update({ stage: 'contact', busy: !contact || state.ticketAccessRequired, error: undefined });
21235
- contactOpening = true;
21236
21381
  const ownSequence = ++sequence;
21382
+ contactOpening = ownSequence;
21237
21383
  try {
21238
21384
  const active = await connect();
21239
21385
  await active.refreshTicketAccessPolicy();
@@ -21256,7 +21402,9 @@ function createHelpDeskSupport(config, options) {
21256
21402
  if (destroyed || ownSequence !== sequence)
21257
21403
  return;
21258
21404
  update({ busy: false, ticketAccessRequired: false, ticketAccessMode: undefined });
21259
- mountContact(pendingComposition ?? { subject: state.issue.trim().split(/\n|(?<=[.!?])\s/)[0].slice(0, 200), body: state.issue }, customer);
21405
+ if (!pendingComposition)
21406
+ composedFrom = state.issue.trim();
21407
+ mountContact(pendingComposition ?? composeIssue(state.issue), customer);
21260
21408
  pendingComposition = null;
21261
21409
  }
21262
21410
  catch (value) {
@@ -21270,8 +21418,8 @@ function createHelpDeskSupport(config, options) {
21270
21418
  notify(options.onError, error);
21271
21419
  }
21272
21420
  finally {
21273
- if (ownSequence === sequence)
21274
- contactOpening = false;
21421
+ if (contactOpening === ownSequence)
21422
+ contactOpening = null;
21275
21423
  }
21276
21424
  }
21277
21425
  async function unlockTicketAccess(password) {
@@ -26181,7 +26329,7 @@ class SparkVault {
26181
26329
  }
26182
26330
  /** Get the SDK version */
26183
26331
  static get version() {
26184
- return '15.11.8';
26332
+ return '15.12.0';
26185
26333
  }
26186
26334
  }
26187
26335
  if (typeof window !== 'undefined') {