@sinequa/atomic-angular 1.0.2 → 1.0.5

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.
@@ -7,7 +7,7 @@ import highlightWords from 'highlight-words';
7
7
  import { ActivatedRoute, Router, NavigationEnd, RouterLink, RouterModule } from '@angular/router';
8
8
  import { withDevtools } from '@angular-architects/ngrx-toolkit';
9
9
  import { signalStore, signalStoreFeature, withState, withMethods, patchState, getState, withComputed } from '@ngrx/signals';
10
- import { globalConfig, EngineType, extraColumns, sysLang, getQueryParamsFromUrl, logout, login, info, warn, error, setGlobalConfig, notify, addConcepts, queryParamsFromUrl, patchUserSettings, deleteUserSettings, fetchUserSettings, buildPathsAndLevels, escapeExpr, isAuthenticated, isExpired, debug, fetchSuggest, isObject, Audit, getMetadata, bisect, isNotInputEvent, fetchSponsoredLinks, fetchQuery, translateAggregationToDateOptions, aggItemRegex, parseValueAndOperatorFromItem, fetchSuggestField, fetchSimilarDocuments, fetchChangePassword, fetchSendPasswordResetEmail, expiresSoon, suggestionsToTreeAggregationNodes, labels, fetchLabels, guid, getRelativeDate, createUserProfile, deleteUserProfileProperty, patchUserProfile, isJsonable, addAuditAdditionalInfo, getToken, setToken, createHeaders } from '@sinequa/atomic';
10
+ import { globalConfig, EngineType, extraColumns, sysLang, getQueryParamsFromUrl, clearSessionTokens, login, info, warn, error, setGlobalConfig, notify, addConcepts, queryParamsFromUrl, patchUserSettings, deleteUserSettings, fetchUserSettings, buildPathsAndLevels, escapeExpr, isAuthenticated, isExpired, debug, AuditEventType, fetchSuggest, isObject, Audit, getMetadata, bisect, isNotInputEvent, fetchSponsoredLinks, fetchQuery, translateAggregationToDateOptions, aggItemRegex, parseValueAndOperatorFromItem, fetchSuggestField, fetchSimilarDocuments, logout, fetchChangePassword, fetchSendPasswordResetEmail, expiresSoon, suggestionsToTreeAggregationNodes, labels, fetchLabels, guid, getRelativeDate, createUserProfile, deleteUserProfileProperty, patchUserProfile, isJsonable, addAuditAdditionalInfo, getToken, setToken, createHeaders } from '@sinequa/atomic';
11
11
  import { HttpClient, HttpParams, httpResource, HttpResponse, HttpHeaders, HttpContextToken } from '@angular/common/http';
12
12
  import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop';
13
13
  import { DatePipe, DATE_PIPE_DEFAULT_TIMEZONE, DATE_PIPE_DEFAULT_OPTIONS, Location, NgTemplateOutlet, NgStyle, NgClass, NgComponentOutlet } from '@angular/common';
@@ -1551,31 +1551,44 @@ function withThemes(app, themes) {
1551
1551
  return app;
1552
1552
  }
1553
1553
 
