@capillarytech/creatives-library 8.0.242-alpha.1 → 8.0.242-alpha.11
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/assets/Android.png +0 -0
- package/assets/iOS.png +0 -0
- package/config/app.js +1 -1
- package/constants/unified.js +2 -2
- package/initialReducer.js +0 -2
- package/package.json +1 -1
- package/services/api.js +5 -10
- package/services/tests/api.test.js +0 -18
- package/translations/en.json +4 -3
- package/utils/common.js +6 -5
- package/utils/commonUtils.js +1 -14
- package/utils/imageUrlUpload.js +141 -0
- package/utils/tests/commonUtil.test.js +0 -224
- package/utils/transformTemplateConfig.js +10 -0
- package/v2Components/CapDeviceContent/index.js +56 -61
- package/v2Components/CapImageUpload/constants.js +2 -0
- package/v2Components/CapImageUpload/index.js +65 -16
- package/v2Components/CapImageUpload/index.scss +4 -1
- package/v2Components/CapImageUpload/messages.js +5 -1
- package/v2Components/CapImageUrlUpload/constants.js +26 -0
- package/v2Components/CapImageUrlUpload/index.js +365 -0
- package/v2Components/CapImageUrlUpload/index.scss +35 -0
- package/v2Components/CapImageUrlUpload/messages.js +47 -0
- package/v2Components/CapTagList/index.js +1 -6
- package/v2Components/CapTagListWithInput/index.js +1 -5
- package/v2Components/CapTagListWithInput/messages.js +1 -1
- package/v2Components/CapWhatsappCTA/tests/index.test.js +0 -5
- package/v2Components/ErrorInfoNote/index.js +72 -412
- package/v2Components/ErrorInfoNote/messages.js +0 -22
- package/v2Components/ErrorInfoNote/style.scss +2 -279
- package/v2Components/HtmlEditor/HTMLEditor.js +89 -210
- package/v2Components/HtmlEditor/__tests__/HTMLEditor.test.js +133 -1132
- package/v2Components/HtmlEditor/__tests__/index.lazy.test.js +12 -17
- package/v2Components/HtmlEditor/_htmlEditor.scss +23 -8
- package/v2Components/HtmlEditor/_index.lazy.scss +1 -1
- package/v2Components/HtmlEditor/components/CodeEditorPane/_codeEditorPane.scss +101 -13
- package/v2Components/HtmlEditor/components/CodeEditorPane/index.js +139 -148
- package/v2Components/HtmlEditor/components/DeviceToggle/_deviceToggle.scss +1 -2
- package/v2Components/HtmlEditor/components/DeviceToggle/index.js +3 -3
- package/v2Components/HtmlEditor/components/EditorToolbar/index.js +1 -1
- package/v2Components/HtmlEditor/components/FullscreenModal/_fullscreenModal.scss +0 -1
- package/v2Components/HtmlEditor/components/InAppPreviewPane/DeviceFrame.js +7 -4
- package/v2Components/HtmlEditor/components/InAppPreviewPane/__tests__/DeviceFrame.test.js +45 -35
- package/v2Components/HtmlEditor/components/InAppPreviewPane/_inAppPreviewPane.scss +3 -1
- package/v2Components/HtmlEditor/components/InAppPreviewPane/constants.js +33 -33
- package/v2Components/HtmlEditor/components/InAppPreviewPane/index.js +6 -7
- package/v2Components/HtmlEditor/components/PreviewPane/_previewPane.scss +6 -3
- package/v2Components/HtmlEditor/components/PreviewPane/index.js +11 -10
- package/v2Components/HtmlEditor/components/SplitContainer/_splitContainer.scss +1 -1
- package/v2Components/HtmlEditor/components/ValidationErrorDisplay/__tests__/index.test.js +62 -87
- package/v2Components/HtmlEditor/components/ValidationErrorDisplay/index.js +31 -49
- package/v2Components/HtmlEditor/constants.js +20 -29
- package/v2Components/HtmlEditor/hooks/__tests__/useInAppContent.test.js +16 -373
- package/v2Components/HtmlEditor/hooks/useEditorContent.js +2 -5
- package/v2Components/HtmlEditor/hooks/useInAppContent.js +146 -88
- package/v2Components/HtmlEditor/index.js +1 -1
- package/v2Components/HtmlEditor/messages.js +85 -95
- package/v2Components/HtmlEditor/utils/liquidTemplateSupport.js +101 -99
- package/v2Components/HtmlEditor/utils/properSyntaxHighlighting.js +25 -23
- package/v2Components/HtmlEditor/utils/validationAdapter.js +41 -34
- package/v2Components/MobilePushPreviewV2/index.js +7 -32
- package/v2Components/TemplatePreview/_templatePreview.scss +24 -44
- package/v2Components/TemplatePreview/index.js +32 -47
- package/v2Components/TemplatePreview/messages.js +0 -4
- package/v2Components/TestAndPreviewSlidebox/index.js +25 -31
- package/v2Containers/App/constants.js +5 -0
- package/v2Containers/BeeEditor/index.js +80 -82
- package/v2Containers/Cap/tests/__snapshots__/index.test.js.snap +4 -3
- package/v2Containers/CreativesContainer/SlideBoxContent.js +118 -148
- package/v2Containers/CreativesContainer/SlideBoxFooter.js +3 -9
- package/v2Containers/CreativesContainer/SlideBoxHeader.js +2 -2
- package/v2Containers/CreativesContainer/constants.js +2 -1
- package/v2Containers/CreativesContainer/index.js +41 -173
- package/v2Containers/CreativesContainer/messages.js +4 -4
- package/v2Containers/CreativesContainer/tests/SlideBoxContent.test.js +210 -0
- package/v2Containers/CreativesContainer/tests/__snapshots__/SlideBoxContent.test.js.snap +354 -38
- package/v2Containers/CreativesContainer/tests/__snapshots__/index.test.js.snap +0 -36
- package/v2Containers/Email/actions.js +0 -7
- package/v2Containers/Email/constants.js +1 -5
- package/v2Containers/Email/index.js +0 -13
- package/v2Containers/Email/messages.js +0 -32
- package/v2Containers/Email/reducer.js +1 -12
- package/v2Containers/Email/sagas.js +6 -41
- package/v2Containers/Email/tests/__snapshots__/reducer.test.js.snap +0 -2
- package/v2Containers/EmailWrapper/components/EmailWrapperView.js +7 -193
- package/v2Containers/EmailWrapper/components/HTMLEditorTesting.js +74 -40
- package/v2Containers/EmailWrapper/components/__tests__/HTMLEditorTesting.test.js +67 -2
- package/v2Containers/EmailWrapper/constants.js +0 -2
- package/v2Containers/EmailWrapper/hooks/useEmailWrapper.js +67 -436
- package/v2Containers/EmailWrapper/index.js +23 -99
- package/v2Containers/EmailWrapper/messages.js +1 -61
- package/v2Containers/EmailWrapper/tests/EmailWrapperView.test.js +1 -26
- package/v2Containers/EmailWrapper/tests/useEmailWrapper.test.js +77 -111
- package/v2Containers/InApp/actions.js +0 -7
- package/v2Containers/InApp/constants.js +4 -20
- package/v2Containers/InApp/index.js +357 -800
- package/v2Containers/InApp/index.scss +3 -4
- package/v2Containers/InApp/messages.js +3 -7
- package/v2Containers/InApp/reducer.js +3 -21
- package/v2Containers/InApp/sagas.js +9 -29
- package/v2Containers/InApp/selectors.js +5 -25
- package/v2Containers/InApp/tests/index.test.js +50 -154
- package/v2Containers/InApp/tests/reducer.test.js +0 -34
- package/v2Containers/InApp/tests/sagas.test.js +9 -61
- package/v2Containers/Line/Container/ImageCarousel/tests/__snapshots__/content.test.js.snap +12 -12
- package/v2Containers/Line/Container/ImageCarousel/tests/__snapshots__/index.test.js.snap +8 -8
- package/v2Containers/Line/Container/Wrapper/tests/__snapshots__/index.test.js.snap +100 -77
- package/v2Containers/Line/Container/tests/__snapshots__/index.test.js.snap +72 -63
- package/v2Containers/Rcs/tests/__snapshots__/index.test.js.snap +184 -150
- package/v2Containers/SmsTrai/Create/tests/__snapshots__/index.test.js.snap +16 -12
- package/v2Containers/SmsTrai/Edit/tests/__snapshots__/index.test.js.snap +32 -28
- package/v2Containers/TagList/index.js +1 -67
- package/v2Containers/Templates/ChannelTypeIllustration.js +13 -1
- package/v2Containers/Templates/_templates.scss +202 -56
- package/v2Containers/Templates/actions.js +2 -1
- package/v2Containers/Templates/constants.js +1 -0
- package/v2Containers/Templates/index.js +278 -128
- package/v2Containers/Templates/messages.js +24 -4
- package/v2Containers/Templates/reducer.js +2 -0
- package/v2Containers/Templates/tests/index.test.js +10 -0
- package/v2Containers/TemplatesV2/index.js +8 -1
- package/v2Containers/TemplatesV2/messages.js +4 -0
- package/v2Containers/WebPush/Create/components/BrandIconSection.js +108 -0
- package/v2Containers/WebPush/Create/components/ButtonForm.js +172 -0
- package/v2Containers/WebPush/Create/components/ButtonItem.js +101 -0
- package/v2Containers/WebPush/Create/components/ButtonList.js +145 -0
- package/v2Containers/WebPush/Create/components/ButtonsLinksSection.js +164 -0
- package/v2Containers/WebPush/Create/components/ButtonsLinksSection.test.js +463 -0
- package/v2Containers/WebPush/Create/components/FormActions.js +54 -0
- package/v2Containers/WebPush/Create/components/FormActions.test.js +163 -0
- package/v2Containers/WebPush/Create/components/MediaSection.js +142 -0
- package/v2Containers/WebPush/Create/components/MediaSection.test.js +341 -0
- package/v2Containers/WebPush/Create/components/MessageSection.js +103 -0
- package/v2Containers/WebPush/Create/components/MessageSection.test.js +268 -0
- package/v2Containers/WebPush/Create/components/NotificationTitleSection.js +87 -0
- package/v2Containers/WebPush/Create/components/NotificationTitleSection.test.js +210 -0
- package/v2Containers/WebPush/Create/components/TemplateNameSection.js +54 -0
- package/v2Containers/WebPush/Create/components/TemplateNameSection.test.js +143 -0
- package/v2Containers/WebPush/Create/components/__snapshots__/ButtonsLinksSection.test.js.snap +86 -0
- package/v2Containers/WebPush/Create/components/__snapshots__/FormActions.test.js.snap +16 -0
- package/v2Containers/WebPush/Create/components/__snapshots__/MediaSection.test.js.snap +41 -0
- package/v2Containers/WebPush/Create/components/__snapshots__/MessageSection.test.js.snap +54 -0
- package/v2Containers/WebPush/Create/components/__snapshots__/NotificationTitleSection.test.js.snap +37 -0
- package/v2Containers/WebPush/Create/components/__snapshots__/TemplateNameSection.test.js.snap +21 -0
- package/v2Containers/WebPush/Create/components/_buttons.scss +246 -0
- package/v2Containers/WebPush/Create/components/tests/ButtonForm.test.js +554 -0
- package/v2Containers/WebPush/Create/components/tests/ButtonItem.test.js +607 -0
- package/v2Containers/WebPush/Create/components/tests/ButtonList.test.js +633 -0
- package/v2Containers/WebPush/Create/components/tests/__snapshots__/ButtonForm.test.js.snap +666 -0
- package/v2Containers/WebPush/Create/components/tests/__snapshots__/ButtonItem.test.js.snap +74 -0
- package/v2Containers/WebPush/Create/components/tests/__snapshots__/ButtonList.test.js.snap +78 -0
- package/v2Containers/WebPush/Create/hooks/useButtonManagement.js +138 -0
- package/v2Containers/WebPush/Create/hooks/useButtonManagement.test.js +406 -0
- package/v2Containers/WebPush/Create/hooks/useCharacterCount.js +30 -0
- package/v2Containers/WebPush/Create/hooks/useCharacterCount.test.js +151 -0
- package/v2Containers/WebPush/Create/hooks/useImageUpload.js +104 -0
- package/v2Containers/WebPush/Create/hooks/useImageUpload.test.js +538 -0
- package/v2Containers/WebPush/Create/hooks/useTagManagement.js +122 -0
- package/v2Containers/WebPush/Create/hooks/useTagManagement.test.js +633 -0
- package/v2Containers/WebPush/Create/index.js +1056 -0
- package/v2Containers/WebPush/Create/index.scss +134 -0
- package/v2Containers/WebPush/Create/messages.js +203 -0
- package/v2Containers/WebPush/Create/preview/DevicePreviewContent.js +228 -0
- package/v2Containers/WebPush/Create/preview/NotificationContainer.js +294 -0
- package/v2Containers/WebPush/Create/preview/PreviewContent.js +90 -0
- package/v2Containers/WebPush/Create/preview/PreviewControls.js +305 -0
- package/v2Containers/WebPush/Create/preview/PreviewDisclaimer.js +23 -0
- package/v2Containers/WebPush/Create/preview/WebPushPreview.js +150 -0
- package/v2Containers/WebPush/Create/preview/assets/Light.svg +53 -0
- package/v2Containers/WebPush/Create/preview/assets/Top.svg +5 -0
- package/v2Containers/WebPush/Create/preview/assets/android-arrow-down.svg +9 -0
- package/v2Containers/WebPush/Create/preview/assets/android-arrow-up.svg +9 -0
- package/v2Containers/WebPush/Create/preview/assets/chrome-icon.png +0 -0
- package/v2Containers/WebPush/Create/preview/assets/edge-icon.png +0 -0
- package/v2Containers/WebPush/Create/preview/assets/firefox-icon.svg +106 -0
- package/v2Containers/WebPush/Create/preview/assets/iOS.svg +26 -0
- package/v2Containers/WebPush/Create/preview/assets/macos-arrow-down-icon.svg +9 -0
- package/v2Containers/WebPush/Create/preview/assets/macos-triple-dot-icon.svg +9 -0
- package/v2Containers/WebPush/Create/preview/assets/opera-icon.svg +18 -0
- package/v2Containers/WebPush/Create/preview/assets/safari-icon.svg +29 -0
- package/v2Containers/WebPush/Create/preview/assets/windows-close-icon.svg +9 -0
- package/v2Containers/WebPush/Create/preview/assets/windows-triple-dot-icon.svg +9 -0
- package/v2Containers/WebPush/Create/preview/components/AndroidMobileChromeHeader.js +47 -0
- package/v2Containers/WebPush/Create/preview/components/AndroidMobileExpanded.js +141 -0
- package/v2Containers/WebPush/Create/preview/components/IOSHeader.js +45 -0
- package/v2Containers/WebPush/Create/preview/components/NotificationExpandedContent.js +68 -0
- package/v2Containers/WebPush/Create/preview/components/NotificationHeader.js +61 -0
- package/v2Containers/WebPush/Create/preview/components/WindowsChromeExpanded.js +99 -0
- package/v2Containers/WebPush/Create/preview/components/tests/AndroidMobileExpanded.test.js +733 -0
- package/v2Containers/WebPush/Create/preview/components/tests/WindowsChromeExpanded.test.js +571 -0
- package/v2Containers/WebPush/Create/preview/components/tests/__snapshots__/AndroidMobileExpanded.test.js.snap +81 -0
- package/v2Containers/WebPush/Create/preview/components/tests/__snapshots__/WindowsChromeExpanded.test.js.snap +81 -0
- package/v2Containers/WebPush/Create/preview/config/notificationMappings.js +50 -0
- package/v2Containers/WebPush/Create/preview/constants.js +637 -0
- package/v2Containers/WebPush/Create/preview/notification-container.scss +79 -0
- package/v2Containers/WebPush/Create/preview/preview.scss +351 -0
- package/v2Containers/WebPush/Create/preview/styles/_android-mobile-chrome.scss +370 -0
- package/v2Containers/WebPush/Create/preview/styles/_android-mobile-edge.scss +12 -0
- package/v2Containers/WebPush/Create/preview/styles/_android-mobile-firefox.scss +12 -0
- package/v2Containers/WebPush/Create/preview/styles/_android-mobile-opera.scss +12 -0
- package/v2Containers/WebPush/Create/preview/styles/_android-tablet-chrome.scss +47 -0
- package/v2Containers/WebPush/Create/preview/styles/_android-tablet-edge.scss +11 -0
- package/v2Containers/WebPush/Create/preview/styles/_android-tablet-firefox.scss +11 -0
- package/v2Containers/WebPush/Create/preview/styles/_android-tablet-opera.scss +11 -0
- package/v2Containers/WebPush/Create/preview/styles/_base.scss +207 -0
- package/v2Containers/WebPush/Create/preview/styles/_ios.scss +153 -0
- package/v2Containers/WebPush/Create/preview/styles/_ipados.scss +107 -0
- package/v2Containers/WebPush/Create/preview/styles/_macos-chrome.scss +101 -0
- package/v2Containers/WebPush/Create/preview/styles/_windows-chrome.scss +229 -0
- package/v2Containers/WebPush/Create/preview/tests/DevicePreviewContent.test.js +909 -0
- package/v2Containers/WebPush/Create/preview/tests/NotificationContainer.test.js +1081 -0
- package/v2Containers/WebPush/Create/preview/tests/PreviewControls.test.js +723 -0
- package/v2Containers/WebPush/Create/preview/tests/WebPushPreview.test.js +943 -0
- package/v2Containers/WebPush/Create/preview/tests/__snapshots__/DevicePreviewContent.test.js.snap +131 -0
- package/v2Containers/WebPush/Create/preview/tests/__snapshots__/NotificationContainer.test.js.snap +112 -0
- package/v2Containers/WebPush/Create/preview/tests/__snapshots__/PreviewControls.test.js.snap +144 -0
- package/v2Containers/WebPush/Create/preview/tests/__snapshots__/WebPushPreview.test.js.snap +129 -0
- package/v2Containers/WebPush/Create/utils/payloadBuilder.js +94 -0
- package/v2Containers/WebPush/Create/utils/payloadBuilder.test.js +390 -0
- package/v2Containers/WebPush/Create/utils/previewUtils.js +89 -0
- package/v2Containers/WebPush/Create/utils/urlValidation.js +115 -0
- package/v2Containers/WebPush/Create/utils/urlValidation.test.js +449 -0
- package/v2Containers/WebPush/Create/utils/validation.js +75 -0
- package/v2Containers/WebPush/Create/utils/validation.test.js +283 -0
- package/v2Containers/WebPush/actions.js +60 -0
- package/v2Containers/WebPush/constants.js +128 -0
- package/v2Containers/WebPush/index.js +2 -0
- package/v2Containers/WebPush/reducer.js +104 -0
- package/v2Containers/WebPush/sagas.js +119 -0
- package/v2Containers/WebPush/selectors.js +65 -0
- package/v2Containers/WebPush/tests/reducer.test.js +863 -0
- package/v2Containers/WebPush/tests/sagas.test.js +566 -0
- package/v2Containers/WebPush/tests/selectors.test.js +843 -0
- package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +528 -431
- package/v2Components/HtmlEditor/components/ValidationTabs/_validationTabs.scss +0 -254
- package/v2Components/HtmlEditor/components/ValidationTabs/index.js +0 -362
- package/v2Components/HtmlEditor/components/ValidationTabs/messages.js +0 -51
- package/v2Containers/BeePopupEditor/constants.js +0 -10
- package/v2Containers/BeePopupEditor/index.js +0 -193
- package/v2Containers/BeePopupEditor/tests/index.test.js +0 -627
- package/v2Containers/EmailWrapper/components/EmailHTMLEditor.js +0 -1045
- package/v2Containers/InApp/__tests__/InAppHTMLEditor.test.js +0 -376
- package/v2Containers/InApp/__tests__/sagas.test.js +0 -363
- package/v2Containers/InApp/tests/selectors.test.js +0 -612
- package/v2Containers/InAppWrapper/components/InAppWrapperView.js +0 -162
- package/v2Containers/InAppWrapper/components/__tests__/InAppWrapperView.test.js +0 -267
- package/v2Containers/InAppWrapper/components/inAppWrapperView.scss +0 -9
- package/v2Containers/InAppWrapper/constants.js +0 -16
- package/v2Containers/InAppWrapper/hooks/__tests__/useInAppWrapper.test.js +0 -473
- package/v2Containers/InAppWrapper/hooks/useInAppWrapper.js +0 -198
- package/v2Containers/InAppWrapper/index.js +0 -148
- package/v2Containers/InAppWrapper/messages.js +0 -49
- package/v2Containers/InappAdvance/index.js +0 -1099
- package/v2Containers/InappAdvance/index.scss +0 -10
- package/v2Containers/InappAdvance/tests/index.test.js +0 -448
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
import { createWebPushPayload } from './payloadBuilder';
|
|
2
|
+
import {
|
|
3
|
+
WEBPUSH,
|
|
4
|
+
WEBPUSH_MEDIA_TYPES,
|
|
5
|
+
IMAGE_UPLOAD_METHODS,
|
|
6
|
+
BRAND_ICON_OPTIONS,
|
|
7
|
+
ON_CLICK_BEHAVIOUR_OPTIONS,
|
|
8
|
+
ACTION_TYPES,
|
|
9
|
+
} from '../../constants';
|
|
10
|
+
|
|
11
|
+
describe('createWebPushPayload', () => {
|
|
12
|
+
const defaultParams = {
|
|
13
|
+
templateName: 'Test Template',
|
|
14
|
+
notificationTitle: 'Test Title',
|
|
15
|
+
message: 'Test Message',
|
|
16
|
+
mediaType: WEBPUSH_MEDIA_TYPES.NONE,
|
|
17
|
+
accountId: 'account123',
|
|
18
|
+
isFullMode: true,
|
|
19
|
+
imageSrc: '',
|
|
20
|
+
imageUrl: '',
|
|
21
|
+
imageUploadMethod: IMAGE_UPLOAD_METHODS.UPLOAD_IMAGE,
|
|
22
|
+
brandIconOption: BRAND_ICON_OPTIONS.DONT_SHOW,
|
|
23
|
+
brandIconSrc: '',
|
|
24
|
+
brandIconUrl: '',
|
|
25
|
+
buttons: [],
|
|
26
|
+
onClickBehaviour: ON_CLICK_BEHAVIOUR_OPTIONS.OPEN_SITE,
|
|
27
|
+
redirectUrl: '',
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
describe('Basic Payload Structure', () => {
|
|
31
|
+
it('should create basic payload with required fields', () => {
|
|
32
|
+
const payload = createWebPushPayload(defaultParams);
|
|
33
|
+
|
|
34
|
+
expect(payload).toEqual({
|
|
35
|
+
name: 'Test Template',
|
|
36
|
+
type: WEBPUSH,
|
|
37
|
+
definition: {
|
|
38
|
+
accountId: 'account123',
|
|
39
|
+
},
|
|
40
|
+
versions: {
|
|
41
|
+
base: {
|
|
42
|
+
content: {
|
|
43
|
+
webpush: {
|
|
44
|
+
title: 'Test Title',
|
|
45
|
+
message: 'Test Message',
|
|
46
|
+
onClickAction: {
|
|
47
|
+
type: ACTION_TYPES.OPEN_SITE,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should use notification title as name when not in full mode', () => {
|
|
57
|
+
const payload = createWebPushPayload({
|
|
58
|
+
...defaultParams,
|
|
59
|
+
isFullMode: false,
|
|
60
|
+
templateName: '',
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
expect(payload.name).toBe('Test Title');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('should use notification title as name when template name is empty in full mode', () => {
|
|
67
|
+
const payload = createWebPushPayload({
|
|
68
|
+
...defaultParams,
|
|
69
|
+
templateName: '',
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
expect(payload.name).toBe('Test Title');
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('should trim template name', () => {
|
|
76
|
+
const payload = createWebPushPayload({
|
|
77
|
+
...defaultParams,
|
|
78
|
+
templateName: ' Test Template ',
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
expect(payload.name).toBe('Test Template');
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('should trim notification title', () => {
|
|
85
|
+
const payload = createWebPushPayload({
|
|
86
|
+
...defaultParams,
|
|
87
|
+
notificationTitle: ' Test Title ',
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
expect(payload.versions.base.content.webpush.title).toBe('Test Title');
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('should trim message', () => {
|
|
94
|
+
const payload = createWebPushPayload({
|
|
95
|
+
...defaultParams,
|
|
96
|
+
message: ' Test Message ',
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
expect(payload.versions.base.content.webpush.message).toBe('Test Message');
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
describe('Media Type Handling', () => {
|
|
104
|
+
it('should include mediaType when not NONE', () => {
|
|
105
|
+
const payload = createWebPushPayload({
|
|
106
|
+
...defaultParams,
|
|
107
|
+
mediaType: WEBPUSH_MEDIA_TYPES.IMAGE,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
expect(payload.versions.base.content.webpush.mediaType).toBe(WEBPUSH_MEDIA_TYPES.IMAGE);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('should not include mediaType when NONE', () => {
|
|
114
|
+
const payload = createWebPushPayload({
|
|
115
|
+
...defaultParams,
|
|
116
|
+
mediaType: WEBPUSH_MEDIA_TYPES.NONE,
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
expect(payload.versions.base.content.webpush.mediaType).toBeUndefined();
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
describe('Image Handling', () => {
|
|
124
|
+
it('should include image when mediaType is IMAGE and upload method is UPLOAD_IMAGE', () => {
|
|
125
|
+
const payload = createWebPushPayload({
|
|
126
|
+
...defaultParams,
|
|
127
|
+
mediaType: WEBPUSH_MEDIA_TYPES.IMAGE,
|
|
128
|
+
imageUploadMethod: IMAGE_UPLOAD_METHODS.UPLOAD_IMAGE,
|
|
129
|
+
imageSrc: 'secure/path/to/image.jpg',
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
expect(payload.versions.base.content.webpush.image).toBe('secure/path/to/image.jpg');
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('should include image when mediaType is IMAGE and upload method is ADD_IMAGE_URL', () => {
|
|
136
|
+
const payload = createWebPushPayload({
|
|
137
|
+
...defaultParams,
|
|
138
|
+
mediaType: WEBPUSH_MEDIA_TYPES.IMAGE,
|
|
139
|
+
imageUploadMethod: IMAGE_UPLOAD_METHODS.ADD_IMAGE_URL,
|
|
140
|
+
imageSrc: 'secure/path/to/image.jpg',
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
expect(payload.versions.base.content.webpush.image).toBe('secure/path/to/image.jpg');
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('should not include image when imageSrc is empty', () => {
|
|
147
|
+
const payload = createWebPushPayload({
|
|
148
|
+
...defaultParams,
|
|
149
|
+
mediaType: WEBPUSH_MEDIA_TYPES.IMAGE,
|
|
150
|
+
imageUploadMethod: IMAGE_UPLOAD_METHODS.UPLOAD_IMAGE,
|
|
151
|
+
imageSrc: '',
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
expect(payload.versions.base.content.webpush.image).toBeUndefined();
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('should not include image when mediaType is NONE', () => {
|
|
158
|
+
const payload = createWebPushPayload({
|
|
159
|
+
...defaultParams,
|
|
160
|
+
mediaType: WEBPUSH_MEDIA_TYPES.NONE,
|
|
161
|
+
imageSrc: 'secure/path/to/image.jpg',
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
expect(payload.versions.base.content.webpush.image).toBeUndefined();
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
describe('Brand Icon Handling', () => {
|
|
169
|
+
it('should include brandIcon when option is UPLOAD_IMAGE', () => {
|
|
170
|
+
const payload = createWebPushPayload({
|
|
171
|
+
...defaultParams,
|
|
172
|
+
brandIconOption: BRAND_ICON_OPTIONS.UPLOAD_IMAGE,
|
|
173
|
+
brandIconSrc: 'secure/path/to/brand-icon.jpg',
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
expect(payload.versions.base.content.webpush.brandIcon).toBe('secure/path/to/brand-icon.jpg');
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it('should not include brandIcon when option is DONT_SHOW', () => {
|
|
180
|
+
const payload = createWebPushPayload({
|
|
181
|
+
...defaultParams,
|
|
182
|
+
brandIconOption: BRAND_ICON_OPTIONS.DONT_SHOW,
|
|
183
|
+
brandIconSrc: 'secure/path/to/brand-icon.jpg',
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
expect(payload.versions.base.content.webpush.brandIcon).toBeUndefined();
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it('should not include brandIcon when brandIconSrc is empty', () => {
|
|
190
|
+
const payload = createWebPushPayload({
|
|
191
|
+
...defaultParams,
|
|
192
|
+
brandIconOption: BRAND_ICON_OPTIONS.UPLOAD_IMAGE,
|
|
193
|
+
brandIconSrc: '',
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
expect(payload.versions.base.content.webpush.brandIcon).toBeUndefined();
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
describe('On-Click Behaviour', () => {
|
|
201
|
+
it('should include onClickAction with URL type when REDIRECT_TO_URL is selected', () => {
|
|
202
|
+
const payload = createWebPushPayload({
|
|
203
|
+
...defaultParams,
|
|
204
|
+
onClickBehaviour: ON_CLICK_BEHAVIOUR_OPTIONS.REDIRECT_TO_URL,
|
|
205
|
+
redirectUrl: 'https://example.com',
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
expect(payload.versions.base.content.webpush.onClickAction).toEqual({
|
|
209
|
+
type: ACTION_TYPES.URL,
|
|
210
|
+
url: 'https://example.com',
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it('should trim redirectUrl', () => {
|
|
215
|
+
const payload = createWebPushPayload({
|
|
216
|
+
...defaultParams,
|
|
217
|
+
onClickBehaviour: ON_CLICK_BEHAVIOUR_OPTIONS.REDIRECT_TO_URL,
|
|
218
|
+
redirectUrl: ' https://example.com ',
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
expect(payload.versions.base.content.webpush.onClickAction.url).toBe('https://example.com');
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it('should include onClickAction with OPEN_SITE type when OPEN_SITE is selected', () => {
|
|
225
|
+
const payload = createWebPushPayload({
|
|
226
|
+
...defaultParams,
|
|
227
|
+
onClickBehaviour: ON_CLICK_BEHAVIOUR_OPTIONS.OPEN_SITE,
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
expect(payload.versions.base.content.webpush.onClickAction).toEqual({
|
|
231
|
+
type: ACTION_TYPES.OPEN_SITE,
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it('should not include onClickAction when redirectUrl is empty and REDIRECT_TO_URL is selected', () => {
|
|
236
|
+
const payload = createWebPushPayload({
|
|
237
|
+
...defaultParams,
|
|
238
|
+
onClickBehaviour: ON_CLICK_BEHAVIOUR_OPTIONS.REDIRECT_TO_URL,
|
|
239
|
+
redirectUrl: '',
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
// When redirectUrl is empty, onClickAction should not be included
|
|
243
|
+
expect(payload.versions.base.content.webpush.onClickAction).toBeUndefined();
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
describe('CTA Buttons', () => {
|
|
248
|
+
it('should include ctas when buttons array has items', () => {
|
|
249
|
+
const buttons = [
|
|
250
|
+
{ text: 'Button 1', url: 'https://example.com/1', type: 'primary' },
|
|
251
|
+
{ text: 'Button 2', url: 'https://example.com/2', type: 'secondary' },
|
|
252
|
+
];
|
|
253
|
+
|
|
254
|
+
const payload = createWebPushPayload({
|
|
255
|
+
...defaultParams,
|
|
256
|
+
buttons,
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
expect(payload.versions.base.content.webpush.ctas).toEqual([
|
|
260
|
+
{
|
|
261
|
+
actionText: 'Button 1',
|
|
262
|
+
type: ACTION_TYPES.URL,
|
|
263
|
+
actionLink: 'https://example.com/1',
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
actionText: 'Button 2',
|
|
267
|
+
type: ACTION_TYPES.URL,
|
|
268
|
+
actionLink: 'https://example.com/2',
|
|
269
|
+
},
|
|
270
|
+
]);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it('should not include ctas when buttons array is empty', () => {
|
|
274
|
+
const payload = createWebPushPayload({
|
|
275
|
+
...defaultParams,
|
|
276
|
+
buttons: [],
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
expect(payload.versions.base.content.webpush.ctas).toBeUndefined();
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
it('should not include ctas when buttons is null', () => {
|
|
283
|
+
const payload = createWebPushPayload({
|
|
284
|
+
...defaultParams,
|
|
285
|
+
buttons: null,
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
expect(payload.versions.base.content.webpush.ctas).toBeUndefined();
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
it('should not include ctas when buttons is undefined', () => {
|
|
292
|
+
const payload = createWebPushPayload({
|
|
293
|
+
...defaultParams,
|
|
294
|
+
buttons: undefined,
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
expect(payload.versions.base.content.webpush.ctas).toBeUndefined();
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
describe('Combined Scenarios', () => {
|
|
302
|
+
it('should create complete payload with all features', () => {
|
|
303
|
+
const buttons = [
|
|
304
|
+
{ text: 'Click Me', url: 'https://example.com', type: 'primary' },
|
|
305
|
+
];
|
|
306
|
+
|
|
307
|
+
const payload = createWebPushPayload({
|
|
308
|
+
templateName: 'Complete Template',
|
|
309
|
+
notificationTitle: 'Complete Title',
|
|
310
|
+
message: 'Complete Message',
|
|
311
|
+
mediaType: WEBPUSH_MEDIA_TYPES.IMAGE,
|
|
312
|
+
accountId: 'account123',
|
|
313
|
+
isFullMode: true,
|
|
314
|
+
imageSrc: 'secure/path/to/image.jpg',
|
|
315
|
+
imageUrl: 'https://example.com/image.jpg',
|
|
316
|
+
imageUploadMethod: IMAGE_UPLOAD_METHODS.UPLOAD_IMAGE,
|
|
317
|
+
brandIconOption: BRAND_ICON_OPTIONS.UPLOAD_IMAGE,
|
|
318
|
+
brandIconSrc: 'secure/path/to/brand-icon.jpg',
|
|
319
|
+
brandIconUrl: '',
|
|
320
|
+
buttons,
|
|
321
|
+
onClickBehaviour: ON_CLICK_BEHAVIOUR_OPTIONS.REDIRECT_TO_URL,
|
|
322
|
+
redirectUrl: 'https://example.com/redirect',
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
expect(payload).toEqual({
|
|
326
|
+
name: 'Complete Template',
|
|
327
|
+
type: WEBPUSH,
|
|
328
|
+
definition: {
|
|
329
|
+
accountId: 'account123',
|
|
330
|
+
},
|
|
331
|
+
versions: {
|
|
332
|
+
base: {
|
|
333
|
+
content: {
|
|
334
|
+
webpush: {
|
|
335
|
+
title: 'Complete Title',
|
|
336
|
+
message: 'Complete Message',
|
|
337
|
+
mediaType: WEBPUSH_MEDIA_TYPES.IMAGE,
|
|
338
|
+
image: 'secure/path/to/image.jpg',
|
|
339
|
+
brandIcon: 'secure/path/to/brand-icon.jpg',
|
|
340
|
+
onClickAction: {
|
|
341
|
+
type: ACTION_TYPES.URL,
|
|
342
|
+
url: 'https://example.com/redirect',
|
|
343
|
+
},
|
|
344
|
+
ctas: [
|
|
345
|
+
{
|
|
346
|
+
actionText: 'Click Me',
|
|
347
|
+
type: ACTION_TYPES.URL,
|
|
348
|
+
actionLink: 'https://example.com',
|
|
349
|
+
},
|
|
350
|
+
],
|
|
351
|
+
},
|
|
352
|
+
},
|
|
353
|
+
},
|
|
354
|
+
},
|
|
355
|
+
});
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
it('should handle empty strings and null values gracefully', () => {
|
|
359
|
+
const payload = createWebPushPayload({
|
|
360
|
+
templateName: '',
|
|
361
|
+
notificationTitle: '',
|
|
362
|
+
message: '',
|
|
363
|
+
mediaType: WEBPUSH_MEDIA_TYPES.NONE,
|
|
364
|
+
accountId: 'account123',
|
|
365
|
+
isFullMode: false,
|
|
366
|
+
imageSrc: '',
|
|
367
|
+
imageUrl: '',
|
|
368
|
+
imageUploadMethod: IMAGE_UPLOAD_METHODS.UPLOAD_IMAGE,
|
|
369
|
+
brandIconOption: BRAND_ICON_OPTIONS.DONT_SHOW,
|
|
370
|
+
brandIconSrc: '',
|
|
371
|
+
brandIconUrl: '',
|
|
372
|
+
buttons: [],
|
|
373
|
+
onClickBehaviour: ON_CLICK_BEHAVIOUR_OPTIONS.OPEN_SITE,
|
|
374
|
+
redirectUrl: '',
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
expect(payload.name).toBe('');
|
|
378
|
+
expect(payload.versions.base.content.webpush.title).toBe('');
|
|
379
|
+
expect(payload.versions.base.content.webpush.message).toBe('');
|
|
380
|
+
expect(payload.versions.base.content.webpush.mediaType).toBeUndefined();
|
|
381
|
+
expect(payload.versions.base.content.webpush.image).toBeUndefined();
|
|
382
|
+
expect(payload.versions.base.content.webpush.brandIcon).toBeUndefined();
|
|
383
|
+
expect(payload.versions.base.content.webpush.onClickAction).toEqual({
|
|
384
|
+
type: ACTION_TYPES.OPEN_SITE,
|
|
385
|
+
});
|
|
386
|
+
expect(payload.versions.base.content.webpush.ctas).toBeUndefined();
|
|
387
|
+
});
|
|
388
|
+
});
|
|
389
|
+
});
|
|
390
|
+
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OS_MACOS,
|
|
3
|
+
OS_IOS,
|
|
4
|
+
OS_IPADOS,
|
|
5
|
+
OS_WINDOWS,
|
|
6
|
+
OS_ANDROID_MOBILE,
|
|
7
|
+
OS_ANDROID_TABLET,
|
|
8
|
+
} from '../preview/constants';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Converts OS name to CSS class name format
|
|
12
|
+
* @param {string} os - Operating system name (e.g., 'macOS', 'Android (Mobile)')
|
|
13
|
+
* @returns {string} CSS class name (e.g., 'macos', 'android-mobile')
|
|
14
|
+
*/
|
|
15
|
+
export const getOSClassName = (os) => {
|
|
16
|
+
if (os == null) return '';
|
|
17
|
+
const osMap = {
|
|
18
|
+
[OS_MACOS]: 'macos',
|
|
19
|
+
[OS_IOS]: 'ios',
|
|
20
|
+
[OS_IPADOS]: 'ipados',
|
|
21
|
+
[OS_WINDOWS]: 'windows',
|
|
22
|
+
[OS_ANDROID_MOBILE]: 'android-mobile',
|
|
23
|
+
[OS_ANDROID_TABLET]: 'android-tablet',
|
|
24
|
+
};
|
|
25
|
+
return osMap[os] || String(os).toLowerCase().replace(/\s+/g, '-').replace(/[()]/g, '');
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Converts Browser name to CSS class name format
|
|
30
|
+
* @param {string} browser - Browser name (e.g., 'Chrome', 'Firefox')
|
|
31
|
+
* @returns {string} CSS class name (e.g., 'chrome', 'firefox')
|
|
32
|
+
*/
|
|
33
|
+
export const getBrowserClassName = (browser) => {
|
|
34
|
+
if (typeof browser === 'string') {
|
|
35
|
+
return browser.toLowerCase();
|
|
36
|
+
}
|
|
37
|
+
return '';
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Gets the combined platform + browser class name for notification-container
|
|
42
|
+
* @param {string} os - Operating system name
|
|
43
|
+
* @param {string} browser - Browser name
|
|
44
|
+
* @returns {string} Combined class name (e.g., 'macos-chrome', 'windows-firefox')
|
|
45
|
+
*/
|
|
46
|
+
export const getNotificationContainerClassName = (os, browser) => {
|
|
47
|
+
const osClass = os ? getOSClassName(os) : '';
|
|
48
|
+
const browserClass = browser ? getBrowserClassName(browser) : '';
|
|
49
|
+
|
|
50
|
+
// If both are missing, return empty string
|
|
51
|
+
if (!osClass && !browserClass) {
|
|
52
|
+
return '';
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Join non-empty parts with a single hyphen
|
|
56
|
+
return [osClass, browserClass].filter(Boolean).join('-');
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Preview-only: strip protocol, drop www. only, remove child paths and trailing slashes
|
|
61
|
+
* @param {string} rawUrl - Raw URL to format
|
|
62
|
+
* @returns {string} Formatted URL for preview display
|
|
63
|
+
*/
|
|
64
|
+
export const formatUrlForPreview = (rawUrl) => {
|
|
65
|
+
// Handle null/undefined
|
|
66
|
+
if (rawUrl == null) return rawUrl;
|
|
67
|
+
|
|
68
|
+
// Ensure rawUrl is a string before calling string methods
|
|
69
|
+
if (typeof rawUrl !== 'string') return rawUrl;
|
|
70
|
+
|
|
71
|
+
const withoutProtocol = rawUrl.replace(/^https?:\/\//i, '');
|
|
72
|
+
const withoutWww = withoutProtocol.startsWith('www.') ? withoutProtocol.slice(4) : withoutProtocol;
|
|
73
|
+
// Remove child paths (everything after the first slash)
|
|
74
|
+
const domainOnly = withoutWww.split('/')[0];
|
|
75
|
+
return domainOnly.replace(/\/+$/, '');
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Transforms form buttons to preview format
|
|
80
|
+
* @param {Array} formButtons - Array of button objects from form
|
|
81
|
+
* @returns {Array} Transformed buttons with id and label
|
|
82
|
+
*/
|
|
83
|
+
export const transformButtonsForPreview = (formButtons = []) => {
|
|
84
|
+
return formButtons.map((button, index) => ({
|
|
85
|
+
id: String(index + 1),
|
|
86
|
+
label: button?.text || '',
|
|
87
|
+
}));
|
|
88
|
+
};
|
|
89
|
+
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* URL Validation Utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides robust URL validation that works across different environments
|
|
5
|
+
* (browser, Node.js, Jest) with multiple fallback strategies.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
SUPPORTED_PROTOCOLS,
|
|
10
|
+
HTTP_URL_PATTERN,
|
|
11
|
+
TLD_PATTERN,
|
|
12
|
+
} from '../../constants';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Resolves the URL constructor available in the current environment
|
|
16
|
+
* @returns {Function|null} URL constructor function or null if not available
|
|
17
|
+
*/
|
|
18
|
+
const resolveUrlConstructor = () => {
|
|
19
|
+
if (typeof window !== 'undefined' && typeof window.URL === 'function') {
|
|
20
|
+
return window.URL;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (typeof URL === 'function') {
|
|
24
|
+
return URL;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return null;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Checks if document API is available for DOM-based validation
|
|
32
|
+
* @returns {boolean} True if document.createElement is available
|
|
33
|
+
*/
|
|
34
|
+
const canUseDocument = () => typeof document !== 'undefined' && typeof document.createElement === 'function';
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Validates if a value is a valid HTTP/HTTPS URL
|
|
38
|
+
* Uses multiple validation strategies for maximum compatibility:
|
|
39
|
+
* 1. Regex pattern check for http:// or https:// prefix
|
|
40
|
+
* 2. URL constructor validation (if available)
|
|
41
|
+
* 3. DOM-based validation using anchor element (if available)
|
|
42
|
+
*
|
|
43
|
+
* @param {string} value - The URL string to validate
|
|
44
|
+
* @returns {boolean} True if the value is a valid HTTP/HTTPS URL
|
|
45
|
+
*/
|
|
46
|
+
export const isValidHttpUrl = (value) => {
|
|
47
|
+
if (!value) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const trimmedValue = value.trim();
|
|
52
|
+
if (!trimmedValue) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// First check: regex pattern for http:// or https:// prefix
|
|
57
|
+
if (!HTTP_URL_PATTERN.test(trimmedValue)) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Second check: ensure URL has a valid TLD (Top Level Domain)
|
|
62
|
+
// URLs like https://google are invalid, but https://google.com is valid
|
|
63
|
+
if (!TLD_PATTERN.test(trimmedValue)) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Third check: try URL constructor if available
|
|
68
|
+
const UrlConstructor = resolveUrlConstructor();
|
|
69
|
+
if (UrlConstructor) {
|
|
70
|
+
try {
|
|
71
|
+
const parsedUrl = new UrlConstructor(trimmedValue);
|
|
72
|
+
if (SUPPORTED_PROTOCOLS.has(parsedUrl.protocol)) {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
} catch (error) {
|
|
76
|
+
// URL constructor failed, fall back to DOM-based validation
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Fourth check: DOM-based validation using anchor element
|
|
81
|
+
if (canUseDocument()) {
|
|
82
|
+
const parser = document.createElement('a');
|
|
83
|
+
parser.href = trimmedValue;
|
|
84
|
+
if (SUPPORTED_PROTOCOLS.has(parser.protocol)) {
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// If all validation methods failed, return false
|
|
90
|
+
return false;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Validates a URL value and returns an error message if invalid
|
|
95
|
+
* This is a higher-level validation function that can be used with form validation
|
|
96
|
+
*
|
|
97
|
+
* @param {string} value - The URL string to validate
|
|
98
|
+
* @param {Function} formatMessage - Function to format error messages (e.g., react-intl formatMessage)
|
|
99
|
+
* @param {Object} messages - Object containing error message keys:
|
|
100
|
+
* - urlRequired: Message for empty URL
|
|
101
|
+
* - urlInvalid: Message for invalid URL format
|
|
102
|
+
* @returns {string} Empty string if valid, error message if invalid
|
|
103
|
+
*/
|
|
104
|
+
export const validateUrl = (value, formatMessage, messages) => {
|
|
105
|
+
if (!value || value.trim() === '') {
|
|
106
|
+
return formatMessage(messages.urlRequired);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (!isValidHttpUrl(value)) {
|
|
110
|
+
return formatMessage(messages.urlInvalid);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return '';
|
|
114
|
+
};
|
|
115
|
+
|