@ai-ad-network/frontend-sdk 1.1.3 → 1.1.4
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 +91 -76
- package/dist/index.js +91 -76
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -3,7 +3,7 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
|
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
4
|
import React, { useMemo, useState, useRef, useCallback, useEffect, createContext, useContext, Component } from "react";
|
|
5
5
|
import useSWR from "swr";
|
|
6
|
-
const SDK_VERSION = "1.1.
|
|
6
|
+
const SDK_VERSION = "1.1.4";
|
|
7
7
|
var IntentType = /* @__PURE__ */ ((IntentType2) => {
|
|
8
8
|
IntentType2["SHOPPING"] = "shopping";
|
|
9
9
|
IntentType2["LEAD_GEN"] = "lead_gen";
|
|
@@ -574,7 +574,6 @@ async function fetcher(url, body, apiKey) {
|
|
|
574
574
|
return result;
|
|
575
575
|
}
|
|
576
576
|
function useAiAds(userQuery, aiResponse, isStreamFinished, options = {}) {
|
|
577
|
-
var _a, _b;
|
|
578
577
|
const stableOptions = useStableOptions(options);
|
|
579
578
|
const {
|
|
580
579
|
enabled = true,
|
|
@@ -640,77 +639,80 @@ function useAiAds(userQuery, aiResponse, isStreamFinished, options = {}) {
|
|
|
640
639
|
() => fetcher(buildUrl(), requestBody(), effectiveApiKey),
|
|
641
640
|
swrConfig
|
|
642
641
|
);
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
642
|
+
useEffect(() => {
|
|
643
|
+
var _a, _b;
|
|
644
|
+
const convertedAds = ((_a = data == null ? void 0 : data.slots) == null ? void 0 : _a.flatMap(
|
|
645
|
+
(slot) => (slot.ads || []).map((adaptedAd) => {
|
|
646
|
+
var _a2, _b2;
|
|
647
|
+
return {
|
|
648
|
+
id: adaptedAd.original.id,
|
|
649
|
+
type: adaptedAd.original.type,
|
|
650
|
+
score: adaptedAd.original.score,
|
|
651
|
+
source: "internal",
|
|
652
|
+
content: {
|
|
653
|
+
title: adaptedAd.adapted.title,
|
|
654
|
+
body: adaptedAd.adapted.body,
|
|
655
|
+
image: (_a2 = adaptedAd.adapted.image) == null ? void 0 : _a2.url,
|
|
656
|
+
cta_text: adaptedAd.adapted.ctaText,
|
|
657
|
+
price: (_b2 = adaptedAd.adapted.price) == null ? void 0 : _b2.display,
|
|
658
|
+
rating: adaptedAd.adapted.rating,
|
|
659
|
+
brand: adaptedAd.adapted.brand
|
|
660
|
+
},
|
|
661
|
+
tracking: {
|
|
662
|
+
click_url: adaptedAd.tracking.clickUrl,
|
|
663
|
+
impression_url: adaptedAd.tracking.impressionUrl
|
|
664
|
+
},
|
|
665
|
+
metadata: {
|
|
666
|
+
viewToken: adaptedAd.tracking.viewToken,
|
|
667
|
+
styling: adaptedAd.adapted.styling
|
|
668
|
+
}
|
|
669
|
+
};
|
|
670
|
+
})
|
|
671
|
+
)) || [];
|
|
672
|
+
const slotsMapData = ((_b = data == null ? void 0 : data.slots) == null ? void 0 : _b.reduce((acc, slot) => {
|
|
673
|
+
const slotAds = (slot.ads || []).map((adaptedAd) => {
|
|
674
|
+
var _a2, _b2;
|
|
675
|
+
return {
|
|
676
|
+
id: adaptedAd.original.id,
|
|
677
|
+
type: adaptedAd.original.type,
|
|
678
|
+
score: adaptedAd.original.score,
|
|
679
|
+
source: "internal",
|
|
680
|
+
content: {
|
|
681
|
+
title: adaptedAd.adapted.title,
|
|
682
|
+
body: adaptedAd.adapted.body,
|
|
683
|
+
image: (_a2 = adaptedAd.adapted.image) == null ? void 0 : _a2.url,
|
|
684
|
+
cta_text: adaptedAd.adapted.ctaText,
|
|
685
|
+
price: (_b2 = adaptedAd.adapted.price) == null ? void 0 : _b2.display,
|
|
686
|
+
rating: adaptedAd.adapted.rating,
|
|
687
|
+
brand: adaptedAd.adapted.brand
|
|
688
|
+
},
|
|
689
|
+
tracking: {
|
|
690
|
+
click_url: adaptedAd.tracking.clickUrl,
|
|
691
|
+
impression_url: adaptedAd.tracking.impressionUrl
|
|
692
|
+
},
|
|
693
|
+
metadata: {
|
|
694
|
+
viewToken: adaptedAd.tracking.viewToken,
|
|
695
|
+
styling: adaptedAd.adapted.styling
|
|
696
|
+
}
|
|
697
|
+
};
|
|
698
|
+
});
|
|
699
|
+
acc[slot.slotId] = {
|
|
700
|
+
ads: slotAds,
|
|
701
|
+
count: slotAds.length,
|
|
702
|
+
status: slot.status
|
|
696
703
|
};
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
if (convertedAds.length > 0) {
|
|
710
|
-
setAds(convertedAds);
|
|
711
|
-
hasRequestedRef.current = true;
|
|
712
|
-
lastQueryRef.current = userQuery;
|
|
713
|
-
}
|
|
704
|
+
return acc;
|
|
705
|
+
}, {})) || {};
|
|
706
|
+
if (data == null ? void 0 : data.requestId) {
|
|
707
|
+
setRequestId(data.requestId);
|
|
708
|
+
}
|
|
709
|
+
setSlotsMap(slotsMapData);
|
|
710
|
+
if (convertedAds.length > 0) {
|
|
711
|
+
setAds(convertedAds);
|
|
712
|
+
hasRequestedRef.current = true;
|
|
713
|
+
lastQueryRef.current = userQuery;
|
|
714
|
+
}
|
|
715
|
+
}, [data, userQuery]);
|
|
714
716
|
if (userQuery !== lastQueryRef.current && isValidating) {
|
|
715
717
|
hasRequestedRef.current = false;
|
|
716
718
|
}
|
|
@@ -2733,10 +2735,23 @@ function AdProvider({ config: configProp, initialConfig, children }) {
|
|
|
2733
2735
|
return merged;
|
|
2734
2736
|
});
|
|
2735
2737
|
useEffect(() => {
|
|
2736
|
-
if (configProp
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2738
|
+
if (configProp) {
|
|
2739
|
+
setConfig((prevConfig) => {
|
|
2740
|
+
const apiKeyChanged = configProp.apiKey !== void 0 && configProp.apiKey !== prevConfig.apiKey;
|
|
2741
|
+
const apiBaseUrlChanged = configProp.apiBaseUrl !== void 0 && configProp.apiBaseUrl !== prevConfig.apiBaseUrl;
|
|
2742
|
+
if (!apiKeyChanged && !apiBaseUrlChanged) {
|
|
2743
|
+
return prevConfig;
|
|
2744
|
+
}
|
|
2745
|
+
const updated = {
|
|
2746
|
+
...prevConfig,
|
|
2747
|
+
...configProp.apiKey !== void 0 && { apiKey: configProp.apiKey },
|
|
2748
|
+
...configProp.apiBaseUrl !== void 0 && { apiBaseUrl: configProp.apiBaseUrl }
|
|
2749
|
+
};
|
|
2750
|
+
if (typeof window !== "undefined") {
|
|
2751
|
+
window.__AD_CONFIG__ = updated;
|
|
2752
|
+
}
|
|
2753
|
+
return updated;
|
|
2754
|
+
});
|
|
2740
2755
|
}
|
|
2741
2756
|
}, [configProp == null ? void 0 : configProp.apiKey, configProp == null ? void 0 : configProp.apiBaseUrl]);
|
|
2742
2757
|
const [analytics, setAnalyticsState] = useState(defaultAnalyticsData);
|
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.4";
|
|
9
9
|
var IntentType = /* @__PURE__ */ ((IntentType2) => {
|
|
10
10
|
IntentType2["SHOPPING"] = "shopping";
|
|
11
11
|
IntentType2["LEAD_GEN"] = "lead_gen";
|
|
@@ -576,7 +576,6 @@ async function fetcher(url, body, apiKey) {
|
|
|
576
576
|
return result;
|
|
577
577
|
}
|
|
578
578
|
function useAiAds(userQuery, aiResponse, isStreamFinished, options = {}) {
|
|
579
|
-
var _a, _b;
|
|
580
579
|
const stableOptions = useStableOptions(options);
|
|
581
580
|
const {
|
|
582
581
|
enabled = true,
|
|
@@ -642,77 +641,80 @@ function useAiAds(userQuery, aiResponse, isStreamFinished, options = {}) {
|
|
|
642
641
|
() => fetcher(buildUrl(), requestBody(), effectiveApiKey),
|
|
643
642
|
swrConfig
|
|
644
643
|
);
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
644
|
+
React.useEffect(() => {
|
|
645
|
+
var _a, _b;
|
|
646
|
+
const convertedAds = ((_a = data == null ? void 0 : data.slots) == null ? void 0 : _a.flatMap(
|
|
647
|
+
(slot) => (slot.ads || []).map((adaptedAd) => {
|
|
648
|
+
var _a2, _b2;
|
|
649
|
+
return {
|
|
650
|
+
id: adaptedAd.original.id,
|
|
651
|
+
type: adaptedAd.original.type,
|
|
652
|
+
score: adaptedAd.original.score,
|
|
653
|
+
source: "internal",
|
|
654
|
+
content: {
|
|
655
|
+
title: adaptedAd.adapted.title,
|
|
656
|
+
body: adaptedAd.adapted.body,
|
|
657
|
+
image: (_a2 = adaptedAd.adapted.image) == null ? void 0 : _a2.url,
|
|
658
|
+
cta_text: adaptedAd.adapted.ctaText,
|
|
659
|
+
price: (_b2 = adaptedAd.adapted.price) == null ? void 0 : _b2.display,
|
|
660
|
+
rating: adaptedAd.adapted.rating,
|
|
661
|
+
brand: adaptedAd.adapted.brand
|
|
662
|
+
},
|
|
663
|
+
tracking: {
|
|
664
|
+
click_url: adaptedAd.tracking.clickUrl,
|
|
665
|
+
impression_url: adaptedAd.tracking.impressionUrl
|
|
666
|
+
},
|
|
667
|
+
metadata: {
|
|
668
|
+
viewToken: adaptedAd.tracking.viewToken,
|
|
669
|
+
styling: adaptedAd.adapted.styling
|
|
670
|
+
}
|
|
671
|
+
};
|
|
672
|
+
})
|
|
673
|
+
)) || [];
|
|
674
|
+
const slotsMapData = ((_b = data == null ? void 0 : data.slots) == null ? void 0 : _b.reduce((acc, slot) => {
|
|
675
|
+
const slotAds = (slot.ads || []).map((adaptedAd) => {
|
|
676
|
+
var _a2, _b2;
|
|
677
|
+
return {
|
|
678
|
+
id: adaptedAd.original.id,
|
|
679
|
+
type: adaptedAd.original.type,
|
|
680
|
+
score: adaptedAd.original.score,
|
|
681
|
+
source: "internal",
|
|
682
|
+
content: {
|
|
683
|
+
title: adaptedAd.adapted.title,
|
|
684
|
+
body: adaptedAd.adapted.body,
|
|
685
|
+
image: (_a2 = adaptedAd.adapted.image) == null ? void 0 : _a2.url,
|
|
686
|
+
cta_text: adaptedAd.adapted.ctaText,
|
|
687
|
+
price: (_b2 = adaptedAd.adapted.price) == null ? void 0 : _b2.display,
|
|
688
|
+
rating: adaptedAd.adapted.rating,
|
|
689
|
+
brand: adaptedAd.adapted.brand
|
|
690
|
+
},
|
|
691
|
+
tracking: {
|
|
692
|
+
click_url: adaptedAd.tracking.clickUrl,
|
|
693
|
+
impression_url: adaptedAd.tracking.impressionUrl
|
|
694
|
+
},
|
|
695
|
+
metadata: {
|
|
696
|
+
viewToken: adaptedAd.tracking.viewToken,
|
|
697
|
+
styling: adaptedAd.adapted.styling
|
|
698
|
+
}
|
|
699
|
+
};
|
|
700
|
+
});
|
|
701
|
+
acc[slot.slotId] = {
|
|
702
|
+
ads: slotAds,
|
|
703
|
+
count: slotAds.length,
|
|
704
|
+
status: slot.status
|
|
698
705
|
};
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
if (convertedAds.length > 0) {
|
|
712
|
-
setAds(convertedAds);
|
|
713
|
-
hasRequestedRef.current = true;
|
|
714
|
-
lastQueryRef.current = userQuery;
|
|
715
|
-
}
|
|
706
|
+
return acc;
|
|
707
|
+
}, {})) || {};
|
|
708
|
+
if (data == null ? void 0 : data.requestId) {
|
|
709
|
+
setRequestId(data.requestId);
|
|
710
|
+
}
|
|
711
|
+
setSlotsMap(slotsMapData);
|
|
712
|
+
if (convertedAds.length > 0) {
|
|
713
|
+
setAds(convertedAds);
|
|
714
|
+
hasRequestedRef.current = true;
|
|
715
|
+
lastQueryRef.current = userQuery;
|
|
716
|
+
}
|
|
717
|
+
}, [data, userQuery]);
|
|
716
718
|
if (userQuery !== lastQueryRef.current && isValidating) {
|
|
717
719
|
hasRequestedRef.current = false;
|
|
718
720
|
}
|
|
@@ -2735,10 +2737,23 @@ function AdProvider({ config: configProp, initialConfig, children }) {
|
|
|
2735
2737
|
return merged;
|
|
2736
2738
|
});
|
|
2737
2739
|
React.useEffect(() => {
|
|
2738
|
-
if (configProp
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2740
|
+
if (configProp) {
|
|
2741
|
+
setConfig((prevConfig) => {
|
|
2742
|
+
const apiKeyChanged = configProp.apiKey !== void 0 && configProp.apiKey !== prevConfig.apiKey;
|
|
2743
|
+
const apiBaseUrlChanged = configProp.apiBaseUrl !== void 0 && configProp.apiBaseUrl !== prevConfig.apiBaseUrl;
|
|
2744
|
+
if (!apiKeyChanged && !apiBaseUrlChanged) {
|
|
2745
|
+
return prevConfig;
|
|
2746
|
+
}
|
|
2747
|
+
const updated = {
|
|
2748
|
+
...prevConfig,
|
|
2749
|
+
...configProp.apiKey !== void 0 && { apiKey: configProp.apiKey },
|
|
2750
|
+
...configProp.apiBaseUrl !== void 0 && { apiBaseUrl: configProp.apiBaseUrl }
|
|
2751
|
+
};
|
|
2752
|
+
if (typeof window !== "undefined") {
|
|
2753
|
+
window.__AD_CONFIG__ = updated;
|
|
2754
|
+
}
|
|
2755
|
+
return updated;
|
|
2756
|
+
});
|
|
2742
2757
|
}
|
|
2743
2758
|
}, [configProp == null ? void 0 : configProp.apiKey, configProp == null ? void 0 : configProp.apiBaseUrl]);
|
|
2744
2759
|
const [analytics, setAnalyticsState] = React.useState(defaultAnalyticsData);
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "1.1.
|
|
1
|
+
export declare const SDK_VERSION = "1.1.4";
|