1554
+ /**
1555
+ * Signs in the user by checking the global configuration for authentication method and acting accordingly.
1556
+ *
1557
+ * This function first clears any existing session tokens to ensure a clean authentication state. It then checks the
1558
+ * global configuration to determine whether to use credentials-based authentication or Single Sign-On (SSO). If
1559
+ * credentials are used, it redirects the user to the login page. If SSO is enabled, it reloads the page to trigger
1560
+ * the SSO login process. If neither method is specified, it attempts a standard login and handles any errors that
1561
+ * may occur during the process.
1562
+ * @returns A promise resolving to a boolean indicating the success of the sign-in operation.
1563
+ */
1554
1564
  async function signIn() {
1555
1565
  assertInInjectionContext(signIn);
1556
1566
  const router = inject(Router);
1557
1567
  const lastUrlAfterNavigation = inject(NavigationService).urlAfterNavigation;
1558
1568
  const { useCredentials, loginPath, useSSO } = globalConfig;
1559
- // Always log out first to clear any existing session
1560
- await logout();
1569
+ // Always clear authentication tokens first to clear any existing session
1570
+ clearSessionTokens();
1561
1571
  // If credentials are used and user override is not active, redirect to the login page
1562
1572
  if (useCredentials) {
1563
1573
  router.navigate([loginPath], { queryParams: { returnUrl: lastUrlAfterNavigation } });
1564
- return; // prevent further execution
1574
+ return false; // prevent further execution
1565
1575
  }
1566
1576
  // SSO is set to true when the browser handles authentication automatically
1567
1577
  // If SSO is used, reload the page to trigger SSO login
1568
1578
  if (useSSO) {
1569
1579
  // reload the page to trigger SSO login
1570
1580
  window.location.reload();
1571
- return; // prevent further execution
1581
+ return false; // prevent further execution
1572
1582
  }
1573
1583
  // Otherwise, perform a standard login
1574
1584
  try {
1575
1585
  const response = await login();
1576
- info("Response from login", response);
1577
- if (!response) {
1578
- warn("No response from login, redirecting to login page", response);
1586
+ if (response) {
1587
+ info("Response from login", response);
1588
+ return true;
1589
+ }
1590
+ else {
1591
+ warn("Response from login", response);
1579
1592
  }
1580
1593
  }
1581
1594
  catch (err) {
@@ -1586,7 +1599,7 @@ async function signIn() {
1586
1599
  }
1587
1600
  throw err;
1588
1601
  }
1589
- return; // prevent further execution
1602
+ return false; // prevent further execution
1590
1603
  }
1591
1604
 
1592
1605
  /**
@@ -1607,24 +1620,28 @@ async function withBootstrapApp(applicationService, { createRoutes = true }) {
1607
1620
  return new Promise(resolve => {
1608
1621
  // Check if the user is authenticated
1609
1622
  signIn()
1610
- .then(() => {
1611
- info('User authenticated, initializing application...');
1612
- // Initialize the application
1613
- applicationService
1614
- .initialize(createRoutes)
1615
- .then(() => {
1616
- info(`Application initialized with routes: ${createRoutes} successfully.`);
1617
- resolve();
1618
- })
1619
- .catch(err => {
1620
- error(`Error initializing application with routes: ${createRoutes}:`, err);
1621
- resolve();
1622
- });
1623
+ .then((response) => {
1624
+ if (response) {
1625
+ info('User authenticated, initializing application...');
1626
+ // Initialize the application
1627
+ applicationService
1628
+ .initialize(createRoutes)
1629
+ .then(() => {
1630
+ info(`Application initialized with routes: ${createRoutes} successfully.`);
1631
+ })
1632
+ .catch(err => {
1633
+ error(`Error initializing application with routes: ${createRoutes}:`, err);
1634
+ });
1635
+ }
1636
+ else {
1637
+ info('User not authenticated, skipping application initialization.');
1638
+ }
1639
+ ;
1623
1640
  })
1624
1641
  .catch(err => {
1625
1642
  error('Error while signing in:', err);
1626
- resolve();
1627
- });
1643
+ })
1644
+ .finally(() => resolve());
1628
1645
  });
1629
1646
  }
1630
1647
 
@@ -3821,7 +3838,7 @@ class AuditService {
3821
3838
  // Second event triggered when we come back
3822
3839
  document.addEventListener('visibilitychange', () => {
3823
3840
  if (document.visibilityState === 'visible') {
3824
- this.notify({ type: "Navigation_Return" /* AuditEventType.Navigation_Return */ });
3841
+ this.notify({ type: AuditEventType.Navigation_Return });
3825
3842
  }
3826
3843
  }, { once: true });
3827
3844
  }
