From d62e00021a097051b6178a33ed64ef1cfb1c200e Mon Sep 17 00:00:00 2001 From: Robert Steilberg Date: Thu, 21 Jan 2021 14:33:10 -0500 Subject: [PATCH] style(use hostname instead of domain prop on domain entry): use hostname instead of domain prop on d affects: @esri/hub-sites --- docs/src/guides/sites-and-pages.md | 4 ++-- packages/sites/src/domains/_lookup-portal.ts | 10 +++++----- .../sites/src/domains/domain-exists-portal.ts | 8 ++++---- packages/sites/src/domains/domain-exists.ts | 10 ++++++---- .../src/domains/get-unique-domain-name.ts | 1 + .../src/domains/is-domain-used-elsewhere.ts | 6 +++--- packages/sites/src/domains/is-valid-domain.ts | 8 ++++---- packages/sites/src/domains/lookup-domain.ts | 8 ++++---- packages/sites/src/domains/types.ts | 1 - packages/sites/src/get-domain.ts | 8 ++++---- .../sites/src/update-site-application-uris.ts | 1 - .../test/domains/_get-auth-header.test.ts | 2 +- .../get-unique-domain-name-portal.test.ts | 2 +- .../domains/is-domain-used-elsewhere.test.ts | 2 +- packages/sites/test/get-domain.test.ts | 20 +++++++++---------- .../test/update-site-application-uris.test.ts | 1 - 16 files changed, 46 insertions(+), 46 deletions(-) diff --git a/docs/src/guides/sites-and-pages.md b/docs/src/guides/sites-and-pages.md index f28d1f989e5..993fa8b0e03 100644 --- a/docs/src/guides/sites-and-pages.md +++ b/docs/src/guides/sites-and-pages.md @@ -29,7 +29,7 @@ import { lookupDomain } from '@esri/hub-sites'; ... return lookupDomain('data-myorg.hub.arcgis.com', hubRequestOptions) .then((domainInfo) => { - console.log(`Domain ${domainInfo.domain} belongs to org ${domainInfo.orgId} and is backed by item ${domainInfo.itemId}) + console.log(`Domain ${domainInfo.hostname} belongs to org ${domainInfo.orgId} and is backed by item ${domainInfo.itemId}) }) ``` @@ -57,7 +57,7 @@ return getDomainsForSite(siteId, hubRequestOptions) // since sites can have multiple domains, let's find the one we want to change const domainToChange = domains.findBy(domains, 'domain', currentDomain); // update the domain property to the new domain - domainToChange.domain = newDomain; + domainToChange.hostname = newDomain; // save the change return updateDomain(domainToChange, hubRequestOptions) }) diff --git a/packages/sites/src/domains/_lookup-portal.ts b/packages/sites/src/domains/_lookup-portal.ts index cae01c2a60d..81dd7fd4f3a 100644 --- a/packages/sites/src/domains/_lookup-portal.ts +++ b/packages/sites/src/domains/_lookup-portal.ts @@ -3,19 +3,19 @@ import { IHubRequestOptions, includes } from "@esri/hub-common"; /** * Lookup a domain in Portal - * @param {string} domain Domain to locate the site for + * @param {string} hostname to locate the site for * @param {IHubRequestOptions} hubRequestOptions * @private */ export function _lookupPortal( - domain: string, + hostname: string, hubRequestOptions: IHubRequestOptions ): Promise<{ hostname: string; siteId: string }> { // for portal we search for a site w/ `hubsubdomain|` type keyword - let subdomain = domain; + let subdomain = hostname; // if this subdomain has a hash in it, knock that off - if (domain.indexOf("#/") > -1) { - subdomain = domain.split("#/")[1]; + if (hostname.indexOf("#/") > -1) { + subdomain = hostname.split("#/")[1]; } const queryTerm = `hubsubdomain|${subdomain}`; diff --git a/packages/sites/src/domains/domain-exists-portal.ts b/packages/sites/src/domains/domain-exists-portal.ts index f3ad53fe793..8fb142d78a6 100644 --- a/packages/sites/src/domains/domain-exists-portal.ts +++ b/packages/sites/src/domains/domain-exists-portal.ts @@ -3,15 +3,15 @@ import { IHubRequestOptions } from "@esri/hub-common"; /** * Check if an item exists with the specified domain keyword - * @param {String} domain domain to check for + * @param {String} hostname to check for * @param {IHubRequestOptions} hubRequestOptions */ export function domainExistsPortal( - domain: string, + hostname: string, hubRequestOptions: IHubRequestOptions ) { - return _lookupPortal(domain, hubRequestOptions) - .then(res => { + return _lookupPortal(hostname, hubRequestOptions) + .then(_ => { return true; }) .catch(_ => { diff --git a/packages/sites/src/domains/domain-exists.ts b/packages/sites/src/domains/domain-exists.ts index 3ec02357e1d..3eeb00fcad4 100644 --- a/packages/sites/src/domains/domain-exists.ts +++ b/packages/sites/src/domains/domain-exists.ts @@ -8,18 +8,20 @@ import { _getAuthHeader } from "./_get-auth-header"; * return the domain entry or throw. However, lookupDomain can work * with ArcGIS Enterprise. * Will throw if used in Portal. - * @param {string} domain Domain entry to check for + * @param {string} hostname Domain entry to check for * @param {IHubRequestOptions} hubRequestOptions */ export function domainExists( - domain: string, + hostname: string, hubRequestOptions: IHubRequestOptions ) { if (hubRequestOptions.isPortal) { throw new Error(`domainExists is not available in ArcGIS Enterprise.`); } - domain = stripProtocol(domain); - const url = `${_getDomainServiceUrl(hubRequestOptions.hubApiUrl)}/${domain}`; + hostname = stripProtocol(hostname); + const url = `${_getDomainServiceUrl( + hubRequestOptions.hubApiUrl + )}/${hostname}`; const headers = _getAuthHeader(hubRequestOptions); return fetch(url, { method: "GET", headers, mode: "cors" }).then( response => response.status !== 404 diff --git a/packages/sites/src/domains/get-unique-domain-name.ts b/packages/sites/src/domains/get-unique-domain-name.ts index d918f7acb76..60109e14c68 100644 --- a/packages/sites/src/domains/get-unique-domain-name.ts +++ b/packages/sites/src/domains/get-unique-domain-name.ts @@ -6,6 +6,7 @@ import { domainExists } from "./domain-exists"; * a subdomain * @param {String} subdomain Subdomain to ensure is unique * @param {String} baseHostname base hostname + * @param hubRequestOptions * @param {Number} step Step number */ export function getUniqueDomainName( diff --git a/packages/sites/src/domains/is-domain-used-elsewhere.ts b/packages/sites/src/domains/is-domain-used-elsewhere.ts index ea2791ee5a8..2c71649a2ca 100644 --- a/packages/sites/src/domains/is-domain-used-elsewhere.ts +++ b/packages/sites/src/domains/is-domain-used-elsewhere.ts @@ -5,16 +5,16 @@ import { lookupDomain } from "./lookup-domain"; * Check to see if a domain is in use by any site other than the * one passed in. This is used in various validators while the * user is editing properties of the site. - * @param {string} domain Domain to check + * @param {string} hostname to check * @param {string} siteId Site Id we are checking for * @param {IHubRequestOptions} hubRequestOptions */ export function isDomainUsedElsewhere( - domain: string, + hostname: string, siteId: string, hubRequestOptions: IHubRequestOptions ) { - return lookupDomain(domain, hubRequestOptions) + return lookupDomain(hostname, hubRequestOptions) .then(domainEntry => { return domainEntry.siteId !== siteId; }) diff --git a/packages/sites/src/domains/is-valid-domain.ts b/packages/sites/src/domains/is-valid-domain.ts index 2a02c04ff8f..9775933e228 100644 --- a/packages/sites/src/domains/is-valid-domain.ts +++ b/packages/sites/src/domains/is-valid-domain.ts @@ -3,11 +3,11 @@ import { IHubRequestOptions } from "@esri/hub-common"; /** * Validate a custom domain - * @param {string} domain Domain to validate + * @param {string} hostname to validate * @param {IHubRequestOptions} hubRequestOptions */ export function isValidDomain( - domain: string, + hostname: string, hubRequestOptions: IHubRequestOptions ) { if (hubRequestOptions.isPortal) { @@ -15,7 +15,7 @@ export function isValidDomain( } const url = `${ hubRequestOptions.hubApiUrl - }/api/v3/domains/validate?hostname=${domain}`; + }/api/v3/domains/validate?hostname=${hostname}`; const headers = _getAuthHeader(hubRequestOptions); return fetch(url, { method: "GET", headers, mode: "cors" }) @@ -25,7 +25,7 @@ export function isValidDomain( .catch(e => { return { success: false, - input: domain, + input: hostname, error: { code: 400, detail: e, diff --git a/packages/sites/src/domains/lookup-domain.ts b/packages/sites/src/domains/lookup-domain.ts index 411ba450d91..1d8281a62fc 100644 --- a/packages/sites/src/domains/lookup-domain.ts +++ b/packages/sites/src/domains/lookup-domain.ts @@ -8,19 +8,19 @@ import { IDomainEntry } from "./types"; /** * Fetch a the information about a domain. * Different implementation for Portal vs AGO - * @param {string} domain Domain record to locate + * @param {string} hostname of domain record to locate * @param {IHubRequestOptions} hubRequestOptions */ export function lookupDomain( - domain: string, + hostname: string, hubRequestOptions: IHubRequestOptions ): Promise { if (hubRequestOptions.isPortal) { - return _lookupPortal(domain, hubRequestOptions); + return _lookupPortal(hostname, hubRequestOptions); } else { const url = `${_getDomainServiceUrl( hubRequestOptions.hubApiUrl - )}/${domain}`; + )}/${hostname}`; const headers = _getAuthHeader(hubRequestOptions); return fetch(url, { method: "GET", headers, mode: "cors" }).then( _checkStatusAndParseJson diff --git a/packages/sites/src/domains/types.ts b/packages/sites/src/domains/types.ts index c560b96b0ef..7fac612c7ae 100644 --- a/packages/sites/src/domains/types.ts +++ b/packages/sites/src/domains/types.ts @@ -1,7 +1,6 @@ export interface IDomainEntry { clientKey: string; createdAt?: string; - domain: string; hostname: string; id: string; orgId: string; diff --git a/packages/sites/src/get-domain.ts b/packages/sites/src/get-domain.ts index da7f3523a5e..bb4194c4a79 100644 --- a/packages/sites/src/get-domain.ts +++ b/packages/sites/src/get-domain.ts @@ -44,21 +44,21 @@ export function getDomain( // ok - in this case, it's likely that we have a default domain and a custom domain... // we want the one that's custom... i.e. does not contain arcgis.com const customEntry = response.reduce((acc: any, entry: any) => { - if (!entry.domain.includes("arcgis.com")) { + if (!entry.hostname.includes("arcgis.com")) { acc = entry; } return acc; }, null); if (customEntry) { // return the custom domain - return customEntry.domain; + return customEntry.hostname; } else { // just pick the first one - return response[0].domain; + return response[0].hostname; } } else { // there is only 1, so return it - return response[0].domain; + return response[0].hostname; } }); } diff --git a/packages/sites/src/update-site-application-uris.ts b/packages/sites/src/update-site-application-uris.ts index 06874380066..a2dce2535d9 100644 --- a/packages/sites/src/update-site-application-uris.ts +++ b/packages/sites/src/update-site-application-uris.ts @@ -59,7 +59,6 @@ export function updateSiteApplicationUris( orgId: hubRequestOptions.portalSelf.id, orgTitle: hubRequestOptions.portalSelf.name, hostname: uri, - domain: uri, siteId: site.item.id, siteTitle: site.item.title, clientKey: site.data.values.clientId, diff --git a/packages/sites/test/domains/_get-auth-header.test.ts b/packages/sites/test/domains/_get-auth-header.test.ts index 3d7c3a17c05..92b4aff00d2 100644 --- a/packages/sites/test/domains/_get-auth-header.test.ts +++ b/packages/sites/test/domains/_get-auth-header.test.ts @@ -1,4 +1,4 @@ -import { _getAuthHeader } from "../../src/domains"; +import { _getAuthHeader } from "../../src"; import { IHubRequestOptions } from "@esri/hub-common"; describe("_getAuthHeader", function() { diff --git a/packages/sites/test/domains/get-unique-domain-name-portal.test.ts b/packages/sites/test/domains/get-unique-domain-name-portal.test.ts index 0d21f1f4d32..69fe5a11eca 100644 --- a/packages/sites/test/domains/get-unique-domain-name-portal.test.ts +++ b/packages/sites/test/domains/get-unique-domain-name-portal.test.ts @@ -1,4 +1,4 @@ -import { getUniqueDomainNamePortal } from "../../src/domains"; +import { getUniqueDomainNamePortal } from "../../src"; import { IHubRequestOptions } from "@esri/hub-common"; import * as domainExistsModule from "../../src/domains/domain-exists-portal"; diff --git a/packages/sites/test/domains/is-domain-used-elsewhere.test.ts b/packages/sites/test/domains/is-domain-used-elsewhere.test.ts index 60d9ab413b2..5d71dd149bf 100644 --- a/packages/sites/test/domains/is-domain-used-elsewhere.test.ts +++ b/packages/sites/test/domains/is-domain-used-elsewhere.test.ts @@ -1,5 +1,5 @@ import * as lookupDomainModule from "../../src/domains/lookup-domain"; -import { isDomainUsedElsewhere } from "../../src/domains"; +import { isDomainUsedElsewhere } from "../../src"; import { IHubRequestOptions } from "@esri/hub-common"; describe("isDomainUsedElsewhere", function() { diff --git a/packages/sites/test/get-domain.test.ts b/packages/sites/test/get-domain.test.ts index b42940dfb61..61fbd60ada4 100644 --- a/packages/sites/test/get-domain.test.ts +++ b/packages/sites/test/get-domain.test.ts @@ -1,4 +1,4 @@ -import { getDomain } from "../src/index"; +import { getDomain } from "../src"; import * as fetchMock from "fetch-mock"; describe("getDomain", () => { @@ -6,7 +6,7 @@ describe("getDomain", () => { it("should return a domain", done => { fetchMock.once("https://hub.arcgis.com/api/v3/domains?f=json&siteId=5bc", [ - { domain: "data.foo.com" } + { hostname: "data.foo.com" } ]); getDomain("5bc") @@ -24,12 +24,12 @@ describe("getDomain", () => { it("should return custom domain if multiple entries exist", done => { fetchMock.once(`https://hub.arcgis.com/api/v3/domains?f=json&siteId=5bc`, [ - { domain: "data.foo.com" }, - { domain: "org.hub.arcgis.com" } + { hostname: "data.foo.com" }, + { hostname: "org.hub.arcgis.com" } ]); getDomain("5bc") - .then(domain => { - expect(domain).toBe("data.foo.com"); + .then(hostname => { + expect(hostname).toBe("data.foo.com"); const [domainUrl] = fetchMock.lastCall( "https://hub.arcgis.com/api/v3/domains?f=json&siteId=5bc" ); @@ -40,12 +40,12 @@ describe("getDomain", () => { }); it("should return first if multiple non-custom entries exist", done => { fetchMock.once(`https://hub.arcgis.com/api/v3/domains?f=json&siteId=5bc`, [ - { domain: "org-beta.hub.arcgis.com" }, - { domain: "org.hub.arcgis.com" } + { hostname: "org-beta.hub.arcgis.com" }, + { hostname: "org.hub.arcgis.com" } ]); getDomain("5bc") - .then(domain => { - expect(domain).toBe("org-beta.hub.arcgis.com"); + .then(hostname => { + expect(hostname).toBe("org-beta.hub.arcgis.com"); expect(fetchMock.done()).toBeTruthy(); const [domainUrl] = fetchMock.lastCall( "https://hub.arcgis.com/api/v3/domains?f=json&siteId=5bc" diff --git a/packages/sites/test/update-site-application-uris.test.ts b/packages/sites/test/update-site-application-uris.test.ts index b08d2f09f3d..9fa0cc293a1 100644 --- a/packages/sites/test/update-site-application-uris.test.ts +++ b/packages/sites/test/update-site-application-uris.test.ts @@ -75,7 +75,6 @@ describe("updateSiteApplicationUris", () => { orgId: ro.portalSelf.id, orgTitle: ro.portalSelf.name, hostname: "bar", - domain: "bar", siteId: site.item.id, siteTitle: site.item.title, clientKey: site.data.values.clientId,