Skip to content

Commit

Permalink
Merge pull request #272 from CleverTap/fix-version-check
Browse files Browse the repository at this point in the history
fix: sdk version check
  • Loading branch information
kkyusuftk authored Oct 10, 2024
2 parents 67ed3ba + 394ae53 commit bb347a9
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Change Log
All notable changes to this project will be documented in this file.

## [1.10.1] - 8 Oct, 2024
- Adding a fix for the version check in visual editor

## [1.10.0] - 8 Oct, 2024
- Adds new api to handle rendering of customized web push prompt

Expand Down
27 changes: 24 additions & 3 deletions clevertap.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion clevertap.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion clevertap.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "clevertap-web-sdk",
"version": "1.10.0",
"version": "1.10.1",
"description": "",
"main": "clevertap.js",
"scripts": {
Expand Down
5 changes: 4 additions & 1 deletion src/modules/visualBuilder/pageBuilder.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CSS_PATH, OVERLAY_PATH, WVE_CLASS } from './builder_constants'
import { updateFormData } from './dataUpdate'
import { versionCompare } from './versionCompare'

export const checkBuilder = (logger, accountId) => {
const search = window.location.search
Expand All @@ -23,11 +24,13 @@ export const checkBuilder = (logger, accountId) => {

if (search === '?ctBuilderSDKCheck') {
if (parentWindow) {
const sdkVersion = '$$PACKAGE_VERSION$$'
const isRequiredVersion = versionCompare(sdkVersion)
parentWindow.postMessage({
message: 'SDKVersion',
accountId,
originUrl: window.location.href,
sdkVersion: '$$PACKAGE_VERSION$$'
sdkVersion: isRequiredVersion ? '1.9.3' : sdkVersion
},
'*'
)
Expand Down
18 changes: 18 additions & 0 deletions src/modules/visualBuilder/versionCompare.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export const versionCompare = (currentVersion) => {
const requiredVersion = '1.9.2'
if (requiredVersion === currentVersion) return true
const splitRequiredVersion = requiredVersion.split('.')
const splitCurrentVersion = currentVersion.split('.')

let p1 = 0
let isWebsiteVersionHigher = false

while (p1 < splitRequiredVersion.length && !isWebsiteVersionHigher) {
if (parseInt(splitRequiredVersion[p1]) < parseInt(splitCurrentVersion[p1])) {
isWebsiteVersionHigher = true
}
p1++
}

return isWebsiteVersionHigher
}

0 comments on commit bb347a9

Please sign in to comment.