@sinequa/atomic 0.0.62 → 0.0.100

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