@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.js CHANGED
@@ -2247,7 +2247,7 @@ var VALID_AD_TYPES = {
2247
2247
  OA: 2,
2248
2248
  VIDEO: 11,
2249
2249
  COMMERCE: 28,
2250
- // Server trả về 28 (không phải 23)
2250
+ // Mã chuẩn cho Commerce Ad
2251
2251
  ARTICLE: 3,
2252
2252
  DISPLAY: 21,
2253
2253
  // Masthead Mobile (Format 1) & Masthead Desktop (Format 2)
@@ -2969,14 +2969,31 @@ function validateUpdateAdPayload(payload, options = {}) {
2969
2969
  );
2970
2970
  }
2971
2971
  }
2972
- if (payload.Type === VALID_AD_TYPES.FORM) {
2972
+ const isNonEmptyStr = (val) => typeof val === "string" && val.trim().length > 0;
2973
+ if (payload.Type === VALID_AD_TYPES.WEBSITE || Number(payload.Type) === 5) {
2974
+ if (!isNonEmptyStr(payload.Settings?.Image?.LandscapeCoverUrl)) {
2975
+ errors.push(
2976
+ "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."
2977
+ );
2978
+ }
2979
+ } else if (payload.Type === VALID_AD_TYPES.FORM || Number(payload.Type) === 18) {
2973
2980
  if (!payload.ZaloFormId || !payload.ZaloFormId.trim()) {
2974
2981
  errors.push("ZaloFormId l\xE0 b\u1EAFt bu\u1ED9c \u0111\u1ED1i v\u1EDBi Qu\u1EA3ng c\xE1o Form (Ad Type 18).");
2975
2982
  }
2983
+ if (!isNonEmptyStr(payload.Settings?.Image?.LandscapeCoverUrl)) {
2984
+ errors.push(
2985
+ "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."
2986
+ );
2987
+ }
2976
2988
  } else if (payload.Type === VALID_AD_TYPES.MESSAGE || payload.Type === VALID_AD_TYPES.MESSAGE_LEGACY || Number(payload.Type) === 19 || Number(payload.Type) === 30) {
2977
- if (!payload.Settings?.Image?.LogoUrl) {
2989
+ if (!isNonEmptyStr(payload.Settings?.Image?.LogoUrl)) {
2978
2990
  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).");
2979
2991
  }
2992
+ if (!isNonEmptyStr(payload.Settings?.Image?.LandscapeCoverUrl)) {
2993
+ errors.push(
2994
+ "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."
2995
+ );
2996
+ }
2980
2997
  const hasFlow = payload.ZaloFlowId && Number(payload.ZaloFlowId) > 0;
2981
2998
  const hasMiniPage = payload.MiniPageId && Number(payload.MiniPageId) > 0;
2982
2999
  if (!hasFlow && !hasMiniPage) {
@@ -2984,30 +3001,58 @@ function validateUpdateAdPayload(payload, options = {}) {
2984
3001
  "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)."
2985
3002
  );
2986
3003
  }
2987
- } else if (payload.Type === VALID_AD_TYPES.COMMERCE) {
3004
+ } else if (payload.Type === VALID_AD_TYPES.COMMERCE || Number(payload.Type) === 28) {
2988
3005
  if (!payload.MiniPageId || payload.MiniPageId <= 0) {
2989
3006
  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).");
2990
3007
  }
2991
- } else if (payload.Type === VALID_AD_TYPES.VIDEO) {
3008
+ const hasSquare = isNonEmptyStr(payload.Settings?.Image?.SquareCoverUrl);
3009
+ const hasLandscape = isNonEmptyStr(payload.Settings?.Image?.LandscapeCoverUrl);
3010
+ if (!hasSquare && !hasLandscape) {
3011
+ errors.push(
3012
+ "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."
3013
+ );
3014
+ }
3015
+ } else if (payload.Type === VALID_AD_TYPES.OA || Number(payload.Type) === 2) {
3016
+ if (!isNonEmptyStr(payload.Settings?.Image?.LandscapeCoverUrl)) {
3017
+ errors.push(
3018
+ "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."
3019
+ );
3020
+ }
3021
+ if (payload.Settings?.AdInfo?.Action !== void 0 && Number(payload.Settings.AdInfo.Action) !== 6) {
3022
+ warnings.push("Qu\u1EA3ng c\xE1o OA ch\u1EC9 ch\u1EA5p nh\u1EADn Action = 6 (Quan t\xE2m OA).");
3023
+ }
3024
+ } else if (payload.Type === VALID_AD_TYPES.ARTICLE || Number(payload.Type) === 3) {
3025
+ if (!payload.ZaloFeedId && !payload.articleId) {
3026
+ 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).");
3027
+ }
3028
+ if (!isNonEmptyStr(payload.Settings?.Image?.LandscapeCoverUrl)) {
3029
+ errors.push(
3030
+ "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."
3031
+ );
3032
+ }
3033
+ } else if (payload.Type === VALID_AD_TYPES.VIDEO || Number(payload.Type) === 11) {
2992
3034
  if (!payload.ZaloVideoId && !payload.Settings?.Image?.VideoUrl) {
2993
3035
  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).");
2994
3036
  }
2995
3037
  if (payload.Settings?.Image?.VideoUrl && !payload.Settings.Image.VideoUrl.includes("zascdn.me")) {
2996
3038
  warnings.push("VideoUrl n\xEAn l\xE0 \u0111\u01B0\u1EDDng d\u1EABn CDN ch\xEDnh th\u1EE9c c\u1EE7a Zalo Ads (*.zascdn.me).");
2997
3039
  }
2998
- } else if (payload.Type === VALID_AD_TYPES.ARTICLE) {
2999
- if (!payload.ZaloFeedId && !payload.articleId) {
3000
- 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).");
3040
+ if (!isNonEmptyStr(payload.Settings?.Image?.LandscapeCoverUrl)) {
3041
+ 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.");
3001
3042
  }
3002
3043
  } 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) {
3003
3044
  const img = payload.Settings?.Image;
3004
- const hasImage = img?.LandscapeCoverUrl || img?.BaseLandscapeCoverUrl || img?.PortraitCoverUrl || img?.SquareCoverUrl;
3045
+ const hasImage = isNonEmptyStr(img?.LandscapeCoverUrl) || isNonEmptyStr(img?.BaseLandscapeCoverUrl) || isNonEmptyStr(img?.PortraitCoverUrl) || isNonEmptyStr(img?.SquareCoverUrl);
3005
3046
  if (!hasImage) {
3006
3047
  errors.push(
3007
3048
  "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)."
3008
3049
  );
3009
3050
  }
3010
3051
  }
3052
+ const coverUrl = payload.Settings?.Image?.LandscapeCoverUrl;
3053
+ if (coverUrl && typeof coverUrl === "string" && !coverUrl.includes("zascdn.me") && !coverUrl.includes("zadn.vn") && !coverUrl.includes("zdn.vn") && !coverUrl.includes("zalo.me")) {
3054
+ 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.");
3055
+ }
3011
3056
  return {
3012
3057
  isValid: errors.length === 0,
3013
3058
  errors,