@sinequa/atomic 0.0.61 → 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 (77) hide show
  1. package/README.md +60 -11
  2. package/dist/atomic.js +1089 -735
  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/index.d.ts +1 -1
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/types/api-endpoints.d.ts +1 -1
  17. package/dist/types/api-endpoints.d.ts.map +1 -1
  18. package/dist/types/config/CCAppPreLogin.d.ts +7 -3
  19. package/dist/types/config/CCAppPreLogin.d.ts.map +1 -1
  20. package/dist/types/config/index.d.ts +2 -5
  21. package/dist/types/config/index.d.ts.map +1 -1
  22. package/dist/types/export/types.d.ts +22 -0
  23. package/dist/types/export/types.d.ts.map +1 -0
  24. package/dist/types/index.d.ts +1 -0
  25. package/dist/types/index.d.ts.map +1 -1
  26. package/dist/types/search/QueryIntentEntity.d.ts +16 -1
  27. package/dist/types/search/QueryIntentEntity.d.ts.map +1 -1
  28. package/dist/types/search/QueryIntentMatch.d.ts +17 -0
  29. package/dist/types/search/QueryIntentMatch.d.ts.map +1 -0
  30. package/dist/types/search/QueryIntentResponse.d.ts +9 -0
  31. package/dist/types/search/QueryIntentResponse.d.ts.map +1 -0
  32. package/dist/types/search/index.d.ts +4 -2
  33. package/dist/types/search/index.d.ts.map +1 -1
  34. package/dist/utils/bisect.d.ts.map +1 -0
  35. package/dist/utils/index.d.ts +4 -1
  36. package/dist/utils/index.d.ts.map +1 -1
  37. package/dist/utils/is-not-input-event.d.ts +2 -0
  38. package/dist/utils/is-not-input-event.d.ts.map +1 -0
  39. package/dist/utils/logger.d.ts +40 -0
  40. package/dist/utils/logger.d.ts.map +1 -0
  41. package/dist/utils/query-params.d.ts +1 -3
  42. package/dist/utils/query-params.d.ts.map +1 -1
  43. package/dist/utils/utilities.d.ts +23 -0
  44. package/dist/utils/utilities.d.ts.map +1 -0
  45. package/dist/web-api/fetch-aggregation.d.ts.map +1 -1
  46. package/dist/web-api/fetch-app.d.ts.map +1 -1
  47. package/dist/web-api/fetch-audit.d.ts +3 -2
  48. package/dist/web-api/fetch-audit.d.ts.map +1 -1
  49. package/dist/web-api/fetch-dataset.d.ts +2 -2
  50. package/dist/web-api/fetch-dataset.d.ts.map +1 -1
  51. package/dist/web-api/fetch-labels.d.ts +1 -1
  52. package/dist/web-api/fetch-labels.d.ts.map +1 -1
  53. package/dist/web-api/fetch-query-export.d.ts +19 -0
  54. package/dist/web-api/fetch-query-export.d.ts.map +1 -0
  55. package/dist/web-api/fetch-query-intent.d.ts +13 -0
  56. package/dist/web-api/fetch-query-intent.d.ts.map +1 -0
  57. package/dist/web-api/fetch-query.d.ts.map +1 -1
  58. package/dist/web-api/fetch-similar-documents.d.ts +13 -0
  59. package/dist/web-api/fetch-similar-documents.d.ts.map +1 -0
  60. package/dist/web-api/fetch-suggest.d.ts.map +1 -1
  61. package/dist/web-api/helpers.d.ts +111 -1
  62. package/dist/web-api/helpers.d.ts.map +1 -1
  63. package/dist/web-api/index.d.ts +11 -8
  64. package/dist/web-api/index.d.ts.map +1 -1
  65. package/package.json +9 -8
  66. package/dist/auth/auth.d.ts +0 -39
  67. package/dist/auth/auth.d.ts.map +0 -1
  68. package/dist/auth/index.d.ts.map +0 -1
  69. package/dist/types/config/ExportDialogModel.d.ts +0 -13
  70. package/dist/types/config/ExportDialogModel.d.ts.map +0 -1
  71. package/dist/types/config/ExportOutputFormat.d.ts +0 -10
  72. package/dist/types/config/ExportOutputFormat.d.ts.map +0 -1
  73. package/dist/types/config/ExportSourceType.d.ts +0 -10
  74. package/dist/types/config/ExportSourceType.d.ts.map +0 -1
  75. package/dist/utils/array/bisect.d.ts.map +0 -1
  76. /package/dist/{auth → authentication}/index.d.ts +0 -0
  77. /package/dist/utils/{array/bisect.d.ts → bisect.d.ts} +0 -0
