@sparkvault/sdk-js 15.3.0 → 15.3.2

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
@@ -3469,6 +3469,9 @@ declare class HelpDeskClient {
3469
3469
  private websiteAccountSuppressed;
3470
3470
  private ticketAccess;
3471
3471
  private currentTicketPolicy;
3472
+ /** Only this client's own sign-in ceremonies create credentials it may revoke on account switch. */
3473
+ private readonly issuedSessions;
3474
+ private ownsSession;
3472
3475
  private constructor();
3473
3476
  /** Discover a desk by its configured host, before any customer credentials are sent. */
3474
3477
  static connect(config: ResolvedConfig, options: HelpDeskConnectOptions): Promise<HelpDeskClient>;
@@ -3490,6 +3493,8 @@ declare class HelpDeskClient {
3490
3493
  subscribeSession(listener: (change: HelpDeskSessionChange) => void): () => void;
3491
3494
  /** Explicitly refresh the host-managed session, for example after a backend handoff. */
3492
3495
  refreshSession(): Promise<string | null>;
3496
+ /** Resume provider authority without starting its proof before an independent access gate. */
3497
+ private resetProviderSession;
3493
3498
  /** Whether company identity can be established without customer interaction. */
3494
3499
  get hasIdentityProvider(): boolean;
3495
3500
  /** The independent ticket gate must be met before rendering authenticated ticket UI. */
@@ -3576,6 +3581,7 @@ declare class HelpDeskClient {
3576
3581
  attachmentDownload(attachmentId: string, number: number): Promise<HelpDeskAttachmentDownload>;
3577
3582
  /** Revoke this bearer, clearing only the session whose logout completed. */
3578
3583
  logout(): Promise<void>;
3584
+ private releaseSession;
3579
3585
  }
3580
3586
 
3581
3587
  /** Internal adapter used by the KB-first widget; legacy forms retain their existing verification flow. */
package/dist/index.mjs CHANGED
@@ -15174,6 +15174,9 @@ class HelpDeskClient {
15174
15174
  this.revision = 0;
15175
15175
  this.websiteAccountSuppressed = false;
15176
15176
  this.ticketAccess = null;
15177
+ /** Only this client's own sign-in ceremonies create credentials it may revoke on account switch. */
15178
+ this.issuedSessions = new WeakMap();
15179
+ this.ownsSession = false;
15177
15180
  this.desk = Object.freeze({ ...desk, branding: Object.freeze({ ...desk.branding }), identity: desk.identity ? Object.freeze({ ...desk.identity }) : null,
15178
15181
  external_identity: desk.external_identity ? Object.freeze({ ...desk.external_identity }) : undefined });
15179
15182
  this.http = http;
@@ -15228,6 +15231,7 @@ class HelpDeskClient {
15228
15231
  throw new ValidationError('session must be a help desk session answer', { field: 'session' });
15229
15232
  }
15230
15233
  const installed = session ? { ...session, customer: { ...session.customer } } : null;
15234
+ this.ownsSession = session !== null && this.issuedSessions.get(session) === session.token;
15231
15235
  this.session = installed;
15232
15236
  this.deadline = installed ? deadline : null;
15233
15237
  this.authentication = null;
@@ -15250,7 +15254,13 @@ class HelpDeskClient {
15250
15254
  }
15251
15255
  /** Explicitly refresh the host-managed session, for example after a backend handoff. */
15252
15256
  async refreshSession() {
15257
+ this.resetProviderSession();
15258
+ return this.getSessionToken();
15259
+ }
15260
+ /** Resume provider authority without starting its proof before an independent access gate. */
15261
+ resetProviderSession() {
15253
15262
  this.session = undefined;
15263
+ this.ownsSession = false;
15254
15264
  this.deadline = null;
15255
15265
  this.authentication = null;
15256
15266
  this.verifiedRequesterId = null;
@@ -15258,7 +15268,6 @@ class HelpDeskClient {
15258
15268
  this.renewedTokens.clear();
15259
15269
  this.revision += 1;
15260
15270
  this.rememberToken(null, 'refresh', true);
15261
- return this.getSessionToken();
15262
15271
  }
15263
15272
  /** Whether company identity can be established without customer interaction. */
15264
15273
  get hasIdentityProvider() { return typeof this.assertionProvider === 'function'; }
@@ -15386,6 +15395,7 @@ class HelpDeskClient {
15386
15395
  throw new AuthenticationError('The help desk session changed during sign-in. Try again.');
15387
15396
  if (!validLifetime(session?.ttl_seconds))
15388
15397
  throw new SparkVaultError('The help desk returned an invalid session.', 'HELP_DESK_INVALID_RESPONSE');
15398
+ this.issuedSessions.set(session, session.token);
15389
15399
  const installed = this.installSession(session, landedDeadline(session));
15390
15400
  if (this.session !== installed || this.token !== session.token)
15391
15401
  throw sessionChanged();
@@ -15466,6 +15476,8 @@ class HelpDeskClient {
15466
15476
  if (sameCustomer && this.token)
15467
15477
  this.renewedTokens.add(this.token);
15468
15478
  const installed = { ...session, customer: { ...session.customer } };
15479
+ this.issuedSessions.set(session, session.token);
15480
+ this.ownsSession = true;
15469
15481
  this.session = installed;
15470
15482
  this.deadline = deadline;
15471
15483
  this.verifiedRequesterId = session.customer.requester_id;
@@ -15533,23 +15545,25 @@ class HelpDeskClient {
15533
15545
  if (!validToken(result?.token) || result.customer?.assurance !== 'identity' || !/^hdwip_[A-Za-z0-9_-]{43}$/.test(result.identity_grant?.token)) {
15534
15546
  throw new SparkVaultError('The help desk returned an invalid support identity.', 'HELP_DESK_INVALID_RESPONSE');
15535
15547
  }
15548
+ this.issuedSessions.set(result, result.token);
15536
15549
  return result;
15537
15550
  });
15538
15551
  }
15539
15552
  /** Choose a different support identity without logging out or changing the host website. */
15540
15553
  switchSupportAccount() {
15541
15554
  this.websiteAccountSuppressed = true;
15542
- return this.logout();
15555
+ return this.releaseSession(false);
15543
15556
  }
15544
15557
  /** The only operation that resumes the website's configured identity provider after an explicit switch. */
15545
15558
  async useWebsiteAccount() {
15546
- await this.logout();
15559
+ await this.releaseSession(false);
15547
15560
  this.websiteAccountSuppressed = false;
15561
+ this.resetProviderSession();
15548
15562
  if (!this.hasTicketAccess)
15549
15563
  return null;
15550
15564
  if (this.assertionProvider)
15551
15565
  return this.authenticate();
15552
- await this.refreshSession();
15566
+ await this.getSessionToken();
15553
15567
  return null;
15554
15568
  }
15555
15569
  getMe() { return this.send('GET', apiPath `/v1/hd/desks/${this.desk.desk_id}/me`); }
@@ -15606,9 +15620,12 @@ class HelpDeskClient {
15606
15620
  }
15607
15621
  /** Revoke this bearer, clearing only the session whose logout completed. */
15608
15622
  async logout() {
15623
+ return this.releaseSession(true);
15624
+ }
15625
+ async releaseSession(revokeBorrowed) {
15609
15626
  // Snapshot first: logging out must not call a provider or renew a session
15610
15627
  // using a website account which may already have changed.
15611
- const token = this.token;
15628
+ const token = revokeBorrowed || this.ownsSession ? this.token : null;
15612
15629
  const accessToken = this.ticketAccess?.token;
15613
15630
  this.clearSession();
15614
15631
  this.clearTicketAccess();
@@ -25003,7 +25020,7 @@ class SparkVault {
25003
25020
  }
25004
25021
  /** Get the SDK version */
25005
25022
  static get version() {
25006
- return '15.3.0';
25023
+ return '15.3.2';
25007
25024
  }
25008
25025
  }
25009
25026
  if (typeof window !== 'undefined') {