@sinequa/atomic 1.0.1 → 1.1.0

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
@@ -1,219 +1,219 @@
1
- <div align="center">
2
-
3
- # @sinequa/atomic
4
-
5
- ![npm](https://img.shields.io/npm/v/@sinequa/atomic.svg)
6
- ![license](https://img.shields.io/npm/l/@sinequa/atomic.svg)
7
- ![TypeScript](https://img.shields.io/badge/TypeScript-5.x-blue)
8
-
9
- **A comprehensive TypeScript library for building modern search applications with [Sinequa](https://www.sinequa.com/)**
10
-
11
- [Documentation](https://sinequa.github.io/sba-mint/atomic/intro) • [Changelog](./changelogs) • [API Reference](https://sinequa.github.io/sba-mint/atomic/api/app)
12
-
13
- </div>
14
-
15
- ---
16
-
17
- ## 📦 Installation
18
-
19
- ```bash
20
- npm install @sinequa/atomic
21
- ```
22
-
23
- ## 🚀 Quick Start
24
-
25
- ```typescript
26
- import {
27
- fetchQuery,
28
- fetchAggregation,
29
- isAuthenticated,
30
- login
31
- } from '@sinequa/atomic';
32
-
33
- // Check authentication status
34
- if (!isAuthenticated()) {
35
- await login({ username: 'user', password: 'pass' });
36
- }
37
-
38
- // Perform a search query
39
- const results = await fetchQuery({
40
- query: 'example search',
41
- pageSize: 10
42
- });
43
-
44
- // Fetch aggregation data
45
- const aggregations = await fetchAggregation({
46
- aggregation: 'category',
47
- query: 'example'
48
- });
49
- ```
50
-
51
- ## ✨ Key Features
52
-
53
- ### 🔐 Authentication & Security
54
-
55
- - **OAuth & SAML Support**: Seamless integration with enterprise authentication providers
56
- - **JWT Token Management**: Automatic token handling and refresh
57
- - **CSRF Protection**: Built-in security measures
58
- - **Credential-Based Authentication**: Direct username/password authentication
59
- - **User Session Management**: Complete login/logout flow with user impersonation controls
60
-
61
- ### 🌐 Web API Integration
62
-
63
- - **Type-Safe API Calls**: Strongly-typed interfaces for all Sinequa APIs
64
- - **Comprehensive Endpoints**: Support for search, aggregations, datasets, preview, and more
65
- - **Error Handling**: Robust error management with fallback mechanisms
66
- - **Response Processing**: Automatic parsing and validation of API responses
67
-
68
- ### 🛠️ Utilities & Helpers
69
-
70
- - **Metadata Processing**: Parse and extract metadata with value pairs
71
- - **Column Management**: Generate engine-specific column configurations
72
- - **Date Utilities**: Advanced date formatting and manipulation
73
- - **Query Parameters**: URL query string handling
74
- - **Logger**: Structured logging with multiple levels
75
- - **Notification System**: User notification management
76
-
77
- ### 📊 Data Management
78
-
79
- - **Aggregation Handling**: Visual selection tracking and data aggregation
80
- - **Filter Configuration**: Configurable included/excluded filters
81
- - **Type Definitions**: Complete TypeScript types for all data structures
82
- - **Password Management**: Expired and forgotten password flows
83
-
84
- ## 📚 Core Modules
85
-
86
- ### Authentication
87
-
88
- ```typescript
89
- import {
90
- login,
91
- logout,
92
- isAuthenticated,
93
- getToken,
94
- setToken,
95
- tryOAuthAuthentication,
96
- trySAMLAuthentication
97
- } from '@sinequa/atomic';
98
- ```
99
-
100
- ### Web APIs
101
-
102
- ```typescript
103
- import {
104
- fetchApp,
105
- fetchQuery,
106
- fetchAggregation,
107
- fetchDatasets,
108
- fetchPreview,
109
- fetchPrincipal,
110
- fetchSimilarDocuments,
111
- fetchSponsoredLinks,
112
- fetchSuggest,
113
- fetchUserSettings
114
- } from '@sinequa/atomic';
115
- ```
116
-
117
- ### Helpers
118
-
119
- ```typescript
120
- import {
121
- getMetadata,
122
- getMetadataWithValues,
123
- makeColumn,
124
- resolveToColumnName,
125
- escapeExpr,
126
- guid,
127
- isObject,
128
- isString
129
- } from '@sinequa/atomic';
130
- ```
131
-
132
- ### Utilities
133
-
134
- ```typescript
135
- import {
136
- bisect,
137
- formatDate,
138
- parseDate,
139
- logger,
140
- queryParamsToString,
141
- syslang
142
- } from '@sinequa/atomic';
143
- ```
144
-
145
- ## 🔄 Recent Updates (v0.0.125 - v0.0.129)
146
-
147
- ### 🎉 New Features
148
-
149
- - ✅ Credential-based authentication with automatic SSO bypass
150
- - ✅ Enhanced metadata parsing with comma-separated string support
151
- - ✅ Forgotten password and expired password handling
152
- - ✅ Visual selection tracking for aggregation items
153
- - ✅ Configurable filter bar with inclusion/exclusion options
154
-
155
- ### 🔒 Security Enhancements
156
-
157
- - 🛡️ Fixed user impersonation vulnerability during credential-based login
158
- - 🔐 JWT tokens now correctly reflect actual user identity
159
-
160
- ### 🐛 Bug Fixes & Improvements
161
-
162
- - ⚡ Enhanced error handling with fallback message fields
163
- - 📝 Improved type safety across all modules
164
- - 🧪 Added 560+ new test cases for better reliability
165
- - 🗂️ Reorganized test structure for better maintainability
166
-
167
- ### 📖 Documentation
168
-
169
- - 📚 Comprehensive JSDoc examples for all major functions
170
- - 📝 Enhanced inline code documentation
171
- - 🔗 API reference documentation
172
-
173
- [View Full Changelog](./changelogs/CHANGELOG_v0.0.124_to_v0.0.129.md)
174
-
175
- ## 🧪 Testing
176
-
177
- This package includes comprehensive test coverage with 560+ test cases:
178
-
179
- ```bash
180
- npm test
181
- ```
182
-
183
- Test coverage includes:
184
-
185
- - Authentication flows (OAuth, SAML, credentials)
186
- - API endpoint integration
187
- - Error handling scenarios
188
- - Metadata parsing and processing
189
- - Date utilities and formatters
190
-
191
- ## 📖 Documentation
192
-
193
- - **Getting Started**: [Introduction Guide](https://sinequa.github.io/sba-mint/atomic/intro)
194
- - **API Reference**: [Complete API Documentation](https://sinequa.github.io/sba-mint/atomic/api)
195
- - **Authentication**: [Auth Documentation](https://sinequa.github.io/sba-mint/atomic/authentication)
196
- - **Examples**: Check the `/docs` folder for detailed examples
197
-
198
- ## 🤝 Contributing
199
-
200
- We welcome contributions! Please ensure:
201
-
202
- - ✅ All tests pass
203
- - ✅ Code follows the existing style (Biome linting)
204
- - ✅ New features include tests and documentation
205
- - ✅ Commit messages follow conventional commits
206
-
207
- ## 📄 License
208
-
209
- This project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.
210
-
211
- ---
212
-
213
- <div align="center">
214
-
215
- **Built with ❤️ for the Sinequa Community**
216
-
217
- [Documentation](https://sinequa.github.io/sba-mint/atomic/intro) • [Report Bug](https://github.com/Product/sba-atomic-js/issues) • [Request Feature](https://github.com/Product/sba-atomic-js/issues)
218
-
219
- </div>
1
+ <div align="center">
2
+
3
+ <img src="https://img.shields.io/npm/v/@sinequa/atomic?style=for-the-badge&color=0ea5e9&label=@sinequa%2Fatomic" alt="npm version" />
4
+ <img src="https://img.shields.io/badge/TypeScript-5.x-3178c6?style=for-the-badge&logo=typescript&logoColor=white" alt="TypeScript" />
5
+ <img src="https://img.shields.io/badge/ESM-ready-f59e0b?style=for-the-badge" alt="ESM" />
6
+ <img src="https://img.shields.io/npm/l/@sinequa/atomic?style=for-the-badge&color=22c55e" alt="MIT License" />
7
+
8
+ <br /><br />
9
+
10
+ # `@sinequa/atomic`
11
+
12
+ **The TypeScript-first SDK for the Sinequa REST API.**
13
+ Authentication, search, aggregations, datasets, preview — everything typed, tree-shakable, zero runtime dependencies.
14
+
15
+ [Docs](https://sinequa.github.io/sba-mint/atomic/intro) · [API Reference](https://sinequa.github.io/sba-mint/atomic/api/app)
16
+
17
+ </div>
18
+
19
+ ---
20
+
21
+ ## Installation
22
+
23
+ ```bash
24
+ npm install @sinequa/atomic
25
+ ```
26
+
27
+ > Requires **Node ≥ 18** or any modern browser. Ships as ESM (`atomic.js`) and CJS (`atomic.umd.cjs`) with full `.d.ts` declarations.
28
+
29
+ ---
30
+
31
+ ## At a glance
32
+
33
+ ```typescript
34
+ import { login, isAuthenticated, fetchQuery, fetchAggregation } from '@sinequa/atomic';
35
+
36
+ if (!isAuthenticated()) {
37
+ await login({ username: 'alice', password: 's3cr3t' });
38
+ }
39
+
40
+ const results = await fetchQuery({ query: 'knowledge management', pageSize: 10 });
41
+ const facets = await fetchAggregation({ aggregation: 'company', query: 'knowledge management' });
42
+ ```
43
+
44
+ ---
45
+
46
+ ## Modules
47
+
48
+ ### Authentication
49
+
50
+ Full auth lifecycle — from first handshake to logout.
51
+
52
+ | Export | Description |
53
+ |---|---|
54
+ | `isAuthenticated()` | Returns `true` when a valid token is present |
55
+ | `login(credentials?)` | Login — handles OAuth, SAML and credential flows automatically |
56
+ | `logout()` | Clears session, returns the server's `redirectUrl` |
57
+ | `getToken()` / `setToken(token)` | Read/write the stored CSRF token |
58
+ | `getJWToken(credentials?)` | Fetches a JWT from the server, returns the CSRF token |
59
+ | `getCsrfToken()` | CSRF token for mutating requests |
60
+ | `deleteWebTokenCookie()` | Explicitly removes the web token cookie |
61
+
62
+ ```typescript
63
+ import { isAuthenticated, login, logout } from '@sinequa/atomic';
64
+
65
+ if (!isAuthenticated()) {
66
+ // SSO (OAuth/SAML) — provider resolved from server config
67
+ const ok = await login();
68
+
69
+ // — or — credential-based login, bypasses SSO
70
+ const ok = await login({ username: 'alice', password: 's3cr3t' });
71
+ }
72
+
73
+ const redirectUrl = await logout();
74
+ ```
75
+
76
+ ---
77
+
78
+ ### Web API — v1
79
+
80
+ Every Sinequa v1 endpoint has a typed wrapper.
81
+
82
+ ```typescript
83
+ import {
84
+ fetchApp,
85
+ fetchQuery,
86
+ fetchAggregation,
87
+ fetchDataset,
88
+ fetchPreview,
89
+ fetchPrincipal,
90
+ fetchSimilarDocuments,
91
+ fetchSponsoredLinks,
92
+ fetchSuggest,
93
+ fetchTextChunk,
94
+ fetchUserSettings,
95
+ fetchAudit,
96
+ fetchLabels,
97
+ fetchQueryExport,
98
+ fetchQueryIntent,
99
+ } from '@sinequa/atomic';
100
+ ```
101
+
102
+ ### Web API — v2
103
+
104
+ ```typescript
105
+ import {
106
+ fetchUserProfile,
107
+ fetchVersion,
108
+ fetchChangePassword,
109
+ fetchForgotPassword,
110
+ } from '@sinequa/atomic';
111
+ ```
112
+
113
+ ---
114
+
115
+ ### Helpers
116
+
117
+ Utilities for transforming Sinequa data structures.
118
+
119
+ ```typescript
120
+ import {
121
+ getMetadata,
122
+ getMetadataWithValues, // parses comma-separated metadata strings
123
+ makeColumn,
124
+ resolveToColumnName,
125
+ escapeExpr,
126
+ guid,
127
+ isObject,
128
+ } from '@sinequa/atomic';
129
+ ```
130
+
131
+ ---
132
+
133
+ ### Utilities
134
+
135
+ ```typescript
136
+ import {
137
+ bisect,
138
+ formatDate,
139
+ parseDate,
140
+ logger,
141
+ queryParamsToString,
142
+ toSQL,
143
+ syslang,
144
+ } from '@sinequa/atomic';
145
+ ```
146
+
147
+ ---
148
+
149
+ ## Types
150
+
151
+ The package re-exports every Sinequa domain type so you never need to cast:
152
+
153
+ ```typescript
154
+ import type {
155
+ CCApp, CCQuery, CCColumn, CCIndex,
156
+ Aggregation, AggregationItem, ListAggregation, TreeAggregation,
157
+ Filter, SimpleFilter, InFilter, BetweenFilter,
158
+ PreviewData,
159
+ Principal,
160
+ AuditEvent, AuditRecord,
161
+ TextChunk,
162
+ } from '@sinequa/atomic';
163
+ ```
164
+
165
+ ---
166
+
167
+ ## Configuration
168
+
169
+ Set a base URL before making any API call (required when the Sinequa server is not same-origin):
170
+
171
+ ```typescript
172
+ import { setConfig } from '@sinequa/atomic';
173
+
174
+ setConfig({ url: 'https://my-sinequa-server.example.com' });
175
+ ```
176
+
177
+ ---
178
+
179
+ ## Testing
180
+
181
+ ```bash
182
+ npm test # run vitest (560+ test cases)
183
+ npm test -- --ui # interactive UI
184
+ ```
185
+
186
+ Coverage spans authentication flows (OAuth, SAML, credentials), all API endpoints, error handling, metadata parsing, date utilities, and SQL helpers.
187
+
188
+ ---
189
+
190
+ ## Development
191
+
192
+ ```bash
193
+ npm run build # production build (vite + tsc)
194
+ npm run watch # rebuild on change
195
+ npm run dev:pack # build + pack locally
196
+ ```
197
+
198
+ ---
199
+
200
+ ## Contributing
201
+
202
+ 1. All tests must pass.
203
+ 2. Lint with [Biome](https://biomejs.dev/) — `npx @biomejs/biome check --write .`
204
+ 3. Follow [Conventional Commits](https://www.conventionalcommits.org/).
205
+ 4. New public API → add tests + JSDoc.
206
+
207
+ ---
208
+
209
+ ## License
210
+
211
+ MIT — see [LICENSE](./LICENSE).
212
+
213
+ ---
214
+
215
+ <div align="center">
216
+
217
+ Built for the [Sinequa](https://www.sinequa.com/) ecosystem · [Report an issue](https://github.com/Product/sba-atomic-js/issues)
218
+
219
+ </div>