aizek-chatbot 1.0.7 → 1.0.8
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/index.cjs +235 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +235 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -32,8 +32,9 @@ interface BackendConfig {
|
|
|
32
32
|
}
|
|
33
33
|
interface AizekChatBotProps {
|
|
34
34
|
clientId: string;
|
|
35
|
-
headers?:
|
|
35
|
+
headers?: HeadersType;
|
|
36
36
|
}
|
|
37
|
+
type HeadersType = Record<string, string>;
|
|
37
38
|
|
|
38
39
|
declare const AizekChatBot: React.FC<AizekChatBotProps>;
|
|
39
40
|
|
package/dist/index.d.ts
CHANGED
|
@@ -32,8 +32,9 @@ interface BackendConfig {
|
|
|
32
32
|
}
|
|
33
33
|
interface AizekChatBotProps {
|
|
34
34
|
clientId: string;
|
|
35
|
-
headers?:
|
|
35
|
+
headers?: HeadersType;
|
|
36
36
|
}
|
|
37
|
+
type HeadersType = Record<string, string>;
|
|
37
38
|
|
|
38
39
|
declare const AizekChatBot: React.FC<AizekChatBotProps>;
|
|
39
40
|
|
package/dist/index.mjs
CHANGED
|
@@ -9,6 +9,25 @@ import remarkGfm from 'remark-gfm';
|
|
|
9
9
|
function cx(...args) {
|
|
10
10
|
return args.filter(Boolean).join(" ");
|
|
11
11
|
}
|
|
12
|
+
function validateHeaders(headers, authConfig, opts = {}) {
|
|
13
|
+
const { caseSensitive = false, allowExtra = false } = opts;
|
|
14
|
+
const normalize = (s) => caseSensitive ? s : s.toLowerCase();
|
|
15
|
+
const headerEntries = Object.entries(headers).map(([k, v]) => [normalize(k), v.trim()]);
|
|
16
|
+
const authEntries = Object.entries(authConfig).map(([k, v]) => [normalize(k), v.trim()]);
|
|
17
|
+
const headerKeys = headerEntries.map(([k]) => k);
|
|
18
|
+
const authKeys = authEntries.map(([k]) => k);
|
|
19
|
+
const requiredSet = new Set(authKeys);
|
|
20
|
+
const missingKeys = authKeys.filter((k) => !headerKeys.includes(k));
|
|
21
|
+
const extraKeys = headerKeys.filter((k) => !requiredSet.has(k));
|
|
22
|
+
const hasAllRequired = missingKeys.length === 0;
|
|
23
|
+
const hasExtraKeys = extraKeys.length > 0 && !allowExtra;
|
|
24
|
+
const emptyValueKeys = authKeys.filter((k) => {
|
|
25
|
+
const val = headerEntries.find(([key]) => key === k)?.[1];
|
|
26
|
+
return !val || val.length === 0;
|
|
27
|
+
});
|
|
28
|
+
const isValid = hasAllRequired && !hasExtraKeys && emptyValueKeys.length === 0;
|
|
29
|
+
return { isValid, missingKeys, extraKeys, emptyValueKeys };
|
|
30
|
+
}
|
|
12
31
|
var base = {
|
|
13
32
|
display: "inline-flex",
|
|
14
33
|
alignItems: "center",
|
|
@@ -167,6 +186,7 @@ var fetchChatWidgetSettings = async (clientId) => {
|
|
|
167
186
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
168
187
|
}
|
|
169
188
|
const data = await response.json();
|
|
189
|
+
console.log(data);
|
|
170
190
|
return data;
|
|
171
191
|
} catch (error) {
|
|
172
192
|
console.error("Error fetching chat widget settings:", error);
|
|
@@ -572,6 +592,109 @@ var getLoadingSpinnerStyles = () => ({
|
|
|
572
592
|
borderRadius: "50%",
|
|
573
593
|
animation: "spin 1s linear infinite"
|
|
574
594
|
});
|
|
595
|
+
|
|
596
|
+
// src/styles/alertStyles.ts
|
|
597
|
+
var getAlertContainerStyles = (type) => {
|
|
598
|
+
const colors = {
|
|
599
|
+
error: {
|
|
600
|
+
background: "linear-gradient(135deg, #ef4444 0%, #dc2626 100%)",
|
|
601
|
+
border: "#dc2626",
|
|
602
|
+
shadow: "rgba(239, 68, 68, 0.2)"
|
|
603
|
+
},
|
|
604
|
+
warning: {
|
|
605
|
+
background: "linear-gradient(135deg, #f59e0b 0%, #d97706 100%)",
|
|
606
|
+
border: "#d97706",
|
|
607
|
+
shadow: "rgba(245, 158, 11, 0.2)"
|
|
608
|
+
},
|
|
609
|
+
success: {
|
|
610
|
+
background: "linear-gradient(135deg, #10b981 0%, #059669 100%)",
|
|
611
|
+
border: "#059669",
|
|
612
|
+
shadow: "rgba(16, 185, 129, 0.2)"
|
|
613
|
+
}
|
|
614
|
+
};
|
|
615
|
+
const selectedColor = colors[type];
|
|
616
|
+
return {
|
|
617
|
+
background: selectedColor.background,
|
|
618
|
+
border: `1px solid ${selectedColor.border}`,
|
|
619
|
+
borderRadius: "12px",
|
|
620
|
+
padding: "14px 16px",
|
|
621
|
+
margin: "12px 16px",
|
|
622
|
+
boxShadow: `0 4px 12px ${selectedColor.shadow}`,
|
|
623
|
+
color: "#ffffff",
|
|
624
|
+
fontSize: "13px",
|
|
625
|
+
display: "flex",
|
|
626
|
+
alignItems: "flex-start",
|
|
627
|
+
gap: "12px",
|
|
628
|
+
position: "relative",
|
|
629
|
+
animation: "slideDown 0.3s ease-out"
|
|
630
|
+
};
|
|
631
|
+
};
|
|
632
|
+
var getAlertIconContainerStyles = () => ({
|
|
633
|
+
display: "flex",
|
|
634
|
+
alignItems: "center",
|
|
635
|
+
justifyContent: "center",
|
|
636
|
+
width: "24px",
|
|
637
|
+
height: "24px",
|
|
638
|
+
flexShrink: 0,
|
|
639
|
+
marginTop: "2px"
|
|
640
|
+
});
|
|
641
|
+
var getAlertContentStyles = () => ({
|
|
642
|
+
flex: 1,
|
|
643
|
+
display: "flex",
|
|
644
|
+
flexDirection: "column",
|
|
645
|
+
gap: "8px"
|
|
646
|
+
});
|
|
647
|
+
var getAlertTitleStyles = () => ({
|
|
648
|
+
fontWeight: 600,
|
|
649
|
+
fontSize: "14px",
|
|
650
|
+
margin: 0,
|
|
651
|
+
lineHeight: 1.4
|
|
652
|
+
});
|
|
653
|
+
var getAlertMessageStyles = () => ({
|
|
654
|
+
margin: 0,
|
|
655
|
+
lineHeight: 1.5,
|
|
656
|
+
opacity: 0.95
|
|
657
|
+
});
|
|
658
|
+
var getAlertListStyles = () => ({
|
|
659
|
+
margin: "8px 0 0 0",
|
|
660
|
+
paddingLeft: "20px",
|
|
661
|
+
listStyle: "none"
|
|
662
|
+
});
|
|
663
|
+
var getAlertListItemStyles = () => ({
|
|
664
|
+
marginBottom: "4px",
|
|
665
|
+
position: "relative",
|
|
666
|
+
paddingLeft: "12px",
|
|
667
|
+
lineHeight: 1.4
|
|
668
|
+
});
|
|
669
|
+
var getAlertCloseButtonStyles = () => ({
|
|
670
|
+
position: "absolute",
|
|
671
|
+
top: "12px",
|
|
672
|
+
right: "12px",
|
|
673
|
+
background: "rgba(255, 255, 255, 0.2)",
|
|
674
|
+
border: "none",
|
|
675
|
+
borderRadius: "6px",
|
|
676
|
+
width: "24px",
|
|
677
|
+
height: "24px",
|
|
678
|
+
display: "flex",
|
|
679
|
+
alignItems: "center",
|
|
680
|
+
justifyContent: "center",
|
|
681
|
+
cursor: "pointer",
|
|
682
|
+
color: "#ffffff",
|
|
683
|
+
transition: "all 0.2s ease",
|
|
684
|
+
padding: 0
|
|
685
|
+
});
|
|
686
|
+
var getAlertAnimationStyles = () => `
|
|
687
|
+
@keyframes slideDown {
|
|
688
|
+
from {
|
|
689
|
+
opacity: 0;
|
|
690
|
+
transform: translateY(-10px);
|
|
691
|
+
}
|
|
692
|
+
to {
|
|
693
|
+
opacity: 1;
|
|
694
|
+
transform: translateY(0);
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
`;
|
|
575
698
|
var AizekChatBot = ({ clientId, headers }) => {
|
|
576
699
|
const defaultConfig = {
|
|
577
700
|
welcomeMessage: "Merhaba! Size nas\u0131l yard\u0131mc\u0131 olabilirim?",
|
|
@@ -591,13 +714,24 @@ var AizekChatBot = ({ clientId, headers }) => {
|
|
|
591
714
|
const [isConfigLoading, setIsConfigLoading] = useState(true);
|
|
592
715
|
const [finalMcpUrl, setFinalMcpUrl] = useState("");
|
|
593
716
|
const [apiKey, setApiKey] = useState("");
|
|
717
|
+
const [validConfig, setValidConfig] = useState(false);
|
|
594
718
|
const { welcomeMessage, buttonBackground, placeholder, buttonPosition, buttonSize, chatWidth, chatHeight, showTypingIndicator, initialOpen, headerBackground, companyLogo, companyName } = config;
|
|
595
719
|
const [isOpen, setIsOpen] = useState(false);
|
|
720
|
+
const [headerValidation, setHeaderValidation] = useState(null);
|
|
721
|
+
const [showAlert, setShowAlert] = useState(true);
|
|
596
722
|
useEffect(() => {
|
|
597
723
|
const loadConfig = async () => {
|
|
598
724
|
try {
|
|
599
725
|
setIsConfigLoading(true);
|
|
600
726
|
const apiResponse = await fetchChatWidgetSettings(clientId);
|
|
727
|
+
if (headers && apiResponse.data.auth_config) {
|
|
728
|
+
const validationResult = validateHeaders(headers, apiResponse.data.auth_config, {
|
|
729
|
+
allowExtra: false,
|
|
730
|
+
caseSensitive: true
|
|
731
|
+
});
|
|
732
|
+
console.log(validationResult);
|
|
733
|
+
setHeaderValidation(validationResult);
|
|
734
|
+
}
|
|
601
735
|
setFinalMcpUrl(apiResponse.data.mcp_url);
|
|
602
736
|
setApiKey(apiResponse.data.openai_key || "");
|
|
603
737
|
const apiConfig = mapApiSettingsToConfig(apiResponse.data.chat_widget_settings);
|
|
@@ -659,6 +793,106 @@ var AizekChatBot = ({ clientId, headers }) => {
|
|
|
659
793
|
}, []);
|
|
660
794
|
return /* @__PURE__ */ jsx("span", { children: dots });
|
|
661
795
|
};
|
|
796
|
+
const HeaderValidationAlert = () => {
|
|
797
|
+
if (!headerValidation || !showAlert) return null;
|
|
798
|
+
const { isValid, missingKeys, extraKeys, emptyValueKeys } = headerValidation;
|
|
799
|
+
if (isValid && missingKeys.length === 0 && extraKeys.length === 0 && emptyValueKeys.length === 0) {
|
|
800
|
+
return null;
|
|
801
|
+
}
|
|
802
|
+
const hasErrors = missingKeys.length > 0 || emptyValueKeys.length > 0;
|
|
803
|
+
const hasWarnings = extraKeys.length > 0;
|
|
804
|
+
const alertType = hasErrors ? "error" : "warning";
|
|
805
|
+
const getAlertIcon = () => {
|
|
806
|
+
if (hasErrors) {
|
|
807
|
+
return /* @__PURE__ */ jsx("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ jsx("path", { d: "M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z" }) });
|
|
808
|
+
}
|
|
809
|
+
return /* @__PURE__ */ jsx("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ jsx("path", { d: "M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z" }) });
|
|
810
|
+
};
|
|
811
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
812
|
+
/* @__PURE__ */ jsx("style", { children: getAlertAnimationStyles() }),
|
|
813
|
+
/* @__PURE__ */ jsxs("div", { style: getAlertContainerStyles(alertType), children: [
|
|
814
|
+
/* @__PURE__ */ jsx("div", { style: getAlertIconContainerStyles(), children: getAlertIcon() }),
|
|
815
|
+
/* @__PURE__ */ jsxs("div", { style: getAlertContentStyles(), children: [
|
|
816
|
+
/* @__PURE__ */ jsx("h4", { style: getAlertTitleStyles(), children: hasErrors ? "Header Do\u011Frulama Hatas\u0131" : "Header Uyar\u0131s\u0131" }),
|
|
817
|
+
/* @__PURE__ */ jsx("p", { style: getAlertMessageStyles(), children: hasErrors && hasWarnings ? "Header yap\u0131land\u0131rman\u0131zda hatalar ve uyar\u0131lar bulundu." : hasErrors ? "Header yap\u0131land\u0131rman\u0131zda hatalar bulundu." : "Header yap\u0131land\u0131rman\u0131zda fazla anahtarlar bulundu." }),
|
|
818
|
+
missingKeys.length > 0 && /* @__PURE__ */ jsxs("div", { children: [
|
|
819
|
+
/* @__PURE__ */ jsx("strong", { style: { fontSize: "13px" }, children: "Eksik Header'lar:" }),
|
|
820
|
+
/* @__PURE__ */ jsx("ul", { style: getAlertListStyles(), children: missingKeys.map((key, index) => /* @__PURE__ */ jsxs("li", { style: getAlertListItemStyles(), children: [
|
|
821
|
+
/* @__PURE__ */ jsx("span", { style: {
|
|
822
|
+
position: "absolute",
|
|
823
|
+
left: "0",
|
|
824
|
+
top: "2px",
|
|
825
|
+
fontWeight: "bold"
|
|
826
|
+
}, children: "\u2022" }),
|
|
827
|
+
/* @__PURE__ */ jsx("code", { style: {
|
|
828
|
+
background: "rgba(255, 255, 255, 0.2)",
|
|
829
|
+
padding: "2px 6px",
|
|
830
|
+
borderRadius: "4px",
|
|
831
|
+
fontFamily: "monospace",
|
|
832
|
+
fontSize: "12px"
|
|
833
|
+
}, children: key })
|
|
834
|
+
] }, index)) })
|
|
835
|
+
] }),
|
|
836
|
+
emptyValueKeys.length > 0 && /* @__PURE__ */ jsxs("div", { children: [
|
|
837
|
+
/* @__PURE__ */ jsx("strong", { style: { fontSize: "13px" }, children: "Bo\u015F De\u011Ferli Header'lar:" }),
|
|
838
|
+
/* @__PURE__ */ jsx("ul", { style: getAlertListStyles(), children: emptyValueKeys.map((key, index) => /* @__PURE__ */ jsxs("li", { style: getAlertListItemStyles(), children: [
|
|
839
|
+
/* @__PURE__ */ jsx("span", { style: {
|
|
840
|
+
position: "absolute",
|
|
841
|
+
left: "0",
|
|
842
|
+
top: "2px",
|
|
843
|
+
fontWeight: "bold"
|
|
844
|
+
}, children: "\u2022" }),
|
|
845
|
+
/* @__PURE__ */ jsx("code", { style: {
|
|
846
|
+
background: "rgba(255, 255, 255, 0.2)",
|
|
847
|
+
padding: "2px 6px",
|
|
848
|
+
borderRadius: "4px",
|
|
849
|
+
fontFamily: "monospace",
|
|
850
|
+
fontSize: "12px"
|
|
851
|
+
}, children: key }),
|
|
852
|
+
/* @__PURE__ */ jsx("span", { style: {
|
|
853
|
+
marginLeft: "6px",
|
|
854
|
+
fontSize: "11px",
|
|
855
|
+
opacity: 0.9
|
|
856
|
+
}, children: "(de\u011Fer bo\u015F olamaz)" })
|
|
857
|
+
] }, index)) })
|
|
858
|
+
] }),
|
|
859
|
+
extraKeys.length > 0 && /* @__PURE__ */ jsxs("div", { children: [
|
|
860
|
+
/* @__PURE__ */ jsx("strong", { style: { fontSize: "13px" }, children: "Fazla Header'lar:" }),
|
|
861
|
+
/* @__PURE__ */ jsx("ul", { style: getAlertListStyles(), children: extraKeys.map((key, index) => /* @__PURE__ */ jsxs("li", { style: getAlertListItemStyles(), children: [
|
|
862
|
+
/* @__PURE__ */ jsx("span", { style: {
|
|
863
|
+
position: "absolute",
|
|
864
|
+
left: "0",
|
|
865
|
+
top: "2px",
|
|
866
|
+
fontWeight: "bold"
|
|
867
|
+
}, children: "\u2022" }),
|
|
868
|
+
/* @__PURE__ */ jsx("code", { style: {
|
|
869
|
+
background: "rgba(255, 255, 255, 0.2)",
|
|
870
|
+
padding: "2px 6px",
|
|
871
|
+
borderRadius: "4px",
|
|
872
|
+
fontFamily: "monospace",
|
|
873
|
+
fontSize: "12px"
|
|
874
|
+
}, children: key })
|
|
875
|
+
] }, index)) })
|
|
876
|
+
] })
|
|
877
|
+
] }),
|
|
878
|
+
/* @__PURE__ */ jsx(
|
|
879
|
+
"button",
|
|
880
|
+
{
|
|
881
|
+
onClick: () => setShowAlert(false),
|
|
882
|
+
style: getAlertCloseButtonStyles(),
|
|
883
|
+
onMouseEnter: (e) => {
|
|
884
|
+
e.currentTarget.style.background = "rgba(255, 255, 255, 0.3)";
|
|
885
|
+
},
|
|
886
|
+
onMouseLeave: (e) => {
|
|
887
|
+
e.currentTarget.style.background = "rgba(255, 255, 255, 0.2)";
|
|
888
|
+
},
|
|
889
|
+
"aria-label": "Uyar\u0131y\u0131 kapat",
|
|
890
|
+
children: /* @__PURE__ */ jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ jsx("path", { d: "M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z" }) })
|
|
891
|
+
}
|
|
892
|
+
)
|
|
893
|
+
] })
|
|
894
|
+
] });
|
|
895
|
+
};
|
|
662
896
|
const ChatInput = () => {
|
|
663
897
|
const [message, setMessage] = useState("");
|
|
664
898
|
const textareaRef = useRef(null);
|
|
@@ -747,6 +981,7 @@ var AizekChatBot = ({ clientId, headers }) => {
|
|
|
747
981
|
] })
|
|
748
982
|
] }),
|
|
749
983
|
/* @__PURE__ */ jsxs("div", { style: getMessagesContainerStyles(), children: [
|
|
984
|
+
/* @__PURE__ */ jsx(HeaderValidationAlert, {}),
|
|
750
985
|
messages.length === 0 ? /* @__PURE__ */ jsxs("div", { style: getEmptyStateStyles(), children: [
|
|
751
986
|
/* @__PURE__ */ jsx("div", { style: { fontSize: "48px", marginBottom: "16px" }, children: "\u{1F4AC}" }),
|
|
752
987
|
/* @__PURE__ */ jsx("h4", { style: { margin: "0 0 8px 0", fontSize: "18px" }, children: welcomeMessage }),
|