@sparkvault/sdk-js 15.3.3 → 15.4.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
@@ -3232,6 +3232,8 @@ interface HelpDeskExternalIdentity {
3232
3232
  interface HelpDeskConnectOptions {
3233
3233
  /** The configured help desk hostname, for example support.example.com. */
3234
3234
  host: string;
3235
+ /** Optionally pin the expected desk within this company (hdd_ for a named desk, acc_ for its original desk). */
3236
+ deskId?: string;
3235
3237
  /** A help desk hdt_ bearer provider. Core access tokens and API keys are never used. */
3236
3238
  getSessionToken?: () => string | null | Promise<string | null>;
3237
3239
  /** Obtain a purpose-specific JWT from the signed-in company's backend. No customer consent is shown. */
@@ -3242,9 +3244,13 @@ interface HelpDeskConnectOptions {
3242
3244
  interface HelpDeskDesk {
3243
3245
  kind: 'desk';
3244
3246
  desk_id: string;
3247
+ /** Owning company. Required in named-desk discovery; legacy desks may omit it. */
3248
+ account_id?: string;
3245
3249
  handle: string;
3246
3250
  canonical_host: string;
3247
3251
  sending_host: string;
3252
+ /** Configured contact/PIN sender, independent of the portal's custom domain. */
3253
+ contact_email?: string;
3248
3254
  organization_name: string | null;
3249
3255
  branding: {
3250
3256
  color: string | null;
package/dist/index.mjs CHANGED
@@ -12204,6 +12204,11 @@ function requireSendId(sendId) {
12204
12204
  }
12205
12205
  }
12206
12206
 
12207
+ /** The original desk uses its account ID; additional desks have their own ID. */
12208
+ function validHelpDeskId(value) {
12209
+ return typeof value === 'string' && (isResourceIdOf('account', value) || /^hdd_[0-9a-f]{32}$/.test(value));
12210
+ }
12211
+
12207
12212
  /**
12208
12213
  * Ingot access logs: which of an ingot's audit events are accesses, and how one
12209
12214
  * audit entry reads as an access. Both SDKs read
@@ -14967,7 +14972,9 @@ function mapInvitation(wire) {
14967
14972
  /** The native support ceremony. Identity receipts stay inside the first-party window. */
14968
14973
  const VALUE = /^[A-Za-z0-9_-]{43}$/;
14969
14974
  /** Open synchronously inside the user's gesture, before preparing the server challenge. */
14970
- function openWidgetIdentity(options, prepare, ready, redeem) {
14975
+ function openWidgetIdentity(options, prepare, ready, redeem, deskId) {
14976
+ if (!validHelpDeskId(deskId))
14977
+ return Promise.reject(new ValidationError('Support sign-in requires a valid desk.'));
14971
14978
  if (typeof window === 'undefined')
14972
14979
  return Promise.reject(new ValidationError('Support sign-in requires a browser.'));
14973
14980
  if (options.signal?.aborted)
@@ -15038,8 +15045,7 @@ function openWidgetIdentity(options, prepare, ready, redeem) {
15038
15045
  const url = new URL(value.sign_in_url);
15039
15046
  if (!VALUE.test(value.challenge_id) || !VALUE.test(value.verifier) || !VALUE.test(value.state) || !Number.isSafeInteger(value.expires_at) ||
15040
15047
  url.protocol !== 'https:' || url.origin !== 'https://auth.sv' || url.username || url.password || url.search || url.hash ||
15041
- !/^\/help-desk\/acc_[0-9a-f]{32}\/[A-Za-z0-9_-]{43}$/.test(url.pathname) ||
15042
- !url.pathname.endsWith(`/${value.challenge_id}`))
15048
+ url.pathname !== `/help-desk/${deskId}/${value.challenge_id}`)
15043
15049
  throw new SparkVaultError('The support sign-in address is invalid.', 'HELP_DESK_INVALID_RESPONSE');
15044
15050
  challenge = value;
15045
15051
  firstPartyOrigin = url.origin;
@@ -15188,6 +15194,9 @@ class HelpDeskClient {
15188
15194
  /** Discover a desk by its configured host, before any customer credentials are sent. */
15189
15195
  static async connect(config, options) {
15190
15196
  const host = hostname(options?.host);
15197
+ if (options.deskId !== undefined && !validHelpDeskId(options.deskId)) {
15198
+ throw new ValidationError('deskId must be a Help Desk ID', { field: 'deskId' });
15199
+ }
15191
15200
  if (options.getSessionToken !== undefined && typeof options.getSessionToken !== 'function') {
15192
15201
  throw new ValidationError('getSessionToken must be a function', { field: 'getSessionToken' });
15193
15202
  }
@@ -15207,7 +15216,11 @@ class HelpDeskClient {
15207
15216
  if (data?.kind === 'moved') {
15208
15217
  throw new SparkVaultError('This help desk has moved. Connect using its current host.', 'HELP_DESK_MOVED', 409, { movedTo: data.moved_to });
15209
15218
  }
15210
- if (data?.kind !== 'desk' || !isResourceIdOf('account', data.desk_id) || data.desk_id !== config.accountId || data.portal_client !== CLIENT) {
15219
+ const originalDesk = data?.kind === 'desk' && isResourceIdOf('account', data.desk_id);
15220
+ const ownerId = data?.kind === 'desk' ? data.account_id ?? (originalDesk ? data.desk_id : null) : null;
15221
+ if (data?.kind !== 'desk' || !validHelpDeskId(data.desk_id) || ownerId !== config.accountId ||
15222
+ (originalDesk && data.desk_id !== config.accountId) ||
15223
+ (options.deskId !== undefined && options.deskId !== data.desk_id) || data.portal_client !== CLIENT) {
15211
15224
  throw new SparkVaultError('The help desk lookup did not identify this account\'s desk.', 'HELP_DESK_INVALID_RESPONSE');
15212
15225
  }
15213
15226
  hostname(data.canonical_host);
@@ -15287,7 +15300,8 @@ class HelpDeskClient {
15287
15300
  const { data } = await this.http.request(apiPath `/v1/hd/desks`, {
15288
15301
  query: { host: this.desk.canonical_host }, headers: { 'X-SV-Client': CLIENT }, credentials: 'omit',
15289
15302
  });
15290
- if (data?.kind !== 'desk' || data.desk_id !== this.desk.desk_id || data.portal_client !== CLIENT) {
15303
+ const ownerId = data?.account_id ?? (isResourceIdOf('account', data?.desk_id) ? data.desk_id : null);
15304
+ if (data?.kind !== 'desk' || data.desk_id !== this.desk.desk_id || ownerId !== (this.desk.account_id ?? this.desk.desk_id) || data.portal_client !== CLIENT) {
15291
15305
  throw new SparkVaultError('This help desk could not refresh its access settings.', 'HELP_DESK_INVALID_RESPONSE');
15292
15306
  }
15293
15307
  if (JSON.stringify(data.ticket_access_control) !== JSON.stringify(this.currentTicketPolicy))
@@ -15547,7 +15561,7 @@ class HelpDeskClient {
15547
15561
  }
15548
15562
  this.issuedSessions.set(result, result.token);
15549
15563
  return result;
15550
- });
15564
+ }, this.desk.desk_id);
15551
15565
  }
15552
15566
  /** Choose a different support identity without logging out or changing the host website. */
15553
15567
  switchSupportAccount() {
@@ -17551,7 +17565,7 @@ function mountHelpDeskForm(client, options) {
17551
17565
  const codeHint = document.createElement('p');
17552
17566
  codeHint.id = `${code.input.id}-hint`;
17553
17567
  codeHint.className = 'svhd-file-hint';
17554
- codeHint.textContent = `It works for ${HELP_DESK_PIN_TTL_MINUTES} minutes. Not in your inbox? Look in spam for mail from ${helpDeskCodeSender(client.desk.sending_host)}.`;
17568
+ codeHint.textContent = `It works for ${HELP_DESK_PIN_TTL_MINUTES} minutes. Not in your inbox? Look in spam for mail from ${client.desk.contact_email ?? helpDeskCodeSender(client.desk.sending_host)}.`;
17555
17569
  code.input.setAttribute('aria-describedby', codeHint.id);
17556
17570
  const resend = document.createElement('button');
17557
17571
  resend.type = 'button';
@@ -18791,8 +18805,8 @@ class HelpDeskKnowledgeBaseClient {
18791
18805
  this.activeMedia = null;
18792
18806
  this.destroyed = false;
18793
18807
  this.close = new AbortController();
18794
- if (!isResourceIdOf('account', deskId))
18795
- throw new ValidationError('deskId must be a Help Desk account');
18808
+ if (!validHelpDeskId(deskId))
18809
+ throw new ValidationError('deskId must be a Help Desk ID');
18796
18810
  }
18797
18811
  getAccessHeaders() {
18798
18812
  if (this.grantDeadline !== null && this.grantDeadline <= Date.now())
@@ -20470,14 +20484,17 @@ function createHelpDeskSupport(config, options) {
20470
20484
  post: async (path, body) => {
20471
20485
  if (destroyed)
20472
20486
  throw new Error('Support is closed.');
20487
+ const deskId = client?.desk.desk_id;
20488
+ if (!deskId)
20489
+ throw new Error('Support is still loading.');
20473
20490
  const prefix = `/hd/desks/${encodeURIComponent(config.accountId)}/support`;
20474
20491
  const suffix = path.slice(prefix.length);
20475
20492
  if (!path.startsWith(prefix))
20476
20493
  throw new Error('Invalid support analytics route.');
20477
20494
  const event = /^\/attempts\/([^/]+)\/events$/.exec(suffix);
20478
- const route = suffix === '/visitor' ? apiPath `/v1/hd/desks/${config.accountId}/support/visitor`
20479
- : suffix === '/attempts' ? apiPath `/v1/hd/desks/${config.accountId}/support/attempts`
20480
- : event ? apiPath `/v1/hd/desks/${config.accountId}/support/attempts/${decodeURIComponent(event[1])}/events` : null;
20495
+ const route = suffix === '/visitor' ? apiPath `/v1/hd/desks/${deskId}/support/visitor`
20496
+ : suffix === '/attempts' ? apiPath `/v1/hd/desks/${deskId}/support/attempts`
20497
+ : event ? apiPath `/v1/hd/desks/${deskId}/support/attempts/${decodeURIComponent(event[1])}/events` : null;
20481
20498
  if (!route)
20482
20499
  throw new Error('Invalid support analytics route.');
20483
20500
  const headers = kb?.getAccessHeaders() ?? {};
@@ -25020,7 +25037,7 @@ class SparkVault {
25020
25037
  }
25021
25038
  /** Get the SDK version */
25022
25039
  static get version() {
25023
- return '15.3.3';
25040
+ return '15.4.0';
25024
25041
  }
25025
25042
  }
25026
25043
  if (typeof window !== 'undefined') {