@sinequa/atomic 0.0.61 → 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 (71) hide show
  1. package/dist/atomic.js +1080 -734
  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/index.d.ts +1 -1
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/types/api-endpoints.d.ts +1 -1
  12. package/dist/types/api-endpoints.d.ts.map +1 -1
  13. package/dist/types/config/CCAppPreLogin.d.ts +7 -3
  14. package/dist/types/config/CCAppPreLogin.d.ts.map +1 -1
  15. package/dist/types/config/index.d.ts +2 -5
  16. package/dist/types/config/index.d.ts.map +1 -1
  17. package/dist/types/export/types.d.ts +22 -0
  18. package/dist/types/export/types.d.ts.map +1 -0
  19. package/dist/types/index.d.ts +1 -0
  20. package/dist/types/index.d.ts.map +1 -1
  21. package/dist/types/search/QueryIntentEntity.d.ts +16 -1
  22. package/dist/types/search/QueryIntentEntity.d.ts.map +1 -1
  23. package/dist/types/search/QueryIntentMatch.d.ts +17 -0
  24. package/dist/types/search/QueryIntentMatch.d.ts.map +1 -0
  25. package/dist/types/search/QueryIntentResponse.d.ts +9 -0
  26. package/dist/types/search/QueryIntentResponse.d.ts.map +1 -0
  27. package/dist/types/search/index.d.ts +4 -2
  28. package/dist/types/search/index.d.ts.map +1 -1
  29. package/dist/utils/bisect.d.ts.map +1 -0
  30. package/dist/utils/index.d.ts +4 -1
  31. package/dist/utils/index.d.ts.map +1 -1
  32. package/dist/utils/is-not-input-event.d.ts +2 -0
  33. package/dist/utils/is-not-input-event.d.ts.map +1 -0
  34. package/dist/utils/logger.d.ts +40 -0
  35. package/dist/utils/logger.d.ts.map +1 -0
  36. package/dist/utils/query-params.d.ts.map +1 -1
  37. package/dist/utils/utilities.d.ts +23 -0
  38. package/dist/utils/utilities.d.ts.map +1 -0
  39. package/dist/web-api/fetch-aggregation.d.ts.map +1 -1
  40. package/dist/web-api/fetch-app.d.ts.map +1 -1
  41. package/dist/web-api/fetch-audit.d.ts +3 -2
  42. package/dist/web-api/fetch-audit.d.ts.map +1 -1
  43. package/dist/web-api/fetch-dataset.d.ts +2 -2
  44. package/dist/web-api/fetch-dataset.d.ts.map +1 -1
  45. package/dist/web-api/fetch-labels.d.ts +1 -1
  46. package/dist/web-api/fetch-labels.d.ts.map +1 -1
  47. package/dist/web-api/fetch-query-export.d.ts +19 -0
  48. package/dist/web-api/fetch-query-export.d.ts.map +1 -0
  49. package/dist/web-api/fetch-query-intent.d.ts +13 -0
  50. package/dist/web-api/fetch-query-intent.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 +11 -8
  58. package/dist/web-api/index.d.ts.map +1 -1
  59. package/package.json +42 -41
  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,512 +1,987 @@
