@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.cjs CHANGED
@@ -15178,6 +15178,9 @@ class HelpDeskClient {
15178
15178
  this.revision = 0;
15179
15179
  this.websiteAccountSuppressed = false;
15180
15180
  this.ticketAccess = null;
15181
+ /** Only this client's own sign-in ceremonies create credentials it may revoke on account switch. */
15182
+ this.issuedSessions = new WeakMap();
15183
+ this.ownsSession = false;
15181
15184
  this.desk = Object.freeze({ ...desk, branding: Object.freeze({ ...desk.branding }), identity: desk.identity ? Object.freeze({ ...desk.identity }) : null,
15182
15185
  external_identity: desk.external_identity ? Object.freeze({ ...desk.external_identity }) : undefined });
15183
15186
  this.http = http;
@@ -15232,6 +15235,7 @@ class HelpDeskClient {
15232
15235
  throw new ValidationError('session must be a help desk session answer', { field: 'session' });
15233
15236
  }
15234
15237
  const installed = session ? { ...session, customer: { ...session.customer } } : null;
15238
+ this.ownsSession = session !== null && this.issuedSessions.get(session) === session.token;
15235
15239
  this.session = installed;
15236
15240
  this.deadline = installed ? deadline : null;
15237
15241
  this.authentication = null;
@@ -15254,7 +15258,13 @@ class HelpDeskClient {
15254
15258
  }
15255
15259
  /** Explicitly refresh the host-managed session, for example after a backend handoff. */
15256
15260
  async refreshSession() {
15261
+ this.resetProviderSession();
15262
+ return this.getSessionToken();
15263
+ }
15264
+ /** Resume provider authority without starting its proof before an independent access gate. */
15265
+ resetProviderSession() {
15257
15266
  this.session = undefined;
15267
+ this.ownsSession = false;
15258
15268
  this.deadline = null;
15259
15269
  this.authentication = null;
15260
15270
  this.verifiedRequesterId = null;
@@ -15262,7 +15272,6 @@ class HelpDeskClient {
15262
15272
  this.renewedTokens.clear();
15263
15273
  this.revision += 1;
15264
15274
  this.rememberToken(null, 'refresh', true);
15265
- return this.getSessionToken();
15266
15275
  }
15267
15276
  /** Whether company identity can be established without customer interaction. */
15268
15277
  get hasIdentityProvider() { return typeof this.assertionProvider === 'function'; }
@@ -15390,6 +15399,7 @@ class HelpDeskClient {
15390
15399
  throw new AuthenticationError('The help desk session changed during sign-in. Try again.');
15391
15400
  if (!validLifetime(session?.ttl_seconds))
15392
15401
  throw new SparkVaultError('The help desk returned an invalid session.', 'HELP_DESK_INVALID_RESPONSE');
15402
+ this.issuedSessions.set(session, session.token);
15393
15403
  const installed = this.installSession(session, landedDeadline(session));
15394
15404
  if (this.session !== installed || this.token !== session.token)
15395
15405
  throw sessionChanged();
@@ -15470,6 +15480,8 @@ class HelpDeskClient {
15470
15480
  if (sameCustomer && this.token)
15471
15481
  this.renewedTokens.add(this.token);
15472
15482
  const installed = { ...session, customer: { ...session.customer } };
15483
+ this.issuedSessions.set(session, session.token);
15484
+ this.ownsSession = true;
15473
15485
  this.session = installed;
15474
15486
  this.deadline = deadline;
15475
15487
  this.verifiedRequesterId = session.customer.requester_id;
@@ -15537,23 +15549,25 @@ class HelpDeskClient {
15537
15549
  if (!validToken(result?.token) || result.customer?.assurance !== 'identity' || !/^hdwip_[A-Za-z0-9_-]{43}$/.test(result.identity_grant?.token)) {
15538
15550
  throw new SparkVaultError('The help desk returned an invalid support identity.', 'HELP_DESK_INVALID_RESPONSE');
15539
15551
  }
15552
+ this.issuedSessions.set(result, result.token);
15540
15553
  return result;
15541
15554
  });
15542
15555
  }
15543
15556
  /** Choose a different support identity without logging out or changing the host website. */
15544
15557
  switchSupportAccount() {
15545
15558
  this.websiteAccountSuppressed = true;
15546
- return this.logout();
15559
+ return this.releaseSession(false);
15547
15560
  }
15548
15561
  /** The only operation that resumes the website's configured identity provider after an explicit switch. */
15549
15562
  async useWebsiteAccount() {
15550
- await this.logout();
15563
+ await this.releaseSession(false);
15551
15564
  this.websiteAccountSuppressed = false;
15565
+ this.resetProviderSession();
15552
15566
  if (!this.hasTicketAccess)
15553
15567
  return null;
15554
15568
  if (this.assertionProvider)
15555
15569
  return this.authenticate();
15556
- await this.refreshSession();
15570
+ await this.getSessionToken();
15557
15571
  return null;
15558
15572
  }
15559
15573
  getMe() { return this.send('GET', apiPath `/v1/hd/desks/${this.desk.desk_id}/me`); }
@@ -15610,9 +15624,12 @@ class HelpDeskClient {
15610
15624
  }
15611
15625
  /** Revoke this bearer, clearing only the session whose logout completed. */
15612
15626
  async logout() {
15627
+ return this.releaseSession(true);
15628
+ }
15629
+ async releaseSession(revokeBorrowed) {
15613
15630
  // Snapshot first: logging out must not call a provider or renew a session
15614
15631
  // using a website account which may already have changed.
15615
- const token = this.token;
15632
+ const token = revokeBorrowed || this.ownsSession ? this.token : null;
15616
15633
  const accessToken = this.ticketAccess?.token;
15617
15634
  this.clearSession();
15618
15635
  this.clearTicketAccess();
@@ -25007,7 +25024,7 @@ class SparkVault {
25007
25024
  }
25008
25025
  /** Get the SDK version */
25009
25026
  static get version() {
25010
- return '15.3.0';
25027
+ return '15.3.2';
25011
25028
  }
25012
25029
  }
25013
25030
  if (typeof window !== 'undefined') {