@sinequa/atomic 0.0.62 → 0.0.96

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.
Files changed (65) hide show
  1. package/dist/atomic.js +1074 -755
  2. package/dist/atomic.umd.cjs +1 -1
  3. package/dist/authentication/auth.d.ts +59 -0
  4. package/dist/authentication/auth.d.ts.map +1 -0
  5. package/dist/authentication/index.d.ts.map +1 -0
  6. package/dist/configurations/global.config.d.ts +18 -15
  7. package/dist/configurations/global.config.d.ts.map +1 -1
  8. package/dist/configurations/index.d.ts +1 -1
  9. package/dist/helpers/utils.d.ts +0 -17
  10. package/dist/helpers/utils.d.ts.map +1 -1
  11. package/dist/index.d.ts +1 -1
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/types/api-endpoints.d.ts +1 -1
  14. package/dist/types/api-endpoints.d.ts.map +1 -1
  15. package/dist/types/config/CCAppPreLogin.d.ts +7 -3
  16. package/dist/types/config/CCAppPreLogin.d.ts.map +1 -1
  17. package/dist/types/config/index.d.ts +2 -5
  18. package/dist/types/config/index.d.ts.map +1 -1
  19. package/dist/types/export/types.d.ts +22 -0
  20. package/dist/types/export/types.d.ts.map +1 -0
  21. package/dist/types/index.d.ts +1 -0
  22. package/dist/types/index.d.ts.map +1 -1
  23. package/dist/types/search/index.d.ts +2 -2
  24. package/dist/types/search/index.d.ts.map +1 -1
  25. package/dist/utils/bisect.d.ts.map +1 -0
  26. package/dist/utils/index.d.ts +4 -1
  27. package/dist/utils/index.d.ts.map +1 -1
  28. package/dist/utils/is-not-input-event.d.ts +2 -0
  29. package/dist/utils/is-not-input-event.d.ts.map +1 -0
  30. package/dist/utils/logger.d.ts +40 -0
  31. package/dist/utils/logger.d.ts.map +1 -0
  32. package/dist/utils/query-params.d.ts.map +1 -1
  33. package/dist/utils/utilities.d.ts +23 -0
  34. package/dist/utils/utilities.d.ts.map +1 -0
  35. package/dist/web-api/fetch-aggregation.d.ts.map +1 -1
  36. package/dist/web-api/fetch-app.d.ts.map +1 -1
  37. package/dist/web-api/fetch-audit.d.ts +3 -2
  38. package/dist/web-api/fetch-audit.d.ts.map +1 -1
  39. package/dist/web-api/fetch-dataset.d.ts +2 -2
  40. package/dist/web-api/fetch-dataset.d.ts.map +1 -1
  41. package/dist/web-api/fetch-labels.d.ts +1 -1
  42. package/dist/web-api/fetch-labels.d.ts.map +1 -1
  43. package/dist/web-api/fetch-query-export.d.ts +19 -0
  44. package/dist/web-api/fetch-query-export.d.ts.map +1 -0
  45. package/dist/web-api/fetch-query.d.ts.map +1 -1
  46. package/dist/web-api/fetch-similar-documents.d.ts +13 -0
  47. package/dist/web-api/fetch-similar-documents.d.ts.map +1 -0
  48. package/dist/web-api/fetch-suggest.d.ts.map +1 -1
  49. package/dist/web-api/helpers.d.ts +111 -1
  50. package/dist/web-api/helpers.d.ts.map +1 -1
  51. package/dist/web-api/index.d.ts +10 -8
  52. package/dist/web-api/index.d.ts.map +1 -1
  53. package/package.json +42 -41
  54. package/dist/auth/auth.d.ts +0 -39
  55. package/dist/auth/auth.d.ts.map +0 -1
  56. package/dist/auth/index.d.ts.map +0 -1
  57. package/dist/types/config/ExportDialogModel.d.ts +0 -13
  58. package/dist/types/config/ExportDialogModel.d.ts.map +0 -1
  59. package/dist/types/config/ExportOutputFormat.d.ts +0 -10
  60. package/dist/types/config/ExportOutputFormat.d.ts.map +0 -1
  61. package/dist/types/config/ExportSourceType.d.ts +0 -10
  62. package/dist/types/config/ExportSourceType.d.ts.map +0 -1
  63. package/dist/utils/array/bisect.d.ts.map +0 -1
  64. /package/dist/{auth → authentication}/index.d.ts +0 -0
  65. /package/dist/utils/{array/bisect.d.ts → bisect.d.ts} +0 -0
