cat-documents-ng 0.2.56 → 0.2.57

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.
@@ -4583,13 +4583,12 @@ class DocumentHistoryService {
4583
4583
  // Ensure the URL is properly formatted
4584
4584
  const fullUrl = this.getFullUrl(documentUrl);
4585
4585
  console.log('Downloading document:', { originalUrl: documentUrl, fullUrl, docName });
4586
- // Get authentication headers from session
4587
- const headers = this.getAuthHeaders();
4588
- console.log('Using headers:', headers);
4589
- this.http.get(fullUrl, {
4590
- responseType: 'blob',
4591
- headers: headers
4592
- }).subscribe({
4586
+ // Let the HTTP interceptor handle authentication - no need to add headers manually
4587
+ const httpOptions = {
4588
+ responseType: 'blob'
4589
+ };
4590
+ console.log('HTTP options being sent (interceptor will add auth):', httpOptions);
4591
+ this.http.get(fullUrl, httpOptions).subscribe({
4593
4592
  next: (blob) => {
4594
4593
  console.log('Download successful, blob size:', blob.size);
4595
4594
  const blobUrl = window.URL.createObjectURL(blob);
@@ -4605,39 +4604,6 @@ class DocumentHistoryService {
4605
4604
  error: (err) => {
4606
4605
  console.error('Download failed:', err);
4607
4606
  console.error(ERRORS.DOWNLOAD_FAIL, err);
4608
- // If the first attempt fails, try without custom headers (let interceptors handle it)
4609
- if (err.status === 401 || err.status === 403) {
4610
- console.log('Retrying download without custom headers to use interceptors...');
4611
- this.downloadDocumentWithInterceptors(fullUrl, docName);
4612
- }
4613
- }
4614
- });
4615
- }
4616
- /**
4617
- * Alternative download method that relies on HTTP interceptors for authentication
4618
- * @param documentUrl - The URL of the document to download
4619
- * @param docName - The name of the document
4620
- */
4621
- downloadDocumentWithInterceptors(documentUrl, docName) {
4622
- this.http.get(documentUrl, {
4623
- responseType: 'blob'
4624
- // No custom headers - let interceptors handle authentication
4625
- }).subscribe({
4626
- next: (blob) => {
4627
- console.log('Download successful with interceptors, blob size:', blob.size);
4628
- const blobUrl = window.URL.createObjectURL(blob);
4629
- const a = document.createElement('a');
4630
- a.href = blobUrl;
4631
- a.download = docName ?? SHARED.DOCUMENT;
4632
- a.style.display = SHARED.NONE;
4633
- document.body.appendChild(a);
4634
- a.click();
4635
- a.remove();
4636
- window.URL.revokeObjectURL(blobUrl);
4637
- },
4638
- error: (err) => {
4639
- console.error('Download failed even with interceptors:', err);
4640
- console.error(ERRORS.DOWNLOAD_FAIL, err);
4641
4607
  }
4642
4608
  });
4643
4609
  }
@@ -4667,52 +4633,6 @@ class DocumentHistoryService {
4667
4633
  // Fallback to original URL
4668
4634
  return documentUrl;
4669
4635
  }
4670
- /**
4671
- * Get authentication headers for HTTP requests
4672
- * @private
4673
- * @returns {HttpHeaders} Headers with authentication token
4674
- */
4675
- getAuthHeaders() {
4676
- const sessionData = this.sessionService.getUserSession();
4677
- console.log('Session data:', sessionData);
4678
- let headers = new HttpHeaders();
4679
- // Check multiple possible token locations in session data
4680
- if (sessionData && sessionData.token) {
4681
- headers = headers.set('Authorization', `Bearer ${sessionData.token}`);
4682
- console.log('Using token from sessionData.token');
4683
- }
4684
- else if (sessionData && sessionData.accessToken) {
4685
- headers = headers.set('Authorization', `Bearer ${sessionData.accessToken}`);
4686
- console.log('Using token from sessionData.accessToken');
4687
- }
4688
- else if (sessionData && sessionData.sessionId) {
4689
- headers = headers.set('Authorization', `Bearer ${sessionData.sessionId}`);
4690
- console.log('Using token from sessionData.sessionId');
4691
- }
4692
- else if (sessionData && sessionData.authToken) {
4693
- headers = headers.set('Authorization', `Bearer ${sessionData.authToken}`);
4694
- console.log('Using token from sessionData.authToken');
4695
- }
4696
- else if (sessionData && sessionData.jwt) {
4697
- headers = headers.set('Authorization', `Bearer ${sessionData.jwt}`);
4698
- console.log('Using token from sessionData.jwt');
4699
- }
4700
- else {
4701
- // Check localStorage directly for common token patterns
4702
- const directToken = localStorage.getItem('token') ||
4703
- localStorage.getItem('accessToken') ||
4704
- localStorage.getItem('authToken') ||
4705
- localStorage.getItem('jwt');
4706
- if (directToken) {
4707
- headers = headers.set('Authorization', `Bearer ${directToken}`);
4708
- console.log('Using token from localStorage');
4709
- }
4710
- else {
4711
- console.warn('No authentication token found in session data or localStorage');
4712
- }
4713
- }
4714
- return headers;
4715
- }
4716
4636
  /**
4717
4637
  * Debug method to help identify issues when the library is used in the main project
4718
4638
  * @public