Repository: saucelabs/node-saucelabs (js)

Issue:
remove us-east-1 datacenter
## Expected Behavior

All datacenter and their APIs exist. Currently, running `sl --headless` doesn't not work

## Actual Behavior

us-east-1 was EOLed some time ago


## Specifications

  - Version:
  - Platform:
  - Subsystem:


Pull request description:
Revert "WIP: us-east-1 is not supported, resolves #244"
Reverts saucelabs/node-saucelabs#243

Patch:
diff --git a/apis/builds.json b/apis/builds.json
index 7b3eec5..1af3576 100644
--- a/apis/builds.json
+++ b/apis/builds.json
@@ -13,7 +13,7 @@
         "region": {
           "default": "us-west-1",
           "description": "region of datacenter",
-          "enum": ["us-west-1", "us-east-4", "eu-central-1", "staging"]
+          "enum": ["us-west-1", "us-east-1", "eu-central-1", "staging"]
         },
         "tld": {
           "default": "com",
diff --git a/apis/sauce.json b/apis/sauce.json
index 063129c..8c9d149 100644
--- a/apis/sauce.json
+++ b/apis/sauce.json
@@ -24,7 +24,7 @@
         "region": {
           "default": "us-west-1",
           "description": "region of datacenter",
-          "enum": ["us-west-1", "us-east-4", "eu-central-1", "staging"]
+          "enum": ["us-west-1", "us-east-1", "eu-central-1", "staging"]
         },
         "tld": {
           "default": "com",
diff --git a/apis/teamManagement.json b/apis/teamManagement.json
index 0a1f97f..27e5eab 100644
--- a/apis/teamManagement.json
+++ b/apis/teamManagement.json
@@ -13,7 +13,7 @@
         "region": {
           "default": "us-west-1",
           "description": "region of datacenter",
-          "enum": ["us-west-1", "us-east-4", "eu-central-1", "staging"]
+          "enum": ["us-west-1", "us-east-1", "eu-central-1", "staging"]
         },
         "tld": {
           "default": "com",
diff --git a/scripts/constants.js b/scripts/constants.js
index 9a94366..449f15c 100644
--- a/scripts/constants.js
+++ b/scripts/constants.js
@@ -25,7 +25,7 @@ export interface SauceLabsOptions {
      *
      * - us-west-1 (short 'us')
      * - eu-central-1 (short 'eu')
-     * - us-east-4
+     * - us-east-1 (headless)
      */
     region?: ${regions};
     /**
diff --git a/src/constants.js b/src/constants.js
index de7a8c4..c74e523 100644
--- a/src/constants.js
+++ b/src/constants.js
@@ -97,7 +97,7 @@ export const ASSET_REGION_MAPPING = {
   us: '',
   eu: 'eu-central-1.',
   'us-west-1': '',
-  'us-east-4': 'us-east-4.',
+  'us-east-1': 'us-east-1.',
   'eu-central-1': 'eu-central-1.',
   staging: 'staging.',
 };
diff --git a/src/utils.js b/src/utils.js
index c69babd..711fc15 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -37,6 +37,7 @@ export function getRegionSubDomain(options = {}) {
 
   if (options.region === 'us') region = 'us-west-1';
   if (options.region === 'eu') region = 'eu-central-1';
+  if (options.headless) region = 'us-east-1';
   return region;
 }
 
@@ -45,7 +46,7 @@ export function getRegionSubDomain(options = {}) {
  * @param  {string}  servers   OpenAPI spec servers property
  * @param  {string}  basePath  OpenAPI spec base path
  * @param  {object}  options   client options
- * @return {string}            endpoint base url (e.g. `https://api.us-east-4.saucelabs.com`)
+ * @return {string}            endpoint base url (e.g. `https://us-east1.headless.saucelabs.com`)
  */
 export function getAPIHost(servers, basePath, options) {
   /**
@@ -85,10 +86,14 @@ export function getAPIHost(servers, basePath, options) {
  * helper to generate host for assets, like:
  * https://assets.saucelabs.com/jobs/<jobId>/selenium-server.log
  * https://assets.eu-central-1.saucelabs.com/jobs/<jobId>/log.json
- * https://assets.us-east-4.saucelabs.com/jobs/<jobId>/log.json
+ * https://assets.us-east-1.saucelabs.com/jobs/<jobId>/log.json
  * https://assets.staging.saucelabs.net/jobs/<jobId>/log.json
  */
 export function getAssetHost(options) {
+  if (options.headless) {
+    options.region = 'us-east-1';
+  }
+
   if (options.region === 'staging') {
     options.tld = options.tld || 'net';
   }


Test patch:
diff --git a/tests/index.test.js b/tests/index.test.js
index 98cea9b..afc0ff0 100644
--- a/tests/index.test.js
+++ b/tests/index.test.js
@@ -79,6 +79,16 @@ test('should expose a webdriverEndpoint', () => {
     'https://ondemand.eu-central-1.saucelabs.com/'
   );
 
+  const api3 = new SauceLabs({
+    user: 'foo',
+    key: 'bar',
+    region: 'eu',
+    headless: true,
+  });
+  expect(api3.webdriverEndpoint).toBe(
+    'https://ondemand.us-east-1.saucelabs.com/'
+  );
+
   const api4 = new SauceLabs({user: 'foo', key: 'bar', region: 'us-central-3'});
   expect(api4.webdriverEndpoint).toBe(
     'https://ondemand.us-central-3.saucelabs.com/'
diff --git a/tests/utils.test.js b/tests/utils.test.js
index 6534417..4296d8f 100644
--- a/tests/utils.test.js
+++ b/tests/utils.test.js
@@ -40,8 +40,14 @@ test('getAPIHost', () => {
     getAPIHost(sauceAPI.servers, sauceAPI.basePath, {region: 'us-west-1'})
   ).toBe('https://api.us-west-1.saucelabs.com/rest');
   expect(
-    getAPIHost(sauceAPI.servers, sauceAPI.basePath, {region: 'us-east-4'})
-  ).toBe('https://api.us-east-4.saucelabs.com/rest');
+    getAPIHost(sauceAPI.servers, sauceAPI.basePath, {region: 'us-east-1'})
+  ).toBe('https://api.us-east-1.saucelabs.com/rest');
+  expect(
+    getAPIHost(sauceAPI.servers, sauceAPI.basePath, {
+      region: 'us-west-1',
+      headless: true,
+    })
+  ).toBe('https://api.us-east-1.saucelabs.com/rest');
   expect(
     getAPIHost(sauceAPI.servers, sauceAPI.basePath, {host: 'http://foobar.com'})
   ).toBe('http://foobar.com/rest');
@@ -85,8 +91,11 @@ test('getAssetHost', () => {
   expect(getAssetHost({region: 'eu-central-1'})).toBe(
     'https://assets.eu-central-1.saucelabs.com'
   );
-  expect(getAssetHost({region: 'us-east-4'})).toBe(
-    'https://assets.us-east-4.saucelabs.com'
+  expect(getAssetHost({headless: true})).toBe(
+    'https://assets.us-east-1.saucelabs.com'
+  );
+  expect(getAssetHost({headless: true, region: 'eu'})).toBe(
+    'https://assets.us-east-1.saucelabs.com'
   );
   expect(getAssetHost({region: 'staging'})).toBe(
     'https://assets.staging.saucelabs.net'