@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 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.3";
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
- const convertedAds = ((_a = data == null ? void 0 : data.slots) == null ? void 0 : _a.flatMap(
644
- (slot) => (slot.ads || []).map((adaptedAd) => {
645
- var _a2, _b2;
646
- return {
647
- id: adaptedAd.original.id,
648
- type: adaptedAd.original.type,
649
- score: adaptedAd.original.score,
650
- source: "internal",
651
- content: {
652
- title: adaptedAd.adapted.title,
653
- body: adaptedAd.adapted.body,
654
- image: (_a2 = adaptedAd.adapted.image) == null ? void 0 : _a2.url,
655
- cta_text: adaptedAd.adapted.ctaText,
656
- price: (_b2 = adaptedAd.adapted.price) == null ? void 0 : _b2.display,
657
- rating: adaptedAd.adapted.rating,
658
- brand: adaptedAd.adapted.brand
659
- },
660
- tracking: {
661
- click_url: adaptedAd.tracking.clickUrl,
662
- impression_url: adaptedAd.tracking.impressionUrl
663
- },
664
- metadata: {
665
- viewToken: adaptedAd.tracking.viewToken,
666
- styling: adaptedAd.adapted.styling
667
- }
668
- };
669
- })
670
- )) || [];
671
- const slotsMapData = ((_b = data == null ? void 0 : data.slots) == null ? void 0 : _b.reduce((acc, slot) => {
672
- const slotAds = (slot.ads || []).map((adaptedAd) => {
673
- var _a2, _b2;
674
- return {
675
- id: adaptedAd.original.id,
676
- type: adaptedAd.original.type,
677
- score: adaptedAd.original.score,
678
- source: "internal",
679
- content: {
680
- title: adaptedAd.adapted.title,
681
- body: adaptedAd.adapted.body,
682
- image: (_a2 = adaptedAd.adapted.image) == null ? void 0 : _a2.url,
683
- cta_text: adaptedAd.adapted.ctaText,
684
- price: (_b2 = adaptedAd.adapted.price) == null ? void 0 : _b2.display,
685
- rating: adaptedAd.adapted.rating,
686
- brand: adaptedAd.adapted.brand
687
- },
688
- tracking: {
689
- click_url: adaptedAd.tracking.clickUrl,
690
- impression_url: adaptedAd.tracking.impressionUrl
691
- },
692
- metadata: {
693
- viewToken: adaptedAd.tracking.viewToken,
694
- styling: adaptedAd.adapted.styling
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
- acc[slot.slotId] = {
699
- ads: slotAds,
700
- count: slotAds.length,
701
- status: slot.status
702
- };
703
- return acc;
704
- }, {})) || {};
705
- if (data == null ? void 0 : data.requestId) {
706
- setRequestId(data.requestId);
707
- }
708
- setSlotsMap(slotsMapData);
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 && typeof window !== "undefined") {
2737
- const updated = { ...config, ...configProp };
2738
- window.__AD_CONFIG__ = updated;
2739
- setConfig(updated);
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.3";
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
- const convertedAds = ((_a = data == null ? void 0 : data.slots) == null ? void 0 : _a.flatMap(
646
- (slot) => (slot.ads || []).map((adaptedAd) => {
647
- var _a2, _b2;
648
- return {
649
- id: adaptedAd.original.id,
650
- type: adaptedAd.original.type,
651
- score: adaptedAd.original.score,
652
- source: "internal",
653
- content: {
654
- title: adaptedAd.adapted.title,
655
- body: adaptedAd.adapted.body,
656
- image: (_a2 = adaptedAd.adapted.image) == null ? void 0 : _a2.url,
657
- cta_text: adaptedAd.adapted.ctaText,
658
- price: (_b2 = adaptedAd.adapted.price) == null ? void 0 : _b2.display,
659
- rating: adaptedAd.adapted.rating,
660
- brand: adaptedAd.adapted.brand
661
- },
662
- tracking: {
663
- click_url: adaptedAd.tracking.clickUrl,
664
- impression_url: adaptedAd.tracking.impressionUrl
665
- },
666
- metadata: {
667
- viewToken: adaptedAd.tracking.viewToken,
668
- styling: adaptedAd.adapted.styling
669
- }
670
- };
671
- })
672
- )) || [];
673
- const slotsMapData = ((_b = data == null ? void 0 : data.slots) == null ? void 0 : _b.reduce((acc, slot) => {
674
- const slotAds = (slot.ads || []).map((adaptedAd) => {
675
- var _a2, _b2;
676
- return {
677
- id: adaptedAd.original.id,
678
- type: adaptedAd.original.type,
679
- score: adaptedAd.original.score,
680
- source: "internal",
681
- content: {
682
- title: adaptedAd.adapted.title,
683
- body: adaptedAd.adapted.body,
684
- image: (_a2 = adaptedAd.adapted.image) == null ? void 0 : _a2.url,
685
- cta_text: adaptedAd.adapted.ctaText,
686
- price: (_b2 = adaptedAd.adapted.price) == null ? void 0 : _b2.display,
687
- rating: adaptedAd.adapted.rating,
688
- brand: adaptedAd.adapted.brand
689
- },
690
- tracking: {
691
- click_url: adaptedAd.tracking.clickUrl,
692
- impression_url: adaptedAd.tracking.impressionUrl
693
- },
694
- metadata: {
695
- viewToken: adaptedAd.tracking.viewToken,
696
- styling: adaptedAd.adapted.styling
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
- acc[slot.slotId] = {
701
- ads: slotAds,
702
- count: slotAds.length,
703
- status: slot.status
704
- };
705
- return acc;
706
- }, {})) || {};
707
- if (data == null ? void 0 : data.requestId) {
708
- setRequestId(data.requestId);
709
- }
710
- setSlotsMap(slotsMapData);
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 && typeof window !== "undefined") {
2739
- const updated = { ...config, ...configProp };
2740
- window.__AD_CONFIG__ = updated;
2741
- setConfig(updated);
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.3";
1
+ export declare const SDK_VERSION = "1.1.4";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-ad-network/frontend-sdk",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "type": "module",
5
5
  "description": "Frontend SDK for Hybrid AI Interactive Ad Network - React + Universal",
6
6
  "main": "dist/index.js",