Skip to content

Commit

Permalink
Merge pull request #12 from AppsFlyerSDK/DELIVERY-62168/semverBugFix
Browse files Browse the repository at this point in the history
Delivery 62168/semver bug fix
  • Loading branch information
GM-appsflyer authored May 26, 2024
2 parents d41f1eb + db523b7 commit 98f4274
Show file tree
Hide file tree
Showing 7 changed files with 3,946 additions and 10 deletions.
19 changes: 19 additions & 0 deletions __tests__/utils/utils.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {isVersionGreaterThanOrEqualTo} from "../../src/platforms/utils/utils.js"

const MINIMUM_OS_VERSION_SUPPORTED = "4.0.0"
let falseDataSet = ["1.0.0", "1.0", "2.0", "3.99", "3.9", "0", "0.0", null, undefined, "", 0, 2]
let trueDataSet = ["4", "4.0.0", "4.1", "4.0.1", "5", "5.0", "5.0.0", 4, 4.1, 5, 5.5, 44]


it.each(falseDataSet)("false response for isVersionGreaterThanOrEqualTo", async (version) => {
console.log(version)
expect(isVersionGreaterThanOrEqualTo(version, MINIMUM_OS_VERSION_SUPPORTED)).toEqual(false);
})

it.each(trueDataSet)("true response for isVersionGreaterThanOrEqualTo", async (version) => {
console.log(version)
expect(isVersionGreaterThanOrEqualTo(version, MINIMUM_OS_VERSION_SUPPORTED)).toEqual(true);
})



2 changes: 1 addition & 1 deletion dist/appsflyerSdk.bundle.js

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "appsflyer-html5-ctv-sdk",
"version": "0.0.2",
"version": "0.0.3",
"description": "AppsFlyer SDK for TV application",
"type": "module",
"directories": {
Expand All @@ -22,15 +22,13 @@
"author": "appsflyer",
"license": "ISC",
"devDependencies": {
"@babel/preset-env": "~7.18.9",
"@babel/preset-env": "7.23.2",
"babel-jest": "~28.1.3",
"babel-loader": "~8.2.5",
"babel-preset-es2015": "~6.24.1",
"eslint": "~8.20.0",
"eslint-config-google": "~0.14.0",
"jest": "~28.1.3",
"jest-fetch-mock": "~3.0.3",
"semver": "~7.3.8",
"webpack": "~5.84.1",
"webpack-cli": "~4.10.0"
}
Expand Down
7 changes: 4 additions & 3 deletions src/AppsFlyerSDK.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import LG from './platforms/lg.js';
import Vizio from './platforms/vizio.js';
import Vidaa from './platforms/vidaa.js';
import {INVALID_SDK, DEVICE_OS_NOT_SUPPORT, NO_PLATFORM_FOUND} from './core/utils/constants.js';
import {MINIMUM_OS_VERSION_SUPPORTED} from './platforms/utils/constants.js';
import {isVersionGreaterThanOrEqualTo} from './platforms/utils/utils.js';
import {Platform} from './platforms/utils/types.js';
import semver from 'semver';

const PLATFORM_MAPPING = [Samsung, LG, Vizio, Vidaa]

Expand Down Expand Up @@ -81,9 +82,9 @@ class AppsFlyerSDK {
setCustomerUserId(userId) {
return this.isSDKValid() ? this.appsflyerInstance.setCustomerUserId(userId) : new Error(INVALID_SDK);
}

async validateOSVersion(os, osVersion){
if((os == Platform.Tizen || os == Platform.Webos) && semver.gte(semver.coerce(osVersion), '4.0.0')){
if((os == Platform.Tizen || os == Platform.Webos) && isVersionGreaterThanOrEqualTo(osVersion, MINIMUM_OS_VERSION_SUPPORTED)){
return true
}else{
let raw = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./);
Expand Down
4 changes: 2 additions & 2 deletions src/platforms/utils/constants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const DEFAULT_DEVICE_ID = "00000000-0000-0000-0000-000000000000";

export const DEFAULT_APP_VERSION = '0.0.0';
export const DEFAULT_APP_VERSION = '0.0.0';
export const MINIMUM_OS_VERSION_SUPPORTED= '4.0.0'
33 changes: 33 additions & 0 deletions src/platforms/utils/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
export const isVersionGreaterThanOrEqualTo = (versionA, versionB) => {
const isValidVersion = (version) => {
return version !== null && version !== undefined && version !== "";
};

if (!isValidVersion(versionA)) {
return false;
}

const normalizeVersion = (v) => v.split('.').map(part => parseInt(part, 10)); // Normalize version string

const compareVersions = (partsA, partsB) => {
const maxLength = Math.max(partsA.length, partsB.length);

for (let i = 0; i < maxLength; i++) {
const partA = partsA[i] || 0; // Use 0 if no more parts in version
const partB = partsB[i] || 0; // Use 0 if no more parts in version

if (partA > partB) {
return true;
} else if (partA < partB) {
return false;
}
}

return true; // Versions are equal
};

const partsA = normalizeVersion(typeof versionA === 'number' ? versionA.toString() : versionA);
const partsB = normalizeVersion(versionB);

return compareVersions(partsA, partsB);
};
Loading

0 comments on commit 98f4274

Please sign in to comment.