@redonvn/zalo-ads-sdk 0.2.30 → 0.2.31

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.mjs CHANGED
@@ -2059,7 +2059,7 @@ var VALID_AD_TYPES = {
2059
2059
  OA: 2,
2060
2060
  VIDEO: 11,
2061
2061
  COMMERCE: 28,
2062
- // Server trả về 28 (không phải 23)
2062
+ // Mã chuẩn cho Commerce Ad
2063
2063
  ARTICLE: 3,
2064
2064
  DISPLAY: 21,
2065
2065
  // Masthead Mobile (Format 1) & Masthead Desktop (Format 2)
@@ -2781,14 +2781,31 @@ function validateUpdateAdPayload(payload, options = {}) {
2781
2781
  );
2782
2782
  }
2783
2783
  }
2784
- if (payload.Type === VALID_AD_TYPES.FORM) {
2784
+ const isNonEmptyStr = (val) => typeof val === "string" && val.trim().length > 0;
2785
+ if (payload.Type === VALID_AD_TYPES.WEBSITE || Number(payload.Type) === 5) {
2786
+ if (!isNonEmptyStr(payload.Settings?.Image?.LandscapeCoverUrl)) {
2787
+ errors.push(
2788
+ "Settings.Image.LandscapeCoverUrl l\xE0 b\u1EAFt bu\u1ED9c \u0111\u1ED1i v\u1EDBi Qu\u1EA3ng c\xE1o Website (Ad Type 5). Vui l\xF2ng upload \u1EA3nh b\xECa t\u1EC9 l\u1EC7 16:9 (1024x533 px) l\xEAn CDN Zalo Ads tr\u01B0\u1EDBc khi l\u01B0u."
2789
+ );
2790
+ }
2791
+ } else if (payload.Type === VALID_AD_TYPES.FORM || Number(payload.Type) === 18) {
2785
2792
  if (!payload.ZaloFormId || !payload.ZaloFormId.trim()) {
2786
2793
  errors.push("ZaloFormId l\xE0 b\u1EAFt bu\u1ED9c \u0111\u1ED1i v\u1EDBi Qu\u1EA3ng c\xE1o Form (Ad Type 18).");
2787
2794
  }
2795
+ if (!isNonEmptyStr(payload.Settings?.Image?.LandscapeCoverUrl)) {
2796
+ errors.push(
2797
+ "Settings.Image.LandscapeCoverUrl l\xE0 b\u1EAFt bu\u1ED9c \u0111\u1ED1i v\u1EDBi Qu\u1EA3ng c\xE1o Form (Ad Type 18). Vui l\xF2ng upload \u1EA3nh b\xECa t\u1EC9 l\u1EC7 16:9 (1024x533 px) l\xEAn CDN Zalo Ads tr\u01B0\u1EDBc khi l\u01B0u."
2798
+ );
2799
+ }
2788
2800
  } else if (payload.Type === VALID_AD_TYPES.MESSAGE || payload.Type === VALID_AD_TYPES.MESSAGE_LEGACY || Number(payload.Type) === 19 || Number(payload.Type) === 30) {
2789
- if (!payload.Settings?.Image?.LogoUrl) {
2801
+ if (!isNonEmptyStr(payload.Settings?.Image?.LogoUrl)) {
2790
2802
  errors.push("Settings.Image.LogoUrl l\xE0 b\u1EAFt bu\u1ED9c \u0111\u1ED1i v\u1EDBi Qu\u1EA3ng c\xE1o Tin Nh\u1EAFn (Ad Type 19/30).");
2791
2803
  }
2804
+ if (!isNonEmptyStr(payload.Settings?.Image?.LandscapeCoverUrl)) {
2805
+ errors.push(
2806
+ "Settings.Image.LandscapeCoverUrl l\xE0 b\u1EAFt bu\u1ED9c \u0111\u1ED1i v\u1EDBi Qu\u1EA3ng c\xE1o Tin Nh\u1EAFn (Ad Type 19/30). Vui l\xF2ng upload \u1EA3nh b\xECa t\u1EC9 l\u1EC7 16:9 (1024x533 px) l\xEAn CDN Zalo Ads tr\u01B0\u1EDBc khi l\u01B0u."
2807
+ );
2808
+ }
2792
2809
  const hasFlow = payload.ZaloFlowId && Number(payload.ZaloFlowId) > 0;
2793
2810
  const hasMiniPage = payload.MiniPageId && Number(payload.MiniPageId) > 0;
2794
2811
  if (!hasFlow && !hasMiniPage) {
@@ -2796,30 +2813,58 @@ function validateUpdateAdPayload(payload, options = {}) {
2796
2813
  "Qu\u1EA3ng c\xE1o Tin Nh\u1EAFn y\xEAu c\u1EA7u ph\u1EA3i ch\u1ECDn K\u1ECBch b\u1EA3n tin nh\u1EAFn (ZaloFlowId > 0) ho\u1EB7c Trang gi\u1EDBi thi\u1EC7u th\u01B0\u01A1ng hi\u1EC7u (MiniPageId > 0)."
2797
2814
  );
2798
2815
  }
2799
- } else if (payload.Type === VALID_AD_TYPES.COMMERCE) {
2816
+ } else if (payload.Type === VALID_AD_TYPES.COMMERCE || Number(payload.Type) === 28) {
2800
2817
  if (!payload.MiniPageId || payload.MiniPageId <= 0) {
2801
2818
  errors.push("MiniPageId l\xE0 b\u1EAFt bu\u1ED9c \u0111\u1ED1i v\u1EDBi Qu\u1EA3ng c\xE1o Commerce (Ad Type 28, Template 1/2/3).");
2802
2819
  }
2803
- } else if (payload.Type === VALID_AD_TYPES.VIDEO) {
2820
+ const hasSquare = isNonEmptyStr(payload.Settings?.Image?.SquareCoverUrl);
2821
+ const hasLandscape = isNonEmptyStr(payload.Settings?.Image?.LandscapeCoverUrl);
2822
+ if (!hasSquare && !hasLandscape) {
2823
+ errors.push(
2824
+ "Settings.Image.SquareCoverUrl (ho\u1EB7c LandscapeCoverUrl) l\xE0 b\u1EAFt bu\u1ED9c \u0111\u1ED1i v\u1EDBi Qu\u1EA3ng c\xE1o Commerce (Ad Type 28). Vui l\xF2ng upload \u1EA3nh s\u1EA3n ph\u1EA9m (1024x1024 px) l\xEAn CDN Zalo Ads tr\u01B0\u1EDBc khi l\u01B0u."
2825
+ );
2826
+ }
2827
+ } else if (payload.Type === VALID_AD_TYPES.OA || Number(payload.Type) === 2) {
2828
+ if (!isNonEmptyStr(payload.Settings?.Image?.LandscapeCoverUrl)) {
2829
+ errors.push(
2830
+ "Settings.Image.LandscapeCoverUrl l\xE0 b\u1EAFt bu\u1ED9c \u0111\u1ED1i v\u1EDBi Qu\u1EA3ng c\xE1o OA (Ad Type 2). Vui l\xF2ng upload \u1EA3nh b\xECa (1024x533 px) l\xEAn CDN Zalo Ads tr\u01B0\u1EDBc khi l\u01B0u."
2831
+ );
2832
+ }
2833
+ if (payload.Settings?.AdInfo?.Action !== void 0 && Number(payload.Settings.AdInfo.Action) !== 6) {
2834
+ warnings.push("Qu\u1EA3ng c\xE1o OA ch\u1EC9 ch\u1EA5p nh\u1EADn Action = 6 (Quan t\xE2m OA).");
2835
+ }
2836
+ } else if (payload.Type === VALID_AD_TYPES.ARTICLE || Number(payload.Type) === 3) {
2837
+ if (!payload.ZaloFeedId && !payload.articleId) {
2838
+ errors.push("ZaloFeedId ho\u1EB7c articleId l\xE0 b\u1EAFt bu\u1ED9c \u0111\u1ED1i v\u1EDBi Qu\u1EA3ng c\xE1o B\xE0i Vi\u1EBFt (Ad Type 3).");
2839
+ }
2840
+ if (!isNonEmptyStr(payload.Settings?.Image?.LandscapeCoverUrl)) {
2841
+ errors.push(
2842
+ "Settings.Image.LandscapeCoverUrl l\xE0 b\u1EAFt bu\u1ED9c \u0111\u1ED1i v\u1EDBi Qu\u1EA3ng c\xE1o B\xE0i Vi\u1EBFt (Ad Type 3). Vui l\xF2ng upload \u1EA3nh \u0111\u1EA1i di\u1EC7n b\xE0i vi\u1EBFt (1024x533 px) l\xEAn CDN Zalo Ads tr\u01B0\u1EDBc khi l\u01B0u."
2843
+ );
2844
+ }
2845
+ } else if (payload.Type === VALID_AD_TYPES.VIDEO || Number(payload.Type) === 11) {
2804
2846
  if (!payload.ZaloVideoId && !payload.Settings?.Image?.VideoUrl) {
2805
2847
  errors.push("ZaloVideoId ho\u1EB7c Settings.Image.VideoUrl l\xE0 b\u1EAFt bu\u1ED9c \u0111\u1ED1i v\u1EDBi Qu\u1EA3ng c\xE1o Video (Ad Type 11).");
2806
2848
  }
2807
2849
  if (payload.Settings?.Image?.VideoUrl && !payload.Settings.Image.VideoUrl.includes("zascdn.me")) {
2808
2850
  warnings.push("VideoUrl n\xEAn l\xE0 \u0111\u01B0\u1EDDng d\u1EABn CDN ch\xEDnh th\u1EE9c c\u1EE7a Zalo Ads (*.zascdn.me).");
2809
2851
  }
2810
- } else if (payload.Type === VALID_AD_TYPES.ARTICLE) {
2811
- if (!payload.ZaloFeedId && !payload.articleId) {
2812
- errors.push("ZaloFeedId ho\u1EB7c articleId l\xE0 b\u1EAFt bu\u1ED9c \u0111\u1ED1i v\u1EDBi Qu\u1EA3ng c\xE1o B\xE0i Vi\u1EBFt (Ad Type 3).");
2852
+ if (!isNonEmptyStr(payload.Settings?.Image?.LandscapeCoverUrl)) {
2853
+ warnings.push("N\xEAn b\u1ED5 sung Settings.Image.LandscapeCoverUrl l\xE0m \u1EA3nh poster \u0111\u1EA1i di\u1EC7n khi video ch\u01B0a t\u1EF1 \u0111\u1ED9ng ph\xE1t.");
2813
2854
  }
2814
2855
  } else if (Number(payload.Type) === 21 || Number(payload.Type) === 23 || Number(payload.Type) === 26 || payload.Type === VALID_AD_TYPES.DISPLAY || payload.Type === VALID_AD_TYPES.DISPLAY_HALFPAGE || payload.Type === VALID_AD_TYPES.DISPLAY_MEDIUM_RECTANGLE) {
2815
2856
  const img = payload.Settings?.Image;
2816
- const hasImage = img?.LandscapeCoverUrl || img?.BaseLandscapeCoverUrl || img?.PortraitCoverUrl || img?.SquareCoverUrl;
2857
+ const hasImage = isNonEmptyStr(img?.LandscapeCoverUrl) || isNonEmptyStr(img?.BaseLandscapeCoverUrl) || isNonEmptyStr(img?.PortraitCoverUrl) || isNonEmptyStr(img?.SquareCoverUrl);
2817
2858
  if (!hasImage) {
2818
2859
  errors.push(
2819
2860
  "Qu\u1EA3ng c\xE1o Display b\u1EAFt bu\u1ED9c ph\u1EA3i c\xF3 \xEDt nh\u1EA5t m\u1ED9t banner h\xECnh \u1EA3nh (Settings.Image.LandscapeCoverUrl ho\u1EB7c BaseLandscapeCoverUrl)."
2820
2861
  );
2821
2862
  }
2822
2863
  }
2864
+ const coverUrl = payload.Settings?.Image?.LandscapeCoverUrl;
2865
+ if (coverUrl && typeof coverUrl === "string" && !coverUrl.includes("zascdn.me") && !coverUrl.includes("zadn.vn") && !coverUrl.includes("zdn.vn") && !coverUrl.includes("zalo.me")) {
2866
+ warnings.push("\u1EA2nh b\xECa (LandscapeCoverUrl) n\xEAn \u0111\u01B0\u1EE3c t\u1EA3i l\xEAn CDN Zalo Ads (*.zascdn.me) \u0111\u1EC3 \u0111\u1EA3m b\u1EA3o duy\u1EC7t.");
2867
+ }
2823
2868
  return {
2824
2869
  isValid: errors.length === 0,
2825
2870
  errors,