@uipath/uipath-typescript 1.1.0 → 1.1.1

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.
@@ -3877,6 +3877,15 @@ class ExecutionContext {
3877
3877
  */
3878
3878
  const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
3879
3879
 
3880
+ /**
3881
+ * Session storage keys used by the auth module
3882
+ */
3883
+ const AUTH_STORAGE_KEYS = {
3884
+ TOKEN_PREFIX: 'uipath_sdk_user_token-',
3885
+ OAUTH_CONTEXT: 'uipath_sdk_oauth_context',
3886
+ CODE_VERIFIER: 'uipath_sdk_code_verifier',
3887
+ };
3888
+
3880
3889
  // Type guard to check if config has OAuth credentials
3881
3890
  function hasOAuthConfig(config) {
3882
3891
  return Boolean(config.clientId && config.redirectUri && config.scope);
@@ -4186,7 +4195,6 @@ class TokenManager {
4186
4195
  this.executionContext = executionContext;
4187
4196
  this.config = config;
4188
4197
  this.isOAuth = isOAuth;
4189
- this.STORAGE_KEY_PREFIX = 'uipath_sdk_user_token-';
4190
4198
  this.refreshPromise = null;
4191
4199
  }
4192
4200
  /**
@@ -4240,7 +4248,7 @@ class TokenManager {
4240
4248
  * Gets the storage key for this TokenManager instance
4241
4249
  */
4242
4250
  _getStorageKey() {
4243
- return `${this.STORAGE_KEY_PREFIX}${this.config.clientId}`;
4251
+ return `${AUTH_STORAGE_KEYS.TOKEN_PREFIX}${this.config.clientId}`;
4244
4252
  }
4245
4253
  /**
4246
4254
  * Loads token from session storage if available
@@ -4486,7 +4494,7 @@ class AuthService {
4486
4494
  return false;
4487
4495
  const urlParams = new URLSearchParams(window.location.search);
4488
4496
  const code = urlParams.get('code');
4489
- const hasCodeVerifier = sessionStorage.getItem('uipath_sdk_code_verifier');
4497
+ const hasCodeVerifier = sessionStorage.getItem(AUTH_STORAGE_KEYS.CODE_VERIFIER);
4490
4498
  return !!(code && hasCodeVerifier);
4491
4499
  }
4492
4500
  /**
@@ -4497,7 +4505,7 @@ class AuthService {
4497
4505
  return null;
4498
4506
  }
4499
4507
  try {
4500
- const stored = sessionStorage.getItem('uipath_sdk_oauth_context');
4508
+ const stored = sessionStorage.getItem(AUTH_STORAGE_KEYS.OAUTH_CONTEXT);
4501
4509
  if (!stored) {
4502
4510
  return null;
4503
4511
  }
@@ -4505,13 +4513,13 @@ class AuthService {
4505
4513
  // Validate required fields
4506
4514
  if (!context.codeVerifier || !context.clientId || !context.redirectUri ||
4507
4515
  !context.baseUrl || !context.orgName) {
4508
- sessionStorage.removeItem('uipath_sdk_oauth_context');
4516
+ sessionStorage.removeItem(AUTH_STORAGE_KEYS.OAUTH_CONTEXT);
4509
4517
  return null;
4510
4518
  }
4511
4519
  return context;
4512
4520
  }
4513
4521
  catch (error) {
4514
- sessionStorage.removeItem('uipath_sdk_oauth_context');
4522
+ sessionStorage.removeItem(AUTH_STORAGE_KEYS.OAUTH_CONTEXT);
4515
4523
  console.warn('Failed to parse stored OAuth context from session storage', error);
4516
4524
  return null;
4517
4525
  }
@@ -4586,7 +4594,7 @@ class AuthService {
4586
4594
  throw new Error('OAuth flow is only supported in browser environments');
4587
4595
  }
4588
4596
  // Check if we have a stored code verifier indicating we're in an OAuth flow
4589
- const codeVerifier = sessionStorage.getItem('uipath_sdk_code_verifier');
4597
+ const codeVerifier = sessionStorage.getItem(AUTH_STORAGE_KEYS.CODE_VERIFIER);
4590
4598
  const isInOAuthFlow = codeVerifier !== null;
4591
4599
  const urlParams = new URLSearchParams(window.location.search);
4592
4600
  const code = urlParams.get('code');
@@ -4595,7 +4603,7 @@ class AuthService {
4595
4603
  // We're expecting a callback - validate parameters
4596
4604
  if (!code) {
4597
4605
  // Clear stored state on error
4598
- sessionStorage.removeItem('uipath_sdk_code_verifier');
4606
+ sessionStorage.removeItem(AUTH_STORAGE_KEYS.CODE_VERIFIER);
4599
4607
  throw new Error('Authorization code missing in OAuth callback');
4600
4608
  }
4601
4609
  // Validate the authorization code format before using it
@@ -4603,7 +4611,7 @@ class AuthService {
4603
4611
  const codePattern = /^[A-Za-z0-9\-._~+/]+=*$/;
4604
4612
  if (!codePattern.test(code)) {
4605
4613
  // Clear stored state on error
4606
- sessionStorage.removeItem('uipath_sdk_code_verifier');
4614
+ sessionStorage.removeItem(AUTH_STORAGE_KEYS.CODE_VERIFIER);
4607
4615
  throw new Error('Invalid authorization code format');
4608
4616
  }
4609
4617
  // Authorization code is present and validated, so we can exchange it for a token.
@@ -4644,6 +4652,24 @@ class AuthService {
4644
4652
  hasValidToken() {
4645
4653
  return this.tokenManager.hasValidToken();
4646
4654
  }
4655
+ /**
4656
+ * Clears all authentication state including tokens and stored OAuth context.
4657
+ */
4658
+ logout() {
4659
+ this.tokenManager.clearToken();
4660
+ // Clear OAuth context from session storage. These are normally cleaned up in _handleOAuthCallback after a successful
4661
+ // token exchange, but if a user calls logout() while an OAuth flow is
4662
+ // mid-redirect (before callback completes), they'd be left behind.
4663
+ if (isBrowser) {
4664
+ try {
4665
+ sessionStorage.removeItem(AUTH_STORAGE_KEYS.OAUTH_CONTEXT);
4666
+ sessionStorage.removeItem(AUTH_STORAGE_KEYS.CODE_VERIFIER);
4667
+ }
4668
+ catch (error) {
4669
+ console.warn('Failed to clear OAuth context from session storage', error);
4670
+ }
4671
+ }
4672
+ }
4647
4673
  /**
4648
4674
  * Get the current token
4649
4675
  */
@@ -4775,8 +4801,8 @@ class AuthService {
4775
4801
  tenantName: this.config.tenantName,
4776
4802
  scope
4777
4803
  };
4778
- sessionStorage.setItem('uipath_sdk_oauth_context', JSON.stringify(oauthContext));
4779
- sessionStorage.setItem('uipath_sdk_code_verifier', codeVerifier);
4804
+ sessionStorage.setItem(AUTH_STORAGE_KEYS.OAUTH_CONTEXT, JSON.stringify(oauthContext));
4805
+ sessionStorage.setItem(AUTH_STORAGE_KEYS.CODE_VERIFIER, codeVerifier);
4780
4806
  const authUrl = this.getAuthorizationUrl({
4781
4807
  clientId,
4782
4808
  redirectUri,
@@ -4786,7 +4812,7 @@ class AuthService {
4786
4812
  window.location.href = authUrl;
4787
4813
  }
4788
4814
  async _handleOAuthCallback(code, clientId, redirectUri) {
4789
- const codeVerifier = sessionStorage.getItem('uipath_sdk_code_verifier');
4815
+ const codeVerifier = sessionStorage.getItem(AUTH_STORAGE_KEYS.CODE_VERIFIER);
4790
4816
  if (!codeVerifier) {
4791
4817
  throw new Error('Code verifier not found in session storage. Authentication may have been interrupted.');
4792
4818
  }
@@ -4797,8 +4823,8 @@ class AuthService {
4797
4823
  codeVerifier
4798
4824
  });
4799
4825
  // Clear OAuth context and code verifier after successful token exchange
4800
- sessionStorage.removeItem('uipath_sdk_oauth_context');
4801
- sessionStorage.removeItem('uipath_sdk_code_verifier');
4826
+ sessionStorage.removeItem(AUTH_STORAGE_KEYS.OAUTH_CONTEXT);
4827
+ sessionStorage.removeItem(AUTH_STORAGE_KEYS.CODE_VERIFIER);
4802
4828
  const url = new URL(window.location.href);
4803
4829
  url.searchParams.delete('code');
4804
4830
  url.searchParams.delete('state');
@@ -4824,7 +4850,7 @@ function normalizeBaseUrl(url) {
4824
4850
  // Connection string placeholder that will be replaced during build
4825
4851
  const CONNECTION_STRING = "InstrumentationKey=a6efa11d-1feb-4508-9738-e13e12dcae5e;IngestionEndpoint=https://westeurope-5.in.applicationinsights.azure.com/;LiveEndpoint=https://westeurope.livediagnostics.monitor.azure.com/;ApplicationId=7c58eb1c-9581-4ba6-839e-11725848a037";
4826
4852
  // SDK Version placeholder
4827
- const SDK_VERSION = "1.1.0";
4853
+ const SDK_VERSION = "1.1.1";
4828
4854
  const VERSION = "Version";
4829
4855
  const SERVICE = "Service";
4830
4856
  const CLOUD_ORGANIZATION_NAME = "CloudOrganizationName";
@@ -5032,6 +5058,65 @@ const telemetryClient = TelemetryClient.getInstance();
5032
5058
  /**
5033
5059
  * SDK Track decorator and function for telemetry
5034
5060
  */
5061
+ /**
5062
+ * Common tracking logic shared between method and function decorators
5063
+ */
5064
+ function createTrackedFunction(originalFunction, nameOrOptions, fallbackName, opts) {
5065
+ return function (...args) {
5066
+ // Determine if we should track this call
5067
+ let shouldTrack = true;
5068
+ if (opts.condition !== undefined) {
5069
+ if (typeof opts.condition === 'function') {
5070
+ shouldTrack = opts.condition.apply(this, args);
5071
+ }
5072
+ else {
5073
+ shouldTrack = opts.condition;
5074
+ }
5075
+ }
5076
+ // Track the event if enabled
5077
+ if (shouldTrack) {
5078
+ // Use the full name provided in the decorator (e.g., "Queue.GetAll")
5079
+ const serviceMethod = typeof nameOrOptions === 'string'
5080
+ ? nameOrOptions
5081
+ : fallbackName;
5082
+ // Use 'Sdk.Run' as the name and serviceMethod as the service
5083
+ telemetryClient.track(serviceMethod, SDK_RUN_EVENT, opts.attributes);
5084
+ }
5085
+ // Execute the original function
5086
+ return originalFunction.apply(this, args);
5087
+ };
5088
+ }
5089
+ /**
5090
+ * Track decorator that can be used to automatically track function calls
5091
+ *
5092
+ * Usage:
5093
+ * @track("Service.Method")
5094
+ * function myFunction() { ... }
5095
+ *
5096
+ * @track("Queue.GetAll")
5097
+ * async getAll() { ... }
5098
+ *
5099
+ * @track("Tasks.Create")
5100
+ * async create() { ... }
5101
+ *
5102
+ * @track("Assets.Update", { condition: false })
5103
+ * function myFunction() { ... }
5104
+ *
5105
+ * @track("Processes.Start", { attributes: { customProp: "value" } })
5106
+ * function myFunction() { ... }
5107
+ */
5108
+ function track(nameOrOptions, options) {
5109
+ return function decorator(_target, propertyKey, descriptor) {
5110
+ const opts = typeof nameOrOptions === 'object' ? nameOrOptions : options || {};
5111
+ if (descriptor && typeof descriptor.value === 'function') {
5112
+ // Method decorator
5113
+ descriptor.value = createTrackedFunction(descriptor.value, nameOrOptions, propertyKey || 'unknown_method', opts);
5114
+ return descriptor;
5115
+ }
5116
+ // Function decorator
5117
+ return (originalFunction) => createTrackedFunction(originalFunction, nameOrOptions, originalFunction.name || 'unknown_function', opts);
5118
+ };
5119
+ }
5035
5120
  /**
5036
5121
  * Direct tracking function
5037
5122
  */
@@ -5250,6 +5335,18 @@ class UiPath {
5250
5335
  getToken() {
5251
5336
  return __classPrivateFieldGet(this, _UiPath_authService, "f").getToken();
5252
5337
  }
5338
+ /**
5339
+ * Logout from the SDK, clearing all authentication state.
5340
+ * After calling this method, the user will need to re-initialize to authenticate again.
5341
+ */
5342
+ logout() {
5343
+ // Secret-based auth has no session to end — skip silently
5344
+ if (hasSecretConfig(__classPrivateFieldGet(this, _UiPath_config, "f"))) {
5345
+ return;
5346
+ }
5347
+ __classPrivateFieldGet(this, _UiPath_authService, "f").logout();
5348
+ __classPrivateFieldSet(this, _UiPath_initialized, false, "f");
5349
+ }
5253
5350
  }
5254
5351
  _UiPath_config = new WeakMap(), _UiPath_authService = new WeakMap(), _UiPath_initialized = new WeakMap();
5255
5352
 
@@ -5276,4 +5373,4 @@ function getLimitedPageSize(pageSize) {
5276
5373
  return Math.max(1, Math.min(pageSize, MAX_PAGE_SIZE));
5277
5374
  }
5278
5375
 
5279
- export { AuthenticationError, AuthorizationError, DEFAULT_ITEMS_FIELD, DEFAULT_PAGE_SIZE, DEFAULT_TOTAL_COUNT_FIELD, ErrorType, HttpStatus, MAX_PAGE_SIZE, NetworkError, NotFoundError, RateLimitError, ServerError, UiPath, UiPathError, ValidationError, getErrorDetails, getLimitedPageSize, isAuthenticationError, isAuthorizationError, isNetworkError, isNotFoundError, isRateLimitError, isServerError, isUiPathError, isValidationError };
5376
+ export { APP_NAME, AuthenticationError, AuthorizationError, CLOUD_CLIENT_ID, CLOUD_ORGANIZATION_NAME, CLOUD_REDIRECT_URI, CLOUD_ROLE_NAME, CLOUD_TENANT_NAME, CLOUD_URL, CONNECTION_STRING, DEFAULT_ITEMS_FIELD, DEFAULT_PAGE_SIZE, DEFAULT_TOTAL_COUNT_FIELD, ErrorType, HttpStatus, MAX_PAGE_SIZE, NetworkError, NotFoundError, RateLimitError, SDK_LOGGER_NAME, SDK_RUN_EVENT, SDK_SERVICE_NAME, SDK_VERSION, SERVICE, ServerError, UNKNOWN, UiPath, UiPathError, VERSION, ValidationError, getErrorDetails, getLimitedPageSize, isAuthenticationError, isAuthorizationError, isNetworkError, isNotFoundError, isRateLimitError, isServerError, isUiPathError, isValidationError, telemetryClient, track, trackEvent };
@@ -1889,7 +1889,7 @@ const EntityFieldTypeMap = {
1889
1889
  // Connection string placeholder that will be replaced during build
1890
1890
  const CONNECTION_STRING = "InstrumentationKey=a6efa11d-1feb-4508-9738-e13e12dcae5e;IngestionEndpoint=https://westeurope-5.in.applicationinsights.azure.com/;LiveEndpoint=https://westeurope.livediagnostics.monitor.azure.com/;ApplicationId=7c58eb1c-9581-4ba6-839e-11725848a037";
1891
1891
  // SDK Version placeholder
1892
- const SDK_VERSION = "1.1.0";
1892
+ const SDK_VERSION = "1.1.1";
1893
1893
  const VERSION = "Version";
1894
1894
  const SERVICE = "Service";
1895
1895
  const CLOUD_ORGANIZATION_NAME = "CloudOrganizationName";
@@ -1887,7 +1887,7 @@ const EntityFieldTypeMap = {
1887
1887
  // Connection string placeholder that will be replaced during build
1888
1888
  const CONNECTION_STRING = "InstrumentationKey=a6efa11d-1feb-4508-9738-e13e12dcae5e;IngestionEndpoint=https://westeurope-5.in.applicationinsights.azure.com/;LiveEndpoint=https://westeurope.livediagnostics.monitor.azure.com/;ApplicationId=7c58eb1c-9581-4ba6-839e-11725848a037";
1889
1889
  // SDK Version placeholder
1890
- const SDK_VERSION = "1.1.0";
1890
+ const SDK_VERSION = "1.1.1";
1891
1891
  const VERSION = "Version";
1892
1892
  const SERVICE = "Service";
1893
1893
  const CLOUD_ORGANIZATION_NAME = "CloudOrganizationName";
package/dist/index.cjs CHANGED
@@ -3886,6 +3886,15 @@ class ExecutionContext {
3886
3886
  */
3887
3887
  const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
3888
3888
 
3889
+ /**
3890
+ * Session storage keys used by the auth module
3891
+ */
3892
+ const AUTH_STORAGE_KEYS = {
3893
+ TOKEN_PREFIX: 'uipath_sdk_user_token-',
3894
+ OAUTH_CONTEXT: 'uipath_sdk_oauth_context',
3895
+ CODE_VERIFIER: 'uipath_sdk_code_verifier',
3896
+ };
3897
+
3889
3898
  // Type guard to check if config has OAuth credentials
3890
3899
  function hasOAuthConfig(config) {
3891
3900
  return Boolean(config.clientId && config.redirectUri && config.scope);
@@ -4209,7 +4218,6 @@ class TokenManager {
4209
4218
  this.executionContext = executionContext;
4210
4219
  this.config = config;
4211
4220
  this.isOAuth = isOAuth;
4212
- this.STORAGE_KEY_PREFIX = 'uipath_sdk_user_token-';
4213
4221
  this.refreshPromise = null;
4214
4222
  }
4215
4223
  /**
@@ -4263,7 +4271,7 @@ class TokenManager {
4263
4271
  * Gets the storage key for this TokenManager instance
4264
4272
  */
4265
4273
  _getStorageKey() {
4266
- return `${this.STORAGE_KEY_PREFIX}${this.config.clientId}`;
4274
+ return `${AUTH_STORAGE_KEYS.TOKEN_PREFIX}${this.config.clientId}`;
4267
4275
  }
4268
4276
  /**
4269
4277
  * Loads token from session storage if available
@@ -4625,7 +4633,7 @@ class AuthService {
4625
4633
  return false;
4626
4634
  const urlParams = new URLSearchParams(window.location.search);
4627
4635
  const code = urlParams.get('code');
4628
- const hasCodeVerifier = sessionStorage.getItem('uipath_sdk_code_verifier');
4636
+ const hasCodeVerifier = sessionStorage.getItem(AUTH_STORAGE_KEYS.CODE_VERIFIER);
4629
4637
  return !!(code && hasCodeVerifier);
4630
4638
  }
4631
4639
  /**
@@ -4636,7 +4644,7 @@ class AuthService {
4636
4644
  return null;
4637
4645
  }
4638
4646
  try {
4639
- const stored = sessionStorage.getItem('uipath_sdk_oauth_context');
4647
+ const stored = sessionStorage.getItem(AUTH_STORAGE_KEYS.OAUTH_CONTEXT);
4640
4648
  if (!stored) {
4641
4649
  return null;
4642
4650
  }
@@ -4644,13 +4652,13 @@ class AuthService {
4644
4652
  // Validate required fields
4645
4653
  if (!context.codeVerifier || !context.clientId || !context.redirectUri ||
4646
4654
  !context.baseUrl || !context.orgName) {
4647
- sessionStorage.removeItem('uipath_sdk_oauth_context');
4655
+ sessionStorage.removeItem(AUTH_STORAGE_KEYS.OAUTH_CONTEXT);
4648
4656
  return null;
4649
4657
  }
4650
4658
  return context;
4651
4659
  }
4652
4660
  catch (error) {
4653
- sessionStorage.removeItem('uipath_sdk_oauth_context');
4661
+ sessionStorage.removeItem(AUTH_STORAGE_KEYS.OAUTH_CONTEXT);
4654
4662
  console.warn('Failed to parse stored OAuth context from session storage', error);
4655
4663
  return null;
4656
4664
  }
@@ -4725,7 +4733,7 @@ class AuthService {
4725
4733
  throw new Error('OAuth flow is only supported in browser environments');
4726
4734
  }
4727
4735
  // Check if we have a stored code verifier indicating we're in an OAuth flow
4728
- const codeVerifier = sessionStorage.getItem('uipath_sdk_code_verifier');
4736
+ const codeVerifier = sessionStorage.getItem(AUTH_STORAGE_KEYS.CODE_VERIFIER);
4729
4737
  const isInOAuthFlow = codeVerifier !== null;
4730
4738
  const urlParams = new URLSearchParams(window.location.search);
4731
4739
  const code = urlParams.get('code');
@@ -4734,7 +4742,7 @@ class AuthService {
4734
4742
  // We're expecting a callback - validate parameters
4735
4743
  if (!code) {
4736
4744
  // Clear stored state on error
4737
- sessionStorage.removeItem('uipath_sdk_code_verifier');
4745
+ sessionStorage.removeItem(AUTH_STORAGE_KEYS.CODE_VERIFIER);
4738
4746
  throw new Error('Authorization code missing in OAuth callback');
4739
4747
  }
4740
4748
  // Validate the authorization code format before using it
@@ -4742,7 +4750,7 @@ class AuthService {
4742
4750
  const codePattern = /^[A-Za-z0-9\-._~+/]+=*$/;
4743
4751
  if (!codePattern.test(code)) {
4744
4752
  // Clear stored state on error
4745
- sessionStorage.removeItem('uipath_sdk_code_verifier');
4753
+ sessionStorage.removeItem(AUTH_STORAGE_KEYS.CODE_VERIFIER);
4746
4754
  throw new Error('Invalid authorization code format');
4747
4755
  }
4748
4756
  // Authorization code is present and validated, so we can exchange it for a token.
@@ -4783,6 +4791,24 @@ class AuthService {
4783
4791
  hasValidToken() {
4784
4792
  return this.tokenManager.hasValidToken();
4785
4793
  }
4794
+ /**
4795
+ * Clears all authentication state including tokens and stored OAuth context.
4796
+ */
4797
+ logout() {
4798
+ this.tokenManager.clearToken();
4799
+ // Clear OAuth context from session storage. These are normally cleaned up in _handleOAuthCallback after a successful
4800
+ // token exchange, but if a user calls logout() while an OAuth flow is
4801
+ // mid-redirect (before callback completes), they'd be left behind.
4802
+ if (isBrowser) {
4803
+ try {
4804
+ sessionStorage.removeItem(AUTH_STORAGE_KEYS.OAUTH_CONTEXT);
4805
+ sessionStorage.removeItem(AUTH_STORAGE_KEYS.CODE_VERIFIER);
4806
+ }
4807
+ catch (error) {
4808
+ console.warn('Failed to clear OAuth context from session storage', error);
4809
+ }
4810
+ }
4811
+ }
4786
4812
  /**
4787
4813
  * Get the current token
4788
4814
  */
@@ -4914,8 +4940,8 @@ class AuthService {
4914
4940
  tenantName: this.config.tenantName,
4915
4941
  scope
4916
4942
  };
4917
- sessionStorage.setItem('uipath_sdk_oauth_context', JSON.stringify(oauthContext));
4918
- sessionStorage.setItem('uipath_sdk_code_verifier', codeVerifier);
4943
+ sessionStorage.setItem(AUTH_STORAGE_KEYS.OAUTH_CONTEXT, JSON.stringify(oauthContext));
4944
+ sessionStorage.setItem(AUTH_STORAGE_KEYS.CODE_VERIFIER, codeVerifier);
4919
4945
  const authUrl = this.getAuthorizationUrl({
4920
4946
  clientId,
4921
4947
  redirectUri,
@@ -4925,7 +4951,7 @@ class AuthService {
4925
4951
  window.location.href = authUrl;
4926
4952
  }
4927
4953
  async _handleOAuthCallback(code, clientId, redirectUri) {
4928
- const codeVerifier = sessionStorage.getItem('uipath_sdk_code_verifier');
4954
+ const codeVerifier = sessionStorage.getItem(AUTH_STORAGE_KEYS.CODE_VERIFIER);
4929
4955
  if (!codeVerifier) {
4930
4956
  throw new Error('Code verifier not found in session storage. Authentication may have been interrupted.');
4931
4957
  }
@@ -4936,8 +4962,8 @@ class AuthService {
4936
4962
  codeVerifier
4937
4963
  });
4938
4964
  // Clear OAuth context and code verifier after successful token exchange
4939
- sessionStorage.removeItem('uipath_sdk_oauth_context');
4940
- sessionStorage.removeItem('uipath_sdk_code_verifier');
4965
+ sessionStorage.removeItem(AUTH_STORAGE_KEYS.OAUTH_CONTEXT);
4966
+ sessionStorage.removeItem(AUTH_STORAGE_KEYS.CODE_VERIFIER);
4941
4967
  const url = new URL(window.location.href);
4942
4968
  url.searchParams.delete('code');
4943
4969
  url.searchParams.delete('state');
@@ -4963,7 +4989,7 @@ function normalizeBaseUrl(url) {
4963
4989
  // Connection string placeholder that will be replaced during build
4964
4990
  const CONNECTION_STRING = "InstrumentationKey=a6efa11d-1feb-4508-9738-e13e12dcae5e;IngestionEndpoint=https://westeurope-5.in.applicationinsights.azure.com/;LiveEndpoint=https://westeurope.livediagnostics.monitor.azure.com/;ApplicationId=7c58eb1c-9581-4ba6-839e-11725848a037";
4965
4991
  // SDK Version placeholder
4966
- const SDK_VERSION = "1.1.0";
4992
+ const SDK_VERSION = "1.1.1";
4967
4993
  const VERSION = "Version";
4968
4994
  const SERVICE = "Service";
4969
4995
  const CLOUD_ORGANIZATION_NAME = "CloudOrganizationName";
@@ -5448,6 +5474,18 @@ let UiPath$1 = class UiPath {
5448
5474
  getToken() {
5449
5475
  return __classPrivateFieldGet(this, _UiPath_authService, "f").getToken();
5450
5476
  }
5477
+ /**
5478
+ * Logout from the SDK, clearing all authentication state.
5479
+ * After calling this method, the user will need to re-initialize to authenticate again.
5480
+ */
5481
+ logout() {
5482
+ // Secret-based auth has no session to end — skip silently
5483
+ if (hasSecretConfig(__classPrivateFieldGet(this, _UiPath_config, "f"))) {
5484
+ return;
5485
+ }
5486
+ __classPrivateFieldGet(this, _UiPath_authService, "f").logout();
5487
+ __classPrivateFieldSet(this, _UiPath_initialized, false, "f");
5488
+ }
5451
5489
  };
5452
5490
  _UiPath_config = new WeakMap(), _UiPath_authService = new WeakMap(), _UiPath_initialized = new WeakMap();
5453
5491
 
package/dist/index.d.ts CHANGED
@@ -56,6 +56,11 @@ interface IUiPath {
56
56
  * Get the current authentication token
57
57
  */
58
58
  getToken(): string | undefined;
59
+ /**
60
+ * Logout from the SDK, clearing all authentication state.
61
+ * After calling this method, the user will need to re-initialize to authenticate again.
62
+ */
63
+ logout(): void;
59
64
  }
60
65
 
61
66
  /**
@@ -116,6 +121,11 @@ declare class UiPath$1 implements IUiPath {
116
121
  * Get the current authentication token
117
122
  */
118
123
  getToken(): string | undefined;
124
+ /**
125
+ * Logout from the SDK, clearing all authentication state.
126
+ * After calling this method, the user will need to re-initialize to authenticate again.
127
+ */
128
+ logout(): void;
119
129
  }
120
130
 
121
131
  /**
@@ -10195,7 +10205,7 @@ declare const telemetryClient: TelemetryClient;
10195
10205
  * SDK Telemetry constants
10196
10206
  */
10197
10207
  declare const CONNECTION_STRING = "InstrumentationKey=a6efa11d-1feb-4508-9738-e13e12dcae5e;IngestionEndpoint=https://westeurope-5.in.applicationinsights.azure.com/;LiveEndpoint=https://westeurope.livediagnostics.monitor.azure.com/;ApplicationId=7c58eb1c-9581-4ba6-839e-11725848a037";
10198
- declare const SDK_VERSION = "1.1.0";
10208
+ declare const SDK_VERSION = "1.1.1";
10199
10209
  declare const VERSION = "Version";
10200
10210
  declare const SERVICE = "Service";
10201
10211
  declare const CLOUD_ORGANIZATION_NAME = "CloudOrganizationName";
package/dist/index.mjs CHANGED
@@ -3884,6 +3884,15 @@ class ExecutionContext {
3884
3884
  */
3885
3885
  const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
3886
3886
 
3887
+ /**
3888
+ * Session storage keys used by the auth module
3889
+ */
3890
+ const AUTH_STORAGE_KEYS = {
3891
+ TOKEN_PREFIX: 'uipath_sdk_user_token-',
3892
+ OAUTH_CONTEXT: 'uipath_sdk_oauth_context',
3893
+ CODE_VERIFIER: 'uipath_sdk_code_verifier',
3894
+ };
3895
+
3887
3896
  // Type guard to check if config has OAuth credentials
3888
3897
  function hasOAuthConfig(config) {
3889
3898
  return Boolean(config.clientId && config.redirectUri && config.scope);
@@ -4207,7 +4216,6 @@ class TokenManager {
4207
4216
  this.executionContext = executionContext;
4208
4217
  this.config = config;
4209
4218
  this.isOAuth = isOAuth;
4210
- this.STORAGE_KEY_PREFIX = 'uipath_sdk_user_token-';
4211
4219
  this.refreshPromise = null;
4212
4220
  }
4213
4221
  /**
@@ -4261,7 +4269,7 @@ class TokenManager {
4261
4269
  * Gets the storage key for this TokenManager instance
4262
4270
  */
4263
4271
  _getStorageKey() {
4264
- return `${this.STORAGE_KEY_PREFIX}${this.config.clientId}`;
4272
+ return `${AUTH_STORAGE_KEYS.TOKEN_PREFIX}${this.config.clientId}`;
4265
4273
  }
4266
4274
  /**
4267
4275
  * Loads token from session storage if available
@@ -4623,7 +4631,7 @@ class AuthService {
4623
4631
  return false;
4624
4632
  const urlParams = new URLSearchParams(window.location.search);
4625
4633
  const code = urlParams.get('code');
4626
- const hasCodeVerifier = sessionStorage.getItem('uipath_sdk_code_verifier');
4634
+ const hasCodeVerifier = sessionStorage.getItem(AUTH_STORAGE_KEYS.CODE_VERIFIER);
4627
4635
  return !!(code && hasCodeVerifier);
4628
4636
  }
4629
4637
  /**
@@ -4634,7 +4642,7 @@ class AuthService {
4634
4642
  return null;
4635
4643
  }
4636
4644
  try {
4637
- const stored = sessionStorage.getItem('uipath_sdk_oauth_context');
4645
+ const stored = sessionStorage.getItem(AUTH_STORAGE_KEYS.OAUTH_CONTEXT);
4638
4646
  if (!stored) {
4639
4647
  return null;
4640
4648
  }
@@ -4642,13 +4650,13 @@ class AuthService {
4642
4650
  // Validate required fields
4643
4651
  if (!context.codeVerifier || !context.clientId || !context.redirectUri ||
4644
4652
  !context.baseUrl || !context.orgName) {
4645
- sessionStorage.removeItem('uipath_sdk_oauth_context');
4653
+ sessionStorage.removeItem(AUTH_STORAGE_KEYS.OAUTH_CONTEXT);
4646
4654
  return null;
4647
4655
  }
4648
4656
  return context;
4649
4657
  }
4650
4658
  catch (error) {
4651
- sessionStorage.removeItem('uipath_sdk_oauth_context');
4659
+ sessionStorage.removeItem(AUTH_STORAGE_KEYS.OAUTH_CONTEXT);
4652
4660
  console.warn('Failed to parse stored OAuth context from session storage', error);
4653
4661
  return null;
4654
4662
  }
@@ -4723,7 +4731,7 @@ class AuthService {
4723
4731
  throw new Error('OAuth flow is only supported in browser environments');
4724
4732
  }
4725
4733
  // Check if we have a stored code verifier indicating we're in an OAuth flow
4726
- const codeVerifier = sessionStorage.getItem('uipath_sdk_code_verifier');
4734
+ const codeVerifier = sessionStorage.getItem(AUTH_STORAGE_KEYS.CODE_VERIFIER);
4727
4735
  const isInOAuthFlow = codeVerifier !== null;
4728
4736
  const urlParams = new URLSearchParams(window.location.search);
4729
4737
  const code = urlParams.get('code');
@@ -4732,7 +4740,7 @@ class AuthService {
4732
4740
  // We're expecting a callback - validate parameters
4733
4741
  if (!code) {
4734
4742
  // Clear stored state on error
4735
- sessionStorage.removeItem('uipath_sdk_code_verifier');
4743
+ sessionStorage.removeItem(AUTH_STORAGE_KEYS.CODE_VERIFIER);
4736
4744
  throw new Error('Authorization code missing in OAuth callback');
4737
4745
  }
4738
4746
  // Validate the authorization code format before using it
@@ -4740,7 +4748,7 @@ class AuthService {
4740
4748
  const codePattern = /^[A-Za-z0-9\-._~+/]+=*$/;
4741
4749
  if (!codePattern.test(code)) {
4742
4750
  // Clear stored state on error
4743
- sessionStorage.removeItem('uipath_sdk_code_verifier');
4751
+ sessionStorage.removeItem(AUTH_STORAGE_KEYS.CODE_VERIFIER);
4744
4752
  throw new Error('Invalid authorization code format');
4745
4753
  }
4746
4754
  // Authorization code is present and validated, so we can exchange it for a token.
@@ -4781,6 +4789,24 @@ class AuthService {
4781
4789
  hasValidToken() {
4782
4790
  return this.tokenManager.hasValidToken();
4783
4791
  }
4792
+ /**
4793
+ * Clears all authentication state including tokens and stored OAuth context.
4794
+ */
4795
+ logout() {
4796
+ this.tokenManager.clearToken();
4797
+ // Clear OAuth context from session storage. These are normally cleaned up in _handleOAuthCallback after a successful
4798
+ // token exchange, but if a user calls logout() while an OAuth flow is
4799
+ // mid-redirect (before callback completes), they'd be left behind.
4800
+ if (isBrowser) {
4801
+ try {
4802
+ sessionStorage.removeItem(AUTH_STORAGE_KEYS.OAUTH_CONTEXT);
4803
+ sessionStorage.removeItem(AUTH_STORAGE_KEYS.CODE_VERIFIER);
4804
+ }
4805
+ catch (error) {
4806
+ console.warn('Failed to clear OAuth context from session storage', error);
4807
+ }
4808
+ }
4809
+ }
4784
4810
  /**
4785
4811
  * Get the current token
4786
4812
  */
@@ -4912,8 +4938,8 @@ class AuthService {
4912
4938
  tenantName: this.config.tenantName,
4913
4939
  scope
4914
4940
  };
4915
- sessionStorage.setItem('uipath_sdk_oauth_context', JSON.stringify(oauthContext));
4916
- sessionStorage.setItem('uipath_sdk_code_verifier', codeVerifier);
4941
+ sessionStorage.setItem(AUTH_STORAGE_KEYS.OAUTH_CONTEXT, JSON.stringify(oauthContext));
4942
+ sessionStorage.setItem(AUTH_STORAGE_KEYS.CODE_VERIFIER, codeVerifier);
4917
4943
  const authUrl = this.getAuthorizationUrl({
4918
4944
  clientId,
4919
4945
  redirectUri,
@@ -4923,7 +4949,7 @@ class AuthService {
4923
4949
  window.location.href = authUrl;
4924
4950
  }
4925
4951
  async _handleOAuthCallback(code, clientId, redirectUri) {
4926
- const codeVerifier = sessionStorage.getItem('uipath_sdk_code_verifier');
4952
+ const codeVerifier = sessionStorage.getItem(AUTH_STORAGE_KEYS.CODE_VERIFIER);
4927
4953
  if (!codeVerifier) {
4928
4954
  throw new Error('Code verifier not found in session storage. Authentication may have been interrupted.');
4929
4955
  }
@@ -4934,8 +4960,8 @@ class AuthService {
4934
4960
  codeVerifier
4935
4961
  });
4936
4962
  // Clear OAuth context and code verifier after successful token exchange
4937
- sessionStorage.removeItem('uipath_sdk_oauth_context');
4938
- sessionStorage.removeItem('uipath_sdk_code_verifier');
4963
+ sessionStorage.removeItem(AUTH_STORAGE_KEYS.OAUTH_CONTEXT);
4964
+ sessionStorage.removeItem(AUTH_STORAGE_KEYS.CODE_VERIFIER);
4939
4965
  const url = new URL(window.location.href);
4940
4966
  url.searchParams.delete('code');
4941
4967
  url.searchParams.delete('state');
@@ -4961,7 +4987,7 @@ function normalizeBaseUrl(url) {
4961
4987
  // Connection string placeholder that will be replaced during build
4962
4988
  const CONNECTION_STRING = "InstrumentationKey=a6efa11d-1feb-4508-9738-e13e12dcae5e;IngestionEndpoint=https://westeurope-5.in.applicationinsights.azure.com/;LiveEndpoint=https://westeurope.livediagnostics.monitor.azure.com/;ApplicationId=7c58eb1c-9581-4ba6-839e-11725848a037";
4963
4989
  // SDK Version placeholder
4964
- const SDK_VERSION = "1.1.0";
4990
+ const SDK_VERSION = "1.1.1";
4965
4991
  const VERSION = "Version";
4966
4992
  const SERVICE = "Service";
4967
4993
  const CLOUD_ORGANIZATION_NAME = "CloudOrganizationName";
@@ -5446,6 +5472,18 @@ let UiPath$1 = class UiPath {
5446
5472
  getToken() {
5447
5473
  return __classPrivateFieldGet(this, _UiPath_authService, "f").getToken();
5448
5474
  }
5475
+ /**
5476
+ * Logout from the SDK, clearing all authentication state.
5477
+ * After calling this method, the user will need to re-initialize to authenticate again.
5478
+ */
5479
+ logout() {
5480
+ // Secret-based auth has no session to end — skip silently
5481
+ if (hasSecretConfig(__classPrivateFieldGet(this, _UiPath_config, "f"))) {
5482
+ return;
5483
+ }
5484
+ __classPrivateFieldGet(this, _UiPath_authService, "f").logout();
5485
+ __classPrivateFieldSet(this, _UiPath_initialized, false, "f");
5486
+ }
5449
5487
  };
5450
5488
  _UiPath_config = new WeakMap(), _UiPath_authService = new WeakMap(), _UiPath_initialized = new WeakMap();
5451
5489