@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/dist/index.d.ts CHANGED
@@ -3692,11 +3692,7 @@ interface HelpDeskDesk {
3692
3692
  logo_dark_url: string | null;
3693
3693
  icon_url?: string | null;
3694
3694
  };
3695
- auth_mode: 'email_pin' | 'identity' | 'identity_unavailable' | 'external_sso' | 'external_unavailable';
3696
- identity: {
3697
- issuer_account_id: string;
3698
- client_id: string;
3699
- } | null;
3695
+ auth_mode: 'email_pin' | 'external_sso' | 'external_unavailable';
3700
3696
  external_identity?: HelpDeskExternalIdentity | null;
3701
3697
  customer_can_mark_resolved: boolean;
3702
3698
  /** Optional plain-text note shown only after a request is confirmed sent. */
@@ -3900,14 +3896,14 @@ interface HelpDeskWidgetIdentityOptions {
3900
3896
  givenName?: string;
3901
3897
  familyName?: string;
3902
3898
  selectAccount?: boolean;
3903
- /** The current employee gate's company. Its own Identity methods and MFA must also complete. */
3899
+ /** The current employee gate's company, whose membership Core checks for the person this sign-in proves. */
3904
3900
  employeeCompanyId?: string;
3905
3901
  signal?: AbortSignal;
3906
3902
  }
3907
3903
  interface HelpDeskWidgetIdentityChallenge {
3908
3904
  challenge_id: string;
3909
3905
  verifier: string;
3910
- /** Private to this window, like the verifier: handed only to the first-party page it opened, which Core requires it from. */
3906
+ /** Private to this window, like the verifier: handed only to the sign-in window it opened, which Core requires it from. */
3911
3907
  state: string;
3912
3908
  sign_in_url: string;
3913
3909
  expires_at: number;
@@ -4044,10 +4040,6 @@ declare class HelpDeskClient {
4044
4040
  }): Promise<HelpDeskSession>;
4045
4041
  startPin(email: string): Promise<HelpDeskPinChallenge>;
4046
4042
  verifyPin(options: HelpDeskVerifyPinOptions): Promise<HelpDeskSession>;
4047
- /** Identity completion still requires a server-approved desk portal origin. */
4048
- completeIdentity(options: {
4049
- token: string;
4050
- }): Promise<HelpDeskSession>;
4051
4043
  /** Uninstalled result: the owning form/controller decides when the new requester becomes current. */
4052
4044
  signInWidgetIdentity(options?: HelpDeskWidgetIdentityOptions): Promise<HelpDeskWidgetIdentitySession>;
4053
4045
  /**
package/dist/index.mjs CHANGED
@@ -1155,6 +1155,18 @@ const SPARKVAULT_FILES_HOST = 'files.sv';
1155
1155
  */
1156
1156
  const SPARKVAULT_HELP_DESK_DOMAIN = 'help.sv';
1157
1157
 
1158
+ /**
1159
+ * The Help Desk sign-in host (`https://signin.help.sv`): the one fixed host of
1160
+ * the window Help Desk's own sign-in opens (`/{desk_id}/{challenge_id}`) and
1161
+ * of the one redirect URI its Identity client registers (`/callback`). Its
1162
+ * label is a reserved organization handle (organization-handle.js), so no desk
1163
+ * can hold it, and the help.sv Worker serves the portal's shell on it as on
1164
+ * every host of the domain. Like every host under the help-desk domain it is
1165
+ * reserved and not owned (isSparkVaultOwnedHostname). Core takes the window's
1166
+ * steps only from exactly this origin.
1167
+ */
1168
+ const SPARKVAULT_HELP_DESK_SIGN_IN_HOST = `signin.${SPARKVAULT_HELP_DESK_DOMAIN}`;
1169
+
1158
1170
  /**
1159
1171
  * Notify's mail domain: each organization's Notify mail goes from a host under
1160
1172
  * it, as its help desk's goes from one under the help-desk domain. On the web
@@ -14737,8 +14749,8 @@ Array.from({ length: 1 << BRAND_BITS.size }, (_, mask) =>
14737
14749
  * presets, size limits, the operator display and desk mode choices, the
14738
14750
  * operator queue's views and orders, the reply review list's views and
14739
14751
  * states, the response-time histogram's bucket edges, the sections of a
14740
- * desk's settings an address names, and the messages the widget's native
14741
- * sign-in posts between the website and its first-party page live here for
14752
+ * desk's settings an address names, and the messages Help Desk's own
14753
+ * sign-in posts between the website and its sign-in window live here for
14742
14754
  * the same reason. So does the one rule a typed or pasted sign-in code is
14743
14755
  * read by (helpDeskPinDigits), which every sign-in form applies. So does the
14744
14756
  * one way a client names a message it sends (newMessageId), which the
@@ -14766,14 +14778,15 @@ const HELP_DESK_CLOSE_REASONS = Object.freeze(['resolved', 'duplicate', 'spam'])
14766
14778
  Object.freeze(HELP_DESK_CLOSE_REASONS.filter((reason) => reason !== 'duplicate'));
14767
14779
 
14768
14780
  /**
14769
- * The messages the widget's native sign-in exchanges between the website's
14770
- * window (the JS SDK's openWidgetIdentity) and the first-party page it opens
14771
- * on auth.sv (Core's widget-identity-page.js), each posted to the other's
14772
- * exact origin: the page asks its opener for the challenge's state (`ready`),
14773
- * the opener answers its own popup alone (`state`), and the page reports the
14774
- * sign-in's code or its cancellation (`result`). Every message names its
14775
- * challenge, and the state is never in the page's URL or its server-rendered
14776
- * context, so only the window that started a challenge can complete it.
14781
+ * The messages Help Desk's own sign-in exchanges between the website's
14782
+ * window (the JS SDK's openWidgetIdentity) and the sign-in window it opens on
14783
+ * the Help Desk sign-in host (the portal's sign-in window page): the window
14784
+ * asks its opener for the challenge's state (`ready`), the opener answers its
14785
+ * own popup alone, at the sign-in origin (`state`), and the window reports
14786
+ * the sign-in's code, only once the person confirms it, or its cancellation
14787
+ * (`result`) to the website's origin alone. Every message names its
14788
+ * challenge, and the state is never in the window's URL, so only the window
14789
+ * that started a challenge can complete it.
14777
14790
  */
