@xpert-ai/chatkit-web-component 0.5.0 → 0.5.2
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/xpert-chatkit.js +118 -22
- package/dist/xpert-chatkit.js.map +1 -1
- package/dist/xpert-chatkit.umd.cjs +118 -22
- package/dist/xpert-chatkit.umd.cjs.map +1 -1
- package/package.json +7 -4
package/dist/xpert-chatkit.js
CHANGED
|
@@ -47,7 +47,7 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
|
|
|
47
47
|
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
48
48
|
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
49
49
|
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
50
|
-
var _a, _b, _setTrainingOptOut_dec, _hideHistory_dec, _showHistory_dec, _sendCustomAction_dec, _shareThread_dec, _setThreadId_dec, _setRuntimeCapabilities_dec, _setComposerValue_dec, _sendUserMessage_dec, _fetchUpdates_dec, _focusComposer_dec, _c, _opts, _frameUrl, _frame, _wrapper, _launcherCloseButton, _launcherOpen, _chatMinimizedToPet, _framePetOptionsOverride, _petClosedByContextMenu, _shadow, _petOverlay, _resolveLoaded, _loaded, _messenger, _ChatKitElementBase_instances, emitAndThrow_fn, setOptionsDataAttributes_fn, getDisplayMode_fn, getConfiguredPetOptions_fn, mergeConfiguredPetPositionDefaults_fn, getOverlayPetOptions_fn, resolvePetAssetUrl_fn, resolveOverlayPetOptions_fn, getFrameOptions_fn, setLauncherOpen_fn, setChatMinimizedToPet_fn, syncPetOverlayOptions_fn, handlePetActivate_fn, handlePetClose_fn, handlePetReply_fn, handlePetThreadSummaryActivate_fn, _handleLauncherClose, getFrameUrl_fn, setFrameUrl_fn, consumeFrameUrl_fn, _handleFrameLoad, _initialized, maybeInit_fn, _init;
|
|
50
|
+
var _a, _b, _setTrainingOptOut_dec, _hideHistory_dec, _showHistory_dec, _sendCustomAction_dec, _shareThread_dec, _setThreadId_dec, _setRuntimeCapabilities_dec, _setComposerValue_dec, _sendUserMessage_dec, _fetchUpdates_dec, _focusComposer_dec, _c, _opts, _frameUrl, _frame, _wrapper, _launcherCloseButton, _launcherOpen, _chatMinimizedToPet, _framePetOptionsOverride, _petClosedByContextMenu, _shadow, _petOverlay, _resolveLoaded, _loaded, _channelId, _messenger, _ChatKitElementBase_instances, emitAndThrow_fn, setOptionsDataAttributes_fn, getDisplayMode_fn, getConfiguredPetOptions_fn, mergeConfiguredPetPositionDefaults_fn, getOverlayPetOptions_fn, resolvePetAssetUrl_fn, resolveOverlayPetOptions_fn, getFrameOptions_fn, setLauncherOpen_fn, setChatMinimizedToPet_fn, syncPetOverlayOptions_fn, handlePetActivate_fn, handlePetClose_fn, handlePetReply_fn, handlePetThreadSummaryActivate_fn, _handleLauncherClose, getFrameUrl_fn, setFrameUrl_fn, consumeFrameUrl_fn, _handleFrameLoad, _initialized, maybeInit_fn, _init;
|
|
51
51
|
class EventEmitter {
|
|
52
52
|
constructor() {
|
|
53
53
|
__publicField(this, "callbacks", /* @__PURE__ */ new Map());
|
|
@@ -366,7 +366,7 @@ const fetchEventSourceWithRetry = async (url, params) => {
|
|
|
366
366
|
}
|
|
367
367
|
});
|
|
368
368
|
};
|
|
369
|
-
function
|
|
369
|
+
function createSecureChannelId() {
|
|
370
370
|
const cryptoRef = globalThis.crypto;
|
|
371
371
|
if (typeof (cryptoRef == null ? void 0 : cryptoRef.randomUUID) === "function") {
|
|
372
372
|
return cryptoRef.randomUUID();
|
|
@@ -378,7 +378,30 @@ function safeRandomUUID() {
|
|
|
378
378
|
bytes[8] = bytes[8] & 63 | 128;
|
|
379
379
|
return [...bytes].map((byte) => byte.toString(16).padStart(2, "0")).join("").replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/, "$1-$2-$3-$4-$5");
|
|
380
380
|
}
|
|
381
|
-
return
|
|
381
|
+
return null;
|
|
382
|
+
}
|
|
383
|
+
function safeRandomUUID() {
|
|
384
|
+
return createSecureChannelId() ?? `ck_${Date.now()}_${Math.random().toString(16).slice(2)}`;
|
|
385
|
+
}
|
|
386
|
+
function isTrustedChatKitMessageEvent(event, { channelId, expectedOrigin, expectedSource }) {
|
|
387
|
+
const payload = event.data;
|
|
388
|
+
if (!payload || typeof payload !== "object" || !("__xpaiChatKit" in payload)) {
|
|
389
|
+
return false;
|
|
390
|
+
}
|
|
391
|
+
if (payload.__xpaiChatKit !== true) {
|
|
392
|
+
return false;
|
|
393
|
+
}
|
|
394
|
+
if (expectedOrigin !== "*" && event.origin !== expectedOrigin) {
|
|
395
|
+
return false;
|
|
396
|
+
}
|
|
397
|
+
if (event.source === expectedSource) {
|
|
398
|
+
return true;
|
|
399
|
+
}
|
|
400
|
+
const normalizedChannelId = channelId == null ? void 0 : channelId.trim();
|
|
401
|
+
if (normalizedChannelId) {
|
|
402
|
+
return "channelId" in payload && payload.channelId === normalizedChannelId;
|
|
403
|
+
}
|
|
404
|
+
return false;
|
|
382
405
|
}
|
|
383
406
|
let IntegrationError$1 = class IntegrationError extends Error {
|
|
384
407
|
constructor(message) {
|
|
@@ -412,10 +435,12 @@ class BaseMessenger {
|
|
|
412
435
|
handlers,
|
|
413
436
|
target,
|
|
414
437
|
targetOrigin,
|
|
438
|
+
channelId,
|
|
415
439
|
fetch: fetch2 = window.fetch
|
|
416
440
|
}) {
|
|
417
441
|
__publicField(this, "targetOrigin");
|
|
418
442
|
__publicField(this, "target");
|
|
443
|
+
__publicField(this, "channelId");
|
|
419
444
|
__publicField(this, "commandHandlers");
|
|
420
445
|
__publicField(this, "_fetch");
|
|
421
446
|
__publicField(this, "emitter", new EventEmitter());
|
|
@@ -446,7 +471,11 @@ class BaseMessenger {
|
|
|
446
471
|
));
|
|
447
472
|
__publicField(this, "handleMessage", async (event) => {
|
|
448
473
|
var _a2, _b2, _c2, _d;
|
|
449
|
-
if (!event
|
|
474
|
+
if (!isTrustedChatKitMessageEvent(event, {
|
|
475
|
+
channelId: this.channelId,
|
|
476
|
+
expectedOrigin: this.targetOrigin,
|
|
477
|
+
expectedSource: this.target()
|
|
478
|
+
})) {
|
|
450
479
|
return;
|
|
451
480
|
}
|
|
452
481
|
const data = event.data;
|
|
@@ -587,6 +616,7 @@ class BaseMessenger {
|
|
|
587
616
|
this.commandHandlers = handlers;
|
|
588
617
|
this.target = target;
|
|
589
618
|
this.targetOrigin = targetOrigin;
|
|
619
|
+
this.channelId = (channelId == null ? void 0 : channelId.trim()) || void 0;
|
|
590
620
|
this._fetch = (...args) => fetch2(...args);
|
|
591
621
|
}
|
|
592
622
|
setTargetOrigin(targetOrigin) {
|
|
@@ -596,6 +626,7 @@ class BaseMessenger {
|
|
|
596
626
|
var _a2;
|
|
597
627
|
const message = {
|
|
598
628
|
__xpaiChatKit: true,
|
|
629
|
+
...this.channelId ? { channelId: this.channelId } : {},
|
|
599
630
|
...data
|
|
600
631
|
};
|
|
601
632
|
(_a2 = this.target()) == null ? void 0 : _a2.postMessage(message, this.targetOrigin, transfer);
|
|
@@ -1396,6 +1427,7 @@ class PetOverlay {
|
|
|
1396
1427
|
this.lastDragPosition = null;
|
|
1397
1428
|
this.lastDragClientX = null;
|
|
1398
1429
|
this.dragAnimation = null;
|
|
1430
|
+
this.activePointerId = null;
|
|
1399
1431
|
this.isDragging = false;
|
|
1400
1432
|
this.isHovering = false;
|
|
1401
1433
|
this.movedDuringDrag = false;
|
|
@@ -1527,7 +1559,7 @@ class PetOverlay {
|
|
|
1527
1559
|
};
|
|
1528
1560
|
this.handlePointerDown = (event) => {
|
|
1529
1561
|
var _a2, _b2;
|
|
1530
|
-
if (event.button !== 0 || event.ctrlKey) {
|
|
1562
|
+
if (event.button !== 0 || event.ctrlKey || this.isDragging) {
|
|
1531
1563
|
return;
|
|
1532
1564
|
}
|
|
1533
1565
|
this.closeContextMenu();
|
|
@@ -1553,12 +1585,17 @@ class PetOverlay {
|
|
|
1553
1585
|
this.movedDuringDrag = false;
|
|
1554
1586
|
this.dragPosition = nextPosition;
|
|
1555
1587
|
this.isDragging = true;
|
|
1588
|
+
this.activePointerId = event.pointerId;
|
|
1556
1589
|
this.clearRestingDelayTimer();
|
|
1557
1590
|
this.isHovering = true;
|
|
1591
|
+
this.captureActivePointer();
|
|
1558
1592
|
this.installDragListeners();
|
|
1559
1593
|
this.rescheduleAnimation();
|
|
1560
1594
|
};
|
|
1561
1595
|
this.handlePointerMove = (event) => {
|
|
1596
|
+
if (!this.isActiveDragPointer(event)) {
|
|
1597
|
+
return;
|
|
1598
|
+
}
|
|
1562
1599
|
const nextPosition = this.getNextDragPosition(event);
|
|
1563
1600
|
const last = this.lastDragPosition;
|
|
1564
1601
|
if (last && (Math.abs(last.x - nextPosition.x) > DRAG_DIRECTION_THRESHOLD_PX || Math.abs(last.y - nextPosition.y) > DRAG_DIRECTION_THRESHOLD_PX)) {
|
|
@@ -1578,20 +1615,18 @@ class PetOverlay {
|
|
|
1578
1615
|
this.render();
|
|
1579
1616
|
};
|
|
1580
1617
|
this.handlePointerUp = (event) => {
|
|
1618
|
+
if (!this.isActiveDragPointer(event)) {
|
|
1619
|
+
return;
|
|
1620
|
+
}
|
|
1581
1621
|
const finalPosition = this.lastDragPosition ?? this.getNextDragPosition(event);
|
|
1582
|
-
this.
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
this.
|
|
1586
|
-
|
|
1587
|
-
this.persistPosition(finalPosition);
|
|
1588
|
-
if (event.pointerType === "mouse" && this.isPointerOverPet(event)) {
|
|
1589
|
-
this.isHovering = true;
|
|
1590
|
-
this.rescheduleAnimation();
|
|
1591
|
-
} else {
|
|
1592
|
-
this.enterRestingAfterDelay();
|
|
1593
|
-
this.rescheduleAnimation();
|
|
1622
|
+
this.finishDrag(finalPosition, event);
|
|
1623
|
+
};
|
|
1624
|
+
this.handleLostPointerCapture = (event) => {
|
|
1625
|
+
if (!this.isActiveDragPointer(event)) {
|
|
1626
|
+
return;
|
|
1594
1627
|
}
|
|
1628
|
+
const finalPosition = this.lastDragPosition ?? this.getNextDragPosition(event);
|
|
1629
|
+
this.finishDrag(finalPosition, event);
|
|
1595
1630
|
};
|
|
1596
1631
|
this.handleClick = () => {
|
|
1597
1632
|
var _a2;
|
|
@@ -1795,6 +1830,7 @@ class PetOverlay {
|
|
|
1795
1830
|
pet.addEventListener("pointerenter", this.handlePointerEnter);
|
|
1796
1831
|
pet.addEventListener("pointerleave", this.handlePointerLeave);
|
|
1797
1832
|
pet.addEventListener("pointerdown", this.handlePointerDown);
|
|
1833
|
+
pet.addEventListener("lostpointercapture", this.handleLostPointerCapture);
|
|
1798
1834
|
pet.addEventListener("contextmenu", this.handleContextMenu);
|
|
1799
1835
|
pet.addEventListener("click", this.handleClick);
|
|
1800
1836
|
overlay.append(style, pet);
|
|
@@ -1804,6 +1840,7 @@ class PetOverlay {
|
|
|
1804
1840
|
}
|
|
1805
1841
|
removeOverlay() {
|
|
1806
1842
|
var _a2;
|
|
1843
|
+
this.cancelActiveDrag();
|
|
1807
1844
|
this.clearRestingDelayTimer();
|
|
1808
1845
|
this.clearTimers();
|
|
1809
1846
|
this.closeContextMenu();
|
|
@@ -1820,6 +1857,10 @@ class PetOverlay {
|
|
|
1820
1857
|
"pointerdown",
|
|
1821
1858
|
this.handlePointerDown
|
|
1822
1859
|
);
|
|
1860
|
+
this.petElement.removeEventListener(
|
|
1861
|
+
"lostpointercapture",
|
|
1862
|
+
this.handleLostPointerCapture
|
|
1863
|
+
);
|
|
1823
1864
|
this.petElement.removeEventListener(
|
|
1824
1865
|
"contextmenu",
|
|
1825
1866
|
this.handleContextMenu
|
|
@@ -2537,6 +2578,34 @@ class PetOverlay {
|
|
|
2537
2578
|
this.render();
|
|
2538
2579
|
}
|
|
2539
2580
|
}
|
|
2581
|
+
captureActivePointer() {
|
|
2582
|
+
const pointerId = this.activePointerId;
|
|
2583
|
+
const pet = this.petElement;
|
|
2584
|
+
if (pointerId === null || typeof (pet == null ? void 0 : pet.setPointerCapture) !== "function") {
|
|
2585
|
+
return;
|
|
2586
|
+
}
|
|
2587
|
+
try {
|
|
2588
|
+
pet.setPointerCapture(pointerId);
|
|
2589
|
+
} catch {
|
|
2590
|
+
}
|
|
2591
|
+
}
|
|
2592
|
+
releaseActivePointer() {
|
|
2593
|
+
const pointerId = this.activePointerId;
|
|
2594
|
+
const pet = this.petElement;
|
|
2595
|
+
this.activePointerId = null;
|
|
2596
|
+
if (pointerId === null || typeof (pet == null ? void 0 : pet.hasPointerCapture) !== "function" || typeof pet.releasePointerCapture !== "function") {
|
|
2597
|
+
return;
|
|
2598
|
+
}
|
|
2599
|
+
try {
|
|
2600
|
+
if (pet.hasPointerCapture(pointerId)) {
|
|
2601
|
+
pet.releasePointerCapture(pointerId);
|
|
2602
|
+
}
|
|
2603
|
+
} catch {
|
|
2604
|
+
}
|
|
2605
|
+
}
|
|
2606
|
+
isActiveDragPointer(event) {
|
|
2607
|
+
return this.isDragging && event.pointerId === this.activePointerId;
|
|
2608
|
+
}
|
|
2540
2609
|
getNextDragPosition(event) {
|
|
2541
2610
|
if (!this.options) {
|
|
2542
2611
|
return { x: 0, y: 0 };
|
|
@@ -2551,12 +2620,35 @@ class PetOverlay {
|
|
|
2551
2620
|
normalizeBoundsPadding(this.options.position.boundsPadding)
|
|
2552
2621
|
);
|
|
2553
2622
|
}
|
|
2623
|
+
finishDrag(finalPosition, event) {
|
|
2624
|
+
this.isDragging = false;
|
|
2625
|
+
this.dragPosition = null;
|
|
2626
|
+
this.dragAnimation = null;
|
|
2627
|
+
this.lastDragClientX = null;
|
|
2628
|
+
this.removeDragListeners();
|
|
2629
|
+
this.releaseActivePointer();
|
|
2630
|
+
this.persistPosition(finalPosition);
|
|
2631
|
+
if (event.pointerType === "mouse" && this.isPointerOverPet(event)) {
|
|
2632
|
+
this.isHovering = true;
|
|
2633
|
+
this.rescheduleAnimation();
|
|
2634
|
+
} else {
|
|
2635
|
+
this.enterRestingAfterDelay();
|
|
2636
|
+
this.rescheduleAnimation();
|
|
2637
|
+
}
|
|
2638
|
+
}
|
|
2639
|
+
cancelActiveDrag() {
|
|
2640
|
+
this.isDragging = false;
|
|
2641
|
+
this.dragPosition = null;
|
|
2642
|
+
this.dragAnimation = null;
|
|
2643
|
+
this.lastDragPosition = null;
|
|
2644
|
+
this.lastDragClientX = null;
|
|
2645
|
+
this.removeDragListeners();
|
|
2646
|
+
this.releaseActivePointer();
|
|
2647
|
+
}
|
|
2554
2648
|
installDragListeners() {
|
|
2555
2649
|
window.addEventListener("pointermove", this.handlePointerMove);
|
|
2556
|
-
window.addEventListener("pointerup", this.handlePointerUp
|
|
2557
|
-
window.addEventListener("pointercancel", this.handlePointerUp
|
|
2558
|
-
once: true
|
|
2559
|
-
});
|
|
2650
|
+
window.addEventListener("pointerup", this.handlePointerUp);
|
|
2651
|
+
window.addEventListener("pointercancel", this.handlePointerUp);
|
|
2560
2652
|
}
|
|
2561
2653
|
removeDragListeners() {
|
|
2562
2654
|
window.removeEventListener("pointermove", this.handlePointerMove);
|
|
@@ -2603,7 +2695,9 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
|
|
|
2603
2695
|
__privateAdd(this, _loaded, new Promise((resolve) => {
|
|
2604
2696
|
__privateSet(this, _resolveLoaded, resolve);
|
|
2605
2697
|
}));
|
|
2698
|
+
__privateAdd(this, _channelId, createSecureChannelId());
|
|
2606
2699
|
__privateAdd(this, _messenger, new ChatFrameMessenger({
|
|
2700
|
+
channelId: __privateGet(this, _channelId) ?? void 0,
|
|
2607
2701
|
fetch: (...args) => {
|
|
2608
2702
|
var _a2;
|
|
2609
2703
|
const customFetch = ((_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.api) && "fetch" in __privateGet(this, _opts).api && __privateGet(this, _opts).api.fetch;
|
|
@@ -3102,6 +3196,7 @@ _shadow = new WeakMap();
|
|
|
3102
3196
|
_petOverlay = new WeakMap();
|
|
3103
3197
|
_resolveLoaded = new WeakMap();
|
|
3104
3198
|
_loaded = new WeakMap();
|
|
3199
|
+
_channelId = new WeakMap();
|
|
3105
3200
|
_messenger = new WeakMap();
|
|
3106
3201
|
_ChatKitElementBase_instances = new WeakSet();
|
|
3107
3202
|
emitAndThrow_fn = function(error) {
|
|
@@ -3312,7 +3407,8 @@ maybeInit_fn = function() {
|
|
|
3312
3407
|
frameURL.hash = encodeBase64({
|
|
3313
3408
|
options: getInnerOptions(__privateMethod(this, _ChatKitElementBase_instances, getFrameOptions_fn).call(this, __privateGet(this, _opts))),
|
|
3314
3409
|
referrer: window.location.origin,
|
|
3315
|
-
profile: this.profile
|
|
3410
|
+
profile: this.profile,
|
|
3411
|
+
...__privateGet(this, _channelId) ? { channelId: __privateGet(this, _channelId) } : {}
|
|
3316
3412
|
});
|
|
3317
3413
|
__privateGet(this, _messenger).connect();
|
|
3318
3414
|
__privateGet(this, _frame).src = frameURL.toString();
|