package/dist/atomic.js CHANGED
@@ -1,512 +1,995 @@
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
+ 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 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 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((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 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 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 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
- 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, 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
- ...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
159
  }
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);
166
- }
167
- function ve(e, t, n) {
168
- var s, i, a, c;
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;
206
+ }
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 d = Object.keys(t.queries).find((C) => C === (n == null ? void 0 : n.toLowerCase()));
270
+ if (r) {
271
+ const l = Object.keys(t.queries).find((I) => I === (r == null ? void 0 : r.toLowerCase()));
172
272
  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);
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((d) => {
280
+ const a = (i = (c = t.indexes) == null ? void 0 : c._) == null ? void 0 : i.columns, n = Object.entries(a).find((l) => {
181
281
  var f;
182
- return (f = d[1].aliases) == null ? void 0 : f.includes(e);
282
+ return (f = l[1].aliases) == null ? void 0 : f.includes(e);
183
283
  });
184
- if (o) return o[0];
185
- }
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 }];
189
- }
190
- function p(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 p(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 p(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 Ue(e) {
203
- return (p(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 X(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 Oe(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 $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(""));
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
+ }
341
+ }
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
+ }
226
413
  }
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
- function P(e) {
231
- let t = q(e.$auditRecord);
232
- t && (W(t), Y(t)), e.$auditRecord = t;
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
+ }
233
497
  }
234
- function q(e) {
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) {
235
528
  if (!e)
236
529
  return;
237
530
  let t;
238
531
  if (Array.isArray(e))
239
532
  t = e;
240
- else if (p(e)) {
241
- const n = e;
242
- if (n.auditEvents || n.mlAuditEvents)
243
- return n;
533
+ else if (D(e)) {
534
+ const r = e;
535
+ if (r.auditEvents || r.mlAuditEvents)
536
+ return r;
244
537
  t = [e];
245
538
  }
246
539
  return { auditEvents: t };
247
540
  }
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;
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;
253
546
  }), e;
254
547
  }