1
- let l = { apiPath: "api/v1", loginPath: "/login", backendUrl: window.location.origin };
2
- function L(e) {
3
- l = { ...l, ...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 } = l;
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
+ let u = { apiPath: "api/v1", loginPath: "/login", backendUrl: window.location.origin };
5
+ function m(e) {
6
+ u = { ...u, ...e };
10
7
  }
11
- async function S(e) {
8
+ function je(e, t) {
12
9
  var n;
13
- if (e.status === 401)
14
- throw l.userOverrideActive ? (l.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 && v(t), await e.json();
24
- }
25
- async function u(e, t, n) {
26
- const r = Q(n == null ? void 0 : n.headers), { app: o, backendUrl: s, apiPath: i } = l, 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 S(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 } = l, 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 S(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 we(e, t, n) {
54
- var i;
55
- const o = await u("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 Ce(e, t, n) {
67
- const { app: r = "" } = l, 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 u("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((d) => Object.assign(d, { value: d.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 Re(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 u("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 be(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
- S(n);
98
+ }).join(" ");
118
99
  }
119
- async function Le() {
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 xe() {
127
- const { app: e } = l, 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 j() {
131
- const { app: e } = l, 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 Pe() {
138
- let { backendUrl: e, app: t } = l;
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
- ...l,
145
- backendUrl: e,
146
- app: t
147
- }), j().then((n) => {
148
- const { autoOAuthProvider: r, autoSAMLProvider: o } = l, s = !r && !n.autoOAuthProvider && !o && !n.autoSAMLProvider;
149
- L({
150
- ...l,
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 De(e, t, n) {
160
- var f;
161
- const r = ((f = e.items) == null ? void 0 : f.length) || 0, o = 10, s = {
162
- query: { ...t, action: "aggregate", aggregations: { [e.name]: { skip: r, count: o } } },
163
- $auditRecord: { auditEvents: [n] }
164
- }, i = await u("query", s), a = await S(i), { aggregations: c } = a, d = c[0];
165
- return d.$hasMore = d.items.length > o, d.items = [...e.items, ...d.items], Promise.resolve(d);
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;
166
180
  }
167
- function ve(e, t, n) {
168
- var s, i, a, c;
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);
259
+ }
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 d = Object.keys(t.queries).find((C) => C === (n == null ? void 0 : n.toLowerCase()));
172
- let f;
173
- d && (f = t.queries[d]);
174
- const w = (i = ((s = f == null ? void 0 : f.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((d) => {
181
- var f;
182
- return (f = d[1].aliases) == null ? void 0 : f.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 ye(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 p(e) {
289
+ function D(e) {
191
290
  return e !== null && typeof e == "object";
192
291
  }
193
- function z(e) {
194
- return p(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 p(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 Ue(e) {
203
- return (p(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 X(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 Oe(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 $e(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
- 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))(_ || {});
228
- const Me = "1.0";
229
- let R, N;
230
369
  function P(e) {
231
- let t = q(e.$auditRecord);
232
- t && (W(t), Y(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
+ }
233
448
  }
234
- function q(e) {
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
+ }
472
+ }
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) {
235
520
  if (!e)
236
521
  return;
237
522
  let t;
238
523
  if (Array.isArray(e))
239
524
  t = e;
240
- else if (p(e)) {
241
- const n = e;
242
- if (n.auditEvents || n.mlAuditEvents)
243
- return n;
525
+ else if (D(e)) {
526
+ const r = e;
527
+ if (r.auditEvents || r.mlAuditEvents)
528
+ return r;
244
529
  t = [e];
245
530
  }
246
531
  return { auditEvents: t };
247
532
  }
248
- function W(e) {
249
- var n;
250
- const t = K();
251
- return (n = e.auditEvents) == null || n.forEach((r) => {
252
- 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;
253
538
  }), e;
254
539
  }
255
- function Y(e) {
256
- var n;
540
+ function Ce(e) {
541
+ var r;
257
542
  const t = decodeURIComponent(window.location.href);
258
- return (n = e == null ? void 0 : e.auditEvents) == null || n.forEach((r) => {
259
- 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;
260
545
  }), e;
261
546
  }
262
- function K() {
263
- return (!R || Z()) && (R = X()), N = /* @__PURE__ */ new Date(), R;
547
+ function Re() {
548
+ return (!A || xe()) && (A = he()), M = /* @__PURE__ */ new Date(), A;
264
549
  }
265
- function Z() {
266
- return (/* @__PURE__ */ new Date()).getTime() - N.getTime() > 10 * 60 * 1e3;
550
+ function xe() {
551
+ return (/* @__PURE__ */ new Date()).getTime() - M.getTime() > 10 * 60 * 1e3;
267
552
  }
268
- async function E(e) {
269
- const t = {
270
- event: _.None,
553
+ async function ve(e, t = !0) {
554
+ const r = {
555
+ event: k.None,
271
556
  $auditRecord: e
272
557
  };
273
- return P(t), u("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);
570
+ }
571
+ async function gt() {
572
+ const { app: e } = u, t = new URLSearchParams({ app: e || "" });
573
+ return b("app", t);
274
574
  }
275
- const Fe = { notify: E };
276
- async function Ie() {
277
- const { app: e } = l, t = new URLSearchParams({
575
+ async function Pe() {
576
+ const { app: e } = u, t = new URLSearchParams({
278
577
  app: e || "",
279
- action: "load"
578
+ preLogin: "true"
280
579
  });
281
- return h("usersettings", t);
580
+ return b("app", t);
282
581
  }
283
- async function T(e, t) {
284
- const n = {
285
- action: "save",
286
- userSettings: e,
287
- $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] }
288
842
  };
289
- return P(n), u("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);
290
860
  }
291
- async function Be(e, t) {
292
- const r = {
293
- action: "patch",
294
- userSettings: e,
295
- $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
+ }
296
891
  };
297
- return P(r), u("usersettings", r);
892
+ return p(l), await d("search.queryexport", l, { responseType: "blob" });
298
893
  }
299
- async function Qe() {
300
- return T({}, { 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
+ );
301
904
  }
302
- async function Ae(e, t, n, r, o) {
303
- const { app: s } = l;
304
- return (await u("search.suggest", {
305
- app: s || "",
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 }));
912
+ }
913
+ async function At(e, t, r, a, n) {
914
+ const { app: o } = u, s = {
915
+ app: o || "",
306
916
  suggestQuery: e,
307
917
  text: t,
308
- filter: n,
309
- kinds: r,
310
- showSource: o
311
- })).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
+ }
312
927
  }
313
- async function Ne(e, t, n, r) {
314
- const { app: o } = l;
315
- return (await u("suggestquery", {
316
- app: o || "",
928
+ async function Nt(e, t, r, a) {
929
+ const { app: n } = u;
930
+ return (await d("suggestquery", {
931
+ app: n || "",
317
932
  suggestQuery: e,
318
933
  text: t,
319
- query: n,
320
- kinds: r
934
+ query: r,
935
+ kinds: a
321
936
  })).suggests;
322
937
  }
323
- async function Ge(e, t) {
938
+ async function Bt(e, t) {
324
939
  if (!t) return Promise.resolve([]);
325
- const { app: n } = l;
326
- return (await u("suggestfield", {
327
- app: n || "",
940
+ const { app: r } = u;
941
+ return (await d("suggestfield", {
942
+ app: r || "",
328
943
  text: e,
329
944
  action: "suggests",
330
945
  fields: t
331
946
  })).suggests;
332
947
  }
333
- async function Ve(e, t) {
334
- var o;
335
- const r = await u("query.links", {
336
- webservice: e,
337
- query: t
338
- });
339
- return (o = r == null ? void 0 : r.links) == null ? void 0 : o.map((s) => ({ ...s, query: t }));
340
- }
341
- async function je(e, t, n, r, o, s) {
342
- return u("doc.textchunks", {
948
+ async function Ft(e, t, r, a, n, o) {
949
+ return d("doc.textchunks", {
343
950
  id: e,
344
951
  textChunks: t,
345
- highlights: n,
346
- query: r,
347
- leftSentencesCount: o,
348
- rightSentencesCount: s
952
+ highlights: r,
953
+ query: a,
954
+ leftSentencesCount: n,
955
+ rightSentencesCount: o
349
956
  });
350
957
  }
351
- async function ze(e, t, n = {}) {
352
- const r = `search.dataset/${e}/${t}`, s = (await u(r, { parameters: n })).datasets[t];
353
- if ("errorCode" in s && "errorMessage" in s)
354
- throw new Error(s.errorMessage);
355
- return s;
356
- }
357
- async function He(e, t) {
358
- const n = `search.dataset/${e}`, { parameters: r = {}, datasets: o = [] } = t;
359
- return (await u(n, { parameters: r, datasets: o })).datasets;
360
- }
361
- async function Je(e) {
362
- return await h(`search.dataset/${e}`);
363
- }
364
- async function Xe(e, t = !0, n) {
365
- return (await u("labels", {
366
- action: "list",
367
- q: e,
368
- public: t,
369
- locale: n,
370
- localize: !1
371
- })).labels;
372
- }
373
- async function ee() {
374
- const { app: e = "" } = l, t = new URLSearchParams({
375
- app: e,
376
- action: "getUserRights"
958
+ async function qt() {
959
+ const { app: e } = u, t = new URLSearchParams({
960
+ app: e || "",
961
+ action: "load"
377
962
  });
378
- return h("labels", t);
963
+ return b("usersettings", t);
379
964
  }
380
- async function te(e, t, n = !0) {
965
+ async function Ae(e, t) {
381
966
  const r = {
382
- action: "add",
383
- labels: e,
384
- ids: t,
385
- public: n,
386
- $auditRecord: {
387
- auditEvents: [
388
- {
389
- type: _.Label_AddDoc,
390
- detail: {
391
- public: n,
392
- label: e ? e.toString() : null,
393
- doccount: t ? t.length : 0
394
- }
395
- }
396
- ],
397
- mlAuditEvents: [
398
- {
399
- actionType: "addToLabel",
400
- documentIds: t
401
- }
402
- ]
403
- }
404
- };
405
- return u("labels", r);
406
- }
407
- async function ne(e, t, n = !0) {
408
- const r = {
409
- action: "remove",
410
- labels: e,
411
- ids: t,
412
- public: n,
413
- $auditRecord: {
414
- auditEvents: [
415
- {
416
- type: _.Label_RemoveDoc,
417
- detail: {
418
- public: n,
419
- label: e ? e.toString() : null,
420
- doccount: t ? t.length : 0
421
- }
422
- }
423
- ],
424
- mlAuditEvents: [
425
- {
426
- actionType: "removeFromLabel",
427
- documentIds: t
428
- }
429
- ]
430
- }
967
+ action: "save",
968
+ userSettings: e,
969
+ $auditRecord: { auditEvents: [t] }
431
970
  };
432
- return u("labels", r);
971
+ return p(r), d("usersettings", r);
433
972
  }
434
- async function re(e, t, n = !0) {
435
- const r = {
436
- action: "rename",
437
- labels: e,
438
- newLabel: t,
439
- public: n,
440
- auditEvents: {
441
- type: _.Label_Rename,
442
- detail: {
443
- public: n,
444
- oldlabel: e ? e.toString() : null,
445
- label: t
446
- }
447
- }
448
- };
449
- return u("labels", r);
450
- }
451
- async function oe(e, t = !0) {
452
- const n = {
453
- action: "delete",
454
- labels: e,
455
- public: t,
456
- auditEvents: {
457
- type: _.Label_Delete,
458
- detail: {
459
- public: t,
460
- label: e ? e.toString() : null
461
- }
462
- }
973
+ async function Qt(e, t) {
974
+ const a = {
975
+ action: "patch",
976
+ userSettings: e,
977
+ $auditRecord: t ? { auditEvents: [t] } : void 0
463
978
  };
464
- return u("labels", n);
979
+ return p(a), d("usersettings", a);
465
980
  }
466
- async function se(e, t, n = !0) {
467
- const r = {
468
- action: "bulkAdd",
469
- labels: e,
470
- query: t,
471
- public: n,
472
- auditEvents: {
473
- type: _.Label_Add,
474
- detail: {
475
- public: n,
476
- label: e ? e.toString() : null,
477
- query: t !== null ? t.name : null
478
- }
479
- }
480
- };
481
- return u("labels", r);
981
+ async function Gt() {
982
+ return Ae({}, { type: "UserSettings_Reset" });
482
983
  }
483
- async function ae(e, t, n = !0) {
484
- const r = {
485
- action: "bulkRemove",
486
- labels: e,
487
- query: t,
488
- public: n,
489
- auditEvents: {
490
- type: _.Label_Delete,
491
- detail: {
492
- public: n,
493
- label: e ? e.toString() : null,
494
- query: t !== null ? t.name : null
495
- }
496
- }
497
- };
498
- return u("labels", r);
499
- }
500
- const qe = {
501
- getUserRights: ee,
502
- add: te,
503
- remove: ne,
504
- rename: re,
505
- delete: oe,
506
- bulkAdd: se,
507
- bulkRemove: ae
508
- };
509
- function g(e) {
984
+ function _(e) {
510
985
  const t = new CustomEvent(
511
986
  "authenticated",
512
987
  {
@@ -517,344 +992,215 @@ function g(e) {
517
992
  );
518
993
  dispatchEvent(t);
519
994
  }
520
- async function ie() {
521
- const { autoOAuthProvider: e } = l, t = {
995
+ const Ne = async () => {
996
+ const { autoOAuthProvider: e } = u, t = {
522
997
  action: "getcode",
523
998
  provider: e,
524
999
  tokenInCookie: !0,
525
1000
  originalUrl: window.location.href
526
- }, n = await u("security.oauth", t);
527
- n.redirectUrl && (window.location.href = n.redirectUrl);
528
- }
529
- async function ce() {
530
- const { autoSAMLProvider: e } = l, t = {
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 () => {
1009
+ const { autoSAMLProvider: e } = u, t = {
531
1010
  action: "getresponse",
532
1011
  provider: e,
533
1012
  tokenInCookie: !0,
534
1013
  originalUrl: window.location.href
535
- }, n = await u("security.saml", t);
536
- n.redirectUrl && (window.location.href = n.redirectUrl);
537
- }
538
- const le = async (e) => {
539
- const { username: t, password: n } = e || {}, o = await u("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 = {
540
1023
  action: "get",
541
1024
  tokenInCookie: !0,
542
1025
  user: t,
543
- password: n,
1026
+ password: r,
544
1027
  noUserOverride: !0,
545
1028
  noAutoAuthentication: !0
546
- });
547
- return o.csrfToken ? (v(o.csrfToken), !0) : !1;
548
- }, ue = 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 () => {
549
1037
  const e = new URLSearchParams({
550
1038
  action: "deleteWebTokenCookie",
551
1039
  noUserOverride: "true",
552
1040
  noAutoAuthentication: "true"
553
1041
  });
554
- return h("challenge", e);
555
- }, D = () => localStorage.getItem("csrfToken") || "", v = (e) => localStorage.setItem("csrfToken", e), We = async (e) => {
556
- const { useSSO: t } = l;
557
- if (D() || t)
558
- return g(!0), !0;
559
- const { username: n, password: r } = e || {};
560
- let o;
561
- return n && r ? (L({ useCredentials: !0 }), o = await le(e)) : o = await de(), g(o), o;
562
- }, Ye = async () => {
563
- const { useCredentials: e, userOverrideActive: t } = l;
564
- localStorage.removeItem("csrfToken"), e && !t ? (await ue()).methodresult === "ok" ? g(!1) : console.error("logout failed") : g(!1);
565
- }, Ke = () => !!D(), de = async () => {
566
- const { backendUrl: e, apiPath: t, autoOAuthProvider: n, autoSAMLProvider: r } = l, s = await (await fetch(`${e}/${t}/challenge?action=getCsrfToken&suppressErrors=true`)).json();
567
- if (s != null && s.csrfToken)
568
- return v(s.csrfToken), !0;
569
- if (n)
570
- await ie();
571
- else if (r)
572
- await ce();
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 });
573
1049
  else
574
- throw new Error("No CSRF token found and no autoOauthProvider nor autoSAMLProvider are specified");
575
- return !1;
576
- };
577
- function Ze(e, t) {
578
- var o;
579
- return !(e != null && e.items) || ((o = e == null ? void 0 : e.items) == null ? void 0 : o.length) === 0 ? [] : e.items.reduce((s, i) => {
580
- if (!i.value || i.value === "") return s;
581
- const a = fe(i, e.column);
582
- return s.push({
583
- operator: a.operator,
584
- value: a.value,
585
- display: i.display || a.display,
586
- filters: a.filters,
587
- disabled: i.count === 0,
588
- hidden: i.count === 0 && e.isDistribution ? !t : !1
589
- }), s;
590
- }, []);
591
- }
592
- function fe(e, t) {
593
- const n = t, r = e.value.match(/.*\:\(?([><=\d\-\.AND ]+)\)?/);
594
- if (r != null && r[1]) {
595
- const s = (r == null ? void 0 : r[1].split(" AND ")).map((i) => {
596
- const a = i.indexOf(">=") !== -1 ? "gte" : "lt";
597
- let c = i.substring(i.indexOf(" ") + 1);
598
- return { field: n, operator: a, value: c, display: e.display || e.value };
599
- });
600
- if (s.length === 2)
601
- return { field: n, operator: "and", filters: s, value: e.value, display: s[0].display || s[0].value };
602
- if (s.length === 1)
603
- return { ...s[0], field: n };
604
- throw new Error("Failed to parse distribution expression");
605
- }
606
- return { field: n, operator: "eq", value: e.value, display: e.display };
607
- }
608
- function Ee(e, t, n) {
609
- return e.valuesAreExpressions ? t.display === n.display : t.value === n.value;
610
- }
611
- function Te(e, t) {
612
- const n = [];
613
- if (e.length > 0) {
614
- const r = /* @__PURE__ */ new Map(), o = t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), s = new RegExp("\\b" + o, "i");
615
- e.forEach((i) => {
616
- if (i.display.length > 1) {
617
- const a = s.exec(i.display);
618
- G(n, r, "/", i.display, +(i.frequency || 0), 1, ((a == null ? void 0 : a.index) || 0) + t.length);
619
- }
620
- });
621
- }
622
- return n;
623
- }
624
- function G(e, t, n, r, o, s, i) {
625
- const a = r.indexOf("/", n.length), c = r.substring(0, a + 1);
626
- let d = t.get(c);
627
- if (!d) {
628
- const f = c.replace(/^\/|\/$/g, "");
629
- d = {
630
- value: r.substring(n.length, a),
631
- count: o,
632
- items: [],
633
- hasChildren: !1,
634
- $level: s,
635
- $opened: i >= c.length,
636
- $path: f
637
- }, t.set(c, d), e.push(d);
638
- }
639
- c.length < r.length && (d.hasChildren = !0, G(d.items, t, c, r, o, s + 1, i));
640
- }
641
- function et(e, t) {
642
- return e.reduce((n, r) => (t(r) ? n.true.push(r) : n.false.push(r), n), { true: [], false: [] });
643
- }
644
- const _e = /(([\+\-])?\(([^\)]+)\))|(([\+\-])?\[([^\]]+)\])|(([\+\-])?\"([^\"]+)\")|(([\+\-])?\/([^\/]+)\/)|(([\+\-])?(\S+))/g, he = 2, $ = 3, ke = 5, M = 6, ge = 8, F = 9, Se = 11, I = 12, pe = 14, B = 15;
645
- function m(e) {
646
- if (!e) return [];
647
- const t = [], n = e.matchAll(_e);
648
- for (let r of n)
649
- r[$] ? t.push({ type: "group", value: r[$], op: r[he] }) : r[M] ? t.push({ type: "adjacent", value: r[M], op: r[ke] }) : r[F] ? t.push({ type: "exact", value: r[F], op: r[ge] }) : r[I] ? t.push({ type: "regex", value: r[I], op: r[Se] }) : r[B] && t.push({ type: "token", value: r[B], op: r[pe] });
650
- return t;
651
- }
652
- function y(e) {
653
- return e.map((t) => {
654
- const n = t.op || "";
655
- switch (t.type) {
656
- case "group":
657
- return `${n}(${t.value})`;
658
- case "adjacent":
659
- return `${n}[${t.value}]`;
660
- case "exact":
661
- return `${n}"${t.value}"`;
662
- case "regex":
663
- return `${n}/${t.value}/`;
664
- case "token":
665
- 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;
666
1067
  }
667
- }).join(" ");
668
- }
669
- function tt(e, t, n) {
670
- let r = m(e);
671
- for (let o of t)
672
- r.push({ type: "adjacent", value: o, op: n });
673
- return y(r);
674
- }
675
- function nt(e, t) {
676
- const n = m(t), r = n.findIndex((o) => o.value === e);
677
- return r !== -1 ? (n.splice(r, 1), t = y(n)) : t;
678
- }
679
- function rt(e) {
680
- const t = m(e).filter((n) => n.type !== "adjacent");
681
- return y(t);
682
- }
683
- function ot(e) {
684
- return m(e).filter((t) => t.type === "adjacent").map((t) => t.value);
685
- }
686
- function st(e, t, n) {
687
- const r = new Intl.RelativeTimeFormat(e, { numeric: "auto" }), { offset: o, unit: s, isFuture: i } = me(t, n);
688
- return r.format(o * (i ? 1 : -1), s);
689
- }
690
- function me(e, t) {
691
- const n = new Date(e), r = t ? new Date(t) : /* @__PURE__ */ new Date(), o = Math.abs(r.getTime() - n.getTime());
692
- return {
693
- offset: Math.floor(o / (1e3 * 60 * 60 * 24)),
694
- unit: "day",
695
- isFuture: n > r
696
- };
697
- }
698
- function at(e) {
699
- if (e === void 0) return;
700
- const { q: t, f: n, p: r, s: o, t: s, ...i } = k(e), [a] = e.split("?");
701
- return {
702
- path: a,
703
- text: t,
704
- filters: n ? V(n) : void 0,
705
- page: r ? parseInt(r, 10) : void 0,
706
- sort: o,
707
- tab: s,
708
- ...i
709
- };
710
- }
711
- function it(e) {
712
- if (e === void 0) return [];
713
- const { f: t } = k(e);
714
- return V(t);
715
- }
716
- function V(e) {
717
- const t = decodeURIComponent(e);
718
- return JSON.parse(t ?? "[]");
719
- }
720
- function k(e) {
721
- const t = e.split("?")[1];
722
- if (t === void 0) return {};
723
- const n = new URLSearchParams(t);
724
- return Object.fromEntries(n);
725
- }
726
- function ct(e) {
727
- const { q: t = "" } = k(e);
728
- return t;
729
- }
730
- function lt(e) {
731
- const { id: t } = k(e);
732
- return decodeURIComponent(t);
733
- }
734
- function ut(e) {
735
- const { p: t = "0" } = k(e);
736
- return parseInt(t, 10);
737
- }
738
- function dt(e) {
739
- const { t } = k(e);
740
- return t;
741
- }
742
- function ft(e, t) {
743
- if (!e)
744
- return e;
745
- let n = 0;
746
- const r = e.length;
747
- let o = 0;
748
- if (e[o] === "[") {
749
- for (; o < r && /[0-9]/.test(e[o]); )
750
- o++;
751
- e[o] === "]" && (n = o + 1);
752
- }
753
- const s = b(e, n, !1);
754
- if (!s)
755
- return e;
756
- const i = t.charCodeAt(0), a = t.charCodeAt(1);
757
- let c = s;
758
- for (; c; )
759
- if (i === c.lang1 && a === c.lang2) {
760
- const f = b(e, c.end + 4, !0);
761
- return e.substring(f.start, f.end);
762
- } else
763
- c = b(e, c.end + 4, !1);
764
- const d = e.substring(s.start, s.end);
765
- return d || e;
766
- }
767
- function b(e, t, n) {
768
- for (let r = t, o = e.length - 3; r < o; r++)
769
- if (e[r] === "[" && e[r + 3] === "]")
770
- return {
771
- start: t,
772
- end: r,
773
- lang1: e.charCodeAt(r + 1),
774
- lang2: e.charCodeAt(r + 2)
775
- };
776
- if (n)
777
- return {
778
- start: t,
779
- end: e.length,
780
- lang1: -1,
781
- lang2: -1
782
- };
783
- }
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
+ };
784
1103
  export {
785
- Fe as Audit,
786
- _ as AuditEventType,
787
- Me as MINIMUM_COMPATIBLE_SERVER_API_VERSION,
788
- P as addAuditAdditionalInfo,
789
- tt as addConcepts,
790
- W as addSessionId,
791
- Y as addUrl,
792
- Ee as aggregationItemStrictCompare,
793
- Pe as appInitializerFn,
794
- et as bisect,
795
- x as buildPathsAndLevels,
796
- Q as createHeaders,
797
- Qe as deleteUserSettings,
798
- ue as deleteWebTokenCookie,
799
- Oe as escapeExpr,
800
- De as fetchAggregation,
801
- xe as fetchApp,
802
- j as fetchAppPreLogin,
803
- Ce as fetchBulkQuery,
804
- ze as fetchDataset,
805
- Je as fetchDatasetList,
806
- He as fetchDatasets,
807
- Xe as fetchLabels,
808
- Re as fetchPreview,
809
- be as fetchPreviewUrl,
810
- Le as fetchPrincipal,
811
- we as fetchQuery,
812
- Ve as fetchSponsoredLinks,
813
- Ae as fetchSuggest,
814
- Ge as fetchSuggestField,
815
- Ne as fetchSuggestQuery,
816
- je as fetchTextChunks,
817
- Ie as fetchUserSettings,
818
- h as get,
819
- ot as getConcepts,
820
- V as getFiltersFromURI,
821
- it as getFiltersFromUrl,
822
- lt as getIdFromUrl,
823
- le as getJWToken,
824
- ye as getMetadata,
825
- me as getOffsetFromDates,
826
- ut as getQueryPageFromUrl,
827
- at as getQueryParamsFromUrl,
828
- dt as getQueryTabFromUrl,
829
- ct as getQueryTextFromUrl,
830
- st as getRelativeDate,
831
- D as getToken,
832
- l as globalConfig,
833
- X as guid,
834
- S as handleResponse,
835
- z as isArrayBuffer,
836
- Ke as isAuthenticated,
837
- H as isBlob,
838
- Ue as isJsonable,
839
- p as isObject,
840
- J as isString,
841
- qe as labels,
842
- We as login,
843
- Ye as logout,
844
- m as parseText,
845
- fe as parseValueAndOperatorFromItem,
846
- Be as patchUserSettings,
847
- u as post,
848
- k as queryParamsFromUrl,
849
- nt as removeConcept,
850
- rt as removeConcepts,
851
- ve as resolveToColumnName,
852
- y as rewriteText,
853
- T as saveUserSettings,
854
- L as setGlobalConfig,
855
- v as setToken,
856
- $e as sha512,
857
- Te as suggestionsToTreeAggregationNodes,
858
- ft as sysLang,
859
- Ze as translateAggregationToDateOptions
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,
1170
+ u as globalConfig,
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
860
1206
  };