@sinequa/atomic 2.0.0 → 2.0.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/README.md CHANGED
@@ -52,8 +52,10 @@ Full auth lifecycle — from first handshake to logout.
52
52
  | Export | Description |
53
53
  |---|---|
54
54
  | `isAuthenticated()` | Returns `true` when a valid token is present |
55
- | `login(credentials?)` | Login — handles OAuth, SAML and credential flows automatically |
55
+ | `login(credentials?)` | Login — switches on the resolved `authMode` (credentials / SSO / OAuth / SAML / bearer) |
56
56
  | `logout()` | Clears session, returns the server's `redirectUrl` |
57
+ | `clearSessionTokens()` | Drops the in-memory/stored session tokens without a server round-trip |
58
+ | `detectAuthMode(config, preLogin?)` | Pure resolution of the `AuthMode` from config + server pre-login (no I/O) |
57
59
  | `getToken()` / `setToken(token)` | Read/write the stored CSRF token |
58
60
  | `getJWToken(credentials?)` | Fetches a JWT from the server, returns the CSRF token |
59
61
  | `getCsrfToken()` | CSRF token for mutating requests |
@@ -63,7 +65,8 @@ Full auth lifecycle — from first handshake to logout.
63
65
  import { isAuthenticated, login, logout } from '@sinequa/atomic';
64
66
 
65
67
  if (!isAuthenticated()) {
66
- // SSO (OAuth/SAML) — provider resolved from server config
68
+ // Auto-resolve: reuse an existing session if any, otherwise try SSO and
69
+ // fall back to the credentials form. Provider resolved from server config.
67
70
  const ok = await login();
68
71
 
69
72
  // — or — credential-based login, bypasses SSO
@@ -73,6 +76,30 @@ if (!isAuthenticated()) {
73
76
  const redirectUrl = await logout();
74
77
  ```
75
78
 
79
+ #### Auth mode (`AuthMode`) — **2.0**
80
+
81
+ `globalConfig.authMode` is the **single source of truth** for the authentication method. It is a
82
+ typed discriminated union — no more juggling overlapping booleans:
83
+
84
+ ```typescript
85
+ import { AuthMode, setGlobalConfig } from '@sinequa/atomic';
86
+
87
+ setGlobalConfig({ authMode: AuthMode.credentials() }); // username/password form
88
+ setGlobalConfig({ authMode: AuthMode.sso() }); // browser/proxy-injected auth
89
+ setGlobalConfig({ authMode: AuthMode.oauth('my-provider') }); // redirect to an OAuth provider
90
+ setGlobalConfig({ authMode: AuthMode.saml('my-provider') }); // redirect to a SAML provider
91
+ setGlobalConfig({ authMode: AuthMode.bearer(token) }); // server-to-server bearer token
92
+ setGlobalConfig({ authMode: AuthMode.unknown() }); // try SSO, then fall back to credentials
93
+
94
+ // `login()` and `detectAuthMode()` branch on `authMode.kind`:
95
+ const kind = globalConfig.authMode.kind; // 'credentials' | 'sso' | 'oauth' | 'saml' | 'bearer' | 'unknown'
96
+ ```
97
+
98
+ > **Migrating from 1.x:** the booleans `useCredentials` / `useSSO` / `useSAML` are now
99
+ > **`@deprecated` read-only getters** derived from `authMode`. Reading them still works, and writing
100
+ > them through `setGlobalConfig({ useSSO: true })` is translated into the matching `authMode` — so
101
+ > existing code keeps working. Prefer `authMode.kind` (and the `AuthMode.*` constructors) in new code.
102
+
76
103
  ---
77
104
 
78
105
  ### Web API — v1
@@ -128,6 +155,29 @@ import {
128
155
  } from '@sinequa/atomic';
129
156
  ```
130
157
 
158
+ #### Filter builder
159
+
160
+ Build structured `query.filters` without hand-writing filter objects. Combinators ignore falsy
161
+ operands and collapse trivial cases (0 → `undefined`, 1 → the operand itself), so filters compose
162
+ cleanly from optional UI state:
163
+
164
+ ```typescript
165
+ import { filter, fetchQuery } from '@sinequa/atomic';
166
+
167
+ const filters = filter.and(
168
+ filter.gt('size', 1000),
169
+ filter.or(
170
+ filter.eq('treepath', '/HR/*'),
171
+ filter.in('authors', ['alice', 'bob']),
172
+ ),
173
+ onlyRecent && filter.between('modified', '2024-01-01', '2024-12-31'),
174
+ );
175
+
176
+ await fetchQuery({ name: '_query', text: 'report', filters });
177
+ ```
178
+
179
+ Leaf operators: `eq` · `neq` · `gt` · `gte` · `lt` · `lte` · `like` · `contains` · `regex` · `isNull` · `isNotNull` · `in` · `between`. Combinators: `and` · `or` · `not`.
180
+
131
181
  ---
132
182
 
133
183
  ### Utilities
@@ -154,7 +204,8 @@ The package re-exports every Sinequa domain type so you never need to cast:
154
204
  import type {
155
205
  CCApp, CCQuery, CCColumn, CCIndex,
156
206
  Aggregation, AggregationItem, ListAggregation, TreeAggregation,
157
- Filter, SimpleFilter, InFilter, BetweenFilter,
207
+ Filter, SimpleFilter, InFilter, BetweenFilter, ExprFilter, NullFilter, NotNullFilter,
208
+ AuthMode, AuthModeKind,
158
209
  PreviewData,
159
210
  Principal,
160
211
  AuditEvent, AuditRecord,
@@ -166,24 +217,35 @@ import type {
166
217
 
167
218
  ## Configuration
168
219
 
169
- Set a base URL before making any API call (required when the Sinequa server is not same-origin):
220
+ Set the backend URL before making any API call (required when the Sinequa server is not
221
+ same-origin). `setGlobalConfig` performs a shallow merge into `globalConfig`:
170
222
 
171
223
  ```typescript
172
- import { setConfig } from '@sinequa/atomic';
224
+ import { setGlobalConfig, globalConfig, AuthMode } from '@sinequa/atomic';
173
225
 
174
- setConfig({ url: 'https://my-sinequa-server.example.com' });
226
+ setGlobalConfig({
227
+ app: 'my-app',
228
+ backendUrl: 'https://my-sinequa-server.example.com',
229
+ authMode: AuthMode.unknown(), // optional — defaults to `unknown`
230
+ });
231
+
232
+ // read it back
233
+ console.log(globalConfig.backendUrl, globalConfig.authMode.kind);
175
234
  ```
176
235
 
236
+ > `appInitializerFn` is also exported as an alias of `initializeAppConfig()`, which resolves the
237
+ > `authMode` from the server pre-login response during app bootstrap.
238
+
177
239
  ---
178
240
 
179
241
  ## Testing
180
242
 
181
243
  ```bash
182
- npm test # run vitest (560+ test cases)
244
+ npm test # run vitest (274 test cases across 24 files)
183
245
  npm test -- --ui # interactive UI
184
246
  ```
185
247
 
186
- Coverage spans authentication flows (OAuth, SAML, credentials), all API endpoints, error handling, metadata parsing, date utilities, and SQL helpers.
248
+ Coverage spans authentication flows (`AuthMode` detection, OAuth, SAML, credentials), all API endpoints, error handling, the filter builder, metadata parsing, date utilities, and SQL helpers.
187
249
 
188
250
  ---
189
251