@nuskin/ns-common-lib
Advanced tools
Comparing version 1.1.0 to 1.2.0
/* eslint-disable max-len */ | ||
const { getFullUrl, getUrlWithExtention } = require("../src/urls"); | ||
const { getFullUrl, getUrlWithExtention, getEnvironmentFromUrl } = require("../src/urls"); | ||
@@ -31,1 +31,23 @@ describe("[urls.js] getFullUrl", () => { | ||
}); | ||
describe("[urls.js] getEnvironmentFromUrl", () => { | ||
test("Can call getEnvironmentFromUrl and get 'dev'", () => { | ||
const baseUrl = "https://dev.nuskin.com"; | ||
expect(getEnvironmentFromUrl(baseUrl)).toBe('dev'); | ||
}); | ||
test("Can call getEnvironmentFromUrl and get 'test'", () => { | ||
const baseUrl = "https://test.nuskin.com"; | ||
expect(getEnvironmentFromUrl(baseUrl)).toBe('test'); | ||
}); | ||
test("Can call getEnvironmentFromUrl and get 'stage'", () => { | ||
const baseUrl = "https://stage.nuskin.com"; | ||
expect(getEnvironmentFromUrl(baseUrl)).toBe('stage'); | ||
}); | ||
test("Can call getEnvironmentFromUrl and get 'prod'", () => { | ||
const baseUrl = "https://www.nuskin.com"; | ||
expect(getEnvironmentFromUrl(baseUrl)).toBe('prod'); | ||
}); | ||
}); |
@@ -0,1 +1,12 @@ | ||
# [1.2.0](https://code.tls.nuskin.io/ns-am/utility/npm/ns-common-lib/compare/v1.1.0...v1.2.0) (2021-04-02) | ||
### Chore | ||
* minor changes with project moved to new location in GitLab ([c8374eb](https://code.tls.nuskin.io/ns-am/utility/npm/ns-common-lib/commit/c8374eb160f8c4078b4f4d6d2b2a8696d9e298e8)) | ||
### Update | ||
* added getEnvironmentFromUrl (#CX12-3039) ([8047df6](https://code.tls.nuskin.io/ns-am/utility/npm/ns-common-lib/commit/8047df61832181772c6dcecae09143d3d959e740)), closes [#CX12-3039](https://code.tls.nuskin.io/ns-am/utility/npm/ns-common-lib/issues/CX12-3039) | ||
# [1.1.0](https://code.tls.nuskin.io/ns-am/platform/ns-common-lib/compare/v1.0.0...v1.1.0) (2020-10-22) | ||
@@ -2,0 +13,0 @@ |
{ | ||
"name": "@nuskin/ns-common-lib", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "This project contains shared common models and code between the backend and frontend.", | ||
@@ -15,3 +15,3 @@ "main": "src/index.js", | ||
"type": "git", | ||
"url": "git@code.tls.nuskin.io:ns-am/platform/ns-common-lib.git" | ||
"url": "git@code.tls.nuskin.io:ns-am/utility/npm/ns-common-lib.git" | ||
}, | ||
@@ -21,3 +21,3 @@ "keywords": [], | ||
"license": "ISC", | ||
"homepage": "https://code.tls.nuskin.io/ns-am/platform/ns-common-lib/blob/master/README.md", | ||
"homepage": "https://code.tls.nuskin.io/ns-am/utility/npm/ns-common-lib/-/blob/master/README.md", | ||
"devDependencies": { | ||
@@ -24,0 +24,0 @@ "eslint": "5.16.0", |
@@ -11,3 +11,7 @@ /** | ||
const { fromJsonString } = require("./json"); | ||
const { getFullUrl, getUrlWithExtention } = require("./urls"); | ||
const { | ||
getFullUrl, | ||
getUrlWithExtention, | ||
getEnvironmentFromUrl | ||
} = require("./urls"); | ||
const { arrayDifference } = require("./arrays"); | ||
@@ -23,4 +27,5 @@ const { getLocaleInfo } = require("./locale"); | ||
getUrlWithExtention, | ||
getEnvironmentFromUrl, | ||
arrayDifference, | ||
getLocaleInfo | ||
}; |
@@ -39,5 +39,96 @@ "use strict"; | ||
/** | ||
* Environment URLs | ||
* Note: These values were copied from ns-util runConfigService.js | ||
*/ | ||
const environmentUrls = { | ||
local: "localhost", | ||
local4502: "localhost:4502", | ||
test: "test.nuskin.com", | ||
testStorefront: "test.mynuskin.com", | ||
testCloud: "tst.nuskin.io", | ||
dev: "dev.nuskin.com", | ||
devCloud: "dev.nuskin.io", | ||
prod: "www.nuskin.com", | ||
prodStorefront: ".mynuskin.com", | ||
prodCloud: "www.nuskin.io", | ||
stage: "stage.nuskin.com", | ||
stageCloud: "stg.nuskin.io", | ||
feature: "dev.usw2.nuskin.io" | ||
}; | ||
/** | ||
* Dev Environment URLs | ||
*/ | ||
const devEnvironmentUrls = [environmentUrls.dev, environmentUrls.devCloud]; | ||
/** | ||
* Test Environment URLs | ||
*/ | ||
const testEnvironmentUrls = [ | ||
environmentUrls.test, | ||
environmentUrls.testStorefront, | ||
environmentUrls.feature, | ||
environmentUrls.testCloud, | ||
environmentUrls.local, | ||
environmentUrls.local4502 | ||
]; | ||
/** | ||
* Stage Environment URLs | ||
*/ | ||
const stageEnvironmentUrls = [ | ||
environmentUrls.stage, | ||
environmentUrls.stageCloud | ||
]; | ||
/** | ||
* Prod Environment URLs | ||
*/ | ||
const prodEnvironmentUrls = [ | ||
environmentUrls.prod, | ||
environmentUrls.prodCloud, | ||
environmentUrls.prodStorefront | ||
]; | ||
/** | ||
* This attempts to get the environment based on the URL of nuskin.com known addresses. | ||
* @param {String} url | ||
*/ | ||
function getEnvironmentFromUrl(url) { | ||
if (url) { | ||
// check if 'dev' environment | ||
if (devEnvironmentUrls.some((envUrl) => url.includes(envUrl))) { | ||
return "dev"; | ||
} | ||
// check if 'test' environment | ||
if (testEnvironmentUrls.some((e) => url.includes(e))) { | ||
return "test"; | ||
} | ||
// check if 'stage' environment | ||
if (stageEnvironmentUrls.some((envUrl) => url.includes(envUrl))) { | ||
return "stage"; | ||
} | ||
// check if 'prod' environment | ||
if (prodEnvironmentUrls.some((envUrl) => url.includes(envUrl))) { | ||
return "prod"; | ||
} | ||
} | ||
// environment is not known | ||
return "unknown"; | ||
} | ||
module.exports = { | ||
getFullUrl, | ||
getUrlWithExtention | ||
getUrlWithExtention, | ||
environmentUrls, | ||
devEnvironmentUrls, | ||
testEnvironmentUrls, | ||
stageEnvironmentUrls, | ||
prodEnvironmentUrls, | ||
getEnvironmentFromUrl | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18583
485
20