@sparkvault/sdk-js 17.0.2 → 18.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -410,9 +410,10 @@ one-line question starts as the Summary, a longer one as the details. Files
410
410
  attach from the details composer by its Attach control, paste or drop. A
411
411
  verified website session sends from that step, named in a "Posting as" line,
412
412
  without another login. Anonymous visitors continue to a second step that asks
413
- nothing: **Sign in and send** opens the native auth.SV Identity window, which
414
- offers the accounts already signed in on the browser or a fresh sign-in, before
415
- the request is sent. An inline (`target`) wizard asks before its page is left
413
+ nothing: **Sign in and send** opens Help Desk's sign-in window
414
+ (`https://signin.help.sv`), which signs the visitor in with an auth.SV account
415
+ and asks them to confirm the website and the account before the request is
416
+ sent. An inline (`target`) wizard asks before its page is left
416
417
  with an unsent request. "Switch account" changes only the support account, once
417
418
  the window answers with one (closing it changes nothing); "Sign out" ends the
418
419
  support session without a window and revokes it, even a session the host lent
@@ -644,8 +645,7 @@ own `onError`.
644
645
  A host can also supply an existing server-issued desk session through
645
646
  `getSessionToken` or `onAuthRequired`; never construct a session from browser
646
647
  user IDs/emails. Return the session answer from `onAuthRequired` and let the form