@@ -4191,7 +4208,7 @@ class PreviewService {
4191
4208
  this.passageOffset.set(undefined);
4192
4209
  const detail = this.getAuditPreviewDetail(id, query);
4193
4210
  const auditEvent = {
4194
- type: "Preview_Close" /* AuditEventType.Preview_Close */,
4211
+ type: AuditEventType.Preview_Close,
4195
4212
  detail
4196
4213
  };
4197
4214
  Audit.notify(auditEvent);
@@ -5785,7 +5802,7 @@ class ExportService {
5785
5802
  exportedColumns: exportedColumns,
5786
5803
  selection: (selection ?? []).length > 0 ? selection : undefined,
5787
5804
  $auditRecord: {
5788
- type: "Search_ExportCSV" /* AuditEventType.Search_ExportCSV */,
5805
+ type: AuditEventType.Search_ExportCSV,
5789
5806
  detail: {
5790
5807
  resultid: results ? results.id : undefined
5791
5808
  }
@@ -7896,11 +7913,16 @@ class AdvancedFiltersComponent {
7896
7913
  }, ...(ngDevMode ? [{ debugName: "allowEmptySearch" }] : []));
7897
7914
  text = "";
7898
7915
  constructor() {
7899
- this.getFirstPageQuery();
7916
+ effect(() => {
7917
+ getState(this.appStore);
7918
+ const query = this.appStore.getDefaultQuery();
7919
+ if (query?.name) {
7920
+ this.getFirstPageQuery(query?.name);
7921
+ }
7922
+ });
7900
7923
  }
7901
- async getFirstPageQuery() {
7902
- const query = this.appStore.getDefaultQuery() || { name: "_default" };
7903
- const response = await fetchQuery({ isFirstPage: true, name: query.name });
7924
+ async getFirstPageQuery(queryName) {
7925
+ const response = await fetchQuery({ isFirstPage: true, name: queryName });
7904
7926
  this.aggregations.set(response.aggregations);
7905
7927
  }
7906
7928
  onTabChange(tab) {
@@ -9079,6 +9101,9 @@ class AggregationDateComponent extends AggregationListComponent {
9079
9101
  };
9080
9102
  this.form.setValue(formValue);
9081
9103
  }
9104
+ toEndOfDay(dateStr) {
9105
+ return `${new Date(dateStr).toLocaleDateString("en-CA", options)} 23:59:59`;
9106
+ }
9082
9107
  getFormValueFilter() {
9083
9108
  const value = this.form.value;
9084
9109
  // value.option is null
@@ -9131,7 +9156,7 @@ class AggregationDateComponent extends AggregationListComponent {
9131
9156
  {
9132
9157
  field: column,
9133
9158
  operator: "lte",
9134
- value: new Date(value.customRange.to).toLocaleDateString("en-CA", options)
9159
+ value: this.toEndOfDay(value.customRange.to)
9135
9160
  }
9136
9161
  ];
9137
9162
  }
@@ -9141,7 +9166,7 @@ class AggregationDateComponent extends AggregationListComponent {
9141
9166
  }
9142
9167
  else if (value.customRange.to) {
9143
9168
  filter.operator = "lte";
9144
- filter.value = new Date(value.customRange.to).toLocaleDateString("en-CA", options);
9169
+ filter.value = this.toEndOfDay(value.customRange.to);
9145
9170
  }
9146
9171
  else {
9147
9172
  throw new Error("filters.customRangeInvalid");
@@ -11857,11 +11882,16 @@ class DrawerAdvancedFiltersComponent extends DrawerComponent {
11857
11882
  text = "";
11858
11883
  constructor() {
11859
11884
  super();
11860
- this.getFirstPageQuery();
11885
+ effect(() => {
11886
+ getState(this.appStore);
11887
+ const query = this.appStore.getDefaultQuery();
11888
+ if (query?.name) {
11889
+ this.getFirstPageQuery(query?.name);
11890
+ }
11891
+ });
11861
11892
  }
11862
- async getFirstPageQuery() {
11863
- const query = this.appStore.getDefaultQuery() || { name: "_default" };
11864
- const response = await fetchQuery({ isFirstPage: true, name: query.name });
11893
+ async getFirstPageQuery(queryName) {
11894
+ const response = await fetchQuery({ isFirstPage: true, name: queryName });
11865
11895
  this.aggregations.set(response.aggregations);
11866
11896
  }
11867
11897
  onTabChange(tab) {