14778
14791
  const HELP_DESK_WIDGET_IDENTITY_MESSAGES = Object.freeze({
14779
14792
  ready: 'sparkvault:help-desk:identity-ready',
@@ -17949,22 +17962,24 @@ function mapInvitation(wire) {
17949
17962
  };
17950
17963
  }
17951
17964
 
17952
- /** The native support ceremony. Identity receipts stay inside the first-party window. */
17965
+ /** The native support ceremony. Identity's answer stays inside the Help Desk sign-in window. */
17953
17966
  const VALUE = /^[A-Za-z0-9_-]{43}$/;
17967
+ /** The one origin the sign-in window runs on. Never read from the challenge's sign-in URL, which is checked against it. */
17968
+ const SIGN_IN_ORIGIN = `https://${SPARKVAULT_HELP_DESK_SIGN_IN_HOST}`;
17954
17969
  /** The website's own opener policy cut the window off: no retry on this page can work, only its owner can fix it. */
17955
17970
  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.';
17956
- /** How often the sign-in window's handle is checked once it leaves for the sign-in page. */
17971
+ /** How often the sign-in window's handle is checked once it leaves for its start page. */
17957
17972
  const HANDLE_CHECK_MS = 500;
17958
17973
  /**
17959
17974
  * What a sign-in window's handle reading `closed` before its page's ready
17960
17975
  * message means. A website serving `Cross-Origin-Opener-Policy: same-origin`
17961
- * severs the window the moment its auth.sv page loads: the handle reads
17976
+ * severs the window the moment its start page loads: the handle reads
17962
17977
  * `closed` while the window stays open in front of the person, showing that
17963
17978
  * page's own "not connected" notice. So:
17964
17979
  * - the website's page holding focus again means the person closed the
17965
17980
  * window and is back on it: a cancellation;
17966
17981
  * - a handle that reads `closed` at the first check after the window left
17967
- * for the sign-in page, while the website's page still lacks focus, is a
17982
+ * for its start page, while the website's page still lacks focus, is a
17968
17983
  * severance: the window is still in front of the person, for no person
17969
17984
  * closes it that fast and then leaves the website;
17970
17985
  * - anything else cannot be told apart (a severance on a slow load, or a
@@ -17981,6 +17996,19 @@ function closedBeforeReady(firstCheck) {
17981
17996
  return new PopupSeveredError(SEVERED_MESSAGE);
17982
17997
  return new SparkVaultError('Support sign-in did not start. Try again.', 'HELP_DESK_WIDGET_SIGN_IN_INTERRUPTED');
17983
17998
  }
17999
+ /**
18000
+ * The challenge's start page, `https://signin.help.sv/{desk_id}/{challenge_id}`:
18001
+ * its sign-in URL when that is exactly the sign-in window's page for this
18002
+ * desk and this challenge, and the challenge's other values have their
18003
+ * shapes; else null.
18004
+ */
18005
+ function startPage(value, deskId) {
18006
+ if (!value || ![value.challenge_id, value.verifier, value.state].every((part) => typeof part === 'string' && VALUE.test(part)) ||
18007
+ !Number.isSafeInteger(value.expires_at))
18008
+ return null;
18009
+ const expected = `${SIGN_IN_ORIGIN}/${deskId}/${value.challenge_id}`;
18010
+ return value.sign_in_url === expected ? expected : null;
18011
+ }
17984
18012
  /**
17985
18013
  * Open synchronously inside the user's gesture, before preparing the server
17986
18014
  * challenge. A session redeemed after the sign-in already ended (cancelled,
@@ -18003,7 +18031,6 @@ function openWidgetIdentity(options, prepare, ready, redeem, discard, deskId) {
18003
18031
  catch { /* The popup may already have navigated. */ }