package/dist/atomic.js CHANGED
@@ -1,536 +1,987 @@
1
+ var T = Object.defineProperty;
2
+ var ee = (e, t, r) => t in e ? T(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
+ var G = (e, t, r) => ee(e, typeof t != "symbol" ? t + "" : t, r);
1
4
  let u = { apiPath: "api/v1", loginPath: "/login", backendUrl: window.location.origin };
2
- function L(e) {
5
+ function m(e) {
3
6
  u = { ...u, ...e };
4
7
  }
5
- function Q(e) {
6
- const t = D(), n = new Headers(e);
7
- n.append("Sinequa-Force-Camel-Case", "true"), n.append("accept", "application/json"), n.append("Sinequa-csrf-token", t);
8
- const { userOverride: r, userOverrideActive: o } = u;
9
- return r && o && (n.append("sinequa-override-user", r.username), n.append("sinequa-override-domain", r.domain)), n;
10
- }
11
- async function p(e) {
8
+ function je(e, t) {
12
9
  var n;
13
- if (e.status === 401)
14
- throw u.userOverrideActive ? (u.userOverrideActive = !1, new Error("Unauthorized... User override failed.")) : await ((n = e.body) == null ? void 0 : n.getReader().read().then(({ done: o, value: s }) => {
15
- if (o)
16
- return e;
17
- const i = JSON.parse(new TextDecoder().decode(s));
18
- return i.status = 401, i;
19
- }));
20
- if (e.status === 500 || e.status !== 200)
21
- throw e;
22
- const t = e.headers.get("sinequa-jwt-refresh");
23
- return t !== null && y(t), await e.json();
24
- }
25
- async function l(e, t, n) {
26
- const r = Q(n == null ? void 0 : n.headers), { app: o, backendUrl: s, apiPath: i } = u, a = {
27
- app: o,
28
- ...t,
29
- locale: t.locale || navigator.language,
30
- noUserOverride: !0,
31
- noAutoAuthentication: !0
32
- }, c = await fetch(
33
- `${s}/${i}/${e}`,
34
- {
35
- method: "POST",
36
- headers: r,
37
- body: JSON.stringify(a)
38
- }
39
- );
40
- return p(c);
10
+ return !(e != null && e.items) || ((n = e == null ? void 0 : e.items) == null ? void 0 : n.length) === 0 ? [] : e.items.reduce((o, s) => {
11
+ if (!s.value || s.value === "") return o;
12
+ const c = te(s, e.column);
13
+ return o.push({
14
+ operator: c.operator,
15
+ value: c.value,
16
+ display: s.display || c.display,
17
+ filters: c.filters,
18
+ disabled: s.count === 0,
19
+ hidden: s.count === 0 && e.isDistribution ? !t : !1
20
+ }), o;
21
+ }, []);
41
22
  }
42
- async function h(e, t, n) {
43
- const r = Q(n == null ? void 0 : n.headers), { backendUrl: o, apiPath: s } = u, i = t ? `?${new URLSearchParams(t)}` : void 0, a = await fetch(
44
- `${o}/${s}/${e}${i}`,
45
- {
46
- method: "GET",
47
- headers: r
48
- }
49
- );
50
- return p(a);
23
+ function te(e, t) {
24
+ const r = t, a = e.value.match(/.*\:\(?([><=\d\-\.AND ]+)\)?/);
25
+ if (a != null && a[1]) {
26
+ const o = (a == null ? void 0 : a[1].split(" AND ")).map((s) => {
27
+ const c = s.indexOf(">=") !== -1 ? "gte" : "lt";
28
+ let i = s.substring(s.indexOf(" ") + 1);
29
+ return { field: r, operator: c, value: i, display: e.display || e.value };
30
+ });
31
+ if (o.length === 2)
32
+ return { field: r, operator: "and", filters: o, value: e.value, display: o[0].display || o[0].value };
33
+ if (o.length === 1)
34
+ return { ...o[0], field: r };
35
+ throw new Error("Failed to parse distribution expression");
36
+ }
37
+ return { field: r, operator: "eq", value: e.value, display: e.display };
51
38
  }
52
- const A = 11;
53
- async function Ce(e, t, n) {
54
- var i;
55
- const o = await l("query", {
56
- query: e,
57
- $auditRecord: t,
58
- queryIntentData: n
59
- });
60
- o.aggregations.forEach((a) => {
61
- a.$hasMore = !1, !a.isDistribution && !a.isTree && a.items && (a.$hasMore = a.items.length === A), a.isTree && a.items && x(a);
62
- }), (i = o.records) == null || i.map((a) => Object.assign(a, { value: a.title, type: "default" }));
63
- const s = { ...o, nextPage: o.page < Math.ceil(o.rowCount / o.pageSize) ? o.page + 1 : void 0, previousPage: o.page > 1 ? o.page - 1 : void 0 };
64
- return Promise.resolve(s);
39
+ function Ve(e, t, r) {
40
+ return e.valuesAreExpressions ? t.display === r.display : t.value === r.value;
65
41
  }
66
- async function Re(e, t, n) {
67
- const { app: r = "" } = u, o = {
68
- methods: [],
69
- mode: t,
70
- propagateErrors: !0,
71
- $auditRecord: { auditEvents: [n] }
72
- };
73
- for (const a of e)
74
- o.methods.push({
75
- method: "query",
76
- app: r,
77
- query: a
78
- });
79
- const s = await l("multi", o);
80
- s.results.forEach((a) => {
81
- a.aggregations.forEach((c) => {
82
- c.$hasMore = !1, !c.isDistribution && !c.isTree && c.items && (c.$hasMore = c.items.length === A), c.isTree && x(c);
42
+ function Je(e, t) {
43
+ const r = [];
44
+ if (e.length > 0) {
45
+ const a = /* @__PURE__ */ new Map(), n = t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), o = new RegExp("\\b" + n, "i");
46
+ e.forEach((s) => {
47
+ if (s.display.length > 1) {
48
+ const c = o.exec(s.display);
49
+ X(r, a, "/", s.display, +(s.frequency || 0), 1, ((c == null ? void 0 : c.index) || 0) + t.length);
50
+ }
83
51
  });
84
- }), s.results.forEach((a) => {
85
- var c;
86
- return (c = a.records) == null ? void 0 : c.map((f) => Object.assign(f, { value: f.title, type: "default" }));
87
- });
88
- const i = s.results.map((a) => ({ ...a, nextPage: a.page < Math.ceil(a.rowCount / a.pageSize) ? a.page + 1 : void 0, previousPage: a.page > 1 ? a.page - 1 : void 0 }));
89
- return Promise.resolve(i);
90
- }
91
- function x(e, t = "", n = 0) {
92
- let r = [];
93
- return e.items && e.items.forEach((o) => {
94
- let s = t ? `${t}/${o.value}` : o.value, i = n + 1;
95
- r.push({ path: s, level: i }), o.$path = s, o.$level = i, o.hasChildren && (r = r.concat(x(o, s, i)));
96
- }), r;
97
- }
98
- async function be(e, t) {
99
- const n = `${window.location.origin}${window.location.pathname}`, r = { name: t == null ? void 0 : t.name, text: t == null ? void 0 : t.text };
100
- return l("preview", {
101
- action: "get",
102
- id: e,
103
- query: r,
104
- browserUrl: n
105
- });
52
+ }
53
+ return r;
54
+ }
55
+ function X(e, t, r, a, n, o, s) {
56
+ const c = a.indexOf("/", r.length), i = a.substring(0, c + 1);
57
+ let l = t.get(i);
58
+ if (!l) {
59
+ const h = i.replace(/^\/|\/$/g, "");
60
+ l = {
61
+ value: a.substring(r.length, c),
62
+ count: n,
63
+ items: [],
64
+ hasChildren: !1,
65
+ $level: o,
66
+ $opened: s >= i.length,
67
+ $path: h
68
+ }, t.set(i, l), e.push(l);
69
+ }
70
+ i.length < a.length && (l.hasChildren = !0, X(l.items, t, i, a, n, o + 1, s));
106
71
  }
107
- async function Le(e) {
108
- const t = new Headers();
109
- t.append("content-type", "text");
110
- const n = await fetch(
111
- e,
112
- {
113
- method: "GET",
114
- headers: t
72
+ function ze(e, t) {
73
+ return e.reduce((r, a) => (t(a) ? r.true.push(a) : r.false.push(a), r), { true: [], false: [] });
74
+ }
75
+ const re = /(([\+\-])?\(([^\)]+)\))|(([\+\-])?\[([^\]]+)\])|(([\+\-])?\"([^\"]+)\")|(([\+\-])?\/([^\/]+)\/)|(([\+\-])?(\S+))/g, ae = 2, j = 3, ne = 5, V = 6, oe = 8, J = 9, se = 11, z = 12, ce = 14, H = 15;
76
+ function U(e) {
77
+ if (!e) return [];
78
+ const t = [], r = e.matchAll(re);
79
+ for (let a of r)
80
+ a[j] ? t.push({ type: "group", value: a[j], op: a[ae] }) : a[V] ? t.push({ type: "adjacent", value: a[V], op: a[ne] }) : a[J] ? t.push({ type: "exact", value: a[J], op: a[oe] }) : a[z] ? t.push({ type: "regex", value: a[z], op: a[se] }) : a[H] && t.push({ type: "token", value: a[H], op: a[ce] });
81
+ return t;
82
+ }
83
+ function N(e) {
84
+ return e.map((t) => {
85
+ const r = t.op || "";
86
+ switch (t.type) {
87
+ case "group":
88
+ return `${r}(${t.value})`;
89
+ case "adjacent":
90
+ return `${r}[${t.value}]`;
91
+ case "exact":
92
+ return `${r}"${t.value}"`;
93
+ case "regex":
94
+ return `${r}/${t.value}/`;
95
+ case "token":
96
+ return `${r}${t.value}`;
115
97
  }
116
- );
117
- p(n);
98
+ }).join(" ");
118
99
  }
119
- async function xe() {
120
- const e = new URLSearchParams({
121
- action: "get",
122
- noAutoAuthentication: "true"
123
- });
124
- return h("principal", e);
100
+ function He(e, t, r) {
101
+ let a = U(e);
102
+ for (let n of t)
103
+ a.push({ type: "adjacent", value: n, op: r });
104
+ return N(a);
125
105
  }
126
- async function Pe() {
127
- const { app: e } = u, t = new URLSearchParams({ app: e || "" });
128
- return h("app", t);
106
+ function We(e, t) {
107
+ const r = U(t), a = r.findIndex((n) => n.value === e);
108
+ return a !== -1 ? (r.splice(a, 1), t = N(r)) : t;
129
109
  }
130
- async function V() {
131
- const { app: e } = u, t = new URLSearchParams({
132
- app: e || "",
133
- preLogin: "true"
134
- });
135
- return h("app", t);
110
+ function Xe(e) {
111
+ const t = U(e).filter((r) => r.type !== "adjacent");
112
+ return N(t);
136
113
  }
137
- function De() {
138
- let { backendUrl: e, app: t } = u;
139
- if (e || (e = window.location.origin), !t) {
140
- const n = window.location.pathname.match(/\/app(?:-debug)?\/([^\/#]+)/);
141
- n && (t = n[1]);
114
+ function Ye(e) {
115
+ return U(e).filter((t) => t.type === "adjacent").map((t) => t.value);
116
+ }
117
+ function Ke(e, t, r) {
118
+ const a = new Intl.RelativeTimeFormat(e, { numeric: "auto" }), { offset: n, unit: o, isFuture: s } = ie(t, r);
119
+ return a.format(n * (s ? 1 : -1), o);
120
+ }
121
+ function ie(e, t) {
122
+ const r = new Date(e), a = t ? new Date(t) : /* @__PURE__ */ new Date(), n = Math.abs(a.getTime() - r.getTime());
123
+ return {
124
+ offset: Math.floor(n / (1e3 * 60 * 60 * 24)),
125
+ unit: "day",
126
+ isFuture: r > a
127
+ };
128
+ }
129
+ function Ze(e) {
130
+ const t = e.target;
131
+ return t && t.nodeName !== "INPUT" && t.nodeName !== "TEXTAREA";
132
+ }
133
+ function Me(e) {
134
+ if (e === void 0) return;
135
+ const { q: t, f: r, p: a, s: n, t: o, ...s } = R(e), [c] = e.split("?");
136
+ return {
137
+ path: c,
138
+ text: t,
139
+ filters: r ? Y(r) : void 0,
140
+ page: a ? parseInt(a, 10) : void 0,
141
+ sort: n,
142
+ tab: o,
143
+ ...s
144
+ };
145
+ }
146
+ function Ee(e) {
147
+ if (e === void 0) return [];
148
+ const { f: t } = R(e);
149
+ return Y(t);
150
+ }
151
+ function Y(e) {
152
+ const t = decodeURIComponent(e);
153
+ try {
154
+ return JSON.parse(t ?? "[]");
155
+ } catch {
156
+ return console.error(`Error parsing filters from URI: ${e}`), [];
142
157
  }
143
- return L({
144
- ...u,
145
- backendUrl: e,
146
- app: t
147
- }), V().then((n) => {
148
- const { autoOAuthProvider: r, autoSAMLProvider: o } = u, s = !r && !n.autoOAuthProvider && !o && !n.autoSAMLProvider;
149
- L({
150
- ...u,
151
- autoOAuthProvider: r || n.autoOAuthProvider,
152
- autoSAMLProvider: o || n.autoSAMLProvider,
153
- useCredentialsOrSSO: s
154
- }), console.log("Application initialized", n);
155
- }).catch((n) => {
156
- throw console.error("Error initializing application", n), n;
157
- });
158
158
  }
159
- async function ye(e, t, n) {
160
- var d;
161
- const r = ((d = e.items) == null ? void 0 : d.length) || 0, o = 10, s = {
162
- query: { ...t, action: "aggregate", aggregations: { [e.name]: { skip: r, count: o } } },
163
- $auditRecord: { auditEvents: [n] }
164
- }, i = await l("query", s), a = await p(i), { aggregations: c } = a, f = c[0];
165
- return f.$hasMore = f.items.length > o, f.items = [...e.items, ...f.items], Promise.resolve(f);
159
+ function R(e) {
160
+ const t = e.split("?")[1];
161
+ if (t === void 0) return {};
162
+ const r = new URLSearchParams(t);
163
+ return Object.fromEntries(r);
164
+ }
165
+ function Te(e) {
166
+ const { q: t = "" } = R(e);
167
+ return t;
168
+ }
169
+ function et(e) {
170
+ const { id: t } = R(e);
171
+ return decodeURIComponent(t);
172
+ }
173
+ function tt(e) {
174
+ const { p: t = "0" } = R(e);
175
+ return parseInt(t, 10);
176
+ }
177
+ function rt(e) {
178
+ const { t } = R(e);
179
+ return t;
180
+ }
181
+ function at(e, t) {
182
+ if (!e)
183
+ return e;
184
+ let r = 0;
185
+ const a = e.length;
186
+ let n = 0;
187
+ if (e[n] === "[") {
188
+ for (; n < a && /[0-9]/.test(e[n]); )
189
+ n++;
190
+ e[n] === "]" && (r = n + 1);
191
+ }
192
+ const o = y(e, r, !1);
193
+ if (!o)
194
+ return e;
195
+ const s = t.charCodeAt(0), c = t.charCodeAt(1);
196
+ let i = o;
197
+ for (; i; )
198
+ if (s === i.lang1 && c === i.lang2) {
199
+ const h = y(e, i.end + 4, !0);
200
+ return e.substring(h.start, h.end);
201
+ } else
202
+ i = y(e, i.end + 4, !1);
203
+ const l = e.substring(o.start, o.end);
204
+ return l || e;
205
+ }
206
+ function y(e, t, r) {
207
+ for (let a = t, n = e.length - 3; a < n; a++)
208
+ if (e[a] === "[" && e[a + 3] === "]")
209
+ return {
210
+ start: t,
211
+ end: a,
212
+ lang1: e.charCodeAt(a + 1),
213
+ lang2: e.charCodeAt(a + 2)
214
+ };
215
+ if (r)
216
+ return {
217
+ start: t,
218
+ end: e.length,
219
+ lang1: -1,
220
+ lang2: -1
221
+ };
222
+ }
223
+ function nt(e, t) {
224
+ const { useLocale: r, useLocaleAsPrefix: a, indexFile: n, path: o, folder: s } = t, c = r ? `${e}/` : null, i = a ? `${e}.${n}` : n ?? "";
225
+ return [o, s, `${c || ""}${i}`].filter((l) => l !== void 0).join("/");
226
+ }
227
+ var K = /* @__PURE__ */ ((e) => (e[e.DEBUG = 0] = "DEBUG", e[e.INFO = 1] = "INFO", e[e.WARN = 2] = "WARN", e[e.ERROR = 3] = "ERROR", e[e.NONE = 4] = "NONE", e))(K || {});
228
+ let L = {
229
+ level: 1,
230
+ enableConsoleOutput: !0
231
+ };
232
+ function ot(e) {
233
+ L = { ...L, ...e };
234
+ }
235
+ function $(e, t, r) {
236
+ if (e < L.level) return;
237
+ const a = (/* @__PURE__ */ new Date()).toISOString(), o = `${`[${K[e]}][${a}]`} ${t}`;
238
+ if (L.enableConsoleOutput)
239
+ switch (e) {
240
+ case 0:
241
+ console.debug(o, r || "");
242
+ break;
243
+ case 1:
244
+ console.info(o, r || "");
245
+ break;
246
+ case 2:
247
+ console.warn(o, r || "");
248
+ break;
249
+ case 3:
250
+ console.error(o, r || "");
251
+ break;
252
+ }
253
+ }
254
+ function x(e, t) {
255
+ $(0, e, t);
256
+ }
257
+ function S(e, t) {
258
+ $(1, e, t);
166
259
  }
167
- function ve(e, t, n) {
168
- var s, i, a, c;
260
+ function C(e, t) {
261
+ $(2, e, t);
262
+ }
263
+ function f(e, t) {
264
+ $(3, e, t);
265
+ }
266
+ function st(e, t, r) {
267
+ var o, s, c, i;
169
268
  if (!e || !t) return;
170
- if (n) {
171
- const f = Object.keys(t.queries).find((C) => C === (n == null ? void 0 : n.toLowerCase()));
172
- let d;
173
- f && (d = t.queries[f]);
174
- const w = (i = ((s = d == null ? void 0 : d.columnsInfo) == null ? void 0 : s.columns) || []) == null ? void 0 : i.find((C) => {
175
- var U, O;
176
- return (O = (U = C.aliases) == null ? void 0 : U.split(",")) == null ? void 0 : O.includes(e);
269
+ if (r) {
270
+ const l = Object.keys(t.queries).find((I) => I === (r == null ? void 0 : r.toLowerCase()));
271
+ let h;
272
+ l && (h = t.queries[l]);
273
+ const v = (s = ((o = h == null ? void 0 : h.columnsInfo) == null ? void 0 : o.columns) || []) == null ? void 0 : s.find((I) => {
274
+ var q, Q;
275
+ return (Q = (q = I.aliases) == null ? void 0 : q.split(",")) == null ? void 0 : Q.includes(e);
177
276
  });
178
- if (w) return w.name;
277
+ if (v) return v.name;
179
278
  }
180
- const r = (c = (a = t.indexes) == null ? void 0 : a._) == null ? void 0 : c.columns, o = Object.entries(r).find((f) => {
181
- var d;
182
- return (d = f[1].aliases) == null ? void 0 : d.includes(e);
279
+ const a = (i = (c = t.indexes) == null ? void 0 : c._) == null ? void 0 : i.columns, n = Object.entries(a).find((l) => {
280
+ var h;
281
+ return (h = l[1].aliases) == null ? void 0 : h.includes(e);
183
282
  });
184
- if (o) return o[0];
283
+ if (n) return n[0];
185
284
  }
186
- function Ue(e, t) {
187
- const n = e[t];
188
- return n === void 0 ? [] : Array.isArray(n) ? n.map((r) => typeof r == "string" ? { display: r } : r) : [{ display: n }];
285
+ function ct(e, t) {
286
+ const r = e[t];
287
+ return r === void 0 ? [] : Array.isArray(r) ? r.map((a) => typeof a == "string" ? { display: a } : a) : [{ display: r }];
189
288
  }
190
- function S(e) {
289
+ function D(e) {
191
290
  return e !== null && typeof e == "object";
192
291
  }
193
- function z(e) {
194
- return S(e) && Object.prototype.toString.call(e) === "[object ArrayBuffer]";
292
+ function le(e) {
293
+ return D(e) && Object.prototype.toString.call(e) === "[object ArrayBuffer]";
195
294
  }
196
- function H(e) {
197
- return S(e) && Object.prototype.toString.call(e) === "[object Blob]";
295
+ function ue(e) {
296
+ return D(e) && Object.prototype.toString.call(e) === "[object Blob]";
198
297
  }
199
- function J(e) {
298
+ function de(e) {
200
299
  return typeof e == "string";
201
300
  }
202
- function Oe(e) {
203
- return (S(e) || Array.isArray(e)) && !z(e) && !H(e) && !J(e);
301
+ function it(e) {
302
+ return (D(e) || Array.isArray(e)) && !le(e) && !ue(e) && !de(e);
204
303
  }
205
- function q(e = !0) {
304
+ function he(e = !0) {
206
305
  let t = Date.now();
207
- return (e ? "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx" : "xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx").replace(/[xy]/g, (r) => {
208
- const o = (t + Math.random() * 16) % 16 | 0;
209
- return t = Math.floor(t / 16), (r === "x" ? o : o & 3 | 8).toString(16);
306
+ return (e ? "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx" : "xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx").replace(/[xy]/g, (a) => {
307
+ const n = (t + Math.random() * 16) % 16 | 0;
308
+ return t = Math.floor(t / 16), (a === "x" ? n : n & 3 | 8).toString(16);
210
309
  });
211
310
  }
212
- function $e(e) {
311
+ function lt(e) {
213
312
  if (!e)
214
313
  return "``";
215
314
  if (e = String(e), e.search(/[\\`]/) === -1)
216
315
  return "`" + e + "`";
217
316
  const t = ["`"];
218
- for (let n = 0, r = e.length; n < r; n++) {
219
- const o = e[n];
220
- (o === "\\" || o === "`") && t.push("\\"), t.push(o);
317
+ for (let r = 0, a = e.length; r < a; r++) {
318
+ const n = e[r];
319
+ (n === "\\" || n === "`") && t.push("\\"), t.push(n);
221
320
  }
222
321
  return t.push("`"), t.join("");
223
322
  }
224
- function Me(e) {
225
- return crypto.subtle.digest("SHA-512", new TextEncoder().encode(e)).then((t) => Array.prototype.map.call(new Uint8Array(t), (n) => ("00" + n.toString(16)).slice(-2)).join(""));
323
+ function ut(e) {
324
+ return crypto.subtle.digest("SHA-512", new TextEncoder().encode(e)).then((t) => Array.prototype.map.call(new Uint8Array(t), (r) => ("00" + r.toString(16)).slice(-2)).join(""));
325
+ }
326
+ var k = /* @__PURE__ */ ((e) => (e.None = "None", e.Search_FirstPage = "Search_FirstPage", e.Search_Text = "Search_Text", e.Search_Refine = "Search_Refine", e.Search_Select_Item = "Search_Select_Item", e.Search_Select_Custom = "Search_Select_Custom", e.Search_Select_Concept = "Search_Select_Concept", e.Search_Select_Correction = "Search_Select_Correction", e.Search_GotoPage = "Search_GotoPage", e.Search_GotoTab = "Search_GotoTab", e.Search_DisplayResult = "Search_DisplayResult", e.Search_RemoveResult = "Search_RemoveResult", e.Search_RemoveAdvanced = "Search_RemoveAdvanced", e.Search_SavedQuery = "Search_SavedQuery", e.Search_WebService = "Search_WebService", e.Search_DidYouMean_Original = "Search_DidYouMean_Original", e.Search_DidYouMean_Correction = "Search_DidYouMean_Correction", e.Search_ExportCSV = "Search_ExportCSV", e.Search_SavedQuery_ExportCSV = "Search_SavedQuery_ExportCSV", e.Search_Selection_ExportCSV = "Search_Selection_ExportCSV", e.Search_AlertQuery = "Search_AlertQuery", e.Search_Select_AnalyticsItem = "Search_Select_AnalyticsItem", e.Search_Sort = "Search_Sort", e.Search_Exit_Logout = "Search_Exit_Logout", e.Search_Timeline_Usage = "Search_Timeline_Usage", e.Search_AutoComplete = "Search_Autocomplete", e.Search_Login_Success = "Login_Success_Form", e.Search_QueryIntent_Detected = "Search_QueryIntent_Detected", e.SavedQuery_Add = "SavedQuery_Add", e.SavedQuery_Delete = "SavedQuery_Delete", e.SavedQuery_DeleteAll = "SavedQuery_DeleteAll", e.SavedQuery_Rename = "SavedQuery_Rename", e.Alert_Edit = "Alert_Edit", e.Alert_Delete = "Alert_Delete", e.Alert_DeleteAll = "Alert_DeleteAll", e.Link_Display = "Link_Display", e.Link_Click = "Link_Click", e.Basket_Add = "Basket_Add", e.Basket_Delete = "Basket_Delete", e.Basket_DeleteAll = "Basket_DeleteAll", e.Basket_Rename = "Basket_Rename", e.Basket_AddDoc = "Basket_AddDoc", e.Basket_RemoveDoc = "Basket_RemoveDoc", e.Basket_Open = "Basket_Open", e.Basket_ExportCSV = "Basket_ExportCSV", e.Label_Add = "Label_Add", e.Label_Delete = "Label_Delete", e.Label_Rename = "Label_Rename", e.Label_Open = "Label_Open", e.Label_AddDoc = "Label_AddDoc", e.Label_RemoveDoc = "Label_RemoveDoc", e.Label_ExportCSV = "Label_ExportCSV", e.Label_Menu_ExportCSV = "Label_Menu_ExportCSV", e.Rating_Set = "Rating_Set", e.Rating_Delete = "Rating_Delete", e.Doc_Preview = "Doc_Preview", e.Doc_CacheHtml = "Doc_CacheHtml", e.Doc_CachePdf = "Doc_CachePdf", e.Doc_CacheOriginal = "Doc_CacheOriginal", e.Doc_Url1 = "Doc_Url1", e.Doc_Url2 = "Doc_Url2", e.Preview_Close = "Preview_Close", e.Click_ResultLink = "Click_ResultLink", e.Click_ResultLink1 = "Click_ResultLink1", e.Click_ResultLink2 = "Click_ResultLink2", e.Click_ResultLink3 = "Click_ResultLink3", e.Click_ResultLink4 = "Click_ResultLink4", e.Click_ResultLink5 = "Click_ResultLink5", e.Click_ResultLink6 = "Click_ResultLink6", e.Click_ResultLink7 = "Click_ResultLink7", e.Click_ResultLink8 = "Click_ResultLink8", e.Click_ResultLink9 = "Click_ResultLink9", e.Click_ResultLink10 = "Click_ResultLink10", e.Click_PreviewLink1 = "Click_PreviewLink1", e.Click_PreviewLink2 = "Click_PreviewLink2", e.Click_PreviewLink3 = "Click_PreviewLink3", e.Click_PreviewLink4 = "Click_PreviewLink4", e.Click_PreviewLink5 = "Click_PreviewLink5", e.Click_PreviewLink6 = "Click_PreviewLink6", e.Click_PreviewLink7 = "Click_PreviewLink7", e.Click_PreviewLink8 = "Click_PreviewLink8", e.Click_PreviewLink9 = "Click_PreviewLink9", e.Click_PreviewLink10 = "Click_PreviewLink10", e.RFM_ClickSet = "RFM_ClickSet", e.RFM_ClickReset = "RFM_ClickReset", e.RFM_Like = "RFM_Like", e.RFM_LikeReset = "RFM_LikeReset", e.RFM_Dislike = "RFM_Dislike", e.RFM_Important = "RFM_Important", e.RFM_ImportantReset = "RFM_ImportantReset", e.RFM_Ban = "RFM_Ban", e.Navigation_Exit = "Navigation_Exit", e.Navigation_Return = "Navigation_Return", e.Navigation_Route = "Navigation_Route", e.Answer_Display = "Answer_Display", e.Answer_Click = "Answer_Click", e.Answer_Result = "Answer_Result", e.Answer_Liked = "Answer_Liked", e.Answer_Disliked = "Answer_Disliked", e.Answer_Liked_Cancelled = "Answer_Liked_Cancelled", e.Answer_Disliked_Cancelled = "Answer_Disliked_Cancelled", e.TopPassages_Display = "TopPassages_Display", e.TopPassages_Click = "TopPassages_Click", e.UserSettings_Reset = "UserSettings_Reset", e))(k || {}), fe = /* @__PURE__ */ ((e) => (e[e.none = 0] = "none", e[e.bool = 1] = "bool", e[e.date = 2] = "date", e[e.dateTime = 3] = "dateTime", e[e.time = 4] = "time", e[e.unsigned = 5] = "unsigned", e[e.integer = 6] = "integer", e[e.float = 7] = "float", e[e.double = 8] = "double", e[e.dates = 9] = "dates", e[e.dateTimes = 10] = "dateTimes", e[e.times = 11] = "times", e[e.varchar = 12] = "varchar", e[e.binary = 13] = "binary", e[e.string = 14] = "string", e[e.csv = 15] = "csv", e))(fe || {}), _e = /* @__PURE__ */ ((e) => (e[e.none = 0] = "none", e[e.a = 2053] = "a", e[e.c = 4] = "c", e[e.d = 8] = "d", e[e.e = 2068] = "e", e[e.i = 256] = "i", e[e.l = 2052] = "l", e[e.n = 8192] = "n", e[e.t = 524292] = "t", e[e.x = 8388608] = "x", e[e.z = 33554432] = "z", e[e.f_ordinal = 8192] = "f_ordinal", e[e.f_multidates = 8192] = "f_multidates", e[e.f_varchar = 33554432] = "f_varchar", e[e.f_binary = 33562624] = "f_binary", e[e.f_string = 33562888] = "f_string", e[e.f_csv = 42477853] = "f_csv", e[e.f_overridable = 33554696] = "f_overridable", e))(_e || {});
327
+ const dt = "1.0";
328
+ var Se = /* @__PURE__ */ ((e) => (e[e.Original = 0] = "Original", e[e.Corrected = 1] = "Corrected", e))(Se || {}), me = /* @__PURE__ */ ((e) => (e[e.none = 0] = "none", e[e.positiveRate = 1] = "positiveRate", e[e.mainlyPosRate = 2] = "mainlyPosRate", e[e.unrate = 4] = "unrate", e[e.mainlyNegRate = 8] = "mainlyNegRate", e[e.negativeRate = 16] = "negativeRate", e[e.all = 31] = "all", e[e.positiveOnly = 7] = "positiveOnly", e[e.negativeOnly = 28] = "negativeOnly", e[e.personalAll = 21] = "personalAll", e[e.personalPosOnly = 5] = "personalPosOnly", e[e.personalNegOnly = 20] = "personalNegOnly", e))(me || {});
329
+ class w extends Error {
330
+ constructor(r, a) {
331
+ super(r);
332
+ G(this, "status");
333
+ this.name = "ApiError", this.status = a;
334
+ }
335
+ }
336
+ class Z extends w {
337
+ constructor(t = "Unauthorized access") {
338
+ super(t, 401), this.name = "UnauthorizedError";
339
+ }
340
+ }
341
+ class we extends w {
342
+ constructor(t = "Server error") {
343
+ super(t, 500), this.name = "ServerError";
344
+ }
345
+ }
346
+ class ke extends w {
347
+ constructor(t = "Request timed out") {
348
+ super(t, 408), this.name = "TimeoutError";
349
+ }
350
+ }
351
+ function ht(e) {
352
+ const t = new AbortController(), { signal: r } = t;
353
+ return e && setTimeout(() => {
354
+ r.aborted || t.abort(new ke(`Request timed out after ${e}ms`));
355
+ }, e), { controller: t, signal: r };
356
+ }
357
+ async function ft(e, t = 0, r = 1e3) {
358
+ let a;
359
+ for (let n = 0; n <= t; n++)
360
+ try {
361
+ return await e();
362
+ } catch (o) {
363
+ if (a = o, o instanceof w && o.status >= 400 && o.status < 500 && o.status !== 429 || o instanceof DOMException && o.name === "AbortError")
364
+ throw o;
365
+ n < t && (C(`Retrying request (${n + 1}/${t})`, { error: o }), await new Promise((s) => setTimeout(s, r)));
366
+ }
367
+ throw a;
226
368
  }
227
- function Fe(e, t, n = !0, r = !0) {
228
- if (!e)
229
- return [];
230
- if (!t)
231
- return [e];
232
- let o;
233
- if (typeof t == "string")
234
- o = e.split(t), n && (o = o.map((s) => s.trim()));
235
- else {
236
- let s = t.map((i) => X(i)).join("|");
237
- n && (s = "(?:^\\s*)|(?:\\s*(?:" + s + ")\\s*)|(?:\\s*$)"), o = e.split(new RegExp(s));
238
- }
239
- return r && (o = o.filter((s) => !s)), o;
240
- }
241
- function X(e) {
242
- const t = /[-\/\\^$*+?.()|[\]{}]/g;
243
- return e ? e.replace(t, "\\$&") : "";
244
- }
245
- var _ = /* @__PURE__ */ ((e) => (e.None = "None", e.Search_FirstPage = "Search_FirstPage", e.Search_Text = "Search_Text", e.Search_Refine = "Search_Refine", e.Search_Select_Item = "Search_Select_Item", e.Search_Select_Custom = "Search_Select_Custom", e.Search_Select_Concept = "Search_Select_Concept", e.Search_Select_Correction = "Search_Select_Correction", e.Search_GotoPage = "Search_GotoPage", e.Search_GotoTab = "Search_GotoTab", e.Search_DisplayResult = "Search_DisplayResult", e.Search_RemoveResult = "Search_RemoveResult", e.Search_RemoveAdvanced = "Search_RemoveAdvanced", e.Search_SavedQuery = "Search_SavedQuery", e.Search_WebService = "Search_WebService", e.Search_DidYouMean_Original = "Search_DidYouMean_Original", e.Search_DidYouMean_Correction = "Search_DidYouMean_Correction", e.Search_ExportCSV = "Search_ExportCSV", e.Search_SavedQuery_ExportCSV = "Search_SavedQuery_ExportCSV", e.Search_Selection_ExportCSV = "Search_Selection_ExportCSV", e.Search_AlertQuery = "Search_AlertQuery", e.Search_Select_AnalyticsItem = "Search_Select_AnalyticsItem", e.Search_Sort = "Search_Sort", e.Search_Exit_Logout = "Search_Exit_Logout", e.Search_Timeline_Usage = "Search_Timeline_Usage", e.Search_AutoComplete = "Search_Autocomplete", e.Search_Login_Success = "Login_Success_Form", e.Search_QueryIntent_Detected = "Search_QueryIntent_Detected", e.SavedQuery_Add = "SavedQuery_Add", e.SavedQuery_Delete = "SavedQuery_Delete", e.SavedQuery_DeleteAll = "SavedQuery_DeleteAll", e.SavedQuery_Rename = "SavedQuery_Rename", e.Alert_Edit = "Alert_Edit", e.Alert_Delete = "Alert_Delete", e.Alert_DeleteAll = "Alert_DeleteAll", e.Link_Display = "Link_Display", e.Link_Click = "Link_Click", e.Basket_Add = "Basket_Add", e.Basket_Delete = "Basket_Delete", e.Basket_DeleteAll = "Basket_DeleteAll", e.Basket_Rename = "Basket_Rename", e.Basket_AddDoc = "Basket_AddDoc", e.Basket_RemoveDoc = "Basket_RemoveDoc", e.Basket_Open = "Basket_Open", e.Basket_ExportCSV = "Basket_ExportCSV", e.Label_Add = "Label_Add", e.Label_Delete = "Label_Delete", e.Label_Rename = "Label_Rename", e.Label_Open = "Label_Open", e.Label_AddDoc = "Label_AddDoc", e.Label_RemoveDoc = "Label_RemoveDoc", e.Label_ExportCSV = "Label_ExportCSV", e.Label_Menu_ExportCSV = "Label_Menu_ExportCSV", e.Rating_Set = "Rating_Set", e.Rating_Delete = "Rating_Delete", e.Doc_Preview = "Doc_Preview", e.Doc_CacheHtml = "Doc_CacheHtml", e.Doc_CachePdf = "Doc_CachePdf", e.Doc_CacheOriginal = "Doc_CacheOriginal", e.Doc_Url1 = "Doc_Url1", e.Doc_Url2 = "Doc_Url2", e.Preview_Close = "Preview_Close", e.Click_ResultLink = "Click_ResultLink", e.Click_ResultLink1 = "Click_ResultLink1", e.Click_ResultLink2 = "Click_ResultLink2", e.Click_ResultLink3 = "Click_ResultLink3", e.Click_ResultLink4 = "Click_ResultLink4", e.Click_ResultLink5 = "Click_ResultLink5", e.Click_ResultLink6 = "Click_ResultLink6", e.Click_ResultLink7 = "Click_ResultLink7", e.Click_ResultLink8 = "Click_ResultLink8", e.Click_ResultLink9 = "Click_ResultLink9", e.Click_ResultLink10 = "Click_ResultLink10", e.Click_PreviewLink1 = "Click_PreviewLink1", e.Click_PreviewLink2 = "Click_PreviewLink2", e.Click_PreviewLink3 = "Click_PreviewLink3", e.Click_PreviewLink4 = "Click_PreviewLink4", e.Click_PreviewLink5 = "Click_PreviewLink5", e.Click_PreviewLink6 = "Click_PreviewLink6", e.Click_PreviewLink7 = "Click_PreviewLink7", e.Click_PreviewLink8 = "Click_PreviewLink8", e.Click_PreviewLink9 = "Click_PreviewLink9", e.Click_PreviewLink10 = "Click_PreviewLink10", e.RFM_ClickSet = "RFM_ClickSet", e.RFM_ClickReset = "RFM_ClickReset", e.RFM_Like = "RFM_Like", e.RFM_LikeReset = "RFM_LikeReset", e.RFM_Dislike = "RFM_Dislike", e.RFM_Important = "RFM_Important", e.RFM_ImportantReset = "RFM_ImportantReset", e.RFM_Ban = "RFM_Ban", e.Navigation_Exit = "Navigation_Exit", e.Navigation_Return = "Navigation_Return", e.Navigation_Route = "Navigation_Route", e.Answer_Display = "Answer_Display", e.Answer_Click = "Answer_Click", e.Answer_Result = "Answer_Result", e.Answer_Liked = "Answer_Liked", e.Answer_Disliked = "Answer_Disliked", e.Answer_Liked_Cancelled = "Answer_Liked_Cancelled", e.Answer_Disliked_Cancelled = "Answer_Disliked_Cancelled", e.TopPassages_Display = "TopPassages_Display", e.TopPassages_Click = "TopPassages_Click", e.UserSettings_Reset = "UserSettings_Reset", e))(_ || {});
246
- const Ie = "1.0";
247
- let R, N;
248
369
  function P(e) {
249
- let t = W(e.$auditRecord);
250
- t && (Y(t), K(t)), e.$auditRecord = t;
370
+ const t = O(), r = new Headers(e);
371
+ r.append("Sinequa-Force-Camel-Case", "true"), r.append("accept", "application/json"), t && r.append("Sinequa-csrf-token", t);
372
+ const { userOverride: a, userOverrideActive: n } = u;
373
+ return a && n && (r.append("sinequa-override-user", a.username), r.append("sinequa-override-domain", a.domain)), r;
374
+ }
375
+ async function g(e, t = "json") {
376
+ const r = e.headers.get("sinequa-jwt-refresh");
377
+ if (r !== null && F(r), e.status === 200)
378
+ switch (t) {
379
+ case "arraybuffer":
380
+ return await e.arrayBuffer();
381
+ case "blob":
382
+ return await e.blob();
383
+ case "text":
384
+ return await e.text();
385
+ case "json":
386
+ default:
387
+ return await e.json();
388
+ }
389
+ if (e.status === 401) {
390
+ if (u.userOverrideActive)
391
+ throw u.userOverrideActive = !1, C("Unauthorized access attempt with user override", { endpoint: e.url }), new Z("Unauthorized... User override failed.");
392
+ await W(e, 401);
393
+ }
394
+ throw e.status === 500 && (f("Server error occurred", { endpoint: e.url }), await W(e, 500)), C(`Unexpected response status: ${e.status}`, { endpoint: e.url }), new w(`Request failed with status ${e.status}`, e.status);
395
+ }
396
+ async function W(e, t) {
397
+ var r;
398
+ try {
399
+ const { done: a, value: n } = await ((r = e.body) == null ? void 0 : r.getReader().read()) || { done: !0, value: void 0 };
400
+ if (a || !n)
401
+ throw new w(`Request failed with status ${t}`, t);
402
+ const o = JSON.parse(new TextDecoder().decode(n));
403
+ throw o.status = t, o;
404
+ } catch (a) {
405
+ throw a instanceof w ? a : t === 401 ? new Z("Failed to parse error response") : t === 500 ? new we("Failed to parse error response") : new w(`Request failed with status ${t}`, t);
406
+ }
407
+ }
408
+ async function d(e, t, r) {
409
+ const a = P(r == null ? void 0 : r.headers), { app: n, backendUrl: o, apiPath: s } = u, c = {
410
+ app: n,
411
+ ...t,
412
+ locale: t.locale || navigator.language,
413
+ noUserOverride: !0,
414
+ noAutoAuthentication: !0
415
+ }, i = `${o}/${s}/${e}`;
416
+ x(`Making POST request to: ${i}`);
417
+ try {
418
+ const l = await fetch(
419
+ i,
420
+ {
421
+ method: "POST",
422
+ headers: a,
423
+ credentials: "include",
424
+ body: JSON.stringify(c)
425
+ }
426
+ );
427
+ return g(l, r == null ? void 0 : r.responseType);
428
+ } catch (l) {
429
+ throw f("Error making POST request:", l), l;
430
+ }
431
+ }
432
+ async function b(e, t, r) {
433
+ const a = P(r == null ? void 0 : r.headers), { backendUrl: n, apiPath: o } = u, s = t ? `?${new URLSearchParams(t)}` : "", c = `${n}/${o}/${e}${s}`;
434
+ x(`Making GET request to: ${c}`);
435
+ try {
436
+ const i = await fetch(
437
+ c,
438
+ {
439
+ method: "GET",
440
+ credentials: "include",
441
+ headers: a
442
+ }
443
+ );
444
+ return g(i, r == null ? void 0 : r.responseType);
445
+ } catch (i) {
446
+ throw f("Error making GET request:", i), i;
447
+ }
448
+ }
449
+ async function _t(e, t, r) {
450
+ const a = P(r == null ? void 0 : r.headers), { app: n, backendUrl: o, apiPath: s } = u, c = {
451
+ app: n,
452
+ ...t,
453
+ locale: t.locale || navigator.language,
454
+ noUserOverride: !0,
455
+ noAutoAuthentication: !0
456
+ }, i = `${o}/${s}/${e}`;
457
+ x(`Making PUT request to: ${i}`);
458
+ try {
459
+ const l = await fetch(
460
+ i,
461
+ {
462
+ method: "PUT",
463
+ headers: a,
464
+ credentials: "include",
465
+ body: JSON.stringify(c)
466
+ }
467
+ );
468
+ return g(l, r == null ? void 0 : r.responseType);
469
+ } catch (l) {
470
+ throw f("Error making PUT request:", l), l;
471
+ }
251
472
  }
252
- function W(e) {
473
+ async function St(e, t, r) {
474
+ const a = P(r == null ? void 0 : r.headers), { backendUrl: n, apiPath: o } = u, s = t ? `?${new URLSearchParams(t)}` : "", c = `${n}/${o}/${e}${s}`;
475
+ x(`Making DELETE request to: ${c}`);
476
+ try {
477
+ const i = await fetch(
478
+ c,
479
+ {
480
+ method: "DELETE",
481
+ credentials: "include",
482
+ headers: a
483
+ }
484
+ );
485
+ return g(i, r == null ? void 0 : r.responseType);
486
+ } catch (i) {
487
+ throw f("Error making DELETE request:", i), i;
488
+ }
489
+ }
490
+ async function mt(e, t, r) {
491
+ const a = P(r == null ? void 0 : r.headers), { app: n, backendUrl: o, apiPath: s } = u, c = {
492
+ app: n,
493
+ ...t,
494
+ locale: t.locale || navigator.language,
495
+ noUserOverride: !0,
496
+ noAutoAuthentication: !0
497
+ }, i = `${o}/${s}/${e}`;
498
+ x(`Making PATCH request to: ${i}`);
499
+ try {
500
+ const l = await fetch(
501
+ i,
502
+ {
503
+ method: "PATCH",
504
+ headers: a,
505
+ credentials: "include",
506
+ body: JSON.stringify(c)
507
+ }
508
+ );
509
+ return g(l, r == null ? void 0 : r.responseType);
510
+ } catch (l) {
511
+ throw f("Error making PATCH request:", l), l;
512
+ }
513
+ }
514
+ let A, M;
515
+ function p(e, t = !0) {
516
+ let r = ge(e.$auditRecord);
517
+ r && (be(r), t && Ce(r)), e.$auditRecord = r;
518
+ }
519
+ function ge(e) {
253
520
  if (!e)
254
521
  return;
255
522
  let t;
256
523
  if (Array.isArray(e))
257
524
  t = e;
258
- else if (S(e)) {
259
- const n = e;
260
- if (n.auditEvents || n.mlAuditEvents)
261
- return n;
525
+ else if (D(e)) {
526
+ const r = e;
527
+ if (r.auditEvents || r.mlAuditEvents)
528
+ return r;
262
529
  t = [e];
263
530
  }
264
531
  return { auditEvents: t };
265
532
  }
266
- function Y(e) {
267
- var n;
268
- const t = Z();
269
- return (n = e.auditEvents) == null || n.forEach((r) => {
270
- r.detail || (r.detail = {}), r.detail.sessionid = t;
533
+ function be(e) {
534
+ var r;
535
+ const t = Re();
536
+ return (r = e.auditEvents) == null || r.forEach((a) => {
537
+ a.detail || (a.detail = {}), a.detail.sessionid = t;
271
538
  }), e;
272
539
  }
273
- function K(e) {
274
- var n;
540
+ function Ce(e) {
541
+ var r;
275
542
  const t = decodeURIComponent(window.location.href);
276
- return (n = e == null ? void 0 : e.auditEvents) == null || n.forEach((r) => {
277
- r.detail || (r.detail = {}), r.detail.url = t;
543
+ return (r = e == null ? void 0 : e.auditEvents) == null || r.forEach((a) => {
544
+ a.detail || (a.detail = {}), a.detail.url = t;
278
545
  }), e;
279
546
  }
280
- function Z() {
281
- return (!R || E()) && (R = q()), N = /* @__PURE__ */ new Date(), R;
547
+ function Re() {
548
+ return (!A || xe()) && (A = he()), M = /* @__PURE__ */ new Date(), A;
282
549
  }
283
- function E() {
284
- return (/* @__PURE__ */ new Date()).getTime() - N.getTime() > 10 * 60 * 1e3;
550
+ function xe() {
551
+ return (/* @__PURE__ */ new Date()).getTime() - M.getTime() > 10 * 60 * 1e3;
285
552
  }
286
- async function T(e) {
287
- const t = {
288
- event: _.None,
553
+ async function ve(e, t = !0) {
554
+ const r = {
555
+ event: k.None,
289
556
  $auditRecord: e
290
557
  };
291
- return P(t), l("audit.notify", t);
558
+ return p(r, t), d("audit.notify", r);
559
+ }
560
+ const wt = { notify: ve };
561
+ async function kt(e, t, r) {
562
+ var h;
563
+ const a = ((h = e.items) == null ? void 0 : h.length) || 0, n = 10, o = {
564
+ query: { ...t, action: "aggregate", aggregations: { [e.name]: { skip: a, count: n } } },
565
+ $auditRecord: { auditEvents: [r] }
566
+ };
567
+ p(o);
568
+ const s = await d("query", o), c = await g(s), { aggregations: i } = c, l = i[0];
569
+ return l.$hasMore = l.items.length > n, l.items = [...e.items, ...l.items], Promise.resolve(l);
292
570
  }
293
- const Be = { notify: T };
294
- async function Qe() {
571
+ async function gt() {
572
+ const { app: e } = u, t = new URLSearchParams({ app: e || "" });
573
+ return b("app", t);
574
+ }
575
+ async function Pe() {
295
576
  const { app: e } = u, t = new URLSearchParams({
296
577
  app: e || "",
297
- action: "load"
578
+ preLogin: "true"
298
579
  });
299
- return h("usersettings", t);
580
+ return b("app", t);
300
581
  }
301
- async function ee(e, t) {
302
- const n = {
303
- action: "save",
304
- userSettings: e,
305
- $auditRecord: { auditEvents: [t] }
582
+ function bt() {
583
+ let { backendUrl: e, app: t } = u;
584
+ if (e || (e = window.location.origin), !t) {
585
+ const r = window.location.pathname.match(/\/app(?:-debug)?\/([^\/#]+)/);
586
+ r && (t = r[1]);
587
+ }
588
+ return m({
589
+ ...u,
590
+ backendUrl: e,
591
+ app: t
592
+ }), Pe().then((r) => {
593
+ const { autoOAuthProvider: a, autoSAMLProvider: n } = u, o = !a && !r.autoOAuthProvider && !n && !r.autoSAMLProvider;
594
+ return m({
595
+ ...u,
596
+ autoOAuthProvider: a || r.autoOAuthProvider,
597
+ autoSAMLProvider: n || r.autoSAMLProvider,
598
+ useCredentialsOrSSO: o
599
+ }), r;
600
+ }).catch((r) => {
601
+ throw console.error("atomic:fetchAppPreLogin error", r), r;
602
+ });
603
+ }
604
+ async function Ct(e, t, r = {}) {
605
+ const a = `search.dataset/${e}/${t}`, n = await d(a, { parameters: r }), o = t[0].toLowerCase() + t.slice(1), s = n.datasets[o];
606
+ if ("errorCode" in s && "errorMessage" in s)
607
+ throw new Error(s.errorMessage);
608
+ return s;
609
+ }
610
+ async function Rt(e, t) {
611
+ const r = `search.dataset/${e}`, { parameters: a = {}, datasets: n = [] } = t;
612
+ return (await d(r, { parameters: a, datasets: n })).datasets;
613
+ }
614
+ async function xt(e) {
615
+ return await b(`search.dataset/${e}`);
616
+ }
617
+ async function vt(e, t = !0, r) {
618
+ try {
619
+ return (await d("labels", {
620
+ action: "list",
621
+ q: e,
622
+ public: t,
623
+ locale: r,
624
+ localize: !1
625
+ })).labels;
626
+ } catch (a) {
627
+ throw f("Error in fetchLabels", a), a;
628
+ }
629
+ }
630
+ async function pe() {
631
+ try {
632
+ const { app: e = "" } = u, t = new URLSearchParams({
633
+ app: e,
634
+ action: "getUserRights"
635
+ });
636
+ return b("labels", t);
637
+ } catch (e) {
638
+ throw f("Error in getUserRights", e), e;
639
+ }
640
+ }
641
+ async function Le(e, t, r = !0) {
642
+ try {
643
+ const a = {
644
+ action: "add",
645
+ labels: e,
646
+ ids: t,
647
+ public: r,
648
+ $auditRecord: {
649
+ auditEvents: [
650
+ {
651
+ type: k.Label_AddDoc,
652
+ detail: {
653
+ public: r,
654
+ label: e ? e.toString() : null,
655
+ doccount: t ? t.length : 0
656
+ }
657
+ }
658
+ ],
659
+ mlAuditEvents: [
660
+ {
661
+ actionType: "addToLabel",
662
+ documentIds: t
663
+ }
664
+ ]
665
+ }
666
+ };
667
+ return d("labels", a);
668
+ } catch (a) {
669
+ throw f("Error in add", a), a;
670
+ }
671
+ }
672
+ async function Oe(e, t, r = !0) {
673
+ try {
674
+ const a = {
675
+ action: "remove",
676
+ labels: e,
677
+ ids: t,
678
+ public: r,
679
+ $auditRecord: {
680
+ auditEvents: [
681
+ {
682
+ type: k.Label_RemoveDoc,
683
+ detail: {
684
+ public: r,
685
+ label: e ? e.toString() : null,
686
+ doccount: t ? t.length : 0
687
+ }
688
+ }
689
+ ],
690
+ mlAuditEvents: [
691
+ {
692
+ actionType: "removeFromLabel",
693
+ documentIds: t
694
+ }
695
+ ]
696
+ }
697
+ };
698
+ return d("labels", a);
699
+ } catch (a) {
700
+ throw f("Error in remove", a), a;
701
+ }
702
+ }
703
+ async function Ue(e, t, r = !0) {
704
+ try {
705
+ const a = {
706
+ action: "rename",
707
+ labels: e,
708
+ newLabel: t,
709
+ public: r,
710
+ auditEvents: {
711
+ type: k.Label_Rename,
712
+ detail: {
713
+ public: r,
714
+ oldlabel: e ? e.toString() : null,
715
+ label: t
716
+ }
717
+ }
718
+ };
719
+ return d("labels", a);
720
+ } catch (a) {
721
+ throw f("Error in rename", a), a;
722
+ }
723
+ }
724
+ async function $e(e, t = !0) {
725
+ try {
726
+ const r = {
727
+ action: "delete",
728
+ labels: e,
729
+ public: t,
730
+ auditEvents: {
731
+ type: k.Label_Delete,
732
+ detail: {
733
+ public: t,
734
+ label: e ? e.toString() : null
735
+ }
736
+ }
737
+ };
738
+ return d("labels", r);
739
+ } catch (r) {
740
+ throw f("Error in deleteLabels", r), r;
741
+ }
742
+ }
743
+ async function De(e, t, r = !0) {
744
+ try {
745
+ const a = {
746
+ action: "bulkAdd",
747
+ labels: e,
748
+ query: t,
749
+ public: r,
750
+ auditEvents: {
751
+ type: k.Label_Add,
752
+ detail: {
753
+ public: r,
754
+ label: e ? e.toString() : null,
755
+ query: t !== null ? t.name : null
756
+ }
757
+ }
758
+ };
759
+ return d("labels", a);
760
+ } catch (a) {
761
+ throw f("Error in bulkAdd", a), a;
762
+ }
763
+ }
764
+ async function Ie(e, t, r = !0) {
765
+ try {
766
+ const a = {
767
+ action: "bulkRemove",
768
+ labels: e,
769
+ query: t,
770
+ public: r,
771
+ auditEvents: {
772
+ type: k.Label_Delete,
773
+ detail: {
774
+ public: r,
775
+ label: e ? e.toString() : null,
776
+ query: t !== null ? t.name : null
777
+ }
778
+ }
779
+ };
780
+ return d("labels", a);
781
+ } catch (a) {
782
+ throw f("Error in bulkRemove", a), a;
783
+ }
784
+ }
785
+ const Pt = {
786
+ getUserRights: pe,
787
+ add: Le,
788
+ remove: Oe,
789
+ rename: Ue,
790
+ delete: $e,
791
+ bulkAdd: De,
792
+ bulkRemove: Ie
793
+ };
794
+ async function pt(e, t) {
795
+ const r = `${window.location.origin}${window.location.pathname}`, a = { name: t == null ? void 0 : t.name, text: t == null ? void 0 : t.text };
796
+ return d("preview", {
797
+ action: "get",
798
+ id: e,
799
+ query: a,
800
+ browserUrl: r
801
+ });
802
+ }
803
+ async function Lt(e) {
804
+ const t = new Headers();
805
+ t.append("content-type", "text");
806
+ const r = await fetch(
807
+ e,
808
+ {
809
+ method: "GET",
810
+ headers: t
811
+ }
812
+ );
813
+ g(r);
814
+ }
815
+ async function ye() {
816
+ const e = new URLSearchParams({
817
+ action: "get",
818
+ noAutoAuthentication: "true"
819
+ });
820
+ return b("principal", e);
821
+ }
822
+ const E = 11;
823
+ async function Ot(e, t, r) {
824
+ var s;
825
+ const n = await d("query", {
826
+ query: e,
827
+ $auditRecord: t,
828
+ queryIntentData: r
829
+ });
830
+ n.aggregations.forEach((c) => {
831
+ c.$hasMore = !1, !c.isDistribution && !c.isTree && c.items && (c.$hasMore = c.items.length === E), c.isTree && c.items && B(c);
832
+ }), (s = n.records) == null || s.map((c) => Object.assign(c, { value: c.title, type: "default" }));
833
+ const o = { ...n, nextPage: n.page < Math.ceil(n.rowCount / n.pageSize) ? n.page + 1 : void 0, previousPage: n.page > 1 ? n.page - 1 : void 0 };
834
+ return Promise.resolve(o);
835
+ }
836
+ async function Ut(e, t, r) {
837
+ const { app: a = "" } = u, n = {
838
+ methods: [],
839
+ mode: t,
840
+ propagateErrors: !0,
841
+ $auditRecord: { auditEvents: [r] }
306
842
  };
307
- return P(n), l("usersettings", n);
843
+ for (const c of e)
844
+ n.methods.push({
845
+ method: "query",
846
+ app: a,
847
+ query: c
848
+ });
849
+ const o = await d("multi", n);
850
+ o.results.forEach((c) => {
851
+ c.aggregations.forEach((i) => {
852
+ i.$hasMore = !1, !i.isDistribution && !i.isTree && i.items && (i.$hasMore = i.items.length === E), i.isTree && B(i);
853
+ });
854
+ }), o.results.forEach((c) => {
855
+ var i;
856
+ return (i = c.records) == null ? void 0 : i.map((l) => Object.assign(l, { value: l.title, type: "default" }));
857
+ });
858
+ const s = o.results.map((c) => ({ ...c, nextPage: c.page < Math.ceil(c.rowCount / c.pageSize) ? c.page + 1 : void 0, previousPage: c.page > 1 ? c.page - 1 : void 0 }));
859
+ return Promise.resolve(s);
308
860
  }
309
- async function Ae(e, t) {
310
- const r = {
311
- action: "patch",
312
- userSettings: e,
313
- $auditRecord: t ? { auditEvents: [t] } : void 0
861
+ function B(e, t = "", r = 0) {
862
+ let a = [];
863
+ return e.items && e.items.forEach((n) => {
864
+ let o = t ? `${t}/${n.value}` : n.value, s = r + 1;
865
+ a.push({ path: o, level: s }), n.$path = o, n.$level = s, n.hasChildren ? a = a.concat(B(n, o, s)) : n.hasChildren = !1;
866
+ }), a;
867
+ }
868
+ async function $t(e) {
869
+ const r = await d("queryintent", {
870
+ query: e
871
+ });
872
+ return r == null ? void 0 : r.intents;
873
+ }
874
+ async function Dt({ model: e, appName: t, query: r, article: a }) {
875
+ const { webservice: n, format: o, maxcount: s, exportedColumns: c, export: i } = e, l = {
876
+ app: t,
877
+ webservice: n,
878
+ query: r,
879
+ type: i,
880
+ format: o,
881
+ maxcount: s,
882
+ exportedColumns: c,
883
+ $auditRecord: {
884
+ auditEvents: [{
885
+ type: "Search_ExportCSV",
886
+ detail: {
887
+ resultid: a ? a.id : void 0
888
+ }
889
+ }]
890
+ }
314
891
  };
315
- return P(r), l("usersettings", r);
892
+ return p(l), await d("search.queryexport", l, { responseType: "blob" });
316
893
  }
317
- async function Ne() {
318
- return ee({}, { type: "UserSettings_Reset" });
894
+ async function It(e, t) {
895
+ return await d(
896
+ "similardocuments",
897
+ {
898
+ sourceDocumentId: e,
899
+ query: {
900
+ name: t
901
+ }
902
+ }
903
+ );
904
+ }
905
+ async function yt(e, t) {
906
+ var n;
907
+ const a = await d("query.links", {
908
+ webservice: e,
909
+ query: t
910
+ });
911
+ return (n = a == null ? void 0 : a.links) == null ? void 0 : n.map((o) => ({ ...o, query: t }));
319
912
  }
320
- async function Ge(e, t, n, r, o) {
321
- const { app: s } = u;
322
- return (await l("search.suggest", {
323
- app: s || "",
913
+ async function At(e, t, r, a, n) {
914
+ const { app: o } = u, s = {
915
+ app: o || "",
324
916
  suggestQuery: e,
325
917
  text: t,
326
- filter: n,
327
- kinds: r,
328
- showSource: o
329
- })).suggests;
918
+ filter: r,
919
+ kinds: a,
920
+ showSource: n
921
+ };
922
+ try {
923
+ return (await d("search.suggest", s)).suggests;
924
+ } catch (c) {
925
+ throw console.error("Error fetching suggestions:", c), c;
926
+ }
330
927
  }
331
- async function je(e, t, n, r) {
332
- const { app: o } = u;
333
- return (await l("suggestquery", {
334
- app: o || "",
928
+ async function Nt(e, t, r, a) {
929
+ const { app: n } = u;
930
+ return (await d("suggestquery", {
931
+ app: n || "",
335
932
  suggestQuery: e,
336
933
  text: t,
337
- query: n,
338
- kinds: r
934
+ query: r,
935
+ kinds: a
339
936
  })).suggests;
340
937
  }
341
- async function Ve(e, t) {
938
+ async function Bt(e, t) {
342
939
  if (!t) return Promise.resolve([]);
343
- const { app: n } = u;
344
- return (await l("suggestfield", {
345
- app: n || "",
940
+ const { app: r } = u;
941
+ return (await d("suggestfield", {
942
+ app: r || "",
346
943
  text: e,
347
944
  action: "suggests",
348
945
  fields: t
349
946
  })).suggests;
350
947
  }
351
- async function ze(e, t) {
352
- var o;
353
- const r = await l("query.links", {
354
- webservice: e,
355
- query: t
356
- });
357
- return (o = r == null ? void 0 : r.links) == null ? void 0 : o.map((s) => ({ ...s, query: t }));
358
- }
359
- async function He(e, t, n, r, o, s) {
360
- return l("doc.textchunks", {
948
+ async function Ft(e, t, r, a, n, o) {
949
+ return d("doc.textchunks", {
361
950
  id: e,
362
951
  textChunks: t,
363
- highlights: n,
364
- query: r,
365
- leftSentencesCount: o,
366
- rightSentencesCount: s
952
+ highlights: r,
953
+ query: a,
954
+ leftSentencesCount: n,
955
+ rightSentencesCount: o
367
956
  });
368
957
  }
369
- async function Je(e, t, n = {}) {
370
- const r = `search.dataset/${e}/${t}`, s = (await l(r, { parameters: n })).datasets[t];
371
- if ("errorCode" in s && "errorMessage" in s)
372
- throw new Error(s.errorMessage);
373
- return s;
374
- }
375
- async function qe(e, t) {
376
- const n = `search.dataset/${e}`, { parameters: r = {}, datasets: o = [] } = t;
377
- return (await l(n, { parameters: r, datasets: o })).datasets;
378
- }
379
- async function Xe(e) {
380
- return await h(`search.dataset/${e}`);
381
- }
382
- async function We(e, t = !0, n) {
383
- return (await l("labels", {
384
- action: "list",
385
- q: e,
386
- public: t,
387
- locale: n,
388
- localize: !1
389
- })).labels;
390
- }
391
- async function te() {
392
- const { app: e = "" } = u, t = new URLSearchParams({
393
- app: e,
394
- action: "getUserRights"
958
+ async function qt() {
959
+ const { app: e } = u, t = new URLSearchParams({
960
+ app: e || "",
961
+ action: "load"
395
962
  });
396
- return h("labels", t);
397
- }
398
- async function ne(e, t, n = !0) {
399
- const r = {
400
- action: "add",
401
- labels: e,
402
- ids: t,
403
- public: n,
404
- $auditRecord: {
405
- auditEvents: [
406
- {
407
- type: _.Label_AddDoc,
408
- detail: {
409
- public: n,
410
- label: e ? e.toString() : null,
411
- doccount: t ? t.length : 0
412
- }
413
- }
414
- ],
415
- mlAuditEvents: [
416
- {
417
- actionType: "addToLabel",
418
- documentIds: t
419
- }
420
- ]
421
- }
422
- };
423
- return l("labels", r);
963
+ return b("usersettings", t);
424
964
  }
425
- async function re(e, t, n = !0) {
426
- const r = {
427
- action: "remove",
428
- labels: e,
429
- ids: t,
430
- public: n,
431
- $auditRecord: {
432
- auditEvents: [
433
- {
434
- type: _.Label_RemoveDoc,
435
- detail: {
436
- public: n,
437
- label: e ? e.toString() : null,
438
- doccount: t ? t.length : 0
439
- }
440
- }
441
- ],
442
- mlAuditEvents: [
443
- {
444
- actionType: "removeFromLabel",
445
- documentIds: t
446
- }
447
- ]
448
- }
449
- };
450
- return l("labels", r);
451
- }
452
- async function oe(e, t, n = !0) {
965
+ async function Ae(e, t) {
453
966
  const r = {
454
- action: "rename",
455
- labels: e,
456
- newLabel: t,
457
- public: n,
458
- auditEvents: {
459
- type: _.Label_Rename,
460
- detail: {
461
- public: n,
462
- oldlabel: e ? e.toString() : null,
463
- label: t
464
- }
465
- }
466
- };
467
- return l("labels", r);
468
- }
469
- async function se(e, t = !0) {
470
- const n = {
471
- action: "delete",
472
- labels: e,
473
- public: t,
474
- auditEvents: {
475
- type: _.Label_Delete,
476
- detail: {
477
- public: t,
478
- label: e ? e.toString() : null
479
- }
480
- }
967
+ action: "save",
968
+ userSettings: e,
969
+ $auditRecord: { auditEvents: [t] }
481
970
  };
482
- return l("labels", n);
971
+ return p(r), d("usersettings", r);
483
972
  }
484
- async function ae(e, t, n = !0) {
485
- const r = {
486
- action: "bulkAdd",
487
- labels: e,
488
- query: t,
489
- public: n,
490
- auditEvents: {
491
- type: _.Label_Add,
492
- detail: {
493
- public: n,
494
- label: e ? e.toString() : null,
495
- query: t !== null ? t.name : null
496
- }
497
- }
973
+ async function Qt(e, t) {
974
+ const a = {
975
+ action: "patch",
976
+ userSettings: e,
977
+ $auditRecord: t ? { auditEvents: [t] } : void 0
498
978
  };
499
- return l("labels", r);
979
+ return p(a), d("usersettings", a);
500
980
  }
501
- async function ie(e, t, n = !0) {
502
- const r = {
503
- action: "bulkRemove",
504
- labels: e,
505
- query: t,
506
- public: n,
507
- auditEvents: {
508
- type: _.Label_Delete,
509
- detail: {
510
- public: n,
511
- label: e ? e.toString() : null,
512
- query: t !== null ? t.name : null
513
- }
514
- }
515
- };
516
- return l("labels", r);
517
- }
518
- const Ye = {
519
- getUserRights: te,
520
- add: ne,
521
- remove: re,
522
- rename: oe,
523
- delete: se,
524
- bulkAdd: ae,
525
- bulkRemove: ie
526
- };
527
- async function Ke(e) {
528
- const n = await l("queryintent", {
529
- query: e
530
- });
531
- return n == null ? void 0 : n.intents;
981
+ async function Gt() {
982
+ return Ae({}, { type: "UserSettings_Reset" });
532
983
  }
533
- function g(e) {
984
+ function _(e) {
534
985
  const t = new CustomEvent(
535
986
  "authenticated",
536
987
  {
@@ -541,347 +992,215 @@ function g(e) {
541
992
  );
542
993
  dispatchEvent(t);
543
994
  }
544
- async function ce() {
995
+ const Ne = async () => {
545
996
  const { autoOAuthProvider: e } = u, t = {
546
997
  action: "getcode",
547
998
  provider: e,
548
999
  tokenInCookie: !0,
549
1000
  originalUrl: window.location.href
550
- }, n = await l("security.oauth", t);
551
- n.redirectUrl && (window.location.href = n.redirectUrl);
552
- }
553
- async function le() {
1001
+ };
1002
+ try {
1003
+ const r = await d("security.oauth", t);
1004
+ return r.redirectUrl && (localStorage.setItem("oauthRedirectUrl", r.redirectUrl), window.location.href = r.redirectUrl), r;
1005
+ } catch (r) {
1006
+ throw console.error("Failed to authenticate with OAuth", r), r;
1007
+ }
1008
+ }, Be = async () => {
554
1009
  const { autoSAMLProvider: e } = u, t = {
555
1010
  action: "getresponse",
556
1011
  provider: e,
557
1012
  tokenInCookie: !0,
558
1013
  originalUrl: window.location.href
559
- }, n = await l("security.saml", t);
560
- n.redirectUrl && (window.location.href = n.redirectUrl);
561
- }
562
- const ue = async (e) => {
563
- const { username: t, password: n } = e || {}, o = await l("webToken", {
1014
+ };
1015
+ try {
1016
+ const r = await d("security.saml", t);
1017
+ return r.redirectUrl && (localStorage.setItem("samlRedirectUrl", r.redirectUrl), window.location.href = r.redirectUrl), r;
1018
+ } catch (r) {
1019
+ throw console.error("Failed to authenticate with SAML", r), r;
1020
+ }
1021
+ }, Fe = async (e) => {
1022
+ const { username: t, password: r } = e || {}, a = {
564
1023
  action: "get",
565
1024
  tokenInCookie: !0,
566
1025
  user: t,
567
- password: n,
1026
+ password: r,
568
1027
  noUserOverride: !0,
569
1028
  noAutoAuthentication: !0
570
- });
571
- return o.csrfToken ? (y(o.csrfToken), !0) : !1;
572
- }, fe = async () => {
1029
+ };
1030
+ try {
1031
+ const n = await d("security.webtoken", a);
1032
+ return n.csrfToken ? (F(n.csrfToken), n.csrfToken) : null;
1033
+ } catch (n) {
1034
+ throw console.error("Failed to get JWT", n), n;
1035
+ }
1036
+ }, qe = async () => {
573
1037
  const e = new URLSearchParams({
574
1038
  action: "deleteWebTokenCookie",
575
1039
  noUserOverride: "true",
576
1040
  noAutoAuthentication: "true"
577
1041
  });
578
- return h("challenge", e);
579
- }, D = () => localStorage.getItem("csrfToken") || "", y = (e) => localStorage.setItem("csrfToken", e), Ze = async (e) => {
580
- const { useSSO: t } = u;
581
- if (D() || t)
582
- return g(!0), !0;
583
- const { username: n, password: r } = e || {};
584
- let o;
585
- return n && r ? (L({ useCredentials: !0 }), o = await ue(e)) : o = await de(), g(o), o;
586
- }, Ee = async () => {
587
- const { useCredentials: e, userOverrideActive: t } = u;
588
- localStorage.removeItem("csrfToken"), e && !t ? (await fe()).methodresult === "ok" ? g(!1) : console.error("logout failed") : g(!1);
589
- }, Te = () => !!D(), de = async () => {
590
- const { backendUrl: e, apiPath: t, autoOAuthProvider: n, autoSAMLProvider: r } = u, s = await (await fetch(`${e}/${t}/challenge?action=getCsrfToken&suppressErrors=true`)).json();
591
- if (s != null && s.csrfToken)
592
- return y(s.csrfToken), !0;
593
- if (n)
594
- await ce();
595
- else if (r)
596
- await le();
1042
+ return b("challenge", e);
1043
+ }, O = () => {
1044
+ const e = localStorage.getItem("csrfToken"), t = sessionStorage.getItem("sinequa-credentials");
1045
+ return t ? JSON.parse(t).data.csrfToken : e || null;
1046
+ }, F = (e) => sessionStorage.setItem("sinequa-credentials", JSON.stringify({ data: { csrfToken: e } })), jt = async (e) => {
1047
+ if (e)
1048
+ S("Attempting authentication using credentials"), m({ useCredentials: !0, useCredentialsOrSSO: !1, useSSO: !1 });
597
1049
  else
598
- throw new Error("No CSRF token found and no autoOauthProvider nor autoSAMLProvider are specified");
599
- return !1;
600
- };
601
- function et(e, t) {
602
- var o;
603
- return !(e != null && e.items) || ((o = e == null ? void 0 : e.items) == null ? void 0 : o.length) === 0 ? [] : e.items.reduce((s, i) => {
604
- if (!i.value || i.value === "") return s;
605
- const a = _e(i, e.column);
606
- return s.push({
607
- operator: a.operator,
608
- value: a.value,
609
- display: i.display || a.display,
610
- filters: a.filters,
611
- disabled: i.count === 0,
612
- hidden: i.count === 0 && e.isDistribution ? !t : !1
613
- }), s;
614
- }, []);
615
- }
616
- function _e(e, t) {
617
- const n = t, r = e.value.match(/.*\:\(?([><=\d\-\.AND ]+)\)?/);
618
- if (r != null && r[1]) {
619
- const s = (r == null ? void 0 : r[1].split(" AND ")).map((i) => {
620
- const a = i.indexOf(">=") !== -1 ? "gte" : "lt";
621
- let c = i.substring(i.indexOf(" ") + 1);
622
- return { field: n, operator: a, value: c, display: e.display || e.value };
623
- });
624
- if (s.length === 2)
625
- return { field: n, operator: "and", filters: s, value: e.value, display: s[0].display || s[0].value };
626
- if (s.length === 1)
627
- return { ...s[0], field: n };
628
- throw new Error("Failed to parse distribution expression");
629
- }
630
- return { field: n, operator: "eq", value: e.value, display: e.display };
631
- }
632
- function tt(e, t, n) {
633
- return e.valuesAreExpressions ? t.display === n.display : t.value === n.value;
634
- }
635
- function nt(e, t) {
636
- const n = [];
637
- if (e.length > 0) {
638
- const r = /* @__PURE__ */ new Map(), o = t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), s = new RegExp("\\b" + o, "i");
639
- e.forEach((i) => {
640
- if (i.display.length > 1) {
641
- const a = s.exec(i.display);
642
- G(n, r, "/", i.display, +(i.frequency || 0), 1, ((a == null ? void 0 : a.index) || 0) + t.length);
643
- }
644
- });
645
- }
646
- return n;
647
- }
648
- function G(e, t, n, r, o, s, i) {
649
- const a = r.indexOf("/", n.length), c = r.substring(0, a + 1);
650
- let f = t.get(c);
651
- if (!f) {
652
- const d = c.replace(/^\/|\/$/g, "");
653
- f = {
654
- value: r.substring(n.length, a),
655
- count: o,
656
- items: [],
657
- hasChildren: !1,
658
- $level: s,
659
- $opened: i >= c.length,
660
- $path: d
661
- }, t.set(c, f), e.push(f);
662
- }
663
- c.length < r.length && (f.hasChildren = !0, G(f.items, t, c, r, o, s + 1, i));
664
- }
665
- function rt(e, t) {
666
- return e.reduce((n, r) => (t(r) ? n.true.push(r) : n.false.push(r), n), { true: [], false: [] });
667
- }
668
- const he = /(([\+\-])?\(([^\)]+)\))|(([\+\-])?\[([^\]]+)\])|(([\+\-])?\"([^\"]+)\")|(([\+\-])?\/([^\/]+)\/)|(([\+\-])?(\S+))/g, ke = 2, $ = 3, ge = 5, M = 6, pe = 8, F = 9, Se = 11, I = 12, me = 14, B = 15;
669
- function m(e) {
670
- if (!e) return [];
671
- const t = [], n = e.matchAll(he);
672
- for (let r of n)
673
- r[$] ? t.push({ type: "group", value: r[$], op: r[ke] }) : r[M] ? t.push({ type: "adjacent", value: r[M], op: r[ge] }) : r[F] ? t.push({ type: "exact", value: r[F], op: r[pe] }) : r[I] ? t.push({ type: "regex", value: r[I], op: r[Se] }) : r[B] && t.push({ type: "token", value: r[B], op: r[me] });
674
- return t;
675
- }
676
- function v(e) {
677
- return e.map((t) => {
678
- const n = t.op || "";
679
- switch (t.type) {
680
- case "group":
681
- return `${n}(${t.value})`;
682
- case "adjacent":
683
- return `${n}[${t.value}]`;
684
- case "exact":
685
- return `${n}"${t.value}"`;
686
- case "regex":
687
- return `${n}/${t.value}/`;
688
- case "token":
689
- return `${n}${t.value}`;
1050
+ try {
1051
+ const s = localStorage.getItem("oauthRedirectUrl"), c = localStorage.getItem("samlRedirectUrl");
1052
+ S("Attempting to retrieve CSRF token");
1053
+ const i = await Qe();
1054
+ if (x("CSRF token retrieval result", i ? "success" : "failed"), i === null) {
1055
+ if (s || c)
1056
+ return C("Redirection from provider failed after previous attempt"), localStorage.removeItem("oauthRedirectUrl"), localStorage.removeItem("samlRedirectUrl"), _(!1), !1;
1057
+ const { autoOAuthProvider: l, autoSAMLProvider: h, useSAML: v } = u;
1058
+ if (l && !v)
1059
+ return S("Initiating OAuth authentication flow"), await Ne(), C("OAuth authentication flow did not redirect as expected"), _(!1), !1;
1060
+ if (h)
1061
+ return S("Initiating SAML authentication flow"), await Be(), C("SAML authentication flow did not redirect as expected"), _(!1), !1;
1062
+ S("No direct authentication method available, will try SSO then credentials"), m({ useCredentials: !0, useSSO: !0, useCredentialsOrSSO: !0 });
1063
+ } else
1064
+ return localStorage.removeItem("oauthRedirectUrl"), localStorage.removeItem("samlRedirectUrl"), S("User authenticated via existing token"), _(!0), !0;
1065
+ } catch (s) {
1066
+ throw f("Unexpected error during authentication", s), _(!1), s;
690
1067
  }
691
- }).join(" ");
692
- }
693
- function ot(e, t, n) {
694
- let r = m(e);
695
- for (let o of t)
696
- r.push({ type: "adjacent", value: o, op: n });
697
- return v(r);
698
- }
699
- function st(e, t) {
700
- const n = m(t), r = n.findIndex((o) => o.value === e);
701
- return r !== -1 ? (n.splice(r, 1), t = v(n)) : t;
702
- }
703
- function at(e) {
704
- const t = m(e).filter((n) => n.type !== "adjacent");
705
- return v(t);
706
- }
707
- function it(e) {
708
- return m(e).filter((t) => t.type === "adjacent").map((t) => t.value);
709
- }
710
- function ct(e, t, n) {
711
- const r = new Intl.RelativeTimeFormat(e, { numeric: "auto" }), { offset: o, unit: s, isFuture: i } = we(t, n);
712
- return r.format(o * (i ? 1 : -1), s);
713
- }
714
- function we(e, t) {
715
- const n = new Date(e), r = t ? new Date(t) : /* @__PURE__ */ new Date(), o = Math.abs(r.getTime() - n.getTime());
716
- return {
717
- offset: Math.floor(o / (1e3 * 60 * 60 * 24)),
718
- unit: "day",
719
- isFuture: n > r
720
- };
721
- }
722
- function lt(e) {
723
- if (e === void 0) return;
724
- const { q: t, f: n, p: r, s: o, t: s, ...i } = k(e), [a] = e.split("?");
725
- return {
726
- path: a,
727
- text: t,
728
- filters: n ? j(n) : void 0,
729
- page: r ? parseInt(r, 10) : void 0,
730
- sort: o,
731
- tab: s,
732
- ...i
733
- };
734
- }
735
- function ut(e) {
736
- if (e === void 0) return [];
737
- const { f: t } = k(e);
738
- return j(t);
739
- }
740
- function j(e) {
741
- const t = decodeURIComponent(e);
742
- return JSON.parse(t ?? "[]");
743
- }
744
- function k(e) {
745
- const t = e.split("?")[1];
746
- if (t === void 0) return {};
747
- const n = new URLSearchParams(t);
748
- return Object.fromEntries(n);
749
- }
750
- function ft(e) {
751
- const { q: t = "" } = k(e);
752
- return t;
753
- }
754
- function dt(e) {
755
- const { id: t } = k(e);
756
- return decodeURIComponent(t);
757
- }
758
- function _t(e) {
759
- const { p: t = "0" } = k(e);
760
- return parseInt(t, 10);
761
- }
762
- function ht(e) {
763
- const { t } = k(e);
764
- return t;
765
- }
766
- function kt(e, t) {
767
- if (!e)
768
- return e;
769
- let n = 0;
770
- const r = e.length;
771
- let o = 0;
772
- if (e[o] === "[") {
773
- for (; o < r && /[0-9]/.test(e[o]); )
774
- o++;
775
- e[o] === "]" && (n = o + 1);
776
- }
777
- const s = b(e, n, !1);
778
- if (!s)
779
- return e;
780
- const i = t.charCodeAt(0), a = t.charCodeAt(1);
781
- let c = s;
782
- for (; c; )
783
- if (i === c.lang1 && a === c.lang2) {
784
- const d = b(e, c.end + 4, !0);
785
- return e.substring(d.start, d.end);
786
- } else
787
- c = b(e, c.end + 4, !1);
788
- const f = e.substring(s.start, s.end);
789
- return f || e;
790
- }
791
- function b(e, t, n) {
792
- for (let r = t, o = e.length - 3; r < o; r++)
793
- if (e[r] === "[" && e[r + 3] === "]")
794
- return {
795
- start: t,
796
- end: r,
797
- lang1: e.charCodeAt(r + 1),
798
- lang2: e.charCodeAt(r + 2)
799
- };
800
- if (n)
801
- return {
802
- start: t,
803
- end: e.length,
804
- lang1: -1,
805
- lang2: -1
806
- };
807
- }
1068
+ const { useSSO: t, useCredentialsOrSSO: r, useCredentials: a } = u;
1069
+ if (r)
1070
+ try {
1071
+ if (S("Checking if user is authenticated via SSO"), await ye())
1072
+ return S("User authenticated using SSO"), m({ useCredentials: !1, useCredentialsOrSSO: !1, useSSO: !0 }), _(!0), !0;
1073
+ } catch (s) {
1074
+ if ((s == null ? void 0 : s.status) === 401)
1075
+ S("SSO authentication failed with 401, falling back to credentials"), m({ useCredentials: !0, useSSO: !1, useCredentialsOrSSO: !1 });
1076
+ else
1077
+ throw f("SSO authentication failed with unexpected error", s), _(!1), f;
1078
+ }
1079
+ if (O() || t)
1080
+ return console.log("user already authenticated", O()), m({ isRedirectUrl: !1 }), _(!0), !0;
1081
+ const { username: n, password: o } = e || {};
1082
+ if (a && !n && !o)
1083
+ return console.error("Credentials are required for authentication"), _(!1), !1;
1084
+ if (n && o)
1085
+ try {
1086
+ return console.log("authentication using credentials..."), m({ useCredentials: !0 }), await Fe(e), _(!0), !0;
1087
+ } catch (s) {
1088
+ throw _(!1), s;
1089
+ }
1090
+ return _(!1), console.error("No authentication method available. Please provide credentials or configure OAuth/SAML."), !1;
1091
+ }, Vt = async () => {
1092
+ const { useCredentials: e, userOverrideActive: t } = u;
1093
+ localStorage.removeItem("csrfToken"), sessionStorage.removeItem("sinequa-credentials"), e && !t ? (await qe()).methodresult === "ok" ? _(!1) : console.error("logout failed") : _(!1);
1094
+ }, Jt = () => !!O(), Qe = async () => {
1095
+ const { backendUrl: e, apiPath: t } = u;
1096
+ try {
1097
+ const a = await (await fetch(`${e}/${t}/challenge?action=getCsrfToken&suppressErrors=true`)).json();
1098
+ return a != null && a.csrfToken ? (F(a.csrfToken), a.csrfToken) : null;
1099
+ } catch (r) {
1100
+ throw console.error("Failed to get CSRF token", r), r;
1101
+ }
1102
+ };
808
1103
  export {
809
- Be as Audit,
810
- _ as AuditEventType,
811
- Ie as MINIMUM_COMPATIBLE_SERVER_API_VERSION,
812
- P as addAuditAdditionalInfo,
813
- ot as addConcepts,
814
- Y as addSessionId,
815
- K as addUrl,
816
- tt as aggregationItemStrictCompare,
817
- De as appInitializerFn,
818
- rt as bisect,
819
- x as buildPathsAndLevels,
820
- Q as createHeaders,
821
- Ne as deleteUserSettings,
822
- fe as deleteWebTokenCookie,
823
- $e as escapeExpr,
824
- ye as fetchAggregation,
825
- Pe as fetchApp,
826
- V as fetchAppPreLogin,
827
- Re as fetchBulkQuery,
828
- Je as fetchDataset,
829
- Xe as fetchDatasetList,
830
- qe as fetchDatasets,
831
- We as fetchLabels,
832
- be as fetchPreview,
833
- Le as fetchPreviewUrl,
834
- xe as fetchPrincipal,
835
- Ce as fetchQuery,
836
- Ke as fetchQueryIntent,
837
- ze as fetchSponsoredLinks,
838
- Ge as fetchSuggest,
839
- Ve as fetchSuggestField,
840
- je as fetchSuggestQuery,
841
- He as fetchTextChunks,
842
- Qe as fetchUserSettings,
843
- h as get,
844
- it as getConcepts,
845
- j as getFiltersFromURI,
846
- ut as getFiltersFromUrl,
847
- dt as getIdFromUrl,
848
- ue as getJWToken,
849
- Ue as getMetadata,
850
- we as getOffsetFromDates,
851
- _t as getQueryPageFromUrl,
852
- lt as getQueryParamsFromUrl,
853
- ht as getQueryTabFromUrl,
854
- ft as getQueryTextFromUrl,
855
- ct as getRelativeDate,
856
- D as getToken,
1104
+ w as ApiError,
1105
+ wt as Audit,
1106
+ k as AuditEventType,
1107
+ Se as DidYouMeanKind,
1108
+ fe as EngineType,
1109
+ _e as EngineTypeModifier,
1110
+ K as LogLevel,
1111
+ dt as MINIMUM_COMPATIBLE_SERVER_API_VERSION,
1112
+ me as RFMDisplay,
1113
+ we as ServerError,
1114
+ ke as TimeoutError,
1115
+ Z as UnauthorizedError,
1116
+ p as addAuditAdditionalInfo,
1117
+ He as addConcepts,
1118
+ be as addSessionId,
1119
+ Ce as addUrl,
1120
+ Ve as aggregationItemStrictCompare,
1121
+ bt as appInitializerFn,
1122
+ ze as bisect,
1123
+ B as buildPathsAndLevels,
1124
+ ot as configureLogger,
1125
+ P as createHeaders,
1126
+ ht as createTimeoutController,
1127
+ x as debug,
1128
+ St as del,
1129
+ Gt as deleteUserSettings,
1130
+ qe as deleteWebTokenCookie,
1131
+ f as error,
1132
+ lt as escapeExpr,
1133
+ kt as fetchAggregation,
1134
+ gt as fetchApp,
1135
+ Pe as fetchAppPreLogin,
1136
+ Ut as fetchBulkQuery,
1137
+ Ct as fetchDataset,
1138
+ xt as fetchDatasetList,
1139
+ Rt as fetchDatasets,
1140
+ vt as fetchLabels,
1141
+ pt as fetchPreview,
1142
+ Lt as fetchPreviewUrl,
1143
+ ye as fetchPrincipal,
1144
+ Ot as fetchQuery,
1145
+ Dt as fetchQueryExport,
1146
+ $t as fetchQueryIntent,
1147
+ It as fetchSimilarDocuments,
1148
+ yt as fetchSponsoredLinks,
1149
+ At as fetchSuggest,
1150
+ Bt as fetchSuggestField,
1151
+ Nt as fetchSuggestQuery,
1152
+ Ft as fetchTextChunks,
1153
+ qt as fetchUserSettings,
1154
+ b as get,
1155
+ Ye as getConcepts,
1156
+ Qe as getCsrfToken,
1157
+ Y as getFiltersFromURI,
1158
+ Ee as getFiltersFromUrl,
1159
+ nt as getHelpIndexUrl,
1160
+ et as getIdFromUrl,
1161
+ Fe as getJWToken,
1162
+ ct as getMetadata,
1163
+ ie as getOffsetFromDates,
1164
+ tt as getQueryPageFromUrl,
1165
+ Me as getQueryParamsFromUrl,
1166
+ rt as getQueryTabFromUrl,
1167
+ Te as getQueryTextFromUrl,
1168
+ Ke as getRelativeDate,
1169
+ O as getToken,
857
1170
  u as globalConfig,
858
- q as guid,
859
- p as handleResponse,
860
- z as isArrayBuffer,
861
- Te as isAuthenticated,
862
- H as isBlob,
863
- Oe as isJsonable,
864
- S as isObject,
865
- J as isString,
866
- Ye as labels,
867
- Ze as login,
868
- Ee as logout,
869
- m as parseText,
870
- _e as parseValueAndOperatorFromItem,
871
- Ae as patchUserSettings,
872
- l as post,
873
- k as queryParamsFromUrl,
874
- X as regExEscape,
875
- st as removeConcept,
876
- at as removeConcepts,
877
- ve as resolveToColumnName,
878
- v as rewriteText,
879
- ee as saveUserSettings,
880
- L as setGlobalConfig,
881
- y as setToken,
882
- Me as sha512,
883
- Fe as split,
884
- nt as suggestionsToTreeAggregationNodes,
885
- kt as sysLang,
886
- et as translateAggregationToDateOptions
1171
+ he as guid,
1172
+ g as handleResponse,
1173
+ S as info,
1174
+ le as isArrayBuffer,
1175
+ Jt as isAuthenticated,
1176
+ ue as isBlob,
1177
+ it as isJsonable,
1178
+ Ze as isNotInputEvent,
1179
+ D as isObject,
1180
+ de as isString,
1181
+ Pt as labels,
1182
+ jt as login,
1183
+ Vt as logout,
1184
+ U as parseText,
1185
+ te as parseValueAndOperatorFromItem,
1186
+ mt as patch,
1187
+ Qt as patchUserSettings,
1188
+ d as post,
1189
+ _t as put,
1190
+ R as queryParamsFromUrl,
1191
+ We as removeConcept,
1192
+ Xe as removeConcepts,
1193
+ st as resolveToColumnName,
1194
+ N as rewriteText,
1195
+ Ae as saveUserSettings,
1196
+ m as setGlobalConfig,
1197
+ F as setToken,
1198
+ ut as sha512,
1199
+ Je as suggestionsToTreeAggregationNodes,
1200
+ at as sysLang,
1201
+ je as translateAggregationToDateOptions,
1202
+ Ne as tryOAuthAuthentication,
1203
+ Be as trySAMLAuthentication,
1204
+ C as warn,
1205
+ ft as withRetry
887
1206
  };