cap-copilot-widget 0.1.5 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/btp-copilot.esm.js +52 -41
- package/dist/btp-copilot.esm.js.map +1 -1
- package/dist/btp-copilot.js +6 -6
- package/dist/btp-copilot.js.map +1 -1
- package/package.json +15 -3
- package/postinstall.js +38 -9
package/dist/btp-copilot.esm.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
const
|
|
1
|
+
const $ = class $ {
|
|
2
2
|
static resolve(e) {
|
|
3
3
|
if (e) return e.replace(/^Bearer\s+/i, "");
|
|
4
4
|
const t = window.__BTP_COPILOT_TOKEN__;
|
|
5
5
|
if (t) return t.replace(/^Bearer\s+/i, "");
|
|
6
|
-
const n =
|
|
6
|
+
const n = $._fromCookie();
|
|
7
7
|
if (n) return n;
|
|
8
8
|
try {
|
|
9
9
|
const r = localStorage.getItem("access_token");
|
|
@@ -20,7 +20,7 @@ const A = class A {
|
|
|
20
20
|
const e = document.cookie.split(";");
|
|
21
21
|
for (const t of e) {
|
|
22
22
|
const [n, ...r] = t.trim().split("=");
|
|
23
|
-
if (
|
|
23
|
+
if ($.XSUAA_COOKIE_NAMES.includes(n.trim()))
|
|
24
24
|
return decodeURIComponent(r.join("=").trim());
|
|
25
25
|
}
|
|
26
26
|
} catch {
|
|
@@ -28,13 +28,13 @@ const A = class A {
|
|
|
28
28
|
return null;
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
|
-
|
|
31
|
+
$.XSUAA_COOKIE_NAMES = [
|
|
32
32
|
"x-uaa-token",
|
|
33
33
|
"xsuaa_token",
|
|
34
34
|
"access_token",
|
|
35
35
|
"X-Authorization"
|
|
36
36
|
];
|
|
37
|
-
let S =
|
|
37
|
+
let S = $;
|
|
38
38
|
class C {
|
|
39
39
|
static getHash() {
|
|
40
40
|
var e, t, n, r;
|
|
@@ -382,31 +382,31 @@ const m = class m {
|
|
|
382
382
|
try {
|
|
383
383
|
const i = new DOMParser().parseFromString(e, "text/xml"), o = /* @__PURE__ */ new Map();
|
|
384
384
|
i.querySelectorAll("EntitySet").forEach((s) => {
|
|
385
|
-
const c = s.getAttribute("EntityType") ?? "", h = c.split(".").pop() ?? c,
|
|
386
|
-
o.set(h,
|
|
385
|
+
const c = s.getAttribute("EntityType") ?? "", h = c.split(".").pop() ?? c, d = s.getAttribute("Name") ?? h;
|
|
386
|
+
o.set(h, d);
|
|
387
387
|
}), i.querySelectorAll("EntityType").forEach((s) => {
|
|
388
388
|
const c = s.getAttribute("Name") ?? "";
|
|
389
389
|
if (!c) return;
|
|
390
390
|
const h = new Set(
|
|
391
391
|
Array.from(s.querySelectorAll("Key > PropertyRef")).map(
|
|
392
|
-
(
|
|
392
|
+
(p) => p.getAttribute("Name") ?? ""
|
|
393
393
|
)
|
|
394
|
-
),
|
|
394
|
+
), d = Array.from(
|
|
395
395
|
s.querySelectorAll("Property")
|
|
396
|
-
).map((
|
|
397
|
-
name:
|
|
398
|
-
type: m._shortType(
|
|
399
|
-
isKey: h.has(
|
|
400
|
-
nullable:
|
|
396
|
+
).map((p) => ({
|
|
397
|
+
name: p.getAttribute("Name") ?? "",
|
|
398
|
+
type: m._shortType(p.getAttribute("Type") ?? ""),
|
|
399
|
+
isKey: h.has(p.getAttribute("Name") ?? ""),
|
|
400
|
+
nullable: p.getAttribute("Nullable") !== "false"
|
|
401
401
|
})), b = Array.from(
|
|
402
402
|
s.querySelectorAll("NavigationProperty")
|
|
403
|
-
).map((
|
|
404
|
-
const v =
|
|
403
|
+
).map((p) => {
|
|
404
|
+
const v = p.getAttribute("Type") ?? p.getAttribute("ToRole") ?? "", w = v.startsWith("Collection("), u = p.querySelector("ReferentialConstraint");
|
|
405
405
|
return {
|
|
406
|
-
name:
|
|
406
|
+
name: p.getAttribute("Name") ?? "",
|
|
407
407
|
type: m._shortType(v),
|
|
408
408
|
cardinality: w ? "*" : "1",
|
|
409
|
-
partner:
|
|
409
|
+
partner: p.getAttribute("Partner") ?? void 0,
|
|
410
410
|
foreignKey: (u == null ? void 0 : u.getAttribute("Property")) ?? void 0,
|
|
411
411
|
referencedKey: (u == null ? void 0 : u.getAttribute("ReferencedProperty")) ?? void 0
|
|
412
412
|
};
|
|
@@ -414,7 +414,7 @@ const m = class m {
|
|
|
414
414
|
n.push({
|
|
415
415
|
name: c,
|
|
416
416
|
entitySetName: o.get(c) ?? c,
|
|
417
|
-
properties:
|
|
417
|
+
properties: d,
|
|
418
418
|
navProperties: b
|
|
419
419
|
});
|
|
420
420
|
});
|
|
@@ -431,14 +431,14 @@ const m = class m {
|
|
|
431
431
|
});
|
|
432
432
|
}
|
|
433
433
|
const l = (s, c) => {
|
|
434
|
-
const h = s.getAttribute("Name") ?? "",
|
|
434
|
+
const h = s.getAttribute("Name") ?? "", d = [];
|
|
435
435
|
let b;
|
|
436
436
|
s.querySelectorAll("Parameter").forEach((w, u) => {
|
|
437
437
|
const x = w.getAttribute("Name") ?? "", g = m._shortType(w.getAttribute("Type") ?? "");
|
|
438
|
-
c && u === 0 ? b = g.replace(/\[\]$/, "") :
|
|
438
|
+
c && u === 0 ? b = g.replace(/\[\]$/, "") : d.push({ name: x, type: g });
|
|
439
439
|
});
|
|
440
|
-
const
|
|
441
|
-
return { name: h, bound: c, entity: b, parameters:
|
|
440
|
+
const p = s.querySelector("ReturnType"), v = p ? m._shortType(p.getAttribute("Type") ?? "") : void 0;
|
|
441
|
+
return { name: h, bound: c, entity: b, parameters: d, returnType: v };
|
|
442
442
|
};
|
|
443
443
|
i.querySelectorAll("Action").forEach((s) => {
|
|
444
444
|
const c = s.getAttribute("IsBound") === "true";
|
|
@@ -448,10 +448,10 @@ const m = class m {
|
|
|
448
448
|
a.push(l(s, c));
|
|
449
449
|
}), i.querySelectorAll("FunctionImport").forEach((s) => {
|
|
450
450
|
const c = s.getAttribute("Name") ?? "", h = [];
|
|
451
|
-
s.querySelectorAll("Parameter").forEach((
|
|
451
|
+
s.querySelectorAll("Parameter").forEach((d) => {
|
|
452
452
|
h.push({
|
|
453
|
-
name:
|
|
454
|
-
type: m._shortType(
|
|
453
|
+
name: d.getAttribute("Name") ?? "",
|
|
454
|
+
type: m._shortType(d.getAttribute("Type") ?? "")
|
|
455
455
|
});
|
|
456
456
|
}), a.push({ name: c, bound: !1, parameters: h });
|
|
457
457
|
});
|
|
@@ -516,16 +516,16 @@ const f = class f {
|
|
|
516
516
|
if (o) {
|
|
517
517
|
const l = y.buildSchemaDocuments(o, t.service_url);
|
|
518
518
|
if (l.length > 0) {
|
|
519
|
-
const h = l.map((
|
|
520
|
-
${
|
|
519
|
+
const h = l.map((d) => `## ${d.title}
|
|
520
|
+
${d.content}`).join(`
|
|
521
521
|
|
|
522
522
|
`);
|
|
523
523
|
t.extra = { ...t.extra ?? {}, schema_hint: h };
|
|
524
524
|
}
|
|
525
525
|
const s = (r = t.extra) == null ? void 0 : r.backend_url;
|
|
526
526
|
if (s && o.rawXml) {
|
|
527
|
-
const h = t.app_id,
|
|
528
|
-
f._registerMetadata(s, h,
|
|
527
|
+
const h = t.app_id, d = t.service_url;
|
|
528
|
+
f._registerMetadata(s, h, d, o.rawXml, i);
|
|
529
529
|
}
|
|
530
530
|
const c = (a = t.entity_data) == null ? void 0 : a._entity;
|
|
531
531
|
if (c && t.service_url)
|
|
@@ -573,16 +573,16 @@ ${p.content}`).join(`
|
|
|
573
573
|
const s = `${t}::${l}`, c = Date.now(), h = f._linkedEntityCache.get(s);
|
|
574
574
|
if (h && c - h.fetchedAt < f._LINKED_CACHE_TTL)
|
|
575
575
|
return h.data;
|
|
576
|
-
const
|
|
576
|
+
const d = {}, b = typeof l == "number" ? String(l) : `'${l}'`, p = y.findLinkedEntities(r, i.name);
|
|
577
577
|
await Promise.all(
|
|
578
|
-
|
|
578
|
+
p.map(async (u) => {
|
|
579
579
|
try {
|
|
580
|
-
const x = `${e}/${u.entitySetName}?$filter=${encodeURIComponent(`${u.foreignKey} eq ${b}`)}&$top=50`, { data: g, error: E, errorContext:
|
|
580
|
+
const x = `${e}/${u.entitySetName}?$filter=${encodeURIComponent(`${u.foreignKey} eq ${b}`)}&$top=50`, { data: g, error: E, errorContext: A } = await y.fetchEntityData(x, a);
|
|
581
581
|
if (E)
|
|
582
|
-
y.recordFetchError(u.entitySetName, x, E),
|
|
582
|
+
y.recordFetchError(u.entitySetName, x, E), A && (d[`linked_${u.entitySetName}_error`] = A);
|
|
583
583
|
else if (g) {
|
|
584
584
|
const I = g.value ?? (Array.isArray(g) ? g : [g]);
|
|
585
|
-
I.length > 0 && (
|
|
585
|
+
I.length > 0 && (d[`linked_${u.entitySetName}`] = I);
|
|
586
586
|
}
|
|
587
587
|
} catch {
|
|
588
588
|
}
|
|
@@ -593,20 +593,20 @@ ${p.content}`).join(`
|
|
|
593
593
|
);
|
|
594
594
|
return await Promise.all(
|
|
595
595
|
w.map(async (u) => {
|
|
596
|
-
if (
|
|
596
|
+
if (d[`linked_${u.name}`] == null)
|
|
597
597
|
try {
|
|
598
598
|
const x = `${e}/${v}(${b})/${u.name}`, { data: g, error: E } = await y.fetchEntityData(x, a);
|
|
599
599
|
if (!E && g) {
|
|
600
|
-
const
|
|
601
|
-
|
|
600
|
+
const A = g.value ?? g;
|
|
601
|
+
A != null && (d[`linked_${u.name}`] = A);
|
|
602
602
|
}
|
|
603
603
|
} catch {
|
|
604
604
|
}
|
|
605
605
|
})
|
|
606
606
|
), f._linkedEntityCache.set(s, {
|
|
607
|
-
data:
|
|
607
|
+
data: d,
|
|
608
608
|
fetchedAt: c
|
|
609
|
-
}),
|
|
609
|
+
}), d;
|
|
610
610
|
}
|
|
611
611
|
static async _registerMetadata(e, t, n, r, a) {
|
|
612
612
|
const i = `${t}::${n}`;
|
|
@@ -840,7 +840,7 @@ const j = `/* ── Host element ───────────────
|
|
|
840
840
|
super(...arguments), this._open = !1, this._isFullscreen = !1, this._iframeEl = null, this._contextTimer = null, this._manualRecord = null;
|
|
841
841
|
}
|
|
842
842
|
connectedCallback() {
|
|
843
|
-
this._config = this._readConfig(), this._buildShadow(), this._startContextPolling();
|
|
843
|
+
this._config = this._readConfig(), this.getAttribute("iframe-url") || this._fetchServerConfig(), this._buildShadow(), this._startContextPolling();
|
|
844
844
|
const e = (t) => {
|
|
845
845
|
if (!t.data || typeof t.data != "object") return;
|
|
846
846
|
const n = this._iframeOrigin();
|
|
@@ -1052,6 +1052,17 @@ const j = `/* ── Host element ───────────────
|
|
|
1052
1052
|
var e, t;
|
|
1053
1053
|
(t = (e = this.shadowRoot) == null ? void 0 : e.querySelector(".badge")) == null || t.classList.remove("visible");
|
|
1054
1054
|
}
|
|
1055
|
+
_fetchServerConfig() {
|
|
1056
|
+
fetch("/__btp-copilot/config").then((e) => e.ok ? e.json() : null).then((e) => {
|
|
1057
|
+
if (!e) return;
|
|
1058
|
+
let t = !1;
|
|
1059
|
+
if (e.iframeUrl && !this.getAttribute("iframe-url") && (this._config = { ...this._config, iframeUrl: e.iframeUrl }, t = !0), e.backendUrl && !this.getAttribute("backend-url") && (this._config = { ...this._config, backendUrl: e.backendUrl }, t = !0), t && this._iframeEl) {
|
|
1060
|
+
const n = this._buildIframeUrl();
|
|
1061
|
+
n && (this._iframeEl.src = n);
|
|
1062
|
+
}
|
|
1063
|
+
}).catch(() => {
|
|
1064
|
+
});
|
|
1065
|
+
}
|
|
1055
1066
|
_esc(e) {
|
|
1056
1067
|
return e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
1057
1068
|
}
|