18004
18032
  return new Promise((resolve, reject) => {
18005
18033
  let challenge = null;
18006
- let firstPartyOrigin = null;
18007
18034
  let settled = false;
18008
18035
  let checking = false;
18009
18036
  let interval;
@@ -18048,19 +18075,19 @@ function openWidgetIdentity(options, prepare, ready, redeem, discard, deskId) {
18048
18075
  finish(null, session);
18049
18076
  };
18050
18077
  const receive = (event) => {
18051
- if (!challenge || event.source !== popup || event.origin !== firstPartyOrigin)
18078
+ if (!challenge || event.source !== popup || event.origin !== SIGN_IN_ORIGIN)
18052
18079
  return;
18053
18080
  const data = event.data;
18054
18081
  if (!data || data.challenge_id !== challenge.challenge_id)
18055
18082
  return;
18056
- // The first-party page this window opened asks for the challenge's
18057
- // state, without which Core takes none of its steps: only this popup,
18058
- // at the first-party origin, is ever answered, so a sign-in link opened
18059
- // in any other window or browser completes nothing.
18083
+ // The sign-in window this page opened asks for the challenge's state,
18084
+ // without which Core takes none of its steps: only this popup, at the
18085
+ // sign-in origin, is ever answered, so a sign-in link opened in any
18086
+ // other window or browser completes nothing.
18060
18087
  if (data.type === HELP_DESK_WIDGET_IDENTITY_MESSAGES.ready) {
18061
18088
  if (watch)
18062
18089
  clearInterval(watch);
18063
- popup.postMessage({ type: HELP_DESK_WIDGET_IDENTITY_MESSAGES.state, challenge_id: challenge.challenge_id, state: challenge.state }, event.origin);
18090
+ popup.postMessage({ type: HELP_DESK_WIDGET_IDENTITY_MESSAGES.state, challenge_id: challenge.challenge_id, state: challenge.state }, SIGN_IN_ORIGIN);
18064
18091
  return;
18065
18092
  }
18066
18093
  if (data.type !== HELP_DESK_WIDGET_IDENTITY_MESSAGES.result || data.state !== challenge.state)
@@ -18077,10 +18104,8 @@ function openWidgetIdentity(options, prepare, ready, redeem, discard, deskId) {
18077
18104
  void prepare().then((value) => {
18078
18105
  if (settled)
18079
18106
  return;
18080
- const url = new URL(value.sign_in_url);
18081
- if (!VALUE.test(value.challenge_id) || !VALUE.test(value.verifier) || !VALUE.test(value.state) || !Number.isSafeInteger(value.expires_at) ||
18082
- url.protocol !== 'https:' || url.origin !== 'https://auth.sv' || url.username || url.password || url.search || url.hash ||
18083
- url.pathname !== `/help-desk/${deskId}/${value.challenge_id}`)
18107
+ const url = startPage(value, deskId);
18108
+ if (!url)
18084
18109
  throw new SparkVaultError('The support sign-in address is invalid.', 'HELP_DESK_INVALID_RESPONSE');
18085
18110
  // The window still holds this page's own placeholder, which no opener
18086
18111
  // policy severs: closed now, the person closed it.
@@ -18089,8 +18114,7 @@ function openWidgetIdentity(options, prepare, ready, redeem, discard, deskId) {
18089
18114
  return;
18090
18115
  }
18091
18116
  challenge = value;
18092
- firstPartyOrigin = url.origin;
18093
- popup.location.replace(url.href);
18117
+ popup.location.replace(url);
18094
18118
  // A window whose handle dies before its page asks for the state can
18095
18119
  // never be handed it, so the sign-in ends at once (closedBeforeReady)
18096
18120
  // rather than polling until the challenge expires.
@@ -18101,8 +18125,8 @@ function openWidgetIdentity(options, prepare, ready, redeem, discard, deskId) {
18101
18125
  finish(closedBeforeReady(checks === 1));
18102
18126
  }, HANDLE_CHECK_MS);
18103
18127
  // Code delivery must survive a browser severing window.opener during
18104
- // the first-party Identity redirect. Polling knows only the original
18105
- // challenge and verifier; no Identity JWT ever reaches this page.
18128
+ // the window's Identity round trip. Polling knows only the original
18129
+ // challenge and verifier; no Identity token ever reaches this page.
18106
18130
  interval = setInterval(() => {
18107
18131
  if (settled || checking || !challenge)
18108
18132
  return;
@@ -18244,7 +18268,7 @@ class HelpDeskClient {
18244
18268
  this.releasedTokens = new Map();
18245
18269
  this.ownsSession = false;
18246
18270
  // Frozen copies of the records this client reads, so a page changing the desk it handed in (`HelpDeskConnectOptions.desk`) changes nothing here.
18247
- this.desk = Object.freeze({ ...desk, branding: Object.freeze({ ...desk.branding }), identity: desk.identity ? Object.freeze({ ...desk.identity }) : null,
18271
+ this.desk = Object.freeze({ ...desk, branding: Object.freeze({ ...desk.branding }),
18248
18272
  external_identity: desk.external_identity ? Object.freeze({ ...desk.external_identity }) : undefined,
18249
18273
  ticket_access_control: desk.ticket_access_control ? Object.freeze({ ...desk.ticket_access_control }) : undefined });
18250
18274
  this.http = http;
@@ -18626,10 +18650,6 @@ class HelpDeskClient {
18626
18650
  challenge_id: options.challengeId, binding_secret: options.bindingSecret, code: options.code,
18627
18651
  });
18628
18652
  }
18629
- /** Identity completion still requires a server-approved desk portal origin. */
18630
- completeIdentity(options) {
18631
- return this.establish(apiPath `/v1/hd/desks/${this.desk.desk_id}/auth/identity/complete`, { token: options.token });
18632
- }
18633
18653
  /** Uninstalled result: the owning form/controller decides when the new requester becomes current. */
18634
18654
  signInWidgetIdentity(options = {}) {
18635
18655
  const revision = this.revision;
@@ -18648,8 +18668,8 @@ class HelpDeskClient {
18648
18668
  const result = await this.send('POST', apiPath `/v1/hd/desks/${this.desk.desk_id}/auth/widget/redeem`, {
18649
18669
  challenge_id: challenge.challenge_id, verifier: challenge.verifier, ...(code && { code }),
18650
18670
  }, undefined, false);
18651
- // A native sign-in opens a session at the desk's issuer: an email sign-in's customer is linked to
18652
- // its Secure Identity (`identity`); a sign-in by the organization's own identity provider carries
18671
+ // A native sign-in opens a session at SparkVault's Identity: an email sign-in's customer carries
18672
+ // the `identity` assurance; a sign-in by the organization's own identity provider carries
18653
18673
  // the `federated` mark and the `federated` assurance together, never one without the other.
18654
18674
  const customer = result?.customer;
18655
18675
  const nativeIdentity = customer?.federated === true ? customer.assurance === 'federated' : customer?.assurance === 'identity';
@@ -21784,9 +21804,7 @@ function mountHelpDeskForm(client, options) {
21784
21804
  return;
21785
21805
  }
21786
21806
  hosted.hidden = newRequestUrl === null;
21787
- message(client.desk.auth_mode === 'identity_unavailable'
21788
- ? 'This help desk cannot sign you in right now. Try again later.'
21789
- : 'This help desk requires sign-in. Open it in a new tab to sign in and submit your request there.');
21807
+ message('This help desk requires sign-in. Open it in a new tab to sign in and submit your request there.');
21790
21808
  }
21791
21809
  async function submit() {
21792
21810
  if (pending || completed || destroyed)
@@ -26797,7 +26815,7 @@ function createHelpDeskSupport(config, options) {
26797
26815
  sourceArticleId = undefined;
26798
26816
  }
26799
26817
  /**
26800
- * Switch account from the contact form: auth.sv's chooser opens in this
26818
+ * Switch account from the contact form: the window's chooser opens in this
26801
26819
  * gesture, the current session staying current until another account's is
26802
26820
  * redeemed. A window that closes or fails rejects, nothing changed, for the
26803
26821
  * form to say so; a redeemed session takes the old one's place.
@@ -31756,7 +31774,7 @@ class SparkVault {
31756
31774
  }
31757
31775
  /** Get the SDK version */
31758
31776
  static get version() {
31759
- return '17.0.2';
31777
+ return '18.0.0';
31760
31778
  }
31761
31779
  }
31762
31780
  if (typeof window !== 'undefined') {