Skip to content

Commit

Permalink
feat(hub-common): add "reharvestSiteCatalog" util (#1279)
Browse files Browse the repository at this point in the history
affects: @esri/hub-common
  • Loading branch information
sonofflynn89 authored Oct 16, 2023
1 parent 92b2bf6 commit 6bdda94
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/common/src/sites/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export * from "./site-schema-version";
export * from "./themes";
export * from "./upgrade-site-schema";
export * from "./feed-configuration";
export * from "./reharvestSiteCatalog";
// No longer exported b/c site app registration is now handled
// by the domain service due to requirement to send signed HMAC request
// export * from "./registerSiteAsApplication";
41 changes: 41 additions & 0 deletions packages/common/src/sites/reharvestSiteCatalog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { IArcGISContext } from "../ArcGISContext";

interface IGroupReharvestInfo {
/**
* Catalog group being harvested
*/
groupId: string;
/**
* Internal job id
*/
jobId: string;
/**
* HTTP status code of the job
*/
status: number;
}

/**
* Trigger a manual update to reharvest each public item within a site's catalog.
* This should only be used when search metadata has gotten out of sync despite
* the nightly reharvest.
*
* @param siteId site's catalog to reharvest
* @param context
* @returns Job info for each group whose content is being harvested
*/
export async function reharvestSiteCatalog(
siteId: string,
context: IArcGISContext
): Promise<IGroupReharvestInfo[]> {
const apiHost = context.hubUrl;
const url = `${apiHost}/api/v3/jobs/site/${siteId}/harvest`;
const options = {
method: "POST",
headers: {
"content-type": "application/json",
authorization: context.hubRequestOptions.authentication.token,
},
};
return fetch(url, options).then((result) => result.json());
}
22 changes: 22 additions & 0 deletions packages/common/test/sites/reharvestSiteCatalog.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as fetchMock from "fetch-mock";
import { MOCK_CONTEXT } from "../mocks/mock-auth";
import { reharvestSiteCatalog } from "../../src/sites/reharvestSiteCatalog";

describe("reharvestSiteCatalog", () => {
it("correctly calls the reharvest endpoint", async () => {
const url = `${MOCK_CONTEXT.hubUrl}/api/v3/jobs/site/some-site-id/harvest`;
const expectedResults = [
{
groupId: "some-group-id",
jobId: "some-job-id",
status: 202,
},
];
fetchMock.once(url, expectedResults);
const actualResults = await reharvestSiteCatalog(
"some-site-id",
MOCK_CONTEXT
);
expect(actualResults).toEqual(expectedResults);
});
});

0 comments on commit 6bdda94

Please sign in to comment.