Skip to content

Commit

Permalink
style(use hostname instead of domain prop on domain entry): use hostn…
Browse files Browse the repository at this point in the history
…ame instead of domain prop on d

affects: @esri/hub-sites
  • Loading branch information
Robert Steilberg committed Jan 21, 2021
1 parent 821cca5 commit d62e000
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 46 deletions.
4 changes: 2 additions & 2 deletions docs/src/guides/sites-and-pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -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})
})
```

Expand Down Expand Up @@ -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)
})
Expand Down
10 changes: 5 additions & 5 deletions packages/sites/src/domains/_lookup-portal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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|<domain>` 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}`;
Expand Down
8 changes: 4 additions & 4 deletions packages/sites/src/domains/domain-exists-portal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(_ => {
Expand Down
10 changes: 6 additions & 4 deletions packages/sites/src/domains/domain-exists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions packages/sites/src/domains/get-unique-domain-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions packages/sites/src/domains/is-domain-used-elsewhere.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
})
Expand Down
8 changes: 4 additions & 4 deletions packages/sites/src/domains/is-valid-domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ 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) {
throw new Error(`isValidDomain is not available in ArcGIS Enterprise.`);
}
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" })
Expand All @@ -25,7 +25,7 @@ export function isValidDomain(
.catch(e => {
return {
success: false,
input: domain,
input: hostname,
error: {
code: 400,
detail: e,
Expand Down
8 changes: 4 additions & 4 deletions packages/sites/src/domains/lookup-domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<IDomainEntry | { hostname: string; siteId: string }> {
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
Expand Down
1 change: 0 additions & 1 deletion packages/sites/src/domains/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export interface IDomainEntry {
clientKey: string;
createdAt?: string;
domain: string;
hostname: string;
id: string;
orgId: string;
Expand Down
8 changes: 4 additions & 4 deletions packages/sites/src/get-domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
});
}
1 change: 0 additions & 1 deletion packages/sites/src/update-site-application-uris.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/sites/test/domains/_get-auth-header.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { _getAuthHeader } from "../../src/domains";
import { _getAuthHeader } from "../../src";
import { IHubRequestOptions } from "@esri/hub-common";

describe("_getAuthHeader", function() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
20 changes: 10 additions & 10 deletions packages/sites/test/get-domain.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { getDomain } from "../src/index";
import { getDomain } from "../src";
import * as fetchMock from "fetch-mock";

describe("getDomain", () => {
afterEach(fetchMock.restore);

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")
Expand All @@ -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"
);
Expand All @@ -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"
Expand Down
1 change: 0 additions & 1 deletion packages/sites/test/update-site-application-uris.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d62e000

Please sign in to comment.