aizek-chatbot 1.0.6 → 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 CHANGED
@@ -35,6 +35,25 @@ var remarkGfm__default = /*#__PURE__*/_interopDefault(remarkGfm);
35
35
  function cx(...args) {
36
36
  return args.filter(Boolean).join(" ");
37
37
  }
38
+ function validateHeaders(headers, authConfig, opts = {}) {
39
+ const { caseSensitive = false, allowExtra = false } = opts;
40
+ const normalize = (s) => caseSensitive ? s : s.toLowerCase();
41
+ const headerEntries = Object.entries(headers).map(([k, v]) => [normalize(k), v.trim()]);
42
+ const authEntries = Object.entries(authConfig).map(([k, v]) => [normalize(k), v.trim()]);
43
+ const headerKeys = headerEntries.map(([k]) => k);
44
+ const authKeys = authEntries.map(([k]) => k);
45
+ const requiredSet = new Set(authKeys);
46
+ const missingKeys = authKeys.filter((k) => !headerKeys.includes(k));
47
+ const extraKeys = headerKeys.filter((k) => !requiredSet.has(k));
48
+ const hasAllRequired = missingKeys.length === 0;
49
+ const hasExtraKeys = extraKeys.length > 0 && !allowExtra;
50
+ const emptyValueKeys = authKeys.filter((k) => {
51
+ const val = headerEntries.find(([key]) => key === k)?.[1];
52
+ return !val || val.length === 0;
53
+ });
54
+ const isValid = hasAllRequired && !hasExtraKeys && emptyValueKeys.length === 0;
55
+ return { isValid, missingKeys, extraKeys, emptyValueKeys };
56
+ }
38
57
  var base = {
39
58
  display: "inline-flex",
40
59
  alignItems: "center",
@@ -128,44 +147,21 @@ var useChatbot = (options = {}) => {
128
147
  setIsLoading(true);
129
148
  try {
130
149
  let resp;
131
- if (options.userToken) {
132
- resp = await client.responses.create({
133
- model: "gpt-5",
134
- tools: [
135
- {
136
- type: "mcp",
137
- server_label: "aizek-mcp",
138
- server_url: mcpUrl,
139
- require_approval: "never",
140
- headers: {
141
- Authorization: `Bearer ${options.userToken}`,
142
- brandId: "c5bfc750-69fd-4653-8dbb-f01614bc3319",
143
- "privy-token": "eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IlNLb3JzbjRsMnJWSllrNEFrd0EtY0NaVVY1M0ticUQ2eHZ6UTNPeDdsY3cifQ.eyJzaWQiOiJjbWdqN25yb3EwMWRqbGEwY2M3a3hoamVzIiwiaXNzIjoicHJpdnkuaW8iLCJpYXQiOjE3NjAwMTMzMTYsImF1ZCI6ImNsc3U1eWM4NTA4d2hpMGZhZWR1a2Uxd3MiLCJzdWIiOiJkaWQ6cHJpdnk6Y2x0Y3d4MTNuMGkwNTEyeXRmNWI5d3NzdSIsImV4cCI6MTc2MDAxNjkxNn0.qzUpTuk5e8W0mggf4FTAAP3zZyjJjwpMi-QXU_2pLO9kgfMV5IYPzymR9XjTEBMfJxgC9dApMDvOAX8MvX7URw"
144
- }
145
- }
146
- ],
147
- input: message,
148
- previous_response_id: responseId || void 0
149
- });
150
- } else {
151
- resp = await client.responses.create({
152
- model: "gpt-5",
153
- tools: [
154
- {
155
- type: "mcp",
156
- server_label: "aizek-mcp",
157
- server_url: mcpUrl,
158
- require_approval: "never",
159
- headers: {
160
- brandId: "c5bfc750-69fd-4653-8dbb-f01614bc3319",
161
- "privy-token": "eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IlNLb3JzbjRsMnJWSllrNEFrd0EtY0NaVVY1M0ticUQ2eHZ6UTNPeDdsY3cifQ.eyJzaWQiOiJjbWdqN25yb3EwMWRqbGEwY2M3a3hoamVzIiwiaXNzIjoicHJpdnkuaW8iLCJpYXQiOjE3NjAwMTMzMTYsImF1ZCI6ImNsc3U1eWM4NTA4d2hpMGZhZWR1a2Uxd3MiLCJzdWIiOiJkaWQ6cHJpdnk6Y2x0Y3d4MTNuMGkwNTEyeXRmNWI5d3NzdSIsImV4cCI6MTc2MDAxNjkxNn0.qzUpTuk5e8W0mggf4FTAAP3zZyjJjwpMi-QXU_2pLO9kgfMV5IYPzymR9XjTEBMfJxgC9dApMDvOAX8MvX7URw"
162
- }
163
- }
164
- ],
165
- input: message,
166
- previous_response_id: responseId || void 0
167
- });
168
- }
150
+ console.log(options.headers);
151
+ resp = await client.responses.create({
152
+ model: "gpt-5",
153
+ tools: [
154
+ {
155
+ type: "mcp",
156
+ server_label: "aizek-mcp",
157
+ server_url: mcpUrl,
158
+ require_approval: "never",
159
+ headers: options.headers || {}
160
+ }
161
+ ],
162
+ input: message,
163
+ previous_response_id: responseId || void 0
164
+ });
169
165
  setResponseId(resp.id);
170
166
  let responseText = "";
171
167
  if (resp && Array.isArray(resp)) {
@@ -216,6 +212,7 @@ var fetchChatWidgetSettings = async (clientId) => {
216
212
  throw new Error(`HTTP error! status: ${response.status}`);
217
213
  }
218
214
  const data = await response.json();
215
+ console.log(data);
219
216
  return data;
220
217
  } catch (error) {
221
218
  console.error("Error fetching chat widget settings:", error);
@@ -621,7 +618,110 @@ var getLoadingSpinnerStyles = () => ({
621
618
  borderRadius: "50%",
622
619
  animation: "spin 1s linear infinite"
623
620
  });
624
- var AizekChatBot = ({ clientId, userToken }) => {
621
+
622
+ // src/styles/alertStyles.ts
623
+ var getAlertContainerStyles = (type) => {
624
+ const colors = {
625
+ error: {
626
+ background: "linear-gradient(135deg, #ef4444 0%, #dc2626 100%)",
627
+ border: "#dc2626",
628
+ shadow: "rgba(239, 68, 68, 0.2)"
629
+ },
630
+ warning: {
631
+ background: "linear-gradient(135deg, #f59e0b 0%, #d97706 100%)",
632
+ border: "#d97706",
633
+ shadow: "rgba(245, 158, 11, 0.2)"
634
+ },
635
+ success: {
636
+ background: "linear-gradient(135deg, #10b981 0%, #059669 100%)",
637
+ border: "#059669",
638
+ shadow: "rgba(16, 185, 129, 0.2)"
639
+ }
640
+ };
641
+ const selectedColor = colors[type];
642
+ return {
643
+ background: selectedColor.background,
644
+ border: `1px solid ${selectedColor.border}`,
645
+ borderRadius: "12px",
646
+ padding: "14px 16px",
647
+ margin: "12px 16px",
648
+ boxShadow: `0 4px 12px ${selectedColor.shadow}`,
649
+ color: "#ffffff",
650
+ fontSize: "13px",
651
+ display: "flex",
652
+ alignItems: "flex-start",
653
+ gap: "12px",
654
+ position: "relative",
655
+ animation: "slideDown 0.3s ease-out"
656
+ };
657
+ };
658
+ var getAlertIconContainerStyles = () => ({
659
+ display: "flex",
660
+ alignItems: "center",
661
+ justifyContent: "center",
662
+ width: "24px",
663
+ height: "24px",
664
+ flexShrink: 0,
665
+ marginTop: "2px"
666
+ });
667
+ var getAlertContentStyles = () => ({
668
+ flex: 1,
669
+ display: "flex",
670
+ flexDirection: "column",
671
+ gap: "8px"
672
+ });
673
+ var getAlertTitleStyles = () => ({
674
+ fontWeight: 600,
675
+ fontSize: "14px",
676
+ margin: 0,
677
+ lineHeight: 1.4
678
+ });
679
+ var getAlertMessageStyles = () => ({
680
+ margin: 0,
681
+ lineHeight: 1.5,
682
+ opacity: 0.95
683
+ });
684
+ var getAlertListStyles = () => ({
685
+ margin: "8px 0 0 0",
686
+ paddingLeft: "20px",
687
+ listStyle: "none"
688
+ });
689
+ var getAlertListItemStyles = () => ({
690
+ marginBottom: "4px",
691
+ position: "relative",
692
+ paddingLeft: "12px",
693
+ lineHeight: 1.4
694
+ });
695
+ var getAlertCloseButtonStyles = () => ({
696
+ position: "absolute",
697
+ top: "12px",
698
+ right: "12px",
699
+ background: "rgba(255, 255, 255, 0.2)",
700
+ border: "none",
701
+ borderRadius: "6px",
702
+ width: "24px",
703
+ height: "24px",
704
+ display: "flex",
705
+ alignItems: "center",
706
+ justifyContent: "center",
707
+ cursor: "pointer",
708
+ color: "#ffffff",
709
+ transition: "all 0.2s ease",
710
+ padding: 0
711
+ });
712
+ var getAlertAnimationStyles = () => `
713
+ @keyframes slideDown {
714
+ from {
715
+ opacity: 0;
716
+ transform: translateY(-10px);
717
+ }
718
+ to {
719
+ opacity: 1;
720
+ transform: translateY(0);
721
+ }
722
+ }
723
+ `;
724
+ var AizekChatBot = ({ clientId, headers }) => {
625
725
  const defaultConfig = {
626
726
  welcomeMessage: "Merhaba! Size nas\u0131l yard\u0131mc\u0131 olabilirim?",
627
727
  buttonBackground: "linear-gradient(135deg, #667eea 0%, #764ba2 100%)",
@@ -640,13 +740,24 @@ var AizekChatBot = ({ clientId, userToken }) => {
640
740
  const [isConfigLoading, setIsConfigLoading] = React.useState(true);
641
741
  const [finalMcpUrl, setFinalMcpUrl] = React.useState("");
642
742
  const [apiKey, setApiKey] = React.useState("");
743
+ const [validConfig, setValidConfig] = React.useState(false);
643
744
  const { welcomeMessage, buttonBackground, placeholder, buttonPosition, buttonSize, chatWidth, chatHeight, showTypingIndicator, initialOpen, headerBackground, companyLogo, companyName } = config;
644
745
  const [isOpen, setIsOpen] = React.useState(false);
746
+ const [headerValidation, setHeaderValidation] = React.useState(null);
747
+ const [showAlert, setShowAlert] = React.useState(true);
645
748
  React.useEffect(() => {
646
749
  const loadConfig = async () => {
647
750
  try {
648
751
  setIsConfigLoading(true);
649
752
  const apiResponse = await fetchChatWidgetSettings(clientId);
753
+ if (headers && apiResponse.data.auth_config) {
754
+ const validationResult = validateHeaders(headers, apiResponse.data.auth_config, {
755
+ allowExtra: false,
756
+ caseSensitive: true
757
+ });
758
+ console.log(validationResult);
759
+ setHeaderValidation(validationResult);
760
+ }
650
761
  setFinalMcpUrl(apiResponse.data.mcp_url);
651
762
  setApiKey(apiResponse.data.openai_key || "");
652
763
  const apiConfig = mapApiSettingsToConfig(apiResponse.data.chat_widget_settings);
@@ -662,7 +773,7 @@ var AizekChatBot = ({ clientId, userToken }) => {
662
773
  };
663
774
  loadConfig();
664
775
  }, [clientId]);
665
- const internalChatbot = useChatbot({ mcpUrl: finalMcpUrl, apiKey, userToken });
776
+ const internalChatbot = useChatbot({ mcpUrl: finalMcpUrl, apiKey, headers });
666
777
  const messages = internalChatbot.messages;
667
778
  const isLoading = internalChatbot.isLoading;
668
779
  const handleSendMessage = internalChatbot.sendMessage;
@@ -708,6 +819,106 @@ var AizekChatBot = ({ clientId, userToken }) => {
708
819
  }, []);
709
820
  return /* @__PURE__ */ jsxRuntime.jsx("span", { children: dots });
710
821
  };
822
+ const HeaderValidationAlert = () => {
823
+ if (!headerValidation || !showAlert) return null;
824
+ const { isValid, missingKeys, extraKeys, emptyValueKeys } = headerValidation;
825
+ if (isValid && missingKeys.length === 0 && extraKeys.length === 0 && emptyValueKeys.length === 0) {
826
+ return null;
827
+ }
828
+ const hasErrors = missingKeys.length > 0 || emptyValueKeys.length > 0;
829
+ const hasWarnings = extraKeys.length > 0;
830
+ const alertType = hasErrors ? "error" : "warning";
831
+ const getAlertIcon = () => {
832
+ if (hasErrors) {
833
+ return /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ jsxRuntime.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" }) });
834
+ }
835
+ return /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z" }) });
836
+ };
837
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
838
+ /* @__PURE__ */ jsxRuntime.jsx("style", { children: getAlertAnimationStyles() }),
839
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: getAlertContainerStyles(alertType), children: [
840
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: getAlertIconContainerStyles(), children: getAlertIcon() }),
841
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: getAlertContentStyles(), children: [
842
+ /* @__PURE__ */ jsxRuntime.jsx("h4", { style: getAlertTitleStyles(), children: hasErrors ? "Header Do\u011Frulama Hatas\u0131" : "Header Uyar\u0131s\u0131" }),
843
+ /* @__PURE__ */ jsxRuntime.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." }),
844
+ missingKeys.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
845
+ /* @__PURE__ */ jsxRuntime.jsx("strong", { style: { fontSize: "13px" }, children: "Eksik Header'lar:" }),
846
+ /* @__PURE__ */ jsxRuntime.jsx("ul", { style: getAlertListStyles(), children: missingKeys.map((key, index) => /* @__PURE__ */ jsxRuntime.jsxs("li", { style: getAlertListItemStyles(), children: [
847
+ /* @__PURE__ */ jsxRuntime.jsx("span", { style: {
848
+ position: "absolute",
849
+ left: "0",
850
+ top: "2px",
851
+ fontWeight: "bold"
852
+ }, children: "\u2022" }),
853
+ /* @__PURE__ */ jsxRuntime.jsx("code", { style: {
854
+ background: "rgba(255, 255, 255, 0.2)",
855
+ padding: "2px 6px",
856
+ borderRadius: "4px",
857
+ fontFamily: "monospace",
858
+ fontSize: "12px"
859
+ }, children: key })
860
+ ] }, index)) })
861
+ ] }),
862
+ emptyValueKeys.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
863
+ /* @__PURE__ */ jsxRuntime.jsx("strong", { style: { fontSize: "13px" }, children: "Bo\u015F De\u011Ferli Header'lar:" }),
864
+ /* @__PURE__ */ jsxRuntime.jsx("ul", { style: getAlertListStyles(), children: emptyValueKeys.map((key, index) => /* @__PURE__ */ jsxRuntime.jsxs("li", { style: getAlertListItemStyles(), children: [
865
+ /* @__PURE__ */ jsxRuntime.jsx("span", { style: {
866
+ position: "absolute",
867
+ left: "0",
868
+ top: "2px",
869
+ fontWeight: "bold"
870
+ }, children: "\u2022" }),
871
+ /* @__PURE__ */ jsxRuntime.jsx("code", { style: {
872
+ background: "rgba(255, 255, 255, 0.2)",
873
+ padding: "2px 6px",
874
+ borderRadius: "4px",
875
+ fontFamily: "monospace",
876
+ fontSize: "12px"
877
+ }, children: key }),
878
+ /* @__PURE__ */ jsxRuntime.jsx("span", { style: {
879
+ marginLeft: "6px",
880
+ fontSize: "11px",
881
+ opacity: 0.9
882
+ }, children: "(de\u011Fer bo\u015F olamaz)" })
883
+ ] }, index)) })
884
+ ] }),
885
+ extraKeys.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
886
+ /* @__PURE__ */ jsxRuntime.jsx("strong", { style: { fontSize: "13px" }, children: "Fazla Header'lar:" }),
887
+ /* @__PURE__ */ jsxRuntime.jsx("ul", { style: getAlertListStyles(), children: extraKeys.map((key, index) => /* @__PURE__ */ jsxRuntime.jsxs("li", { style: getAlertListItemStyles(), children: [
888
+ /* @__PURE__ */ jsxRuntime.jsx("span", { style: {
889
+ position: "absolute",
890
+ left: "0",
891
+ top: "2px",
892
+ fontWeight: "bold"
893
+ }, children: "\u2022" }),
894
+ /* @__PURE__ */ jsxRuntime.jsx("code", { style: {
895
+ background: "rgba(255, 255, 255, 0.2)",
896
+ padding: "2px 6px",
897
+ borderRadius: "4px",
898
+ fontFamily: "monospace",
899
+ fontSize: "12px"
900
+ }, children: key })
901
+ ] }, index)) })
902
+ ] })
903
+ ] }),
904
+ /* @__PURE__ */ jsxRuntime.jsx(
905
+ "button",
906
+ {
907
+ onClick: () => setShowAlert(false),
908
+ style: getAlertCloseButtonStyles(),
909
+ onMouseEnter: (e) => {
910
+ e.currentTarget.style.background = "rgba(255, 255, 255, 0.3)";
911
+ },
912
+ onMouseLeave: (e) => {
913
+ e.currentTarget.style.background = "rgba(255, 255, 255, 0.2)";
914
+ },
915
+ "aria-label": "Uyar\u0131y\u0131 kapat",
916
+ children: /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ jsxRuntime.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" }) })
917
+ }
918
+ )
919
+ ] })
920
+ ] });
921
+ };
711
922
  const ChatInput = () => {
712
923
  const [message, setMessage] = React.useState("");
713
924
  const textareaRef = React.useRef(null);
@@ -796,6 +1007,7 @@ var AizekChatBot = ({ clientId, userToken }) => {
796
1007
  ] })
797
1008
  ] }),
798
1009
  /* @__PURE__ */ jsxRuntime.jsxs("div", { style: getMessagesContainerStyles(), children: [
1010
+ /* @__PURE__ */ jsxRuntime.jsx(HeaderValidationAlert, {}),
799
1011
  messages.length === 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { style: getEmptyStateStyles(), children: [
800
1012
  /* @__PURE__ */ jsxRuntime.jsx("div", { style: { fontSize: "48px", marginBottom: "16px" }, children: "\u{1F4AC}" }),
801
1013
  /* @__PURE__ */ jsxRuntime.jsx("h4", { style: { margin: "0 0 8px 0", fontSize: "18px" }, children: welcomeMessage }),