@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/README.md CHANGED
@@ -258,6 +258,12 @@ its bytes again. A full ticket-status page remains in the hosted customer portal
258
258
 
259
259
  For a custom UI, use the same customer API without injecting markup:
260
260
 
261
+ Each desk is discovered from its own hostname and checked against the SDK's
262
+ configured company account. Add `deskId` to `connect`, `mountForm`, `openForm`,
263
+ or `attach` to pin an expected desk, for example
264
+ `{ host: 'subscribers.example.com', deskId: 'hdd_0123456789abcdef0123456789abcdef' }`.
265
+ Separate clients keep their customer sessions and ticket requests in their own desks.
266
+
261
267
  ```typescript
262
268
  const desk = await sv.products.helpDesk.connect({ host: 'support.example.com' });
263
269
  const challenge = await desk.startPin(email);
package/dist/index.cjs CHANGED
@@ -12208,6 +12208,11 @@ function requireSendId(sendId) {
12208
12208
  }
12209
12209
  }
12210
12210
 
12211
+ /** The original desk uses its account ID; additional desks have their own ID. */
12212
+ function validHelpDeskId(value) {
12213
+ return typeof value === 'string' && (isResourceIdOf('account', value) || /^hdd_[0-9a-f]{32}$/.test(value));
12214
+ }
12215
+
12211
12216
  /**
12212
12217
  * Ingot access logs: which of an ingot's audit events are accesses, and how one
12213
12218
  * audit entry reads as an access. Both SDKs read
@@ -14971,7 +14976,9 @@ function mapInvitation(wire) {
14971
14976
  /** The native support ceremony. Identity receipts stay inside the first-party window. */
14972
14977
  const VALUE = /^[A-Za-z0-9_-]{43}$/;
14973
14978
  /** Open synchronously inside the user's gesture, before preparing the server challenge. */
14974
- function openWidgetIdentity(options, prepare, ready, redeem) {
14979
+ function openWidgetIdentity(options, prepare, ready, redeem, deskId) {
14980
+ if (!validHelpDeskId(deskId))
14981
+ return Promise.reject(new ValidationError('Support sign-in requires a valid desk.'));
14975
14982
  if (typeof window === 'undefined')
14976
14983
  return Promise.reject(new ValidationError('Support sign-in requires a browser.'));
14977
14984
  if (options.signal?.aborted)
@@ -15042,8 +15049,7 @@ function openWidgetIdentity(options, prepare, ready, redeem) {
15042
15049
  const url = new URL(value.sign_in_url);
15043
15050
  if (!VALUE.test(value.challenge_id) || !VALUE.test(value.verifier) || !VALUE.test(value.state) || !Number.isSafeInteger(value.expires_at) ||
15044
15051
  url.protocol !== 'https:' || url.origin !== 'https://auth.sv' || url.username || url.password || url.search || url.hash ||
15045
- !/^\/help-desk\/acc_[0-9a-f]{32}\/[A-Za-z0-9_-]{43}$/.test(url.pathname) ||
15046
- !url.pathname.endsWith(`/${value.challenge_id}`))
15052
+ url.pathname !== `/help-desk/${deskId}/${value.challenge_id}`)
15047
15053
  throw new SparkVaultError('The support sign-in address is invalid.', 'HELP_DESK_INVALID_RESPONSE');
15048
15054
  challenge = value;
15049
15055
  firstPartyOrigin = url.origin;
@@ -15192,6 +15198,9 @@ class HelpDeskClient {
15192
15198
  /** Discover a desk by its configured host, before any customer credentials are sent. */
15193
15199
  static async connect(config, options) {
15194
15200
  const host = hostname(options?.host);
15201
+ if (options.deskId !== undefined && !validHelpDeskId(options.deskId)) {
15202
+ throw new ValidationError('deskId must be a Help Desk ID', { field: 'deskId' });
15203
+ }
15195
15204
  if (options.getSessionToken !== undefined && typeof options.getSessionToken !== 'function') {
15196
15205
  throw new ValidationError('getSessionToken must be a function', { field: 'getSessionToken' });
15197
15206
  }
@@ -15211,7 +15220,11 @@ class HelpDeskClient {
15211
15220
  if (data?.kind === 'moved') {
15212
15221
  throw new SparkVaultError('This help desk has moved. Connect using its current host.', 'HELP_DESK_MOVED', 409, { movedTo: data.moved_to });
15213
15222
  }
15214
- if (data?.kind !== 'desk' || !isResourceIdOf('account', data.desk_id) || data.desk_id !== config.accountId || data.portal_client !== CLIENT) {
15223
+ const originalDesk = data?.kind === 'desk' && isResourceIdOf('account', data.desk_id);
15224
+ const ownerId = data?.kind === 'desk' ? data.account_id ?? (originalDesk ? data.desk_id : null) : null;
15225
+ if (data?.kind !== 'desk' || !validHelpDeskId(data.desk_id) || ownerId !== config.accountId ||
15226
+ (originalDesk && data.desk_id !== config.accountId) ||
15227
+ (options.deskId !== undefined && options.deskId !== data.desk_id) || data.portal_client !== CLIENT) {
15215
15228
  throw new SparkVaultError('The help desk lookup did not identify this account\'s desk.', 'HELP_DESK_INVALID_RESPONSE');
15216
15229
  }
15217
15230
  hostname(data.canonical_host);
@@ -15291,7 +15304,8 @@ class HelpDeskClient {
15291
15304
  const { data } = await this.http.request(apiPath `/v1/hd/desks`, {
15292
15305
  query: { host: this.desk.canonical_host }, headers: { 'X-SV-Client': CLIENT }, credentials: 'omit',
15293
15306
  });
15294
- if (data?.kind !== 'desk' || data.desk_id !== this.desk.desk_id || data.portal_client !== CLIENT) {
15307
+ const ownerId = data?.account_id ?? (isResourceIdOf('account', data?.desk_id) ? data.desk_id : null);
15308
+ if (data?.kind !== 'desk' || data.desk_id !== this.desk.desk_id || ownerId !== (this.desk.account_id ?? this.desk.desk_id) || data.portal_client !== CLIENT) {
15295
15309
  throw new SparkVaultError('This help desk could not refresh its access settings.', 'HELP_DESK_INVALID_RESPONSE');
15296
15310
  }
15297
15311
  if (JSON.stringify(data.ticket_access_control) !== JSON.stringify(this.currentTicketPolicy))
@@ -15551,7 +15565,7 @@ class HelpDeskClient {
15551
15565
  }
15552
15566
  this.issuedSessions.set(result, result.token);
15553
15567
  return result;
15554
- });
15568
+ }, this.desk.desk_id);
15555
15569
  }
15556
15570
  /** Choose a different support identity without logging out or changing the host website. */
15557
15571
  switchSupportAccount() {
@@ -17555,7 +17569,7 @@ function mountHelpDeskForm(client, options) {
17555
17569
  const codeHint = document.createElement('p');
17556
17570
  codeHint.id = `${code.input.id}-hint`;
17557
17571
  codeHint.className = 'svhd-file-hint';
17558
- 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)}.`;
17572
+ 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)}.`;
17559
17573
  code.input.setAttribute('aria-describedby', codeHint.id);
17560
17574
  const resend = document.createElement('button');
17561
17575
  resend.type = 'button';
@@ -18795,8 +18809,8 @@ class HelpDeskKnowledgeBaseClient {
18795
18809
  this.activeMedia = null;
18796
18810
  this.destroyed = false;
18797
18811
  this.close = new AbortController();
18798
- if (!isResourceIdOf('account', deskId))
18799
- throw new ValidationError('deskId must be a Help Desk account');
18812
+ if (!validHelpDeskId(deskId))
18813
+ throw new ValidationError('deskId must be a Help Desk ID');
18800
18814
  }
18801
18815
  getAccessHeaders() {
18802
18816
  if (this.grantDeadline !== null && this.grantDeadline <= Date.now())
@@ -20474,14 +20488,17 @@ function createHelpDeskSupport(config, options) {
20474
20488
  post: async (path, body) => {
20475
20489
  if (destroyed)
20476
20490
  throw new Error('Support is closed.');
20491
+ const deskId = client?.desk.desk_id;
20492
+ if (!deskId)
20493
+ throw new Error('Support is still loading.');
20477
20494
  const prefix = `/hd/desks/${encodeURIComponent(config.accountId)}/support`;
20478
20495
  const suffix = path.slice(prefix.length);
20479
20496
  if (!path.startsWith(prefix))
20480
20497
  throw new Error('Invalid support analytics route.');
20481
20498
  const event = /^\/attempts\/([^/]+)\/events$/.exec(suffix);
20482
- const route = suffix === '/visitor' ? apiPath `/v1/hd/desks/${config.accountId}/support/visitor`
20483
- : suffix === '/attempts' ? apiPath `/v1/hd/desks/${config.accountId}/support/attempts`
20484
- : event ? apiPath `/v1/hd/desks/${config.accountId}/support/attempts/${decodeURIComponent(event[1])}/events` : null;
20499
+ const route = suffix === '/visitor' ? apiPath `/v1/hd/desks/${deskId}/support/visitor`
20500
+ : suffix === '/attempts' ? apiPath `/v1/hd/desks/${deskId}/support/attempts`
20501
+ : event ? apiPath `/v1/hd/desks/${deskId}/support/attempts/${decodeURIComponent(event[1])}/events` : null;
20485
20502
  if (!route)
20486
20503
  throw new Error('Invalid support analytics route.');
20487
20504
  const headers = kb?.getAccessHeaders() ?? {};
@@ -25024,7 +25041,7 @@ class SparkVault {
25024
25041
  }
25025
25042
  /** Get the SDK version */
25026
25043
  static get version() {
25027
- return '15.3.3';
25044
+ return '15.4.0';
25028
25045
  }
25029
25046
  }
25030
25047
  if (typeof window !== 'undefined') {