255
- function Y(e) {
256
- var n;
548
+ function Ce(e) {
549
+ var r;
257
550
  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;
551
+ return (r = e == null ? void 0 : e.auditEvents) == null || r.forEach((a) => {
552
+ a.detail || (a.detail = {}), a.detail.url = t;
260
553
  }), e;
261
554
  }
262
- function K() {
263
- return (!R || Z()) && (R = X()), N = /* @__PURE__ */ new Date(), R;
555
+ function Re() {
556
+ return (!A || xe()) && (A = fe()), M = /* @__PURE__ */ new Date(), A;
264
557
  }
265
- function Z() {
266
- return (/* @__PURE__ */ new Date()).getTime() - N.getTime() > 10 * 60 * 1e3;
558
+ function xe() {
559
+ return (/* @__PURE__ */ new Date()).getTime() - M.getTime() > 10 * 60 * 1e3;
267
560
  }
268
- async function E(e) {
269
- const t = {
270
- event: _.None,
561
+ async function pe(e, t = !0) {
562
+ const r = {
563
+ event: k.None,
271
564
  $auditRecord: e
272
565
  };
273
- return P(t), u("audit.notify", t);
566
+ return P(r, t), d("audit.notify", r);
274
567
  }
275
- const Fe = { notify: E };
276
- async function Ie() {
277
- const { app: e } = l, t = new URLSearchParams({
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);
582
+ }
583
+ async function ve() {
584
+ const { app: e } = u, t = new URLSearchParams({
278
585
  app: e || "",
279
- action: "load"
586
+ preLogin: "true"
280
587
  });
281
- return h("usersettings", t);
588
+ return b("app", t);
282
589
  }
283
- async function T(e, t) {
284
- const n = {
285
- action: "save",
286
- userSettings: e,
287
- $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] }
288
850
  };
289
- return P(n), u("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);
290
868
  }
291
- async function Be(e, t) {
292
- const r = {
293
- action: "patch",
294
- userSettings: e,
295
- $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
+ }
296
899
  };
297
- return P(r), u("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
+ );
298
912
  }
299
- async function Qe() {
300
- return T({}, { 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 }));
301
920
  }
302
- async function Ae(e, t, n, r, o) {
303
- const { app: s } = l;
304
- return (await u("search.suggest", {
305
- app: s || "",
921
+ async function At(e, t, r, a, n) {
922
+ const { app: o } = u, s = {
923
+ app: o || "",
306
924
  suggestQuery: e,
307
925
  text: t,
308
- filter: n,
309
- kinds: r,
310
- showSource: o
311
- })).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
+ }
312
935
  }
313
- async function Ne(e, t, n, r) {
314
- const { app: o } = l;
315
- return (await u("suggestquery", {
316
- app: o || "",
936
+ async function Nt(e, t, r, a) {
937
+ const { app: n } = u;
938
+ return (await d("suggestquery", {
939
+ app: n || "",
317
940
  suggestQuery: e,
318
941
  text: t,
319
- query: n,
320
- kinds: r
942
+ query: r,
943
+ kinds: a
321
944
  })).suggests;
322
945
  }
323
- async function Ge(e, t) {
946
+ async function Bt(e, t) {
324
947
  if (!t) return Promise.resolve([]);
325
- const { app: n } = l;
326
- return (await u("suggestfield", {
327
- app: n || "",
948
+ const { app: r } = u;
949
+ return (await d("suggestfield", {
950
+ app: r || "",
328
951
  text: e,
329
952
  action: "suggests",
330
953
  fields: t
331
954
  })).suggests;
332
955
  }
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", {
956
+ async function Ft(e, t, r, a, n, o) {
957
+ return d("doc.textchunks", {
343
958
  id: e,
344
959
  textChunks: t,
345
- highlights: n,
346
- query: r,
347
- leftSentencesCount: o,
348
- rightSentencesCount: s
960
+ highlights: r,
961
+ query: a,
962
+ leftSentencesCount: n,
963
+ rightSentencesCount: o
349
964
  });
350
965
  }
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"
966
+ async function qt() {
967
+ const { app: e } = u, t = new URLSearchParams({
968
+ app: e || "",
969
+ action: "load"
377
970
  });
378
- return h("labels", t);
379
- }
380
- async function te(e, t, n = !0) {
381
- 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);
971
+ return b("usersettings", t);
406
972
  }
407
- async function ne(e, t, n = !0) {
973
+ async function Ae(e, t) {
408
974
  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
- }
975
+ action: "save",
976
+ userSettings: e,
977
+ $auditRecord: { auditEvents: [t] }
431
978
  };
432
- return u("labels", r);
979
+ return P(r), d("usersettings", r);
433
980
  }
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
- }
981
+ async function Qt(e, t) {
982
+ const a = {
983
+ action: "patch",
984
+ userSettings: e,
985
+ $auditRecord: t ? { auditEvents: [t] } : void 0
463
986
  };
464
- return u("labels", n);
987
+ return P(a), d("usersettings", a);
465
988
  }
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);
989
+ async function Gt() {
990
+ return Ae({}, { type: "UserSettings_Reset" });
482
991
  }
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) {
992
+ function _(e) {
510
993
  const t = new CustomEvent(
511
994
  "authenticated",
512
995
  {
@@ -517,344 +1000,215 @@ function g(e) {
517
1000
  );
518
1001
  dispatchEvent(t);
519
1002
  }
520
- async function ie() {
521
- const { autoOAuthProvider: e } = l, t = {
1003
+ const Ne = async () => {
1004
+ const { autoOAuthProvider: e } = u, t = {
522
1005
  action: "getcode",
523
1006
  provider: e,
524
1007
  tokenInCookie: !0,
525
1008
  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 = {
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 () => {
1017
+ const { autoSAMLProvider: e } = u, t = {
531
1018
  action: "getresponse",
532
1019
  provider: e,
533
1020
  tokenInCookie: !0,
534
1021
  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", {
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 = {
540
1031
  action: "get",
541
1032
  tokenInCookie: !0,
542
1033
  user: t,
543
- password: n,
1034
+ password: r,
544
1035
  noUserOverride: !0,
545
1036
  noAutoAuthentication: !0
546
- });
547
- return o.csrfToken ? (v(o.csrfToken), !0) : !1;
548
- }, ue = 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 () => {
549
1045
  const e = new URLSearchParams({
550
1046
  action: "deleteWebTokenCookie",
551
1047
  noUserOverride: "true",
552
1048
  noAutoAuthentication: "true"
553
1049
  });
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();
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 });
573
1057
  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}`;
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;
666
1075
  }
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
- }
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
+ };
784
1111
  export {
785
- Fe as Audit,
786
- _ as AuditEventType,
787
- Me 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,
788
1124
  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
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,
1178
+ u as globalConfig,
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
860
1214
  };