647
- install it, rather than calling `setSession` inside the callback. Identity-mode
648
- completion remains restricted to desk portal origins. See the
648
+ install it, rather than calling `setSession` inside the callback. See the
649
649
  [website integration guide](https://github.com/Spark-Vault/platform/blob/main/docs/HELP_DESK_WEBSITE_INTEGRATION.md)
650
650
  and [company-session contract](https://github.com/Spark-Vault/platform/blob/main/docs/HELP_DESK_IDENTITY_HANDOFF.md).
651
651
 
package/dist/index.cjs CHANGED
@@ -1159,6 +1159,18 @@ const SPARKVAULT_FILES_HOST = 'files.sv';
1159
1159
  */
1160
1160
  const SPARKVAULT_HELP_DESK_DOMAIN = 'help.sv';
1161
1161
 
1162
+ /**
1163
+ * The Help Desk sign-in host (`https://signin.help.sv`): the one fixed host of
1164
+ * the window Help Desk's own sign-in opens (`/{desk_id}/{challenge_id}`) and
1165
+ * of the one redirect URI its Identity client registers (`/callback`). Its
1166
+ * label is a reserved organization handle (organization-handle.js), so no desk
1167
+ * can hold it, and the help.sv Worker serves the portal's shell on it as on
1168
+ * every host of the domain. Like every host under the help-desk domain it is
1169
+ * reserved and not owned (isSparkVaultOwnedHostname). Core takes the window's
1170
+ * steps only from exactly this origin.
1171
+ */
1172
+ const SPARKVAULT_HELP_DESK_SIGN_IN_HOST = `signin.${SPARKVAULT_HELP_DESK_DOMAIN}`;
1173
+
1162
1174
  /**
1163
1175
  * Notify's mail domain: each organization's Notify mail goes from a host under
1164
1176
  * it, as its help desk's goes from one under the help-desk domain. On the web
@@ -14741,8 +14753,8 @@ Array.from({ length: 1 << BRAND_BITS.size }, (_, mask) =>
14741
14753
  * presets, size limits, the operator display and desk mode choices, the
14742
14754
  * operator queue's views and orders, the reply review list's views and
14743
14755
  * states, the response-time histogram's bucket edges, the sections of a
14744
- * desk's settings an address names, and the messages the widget's native
14745
- * sign-in posts between the website and its first-party page live here for
14756
+ * desk's settings an address names, and the messages Help Desk's own
14757
+ * sign-in posts between the website and its sign-in window live here for
14746
14758
  * the same reason. So does the one rule a typed or pasted sign-in code is
14747
14759
  * read by (helpDeskPinDigits), which every sign-in form applies. So does the
14748
14760
  * one way a client names a message it sends (newMessageId), which the
@@ -14770,14 +14782,15 @@ const HELP_DESK_CLOSE_REASONS = Object.freeze(['resolved', 'duplicate', 'spam'])
14770
14782
  Object.freeze(HELP_DESK_CLOSE_REASONS.filter((reason) => reason !== 'duplicate'));
14771
14783
 
14772
14784
  /**
14773
- * The messages the widget's native sign-in exchanges between the website's
14774
- * window (the JS SDK's openWidgetIdentity) and the first-party page it opens
14775
- * on auth.sv (Core's widget-identity-page.js), each posted to the other's
14776
- * exact origin: the page asks its opener for the challenge's state (`ready`),
14777
- * the opener answers its own popup alone (`state`), and the page reports the
14778
- * sign-in's code or its cancellation (`result`). Every message names its
14779
- * challenge, and the state is never in the page's URL or its server-rendered
14780
- * context, so only the window that started a challenge can complete it.
14785
+ * The messages Help Desk's own sign-in exchanges between the website's
14786
+ * window (the JS SDK's openWidgetIdentity) and the sign-in window it opens on
14787
+ * the Help Desk sign-in host (the portal's sign-in window page): the window
14788
+ * asks its opener for the challenge's state (`ready`), the opener answers its
14789
+ * own popup alone, at the sign-in origin (`state`), and the window reports
14790
+ * the sign-in's code, only once the person confirms it, or its cancellation
14791
+ * (`result`) to the website's origin alone. Every message names its
14792
+ * challenge, and the state is never in the window's URL, so only the window
14793
+ * that started a challenge can complete it.
14781
14794
  */
14782
14795
  const HELP_DESK_WIDGET_IDENTITY_MESSAGES = Object.freeze({
14783
14796
  ready: 'sparkvault:help-desk:identity-ready',
@@ -17953,22 +17966,24 @@ function mapInvitation(wire) {
17953
17966
  };
17954
17967
  }
17955
17968
 
17956
- /** The native support ceremony. Identity receipts stay inside the first-party window. */
17969
+ /** The native support ceremony. Identity's answer stays inside the Help Desk sign-in window. */
17957
17970
  const VALUE = /^[A-Za-z0-9_-]{43}$/;
17971
+ /** The one origin the sign-in window runs on. Never read from the challenge's sign-in URL, which is checked against it. */
17972
+ const SIGN_IN_ORIGIN = `https://${SPARKVAULT_HELP_DESK_SIGN_IN_HOST}`;
17958
17973
  /** The website's own opener policy cut the window off: no retry on this page can work, only its owner can fix it. */
17959
17974
  const SEVERED_MESSAGE = 'This website stops the support sign-in window from reporting back, so sign-in cannot finish here. Let the website\'s owner know.';
17960
- /** How often the sign-in window's handle is checked once it leaves for the sign-in page. */
17975
+ /** How often the sign-in window's handle is checked once it leaves for its start page. */
17961
17976
  const HANDLE_CHECK_MS = 500;
17962
17977
  /**
17963
17978
  * What a sign-in window's handle reading `closed` before its page's ready
17964
17979
  * message means. A website serving `Cross-Origin-Opener-Policy: same-origin`
17965
- * severs the window the moment its auth.sv page loads: the handle reads
17980
+ * severs the window the moment its start page loads: the handle reads
17966
17981
  * `closed` while the window stays open in front of the person, showing that
17967
17982
  * page's own "not connected" notice. So:
17968
17983
  * - the website's page holding focus again means the person closed the
17969
17984
  * window and is back on it: a cancellation;
17970
17985
  * - a handle that reads `closed` at the first check after the window left
17971
- * for the sign-in page, while the website's page still lacks focus, is a
17986
+ * for its start page, while the website's page still lacks focus, is a
17972
17987
  * severance: the window is still in front of the person, for no person
17973
17988
  * closes it that fast and then leaves the website;
17974
17989
  * - anything else cannot be told apart (a severance on a slow load, or a
@@ -17985,6 +18000,19 @@ function closedBeforeReady(firstCheck) {
17985
18000
  return new PopupSeveredError(SEVERED_MESSAGE);
17986
18001
  return new SparkVaultError('Support sign-in did not start. Try again.', 'HELP_DESK_WIDGET_SIGN_IN_INTERRUPTED');
17987
18002
  }
18003
+ /**
18004
+ * The challenge's start page, `https://signin.help.sv/{desk_id}/{challenge_id}`:
18005
+ * its sign-in URL when that is exactly the sign-in window's page for this
18006
+ * desk and this challenge, and the challenge's other values have their
18007
+ * shapes; else null.
18008
+ */
18009
+ function startPage(value, deskId) {
18010
+ if (!value || ![value.challenge_id, value.verifier, value.state].every((part) => typeof part === 'string' && VALUE.test(part)) ||
18011
+ !Number.isSafeInteger(value.expires_at))
18012
+ return null;
18013
+ const expected = `${SIGN_IN_ORIGIN}/${deskId}/${value.challenge_id}`;
18014
+ return value.sign_in_url === expected ? expected : null;
18015
+ }
17988
18016
  /**
17989
18017
  * Open synchronously inside the user's gesture, before preparing the server
17990
18018
  * challenge. A session redeemed after the sign-in already ended (cancelled,
@@ -18007,7 +18035,6 @@ function openWidgetIdentity(options, prepare, ready, redeem, discard, deskId) {
18007
18035
  catch { /* The popup may already have navigated. */ }
18008
18036
  return new Promise((resolve, reject) => {
18009
18037
  let challenge = null;
18010
- let firstPartyOrigin = null;
18011
18038
  let settled = false;
18012
18039
  let checking = false;
18013
18040
  let interval;
@@ -18052,19 +18079,19 @@ function openWidgetIdentity(options, prepare, ready, redeem, discard, deskId) {
18052
18079
  finish(null, session);
18053
18080
  };
18054
18081
  const receive = (event) => {
18055
- if (!challenge || event.source !== popup || event.origin !== firstPartyOrigin)
18082
+ if (!challenge || event.source !== popup || event.origin !== SIGN_IN_ORIGIN)
18056
18083
  return;
18057
18084
  const data = event.data;
18058
18085
  if (!data || data.challenge_id !== challenge.challenge_id)
18059
18086
  return;
18060
- // The first-party page this window opened asks for the challenge's
18061
- // state, without which Core takes none of its steps: only this popup,
18062
- // at the first-party origin, is ever answered, so a sign-in link opened
18063
- // in any other window or browser completes nothing.
18087
+ // The sign-in window this page opened asks for the challenge's state,
18088
+ // without which Core takes none of its steps: only this popup, at the
18089
+ // sign-in origin, is ever answered, so a sign-in link opened in any
18090
+ // other window or browser completes nothing.
18064
18091
  if (data.type === HELP_DESK_WIDGET_IDENTITY_MESSAGES.ready) {
18065
18092
  if (watch)
18066
18093
  clearInterval(watch);
18067
- popup.postMessage({ type: HELP_DESK_WIDGET_IDENTITY_MESSAGES.state, challenge_id: challenge.challenge_id, state: challenge.state }, event.origin);
18094
+ popup.postMessage({ type: HELP_DESK_WIDGET_IDENTITY_MESSAGES.state, challenge_id: challenge.challenge_id, state: challenge.state }, SIGN_IN_ORIGIN);
18068
18095
  return;
18069
18096
  }
18070
18097
  if (data.type !== HELP_DESK_WIDGET_IDENTITY_MESSAGES.result || data.state !== challenge.state)
@@ -18081,10 +18108,8 @@ function openWidgetIdentity(options, prepare, ready, redeem, discard, deskId) {
18081
18108
  void prepare().then((value) => {
18082
18109
  if (settled)
18083
18110
  return;
18084
- const url = new URL(value.sign_in_url);
18085
- if (!VALUE.test(value.challenge_id) || !VALUE.test(value.verifier) || !VALUE.test(value.state) || !Number.isSafeInteger(value.expires_at) ||
18086
- url.protocol !== 'https:' || url.origin !== 'https://auth.sv' || url.username || url.password || url.search || url.hash ||
18087
- url.pathname !== `/help-desk/${deskId}/${value.challenge_id}`)
18111
+ const url = startPage(value, deskId);
18112
+ if (!url)
18088
18113
  throw new SparkVaultError('The support sign-in address is invalid.', 'HELP_DESK_INVALID_RESPONSE');
18089
18114
  // The window still holds this page's own placeholder, which no opener
18090
18115
  // policy severs: closed now, the person closed it.
@@ -18093,8 +18118,7 @@ function openWidgetIdentity(options, prepare, ready, redeem, discard, deskId) {
18093
18118
  return;
18094
18119
  }
18095
18120
  challenge = value;
18096
- firstPartyOrigin = url.origin;
18097
- popup.location.replace(url.href);
18121
+ popup.location.replace(url);
18098
18122
  // A window whose handle dies before its page asks for the state can
18099
18123
  // never be handed it, so the sign-in ends at once (closedBeforeReady)
18100
18124
  // rather than polling until the challenge expires.
@@ -18105,8 +18129,8 @@ function openWidgetIdentity(options, prepare, ready, redeem, discard, deskId) {
18105
18129
  finish(closedBeforeReady(checks === 1));
18106
18130
  }, HANDLE_CHECK_MS);
18107
18131
  // Code delivery must survive a browser severing window.opener during
18108
- // the first-party Identity redirect. Polling knows only the original
18109
- // challenge and verifier; no Identity JWT ever reaches this page.
18132
+ // the window's Identity round trip. Polling knows only the original
18133
+ // challenge and verifier; no Identity token ever reaches this page.
18110
18134
  interval = setInterval(() => {
18111
18135
  if (settled || checking || !challenge)
18112
18136
  return;
@@ -18248,7 +18272,7 @@ class HelpDeskClient {
18248
18272
  this.releasedTokens = new Map();
18249
18273
  this.ownsSession = false;
18250
18274
  // Frozen copies of the records this client reads, so a page changing the desk it handed in (`HelpDeskConnectOptions.desk`) changes nothing here.
18251
- this.desk = Object.freeze({ ...desk, branding: Object.freeze({ ...desk.branding }), identity: desk.identity ? Object.freeze({ ...desk.identity }) : null,
18275
+ this.desk = Object.freeze({ ...desk, branding: Object.freeze({ ...desk.branding }),
18252
18276
  external_identity: desk.external_identity ? Object.freeze({ ...desk.external_identity }) : undefined,
18253
18277
  ticket_access_control: desk.ticket_access_control ? Object.freeze({ ...desk.ticket_access_control }) : undefined });
18254
18278
  this.http = http;
@@ -18630,10 +18654,6 @@ class HelpDeskClient {
18630
18654
  challenge_id: options.challengeId, binding_secret: options.bindingSecret, code: options.code,
18631
18655
  });
18632
18656
  }
18633
- /** Identity completion still requires a server-approved desk portal origin. */
18634
- completeIdentity(options) {
18635
- return this.establish(apiPath `/v1/hd/desks/${this.desk.desk_id}/auth/identity/complete`, { token: options.token });
18636
- }
18637
18657
  /** Uninstalled result: the owning form/controller decides when the new requester becomes current. */
18638
18658
  signInWidgetIdentity(options = {}) {
18639
18659
  const revision = this.revision;
@@ -18652,8 +18672,8 @@ class HelpDeskClient {
18652
18672
  const result = await this.send('POST', apiPath `/v1/hd/desks/${this.desk.desk_id}/auth/widget/redeem`, {
18653
18673
  challenge_id: challenge.challenge_id, verifier: challenge.verifier, ...(code && { code }),
18654
18674
  }, undefined, false);
18655
- // A native sign-in opens a session at the desk's issuer: an email sign-in's customer is linked to
18656
- // its Secure Identity (`identity`); a sign-in by the organization's own identity provider carries
18675
+ // A native sign-in opens a session at SparkVault's Identity: an email sign-in's customer carries
18676
+ // the `identity` assurance; a sign-in by the organization's own identity provider carries
18657
18677
  // the `federated` mark and the `federated` assurance together, never one without the other.
18658
18678
  const customer = result?.customer;
18659
18679
  const nativeIdentity = customer?.federated === true ? customer.assurance === 'federated' : customer?.assurance === 'identity';
@@ -21788,9 +21808,7 @@ function mountHelpDeskForm(client, options) {
21788
21808
  return;
21789
21809
  }
21790
21810
  hosted.hidden = newRequestUrl === null;
21791
- message(client.desk.auth_mode === 'identity_unavailable'
21792
- ? 'This help desk cannot sign you in right now. Try again later.'
21793
- : 'This help desk requires sign-in. Open it in a new tab to sign in and submit your request there.');
21811
+ message('This help desk requires sign-in. Open it in a new tab to sign in and submit your request there.');
21794
21812
  }
21795
21813
  async function submit() {
21796
21814
  if (pending || completed || destroyed)
@@ -26801,7 +26819,7 @@ function createHelpDeskSupport(config, options) {
26801
26819
  sourceArticleId = undefined;
26802
26820
  }
26803
26821
  /**
26804
- * Switch account from the contact form: auth.sv's chooser opens in this
26822
+ * Switch account from the contact form: the window's chooser opens in this
26805
26823
  * gesture, the current session staying current until another account's is
26806
26824
  * redeemed. A window that closes or fails rejects, nothing changed, for the
26807
26825
  * form to say so; a redeemed session takes the old one's place.
@@ -31760,7 +31778,7 @@ class SparkVault {
31760
31778
  }
31761
31779
  /** Get the SDK version */
31762
31780
  static get version() {
31763
- return '17.0.2';
31781
+ return '18.0.0';
31764
31782
  }
31765
31783
  }
31766
31784
  if (typeof window !== 'undefined') {