@ai-ad-network/frontend-sdk 1.1.9 → 1.1.10
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.esm.js +17 -26
- package/dist/index.js +16 -25
- package/dist/style.css +0 -3
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
-
import React, { useMemo, useState,
|
|
4
|
+
import React, { useMemo, useState, useCallback, useEffect, useRef, createContext, useContext, Component } from "react";
|
|
5
5
|
import useSWR from "swr";
|
|
6
|
-
const SDK_VERSION = "1.1.
|
|
6
|
+
const SDK_VERSION = "1.1.10";
|
|
7
7
|
var IntentType = /* @__PURE__ */ ((IntentType2) => {
|
|
8
8
|
IntentType2["SHOPPING"] = "shopping";
|
|
9
9
|
IntentType2["LEAD_GEN"] = "lead_gen";
|
|
@@ -769,8 +769,6 @@ function useAiAds(userQuery, aiResponse, isStreamFinished, options = {}) {
|
|
|
769
769
|
apiKey: optionsApiKey
|
|
770
770
|
} = stableOptions;
|
|
771
771
|
const [ads, setAds] = useState([]);
|
|
772
|
-
const hasRequestedRef = useRef(false);
|
|
773
|
-
const lastQueryRef = useRef();
|
|
774
772
|
const [requestId, setRequestId] = useState(null);
|
|
775
773
|
const [slotsMap, setSlotsMap] = useState({});
|
|
776
774
|
const buildUrl = useCallback(
|
|
@@ -809,7 +807,16 @@ function useAiAds(userQuery, aiResponse, isStreamFinished, options = {}) {
|
|
|
809
807
|
slots
|
|
810
808
|
};
|
|
811
809
|
}, [userQuery, aiResponse, isStreamFinished, formats, placement]);
|
|
812
|
-
const shouldFetch = enabled && isStreamFinished && !!userQuery &&
|
|
810
|
+
const shouldFetch = enabled && isStreamFinished && !!userQuery && !!aiResponse;
|
|
811
|
+
if (process.env.NODE_ENV === "development" && userQuery) {
|
|
812
|
+
console.log("[useAiAds] shouldFetch result:", {
|
|
813
|
+
userQuery,
|
|
814
|
+
aiResponse,
|
|
815
|
+
shouldFetch,
|
|
816
|
+
enabled,
|
|
817
|
+
isStreamFinished
|
|
818
|
+
});
|
|
819
|
+
}
|
|
813
820
|
const swrConfig = {
|
|
814
821
|
revalidateOnFocus: false,
|
|
815
822
|
revalidateOnReconnect: false,
|
|
@@ -825,10 +832,11 @@ function useAiAds(userQuery, aiResponse, isStreamFinished, options = {}) {
|
|
|
825
832
|
return {
|
|
826
833
|
url: buildUrl(),
|
|
827
834
|
query: userQuery,
|
|
835
|
+
response: aiResponse,
|
|
828
836
|
formats: formats.join(","),
|
|
829
837
|
placement
|
|
830
838
|
};
|
|
831
|
-
}, [shouldFetch, buildUrl, userQuery, formats, placement]);
|
|
839
|
+
}, [shouldFetch, buildUrl, userQuery, aiResponse, formats, placement]);
|
|
832
840
|
const { data, error, isValidating, mutate } = useSWR(
|
|
833
841
|
swrCacheKey,
|
|
834
842
|
() => fetcher(buildUrl(), requestBody(), effectiveApiKey),
|
|
@@ -837,8 +845,7 @@ function useAiAds(userQuery, aiResponse, isStreamFinished, options = {}) {
|
|
|
837
845
|
if (process.env.NODE_ENV === "development") {
|
|
838
846
|
console.log("[useAiAds] SWR Debug:", {
|
|
839
847
|
userQuery,
|
|
840
|
-
|
|
841
|
-
hasRequested: hasRequestedRef.current,
|
|
848
|
+
aiResponse,
|
|
842
849
|
shouldFetch,
|
|
843
850
|
isValidating,
|
|
844
851
|
swrCacheKey
|
|
@@ -990,25 +997,9 @@ function useAiAds(userQuery, aiResponse, isStreamFinished, options = {}) {
|
|
|
990
997
|
});
|
|
991
998
|
}
|
|
992
999
|
}
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
hasRequestedRef.current = true;
|
|
996
|
-
lastQueryRef.current = userQuery;
|
|
997
|
-
}
|
|
998
|
-
}, [data, userQuery]);
|
|
999
|
-
useEffect(() => {
|
|
1000
|
-
if (userQuery && userQuery !== lastQueryRef.current) {
|
|
1001
|
-
if (process.env.NODE_ENV === "development") {
|
|
1002
|
-
console.log("[useAiAds] Query changed, resetting hasRequestedRef", {
|
|
1003
|
-
oldQuery: lastQueryRef.current,
|
|
1004
|
-
newQuery: userQuery
|
|
1005
|
-
});
|
|
1006
|
-
}
|
|
1007
|
-
hasRequestedRef.current = false;
|
|
1008
|
-
}
|
|
1009
|
-
}, [userQuery]);
|
|
1000
|
+
setAds(convertedAds);
|
|
1001
|
+
}, [data]);
|
|
1010
1002
|
const refetch = useCallback(() => {
|
|
1011
|
-
hasRequestedRef.current = false;
|
|
1012
1003
|
mutate();
|
|
1013
1004
|
}, [mutate]);
|
|
1014
1005
|
const getAdAnalytics = useCallback((adId) => {
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
5
5
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
6
6
|
const React = require("react");
|
|
7
7
|
const useSWR = require("swr");
|
|
8
|
-
const SDK_VERSION = "1.1.
|
|
8
|
+
const SDK_VERSION = "1.1.10";
|
|
9
9
|
var IntentType = /* @__PURE__ */ ((IntentType2) => {
|
|
10
10
|
IntentType2["SHOPPING"] = "shopping";
|
|
11
11
|
IntentType2["LEAD_GEN"] = "lead_gen";
|
|
@@ -771,8 +771,6 @@ function useAiAds(userQuery, aiResponse, isStreamFinished, options = {}) {
|
|
|
771
771
|
apiKey: optionsApiKey
|
|
772
772
|
} = stableOptions;
|
|
773
773
|
const [ads, setAds] = React.useState([]);
|
|
774
|
-
const hasRequestedRef = React.useRef(false);
|
|
775
|
-
const lastQueryRef = React.useRef();
|
|
776
774
|
const [requestId, setRequestId] = React.useState(null);
|
|
777
775
|
const [slotsMap, setSlotsMap] = React.useState({});
|
|
778
776
|
const buildUrl = React.useCallback(
|
|
@@ -811,7 +809,16 @@ function useAiAds(userQuery, aiResponse, isStreamFinished, options = {}) {
|
|
|
811
809
|
slots
|
|
812
810
|
};
|
|
813
811
|
}, [userQuery, aiResponse, isStreamFinished, formats, placement]);
|
|
814
|
-
const shouldFetch = enabled && isStreamFinished && !!userQuery &&
|
|
812
|
+
const shouldFetch = enabled && isStreamFinished && !!userQuery && !!aiResponse;
|
|
813
|
+
if (process.env.NODE_ENV === "development" && userQuery) {
|
|
814
|
+
console.log("[useAiAds] shouldFetch result:", {
|
|
815
|
+
userQuery,
|
|
816
|
+
aiResponse,
|
|
817
|
+
shouldFetch,
|
|
818
|
+
enabled,
|
|
819
|
+
isStreamFinished
|
|
820
|
+
});
|
|
821
|
+
}
|
|
815
822
|
const swrConfig = {
|
|
816
823
|
revalidateOnFocus: false,
|
|
817
824
|
revalidateOnReconnect: false,
|
|
@@ -827,10 +834,11 @@ function useAiAds(userQuery, aiResponse, isStreamFinished, options = {}) {
|
|
|
827
834
|
return {
|
|
828
835
|
url: buildUrl(),
|
|
829
836
|
query: userQuery,
|
|
837
|
+
response: aiResponse,
|
|
830
838
|
formats: formats.join(","),
|
|
831
839
|
placement
|
|
832
840
|
};
|
|
833
|
-
}, [shouldFetch, buildUrl, userQuery, formats, placement]);
|
|
841
|
+
}, [shouldFetch, buildUrl, userQuery, aiResponse, formats, placement]);
|
|
834
842
|
const { data, error, isValidating, mutate } = useSWR(
|
|
835
843
|
swrCacheKey,
|
|
836
844
|
() => fetcher(buildUrl(), requestBody(), effectiveApiKey),
|
|
@@ -839,8 +847,7 @@ function useAiAds(userQuery, aiResponse, isStreamFinished, options = {}) {
|
|
|
839
847
|
if (process.env.NODE_ENV === "development") {
|
|
840
848
|
console.log("[useAiAds] SWR Debug:", {
|
|
841
849
|
userQuery,
|
|
842
|
-
|
|
843
|
-
hasRequested: hasRequestedRef.current,
|
|
850
|
+
aiResponse,
|
|
844
851
|
shouldFetch,
|
|
845
852
|
isValidating,
|
|
846
853
|
swrCacheKey
|
|
@@ -992,25 +999,9 @@ function useAiAds(userQuery, aiResponse, isStreamFinished, options = {}) {
|
|
|
992
999
|
});
|
|
993
1000
|
}
|
|
994
1001
|
}
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
hasRequestedRef.current = true;
|
|
998
|
-
lastQueryRef.current = userQuery;
|
|
999
|
-
}
|
|
1000
|
-
}, [data, userQuery]);
|
|
1001
|
-
React.useEffect(() => {
|
|
1002
|
-
if (userQuery && userQuery !== lastQueryRef.current) {
|
|
1003
|
-
if (process.env.NODE_ENV === "development") {
|
|
1004
|
-
console.log("[useAiAds] Query changed, resetting hasRequestedRef", {
|
|
1005
|
-
oldQuery: lastQueryRef.current,
|
|
1006
|
-
newQuery: userQuery
|
|
1007
|
-
});
|
|
1008
|
-
}
|
|
1009
|
-
hasRequestedRef.current = false;
|
|
1010
|
-
}
|
|
1011
|
-
}, [userQuery]);
|
|
1002
|
+
setAds(convertedAds);
|
|
1003
|
+
}, [data]);
|
|
1012
1004
|
const refetch = React.useCallback(() => {
|
|
1013
|
-
hasRequestedRef.current = false;
|
|
1014
1005
|
mutate();
|
|
1015
1006
|
}, [mutate]);
|
|
1016
1007
|
const getAdAnalytics = React.useCallback((adId) => {
|
package/dist/style.css
CHANGED
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "1.1.
|
|
1
|
+
export declare const SDK_VERSION = "1.1.10";
|