@redonvn/zalo-ads-sdk 0.2.19 → 0.2.20

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
@@ -2117,11 +2117,18 @@ function validateCreateCampaignPayload(payload, options = {}) {
2117
2117
  `campaignType: ${payload.campaignType} kh\xF4ng h\u1EE3p l\u1EC7. C\xE1c lo\u1EA1i h\u1ED7 tr\u1EE3: 6 (Website), 17 (Form), 18 (Message), 3 (OA), 14 (Video), 22 (Commerce), 4 (Article), 20 (Display).`
2118
2118
  );
2119
2119
  }
2120
- if (payload.campaignType !== VALID_CAMPAIGN_TYPES.DISPLAY) {
2120
+ const OA_REQUIRED_CAMPAIGN_TYPES = [
2121
+ VALID_CAMPAIGN_TYPES.FORM,
2122
+ VALID_CAMPAIGN_TYPES.MESSAGE,
2123
+ VALID_CAMPAIGN_TYPES.OA,
2124
+ VALID_CAMPAIGN_TYPES.COMMERCE,
2125
+ VALID_CAMPAIGN_TYPES.ARTICLE
2126
+ ];
2127
+ if (payload.campaignType !== void 0 && OA_REQUIRED_CAMPAIGN_TYPES.includes(payload.campaignType)) {
2121
2128
  if (!payload.pageId || payload.pageId <= 0) {
2122
- errors.push("pageId c\u1EE7a Official Account l\xE0 b\u1EAFt bu\u1ED9c \u0111\u1ED1i v\u1EDBi lo\u1EA1i chi\u1EBFn d\u1ECBch n\xE0y (ph\u1EA3i > 0).");
2129
+ errors.push("pageId c\u1EE7a Official Account l\xE0 b\u1EAFt bu\u1ED9c \u0111\u1ED1i v\u1EDBi lo\u1EA1i chi\u1EBFn d\u1ECBch n\xE0y (ph\u1EA3i > 0, ch\u1ECDn t\u1EEB Danh s\xE1ch t\xE0i kho\u1EA3n OA).");
2123
2130
  }
2124
- } else {
2131
+ } else if (payload.campaignType === VALID_CAMPAIGN_TYPES.DISPLAY) {
2125
2132
  if (payload.pageId !== -1 && payload.pageId !== 0 && !payload.pageId) {
2126
2133
  warnings.push("Qu\u1EA3ng c\xE1o Display th\u01B0\u1EDDng s\u1EED d\u1EE5ng pageId = -1.");
2127
2134
  }
@@ -2600,14 +2607,171 @@ function validateCropCoordinates(input) {
2600
2607
  data: errors.length === 0 ? cleanData : void 0
2601
2608
  };
2602
2609
  }
2610
+ function validateCreateCommerceCampaign(payload, options = {}) {
2611
+ const errors = [];
2612
+ const warnings = [];
2613
+ if (!payload.name || typeof payload.name !== "string" || !payload.name.trim()) {
2614
+ errors.push("T\xEAn chi\u1EBFn d\u1ECBch ('name') l\xE0 b\u1EAFt bu\u1ED9c v\xE0 kh\xF4ng \u0111\u01B0\u1EE3c \u0111\u1EC3 tr\u1ED1ng.");
2615
+ } else if (payload.name.length > 255) {
2616
+ errors.push("T\xEAn chi\u1EBFn d\u1ECBch ('name') kh\xF4ng \u0111\u01B0\u1EE3c v\u01B0\u1EE3t qu\xE1 255 k\xFD t\u1EF1.");
2617
+ }
2618
+ if (!payload.pageId || payload.pageId <= 0) {
2619
+ errors.push("T\xE0i kho\u1EA3n OA ('pageId') l\xE0 b\u1EAFt bu\u1ED9c \u0111\u1ED1i v\u1EDBi Qu\u1EA3ng c\xE1o Commerce (ch\u1ECDn t\u1EEB Danh s\xE1ch t\xE0i kho\u1EA3n OA, ph\u1EA3i > 0).");
2620
+ }
2621
+ if (payload.productId === void 0 || payload.productId === null || payload.productId <= 0) {
2622
+ warnings.push("Qu\u1EA3ng c\xE1o Commerce n\xEAn ch\u1EC9 \u0111\u1ECBnh productId (ho\u1EB7c -1/0 khi d\xF9ng Instant Page s\u1EA3n ph\u1EA9m).");
2623
+ }
2624
+ return { isValid: errors.length === 0, errors, warnings };
2625
+ }
2626
+ function validateCreateDisplayCampaign(payload, options = {}) {
2627
+ const errors = [];
2628
+ const warnings = [];
2629
+ if (!payload.name || typeof payload.name !== "string" || !payload.name.trim()) {
2630
+ errors.push("T\xEAn chi\u1EBFn d\u1ECBch ('name') l\xE0 b\u1EAFt bu\u1ED9c v\xE0 kh\xF4ng \u0111\u01B0\u1EE3c \u0111\u1EC3 tr\u1ED1ng.");
2631
+ } else if (payload.name.length > 255) {
2632
+ errors.push("T\xEAn chi\u1EBFn d\u1ECBch ('name') kh\xF4ng \u0111\u01B0\u1EE3c v\u01B0\u1EE3t qu\xE1 255 k\xFD t\u1EF1.");
2633
+ }
2634
+ if (payload.targetUrl && !/^https?:\/\/.+/i.test(payload.targetUrl)) {
2635
+ errors.push("targetUrl ph\u1EA3i l\xE0 m\u1ED9t \u0111\u01B0\u1EDDng link h\u1EE3p l\u1EC7 b\u1EAFt \u0111\u1EA7u b\u1EB1ng http:// ho\u1EB7c https://.");
2636
+ }
2637
+ return { isValid: errors.length === 0, errors, warnings };
2638
+ }
2639
+ function validateCreateWebsiteCampaign(payload, options = {}) {
2640
+ const errors = [];
2641
+ const warnings = [];
2642
+ if (!payload.name || typeof payload.name !== "string" || !payload.name.trim()) {
2643
+ errors.push("T\xEAn chi\u1EBFn d\u1ECBch ('name') l\xE0 b\u1EAFt bu\u1ED9c v\xE0 kh\xF4ng \u0111\u01B0\u1EE3c \u0111\u1EC3 tr\u1ED1ng.");
2644
+ } else if (payload.name.length > 255) {
2645
+ errors.push("T\xEAn chi\u1EBFn d\u1ECBch ('name') kh\xF4ng \u0111\u01B0\u1EE3c v\u01B0\u1EE3t qu\xE1 255 k\xFD t\u1EF1.");
2646
+ }
2647
+ if (!payload.targetUrl || typeof payload.targetUrl !== "string" || !payload.targetUrl.trim()) {
2648
+ errors.push("Li\xEAn k\u1EBFt website ('targetUrl') l\xE0 b\u1EAFt bu\u1ED9c \u0111\u1ED1i v\u1EDBi Qu\u1EA3ng c\xE1o Website.");
2649
+ } else if (!/^https?:\/\/.+/i.test(payload.targetUrl)) {
2650
+ errors.push("Li\xEAn k\u1EBFt website ('targetUrl') ph\u1EA3i l\xE0 \u0111\u01B0\u1EDDng link h\u1EE3p l\u1EC7 b\u1EAFt \u0111\u1EA7u b\u1EB1ng http:// ho\u1EB7c https://.");
2651
+ }
2652
+ return { isValid: errors.length === 0, errors, warnings };
2653
+ }
2654
+ function validateCreateFormCampaign(payload, options = {}) {
2655
+ const errors = [];
2656
+ const warnings = [];
2657
+ if (!payload.name || typeof payload.name !== "string" || !payload.name.trim()) {
2658
+ errors.push("T\xEAn chi\u1EBFn d\u1ECBch ('name') l\xE0 b\u1EAFt bu\u1ED9c v\xE0 kh\xF4ng \u0111\u01B0\u1EE3c \u0111\u1EC3 tr\u1ED1ng.");
2659
+ } else if (payload.name.length > 255) {
2660
+ errors.push("T\xEAn chi\u1EBFn d\u1ECBch ('name') kh\xF4ng \u0111\u01B0\u1EE3c v\u01B0\u1EE3t qu\xE1 255 k\xFD t\u1EF1.");
2661
+ }
2662
+ if (!payload.pageId || payload.pageId <= 0) {
2663
+ errors.push("T\xE0i kho\u1EA3n OA ('pageId') l\xE0 b\u1EAFt bu\u1ED9c \u0111\u1ED1i v\u1EDBi Qu\u1EA3ng c\xE1o Form (ch\u1ECDn t\u1EEB Danh s\xE1ch t\xE0i kho\u1EA3n OA, ph\u1EA3i > 0).");
2664
+ }
2665
+ return { isValid: errors.length === 0, errors, warnings };
2666
+ }
2667
+ function validateCreateMessageCampaign(payload, options = {}) {
2668
+ const errors = [];
2669
+ const warnings = [];
2670
+ if (!payload.name || typeof payload.name !== "string" || !payload.name.trim()) {
2671
+ errors.push("T\xEAn chi\u1EBFn d\u1ECBch ('name') l\xE0 b\u1EAFt bu\u1ED9c v\xE0 kh\xF4ng \u0111\u01B0\u1EE3c \u0111\u1EC3 tr\u1ED1ng.");
2672
+ } else if (payload.name.length > 255) {
2673
+ errors.push("T\xEAn chi\u1EBFn d\u1ECBch ('name') kh\xF4ng \u0111\u01B0\u1EE3c v\u01B0\u1EE3t qu\xE1 255 k\xFD t\u1EF1.");
2674
+ }
2675
+ if (!payload.pageId || payload.pageId <= 0) {
2676
+ errors.push("T\xE0i kho\u1EA3n OA ('pageId') l\xE0 b\u1EAFt bu\u1ED9c \u0111\u1ED1i v\u1EDBi Qu\u1EA3ng c\xE1o Tin nh\u1EAFn (ch\u1ECDn t\u1EEB Danh s\xE1ch t\xE0i kho\u1EA3n OA, ph\u1EA3i > 0).");
2677
+ }
2678
+ return { isValid: errors.length === 0, errors, warnings };
2679
+ }
2680
+ function validateCreateOfficialAccountCampaign(payload, options = {}) {
2681
+ const errors = [];
2682
+ const warnings = [];
2683
+ if (!payload.name || typeof payload.name !== "string" || !payload.name.trim()) {
2684
+ errors.push("T\xEAn chi\u1EBFn d\u1ECBch ('name') l\xE0 b\u1EAFt bu\u1ED9c v\xE0 kh\xF4ng \u0111\u01B0\u1EE3c \u0111\u1EC3 tr\u1ED1ng.");
2685
+ } else if (payload.name.length > 255) {
2686
+ errors.push("T\xEAn chi\u1EBFn d\u1ECBch ('name') kh\xF4ng \u0111\u01B0\u1EE3c v\u01B0\u1EE3t qu\xE1 255 k\xFD t\u1EF1.");
2687
+ }
2688
+ if (!payload.pageId || payload.pageId <= 0) {
2689
+ errors.push("T\xE0i kho\u1EA3n OA ('pageId') l\xE0 b\u1EAFt bu\u1ED9c \u0111\u1ED1i v\u1EDBi Qu\u1EA3ng c\xE1o Zalo Official Account (ch\u1ECDn t\u1EEB Danh s\xE1ch t\xE0i kho\u1EA3n OA, ph\u1EA3i > 0).");
2690
+ }
2691
+ return { isValid: errors.length === 0, errors, warnings };
2692
+ }
2693
+ function validateCreateArticleCampaign(payload, options = {}) {
2694
+ const errors = [];
2695
+ const warnings = [];
2696
+ if (!payload.name || typeof payload.name !== "string" || !payload.name.trim()) {
2697
+ errors.push("T\xEAn chi\u1EBFn d\u1ECBch ('name') l\xE0 b\u1EAFt bu\u1ED9c v\xE0 kh\xF4ng \u0111\u01B0\u1EE3c \u0111\u1EC3 tr\u1ED1ng.");
2698
+ } else if (payload.name.length > 255) {
2699
+ errors.push("T\xEAn chi\u1EBFn d\u1ECBch ('name') kh\xF4ng \u0111\u01B0\u1EE3c v\u01B0\u1EE3t qu\xE1 255 k\xFD t\u1EF1.");
2700
+ }
2701
+ if (!payload.pageId || payload.pageId <= 0) {
2702
+ errors.push("T\xE0i kho\u1EA3n OA ('pageId') l\xE0 b\u1EAFt bu\u1ED9c \u0111\u1ED1i v\u1EDBi Qu\u1EA3ng c\xE1o B\xE0i vi\u1EBFt (ch\u1ECDn t\u1EEB Danh s\xE1ch t\xE0i kho\u1EA3n OA, ph\u1EA3i > 0).");
2703
+ }
2704
+ if (!payload.articleId || payload.articleId <= 0) {
2705
+ errors.push("B\xE0i vi\u1EBFt ('articleId') l\xE0 b\u1EAFt bu\u1ED9c \u0111\u1ED1i v\u1EDBi Qu\u1EA3ng c\xE1o B\xE0i vi\u1EBFt (ch\u1ECDn t\u1EEB Danh s\xE1ch b\xE0i vi\u1EBFt c\u1EE7a OA \u0111\xF3, l\u1EA5y qua getOwnedArticles).");
2706
+ }
2707
+ return { isValid: errors.length === 0, errors, warnings };
2708
+ }
2709
+ function validateCreateVideoCampaign(payload, options = {}) {
2710
+ const errors = [];
2711
+ const warnings = [];
2712
+ if (!payload.name || typeof payload.name !== "string" || !payload.name.trim()) {
2713
+ errors.push("T\xEAn chi\u1EBFn d\u1ECBch ('name') l\xE0 b\u1EAFt bu\u1ED9c v\xE0 kh\xF4ng \u0111\u01B0\u1EE3c \u0111\u1EC3 tr\u1ED1ng.");
2714
+ } else if (payload.name.length > 255) {
2715
+ errors.push("T\xEAn chi\u1EBFn d\u1ECBch ('name') kh\xF4ng \u0111\u01B0\u1EE3c v\u01B0\u1EE3t qu\xE1 255 k\xFD t\u1EF1.");
2716
+ }
2717
+ if (!payload.targetUrl || typeof payload.targetUrl !== "string" || !payload.targetUrl.trim()) {
2718
+ errors.push("Li\xEAn k\u1EBFt Website ('targetUrl') l\xE0 b\u1EAFt bu\u1ED9c \u0111\u1ED1i v\u1EDBi Qu\u1EA3ng c\xE1o Video.");
2719
+ } else if (!/^https?:\/\/.+/i.test(payload.targetUrl)) {
2720
+ errors.push("Li\xEAn k\u1EBFt Website ('targetUrl') ph\u1EA3i l\xE0 \u0111\u01B0\u1EDDng link h\u1EE3p l\u1EC7 b\u1EAFt \u0111\u1EA7u b\u1EB1ng http:// ho\u1EB7c https://.");
2721
+ }
2722
+ return { isValid: errors.length === 0, errors, warnings };
2723
+ }
2724
+ function validateUpdateWebsiteAd(payload, options = {}) {
2725
+ return validateUpdateAdPayload({ ...payload, Type: VALID_AD_TYPES.WEBSITE }, options);
2726
+ }
2727
+ function validateUpdateDisplayAd(payload, options = {}) {
2728
+ return validateUpdateAdPayload({ ...payload, Type: VALID_AD_TYPES.DISPLAY }, options);
2729
+ }
2730
+ function validateUpdateVideoAd(payload, options = {}) {
2731
+ return validateUpdateAdPayload({ ...payload, Type: VALID_AD_TYPES.VIDEO }, options);
2732
+ }
2733
+ function validateUpdateCommerceAd(payload, options = {}) {
2734
+ return validateUpdateAdPayload({ ...payload, Type: VALID_AD_TYPES.COMMERCE }, options);
2735
+ }
2736
+ function validateUpdateFormAd(payload, options = {}) {
2737
+ return validateUpdateAdPayload({ ...payload, Type: VALID_AD_TYPES.FORM }, options);
2738
+ }
2739
+ function validateUpdateMessageAd(payload, options = {}) {
2740
+ return validateUpdateAdPayload({ ...payload, Type: VALID_AD_TYPES.MESSAGE }, options);
2741
+ }
2742
+ function validateUpdateOfficialAccountAd(payload, options = {}) {
2743
+ return validateUpdateAdPayload({ ...payload, Type: VALID_AD_TYPES.OA }, options);
2744
+ }
2745
+ function validateUpdateArticleAd(payload, options = {}) {
2746
+ return validateUpdateAdPayload({ ...payload, Type: VALID_AD_TYPES.ARTICLE }, options);
2747
+ }
2603
2748
  var ZaloCampaignsValidator = {
2749
+ // Generic
2604
2750
  createCampaign: validateCreateCampaignPayload,
2605
2751
  updateAd: validateUpdateAdPayload,
2606
2752
  renameCampaign: validateRenameCampaignParams,
2607
2753
  changeStatus: validateChangeCampaignStatusParams,
2608
2754
  duplicateAd: validateDuplicateAdParams,
2609
2755
  validateCropCoordinates,
2610
- validateUploadCropAdImage: validateCropCoordinates
2756
+ validateUploadCropAdImage: validateCropCoordinates,
2757
+ // Specific Create Campaign
2758
+ createCommerceCampaign: validateCreateCommerceCampaign,
2759
+ createDisplayCampaign: validateCreateDisplayCampaign,
2760
+ createWebsiteCampaign: validateCreateWebsiteCampaign,
2761
+ createFormCampaign: validateCreateFormCampaign,
2762
+ createMessageCampaign: validateCreateMessageCampaign,
2763
+ createOfficialAccountCampaign: validateCreateOfficialAccountCampaign,
2764
+ createArticleCampaign: validateCreateArticleCampaign,
2765
+ createVideoCampaign: validateCreateVideoCampaign,
2766
+ // Specific Update Ad
2767
+ updateWebsiteAd: validateUpdateWebsiteAd,
2768
+ updateDisplayAd: validateUpdateDisplayAd,
2769
+ updateVideoAd: validateUpdateVideoAd,
2770
+ updateCommerceAd: validateUpdateCommerceAd,
2771
+ updateFormAd: validateUpdateFormAd,
2772
+ updateMessageAd: validateUpdateMessageAd,
2773
+ updateOfficialAccountAd: validateUpdateOfficialAccountAd,
2774
+ updateArticleAd: validateUpdateArticleAd
2611
2775
  };
2612
2776
 
2613
2777
  // src/services/campaigns.service.ts
@@ -5759,8 +5923,8 @@ function validateListFormLeadsRequest(input) {
5759
5923
  const offset = typeof raw.offset === "number" && raw.offset >= 0 ? Math.floor(raw.offset) : 0;
5760
5924
  const status = typeof raw.status === "string" && raw.status.trim() !== "" ? raw.status.trim() : "2,6,1,0,7,4,5,3";
5761
5925
  const now = Math.floor(Date.now() / 1e3);
5762
- const fromTime = typeof raw.fromTime === "number" && raw.fromTime >= 0 ? Math.floor(raw.fromTime) : now - 90 * 86400;
5763
- const toTime = typeof raw.toTime === "number" && raw.toTime >= 0 ? Math.floor(raw.toTime) : now;
5926
+ const fromTime = typeof raw.fromTime === "number" && raw.fromTime >= 0 ? raw.fromTime >= 1e10 ? Math.floor(raw.fromTime / 1e3) : Math.floor(raw.fromTime) : now - 90 * 86400;
5927
+ const toTime = typeof raw.toTime === "number" && raw.toTime >= 0 ? raw.toTime >= 1e10 ? Math.floor(raw.toTime / 1e3) : Math.floor(raw.toTime) : now;
5764
5928
  if (toTime < fromTime) {
5765
5929
  errors.push("M\u1ED1c th\u1EDDi gian k\u1EBFt th\xFAc 'toTime' ph\u1EA3i l\u1EDBn h\u01A1n ho\u1EB7c b\u1EB1ng 'fromTime'.");
5766
5930
  }
@@ -8781,18 +8945,26 @@ export {
8781
8945
  sanitizeCanvasKeys,
8782
8946
  validateChangeCampaignStatusParams,
8783
8947
  validateCloneInstantPageRequest,
8948
+ validateCreateArticleCampaign,
8784
8949
  validateCreateCampaignPayload,
8950
+ validateCreateCommerceCampaign,
8785
8951
  validateCreateCustomAudienceRequest,
8952
+ validateCreateDisplayCampaign,
8786
8953
  validateCreateFlowRequest,
8954
+ validateCreateFormCampaign,
8787
8955
  validateCreateFormEventAudienceRequest,
8788
8956
  validateCreateFormRequest,
8789
8957
  validateCreateInstantPageRequest,
8790
8958
  validateCreateLookalikeAudienceRequest,
8959
+ validateCreateMessageCampaign,
8791
8960
  validateCreateMessageOaEventAudienceRequest,
8792
8961
  validateCreateMessagePersonalEventAudienceRequest,
8793
8962
  validateCreateOaPageRequest,
8963
+ validateCreateOfficialAccountCampaign,
8794
8964
  validateCreatePhoneAudienceRequest,
8795
8965
  validateCreateSavedAudienceRequest,
8966
+ validateCreateVideoCampaign,
8967
+ validateCreateWebsiteCampaign,
8796
8968
  validateCropCoordinates,
8797
8969
  validateDateRangeReportRequest,
8798
8970
  validateDuplicateAdParams,
@@ -8815,10 +8987,18 @@ export {
8815
8987
  validateSearchInstantPagesRequest,
8816
8988
  validateToggleLeadNotificationRequest,
8817
8989
  validateUpdateAdPayload,
8990
+ validateUpdateArticleAd,
8991
+ validateUpdateCommerceAd,
8992
+ validateUpdateDisplayAd,
8818
8993
  validateUpdateFlowRequest,
8994
+ validateUpdateFormAd,
8819
8995
  validateUpdateInstantPageRequest,
8820
8996
  validateUpdateInstantPageSharesRequest,
8821
8997
  validateUpdateLeadNotificationIntervalRequest,
8998
+ validateUpdateMessageAd,
8999
+ validateUpdateOfficialAccountAd,
9000
+ validateUpdateVideoAd,
9001
+ validateUpdateWebsiteAd,
8822
9002
  validateUploadCustomAudiencePhoneListRequest,
8823
9003
  validateUploadMediaRequest,
8824
9004
  validateUpsertCustomReportRequest,