diff --git a/__tests__/actionCreators/search.test.js b/__tests__/actionCreators/search.test.js index 9ad54d29a..9305f3753 100644 --- a/__tests__/actionCreators/search.test.js +++ b/__tests__/actionCreators/search.test.js @@ -4,14 +4,11 @@ import { fetchQASearchResults, } from "actionCreators/search" import * as server from "sinopiaSearch" -import Swagger from "swagger-client" import configureMockStore from "redux-mock-store" import thunk from "redux-thunk" import { createState } from "stateUtils" import * as sinopiaApi from "sinopiaApi" -jest.mock("swagger-client") - const mockStore = configureMockStore([thunk]) describe("fetchSinopiaSearchResults", () => { @@ -88,7 +85,8 @@ describe("fetchSinopiaSearchResults", () => { describe("fetchQASearchResults", () => { const query = "*" const uri = "urn:ld4p:qa:sharevde_stanford_ld4l_cache:all" - it("dispatches action", async () => { + + describe("when happy path", () => { const mockSearchResults = [ { uri: "http://share-vde.org/sharevde/rdfBibframe/Work/3107365", @@ -147,77 +145,82 @@ describe("fetchQASearchResults", () => { ], }, ] - const mockActionFunction = jest.fn().mockResolvedValue({ + const mockResponse = { body: { results: mockSearchResults, response_header: { total_records: 15 }, }, - }) - const client = { - apis: { SearchQuery: { GET_searchAuthority: mockActionFunction } }, } - Swagger.mockResolvedValue(client) - sinopiaApi.putUserHistory = jest.fn().mockResolvedValue() - const store = mockStore(createState()) - await store.dispatch(fetchQASearchResults(query, uri, "testerrorkey")) + beforeEach(() => { + global.fetch = jest + .fn() + .mockImplementation(() => Promise.resolve(mockResponse)) + }) - const actions = store.getActions() + it("dispatches action", async () => { + sinopiaApi.putUserHistory = jest.fn().mockResolvedValue() - expect(actions).toHaveLength(3) - expect(actions).toHaveAction("CLEAR_ERRORS") - expect(actions).toHaveAction("SET_SEARCH_RESULTS", { - searchType: "resource", - uri, - query, - results: mockSearchResults, - totalResults: 15, - options: {}, - error: undefined, - facetResults: {}, - }) - expect(actions).toHaveAction("ADD_SEARCH_HISTORY", { - authorityUri: uri, - authorityLabel: "SHAREVDE STANFORD (QA)", - query, + const store = mockStore(createState()) + await store.dispatch(fetchQASearchResults(query, uri, "testerrorkey")) + + const actions = store.getActions() + + expect(actions).toHaveLength(3) + expect(actions).toHaveAction("CLEAR_ERRORS") + expect(actions).toHaveAction("SET_SEARCH_RESULTS", { + searchType: "resource", + uri, + query, + results: mockSearchResults, + totalResults: 15, + options: {}, + error: undefined, + facetResults: {}, + }) + expect(actions).toHaveAction("ADD_SEARCH_HISTORY", { + authorityUri: uri, + authorityLabel: "SHAREVDE STANFORD (QA)", + query, + }) + expect(sinopiaApi.putUserHistory).toHaveBeenCalledWith( + "Foo McBar", + "search", + "4682c287952df68172c6c4a63bdc2887", + '{"authorityUri":"urn:ld4p:qa:sharevde_stanford_ld4l_cache:all","query":"*"}' + ) }) - expect(sinopiaApi.putUserHistory).toHaveBeenCalledWith( - "Foo McBar", - "search", - "4682c287952df68172c6c4a63bdc2887", - '{"authorityUri":"urn:ld4p:qa:sharevde_stanford_ld4l_cache:all","query":"*"}' - ) }) - it("dispatches action when error", async () => { - const mockActionFunction = jest - .fn() - .mockRejectedValue(new Error("Ooops...")) - const client = { - apis: { SearchQuery: { GET_searchAuthority: mockActionFunction } }, - } - Swagger.mockResolvedValue(client) + describe("when error occurs", () => { + beforeEach(() => { + global.fetch = jest + .fn() + .mockImplementation(() => Promise.reject(new Error("Ooops..."))) + }) - const store = mockStore(createState()) - await store.dispatch(fetchQASearchResults(query, uri, "testerrorkey")) + it("dispatches action when error", async () => { + const store = mockStore(createState()) + await store.dispatch(fetchQASearchResults(query, uri, "testerrorkey")) - const actions = store.getActions() + const actions = store.getActions() - expect(actions).toHaveLength(3) - expect(actions).toHaveAction("CLEAR_ERRORS") - expect(actions).toHaveAction("SET_SEARCH_RESULTS", { - searchType: "resource", - uri, - query, - results: [], - totalResults: 0, - options: {}, - facetResults: {}, - error: "Ooops...", - }) - expect(actions).toHaveAction("ADD_ERROR", { - errorKey: "testerrorkey", - error: ["An error occurred while searching: Ooops..."], + expect(actions).toHaveLength(3) + expect(actions).toHaveAction("CLEAR_ERRORS") + expect(actions).toHaveAction("SET_SEARCH_RESULTS", { + searchType: "resource", + uri, + query, + results: [], + totalResults: 0, + options: {}, + facetResults: {}, + error: "Ooops...", + }) + expect(actions).toHaveAction("ADD_ERROR", { + errorKey: "testerrorkey", + error: ["An error occurred while searching: Ooops..."], + }) }) }) }) diff --git a/__tests__/components/search/Search.test.js b/__tests__/components/search/Search.test.js index 0b24e6223..4fd7f4d29 100644 --- a/__tests__/components/search/Search.test.js +++ b/__tests__/components/search/Search.test.js @@ -1,59 +1,56 @@ import { renderApp } from "testUtils" import { fireEvent, waitFor, screen } from "@testing-library/react" import * as server from "sinopiaSearch" -import Swagger from "swagger-client" import Config from "Config" import * as sinopiaApi from "sinopiaApi" -jest.mock("swagger-client") - describe("", () => { jest.spyOn(sinopiaApi, "putUserHistory").mockResolvedValue() - it("requests a QA search", async () => { - const mockSearchResults = [ - { - uri: "http://share-vde.org/sharevde/rdfBibframe/Work/3107365", - id: "http://share-vde.org/sharevde/rdfBibframe/Work/3107365", - label: "These twain", - context: [ - { - property: "Title", - values: [" These twain"], - selectable: true, - drillable: false, - }, - { - property: "Type", - values: [ - "http://id.loc.gov/ontologies/bflc/Hub", - "http://id.loc.gov/ontologies/bibframe/Work", - ], - selectable: false, - drillable: false, - }, - { - property: "Contributor", - values: ["Bennett, Arnold,1867-1931."], - selectable: false, - drillable: false, - }, - ], - }, - ] - const mockActionFunction = jest.fn().mockResolvedValue({ - body: { - results: mockSearchResults, - response_header: { total_records: 15 }, - }, - }) - const client = { - apis: { - SearchQuery: { GET_nonldSearchWithSubauthority: mockActionFunction }, - }, - } - Swagger.mockResolvedValue(client) + const mockSearchResults = [ + { + uri: "http://share-vde.org/sharevde/rdfBibframe/Work/3107365", + id: "http://share-vde.org/sharevde/rdfBibframe/Work/3107365", + label: "These twain", + context: [ + { + property: "Title", + values: [" These twain"], + selectable: true, + drillable: false, + }, + { + property: "Type", + values: [ + "http://id.loc.gov/ontologies/bflc/Hub", + "http://id.loc.gov/ontologies/bibframe/Work", + ], + selectable: false, + drillable: false, + }, + { + property: "Contributor", + values: ["Bennett, Arnold,1867-1931."], + selectable: false, + drillable: false, + }, + ], + }, + ] + const mockResponse = { + body: { + results: mockSearchResults, + response_header: { total_records: 15 }, + }, + } + + beforeEach(() => { + global.fetch = jest + .fn() + .mockImplementation(() => Promise.resolve(mockResponse)) + }) + it("requests a QA search", async () => { renderApp() fireEvent.click(screen.getByText("Linked Data Editor", { selector: "a" })) diff --git a/__tests__/utilities/QuestioningAuthority.test.js b/__tests__/utilities/QuestioningAuthority.test.js index e61eb5ebe..b50e10d45 100644 --- a/__tests__/utilities/QuestioningAuthority.test.js +++ b/__tests__/utilities/QuestioningAuthority.test.js @@ -1,81 +1,78 @@ // Copyright 2019 Stanford University see LICENSE for license import { createLookupPromise, getTerm } from "utilities/QuestioningAuthority" import { findAuthorityConfig } from "utilities/authorityConfig" -import Swagger from "swagger-client" - -jest.mock("swagger-client") describe("createLookupPromise()", () => { - it("returns a promise from a search", async () => { - const response = { - ok: true, - url: "https://lookup.ld4l.org/authorities/search/linked_data/agrovoc_ld4l_cache?q=Corn&maxRecords=8&lang=en&context=true", - status: 200, - statusText: "OK", - body: { - response_header: { - start_record: 1, - requested_records: 8, - retrieved_records: 8, - total_records: 23, - }, - results: [ - { - uri: "http://aims.fao.org/aos/agrovoc/c_331388", - id: "http://aims.fao.org/aos/agrovoc/c_331388", - label: "corn sheller", - }, - { - uri: "http://aims.fao.org/aos/agrovoc/c_33224", - id: "http://aims.fao.org/aos/agrovoc/c_33224", - label: "Corn Belt (USA)", - }, - { - uri: "http://aims.fao.org/aos/agrovoc/c_16171", - id: "http://aims.fao.org/aos/agrovoc/c_16171", - label: "corn cob mix", - }, - { - uri: "http://aims.fao.org/aos/agrovoc/c_14385", - id: "http://aims.fao.org/aos/agrovoc/c_14385", - label: "soft corn", - }, - { - uri: "http://aims.fao.org/aos/agrovoc/c_fd817c5d", - id: "http://aims.fao.org/aos/agrovoc/c_fd817c5d", - label: "southern leaf blight of maize", - }, - { - uri: "http://aims.fao.org/aos/agrovoc/c_34f087cf", - id: "http://aims.fao.org/aos/agrovoc/c_34f087cf", - label: "maize gluten", - }, - { - uri: "http://aims.fao.org/aos/agrovoc/c_d859f064", - id: "http://aims.fao.org/aos/agrovoc/c_d859f064", - label: "maize bran", - }, - { - uri: "http://aims.fao.org/aos/agrovoc/c_7552", - id: "http://aims.fao.org/aos/agrovoc/c_7552", - label: "sweet corn", - }, - ], + const response = { + ok: true, + url: "https://lookup.ld4l.org/search/agrovoc_ld4l_cache?q=Corn&maxRecords=8&lang=en&context=true&response_header=true&startRecord=1", + status: 200, + statusText: "OK", + body: { + response_header: { + start_record: 1, + requested_records: 8, + retrieved_records: 8, + total_records: 23, }, - authLabel: "AGROVOC (QA)", - authURI: "urn:ld4p:qa:agrovoc", - label: "AGROVOC (QA)", - id: "urn:ld4p:qa:agrovoc", - } + results: [ + { + uri: "http://aims.fao.org/aos/agrovoc/c_331388", + id: "http://aims.fao.org/aos/agrovoc/c_331388", + label: "corn sheller", + }, + { + uri: "http://aims.fao.org/aos/agrovoc/c_33224", + id: "http://aims.fao.org/aos/agrovoc/c_33224", + label: "Corn Belt (USA)", + }, + { + uri: "http://aims.fao.org/aos/agrovoc/c_16171", + id: "http://aims.fao.org/aos/agrovoc/c_16171", + label: "corn cob mix", + }, + { + uri: "http://aims.fao.org/aos/agrovoc/c_14385", + id: "http://aims.fao.org/aos/agrovoc/c_14385", + label: "soft corn", + }, + { + uri: "http://aims.fao.org/aos/agrovoc/c_fd817c5d", + id: "http://aims.fao.org/aos/agrovoc/c_fd817c5d", + label: "southern leaf blight of maize", + }, + { + uri: "http://aims.fao.org/aos/agrovoc/c_34f087cf", + id: "http://aims.fao.org/aos/agrovoc/c_34f087cf", + label: "maize gluten", + }, + { + uri: "http://aims.fao.org/aos/agrovoc/c_d859f064", + id: "http://aims.fao.org/aos/agrovoc/c_d859f064", + label: "maize bran", + }, + { + uri: "http://aims.fao.org/aos/agrovoc/c_7552", + id: "http://aims.fao.org/aos/agrovoc/c_7552", + label: "sweet corn", + }, + ], + }, + authLabel: "AGROVOC (QA)", + authURI: "urn:ld4p:qa:agrovoc", + label: "AGROVOC (QA)", + id: "urn:ld4p:qa:agrovoc", + } - const mockActionFunction = jest.fn().mockResolvedValue(response) - const client = { - apis: { SearchQuery: { GET_searchAuthority: mockActionFunction } }, - } - Swagger.mockResolvedValue(client) + beforeEach(() => { + global.fetch = jest.fn().mockImplementation(() => Promise.resolve(response)) + }) + it("returns a promise from a search", async () => { const authorityConfig = findAuthorityConfig("urn:ld4p:qa:agrovoc") const result = await createLookupPromise("Corn", authorityConfig) + expect(global.fetch).toHaveBeenCalledTimes(1) + expect(global.fetch).toHaveBeenCalledWith(response.url) expect(result.body.results.length).toEqual(8) }) }) diff --git a/package-lock.json b/package-lock.json index 58642d0e8..aef471bb3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -52,7 +52,6 @@ "redux-thunk": "^2.3.0", "reselect": "^4.0.0", "stream-browserify": "^3.0.0", - "swagger-client": "^3.16.0", "uuid": "^8.3.1" }, "devDependencies": { @@ -3217,6 +3216,7 @@ "version": "7.16.0", "resolved": "https://registry.npmjs.org/@babel/runtime-corejs3/-/runtime-corejs3-7.16.0.tgz", "integrity": "sha512-Oi2qwQ21X7/d9gn3WiwkDTJmq3TQtYNz89lRnoFy8VeZpWlsyXvzSwiRrRZ8cXluvSwqKxqHJ6dBd9Rv+p0ZGQ==", + "dev": true, "dependencies": { "core-js-pure": "^3.19.0", "regenerator-runtime": "^0.13.4" @@ -7240,17 +7240,6 @@ "node-int64": "^0.4.0" } }, - "node_modules/btoa": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/btoa/-/btoa-1.2.1.tgz", - "integrity": "sha512-SB4/MIGlsiVkMcHmT+pSmIPoNDoHg+7cMzmt3Uxt628MTz2487DKSqK/fuhFBrkuqrYv5UCEnACpF4dTFNKc/g==", - "bin": { - "btoa": "bin/btoa.js" - }, - "engines": { - "node": ">= 0.4.0" - } - }, "node_modules/buffer": { "version": "6.0.3", "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", @@ -8125,6 +8114,7 @@ "version": "3.19.1", "resolved": "https://registry.npmjs.org/core-js-pure/-/core-js-pure-3.19.1.tgz", "integrity": "sha512-Q0Knr8Es84vtv62ei6/6jXH/7izKmOrtrxH9WJTHLCMAVeU+8TF8z8Nr08CsH4Ot0oJKzBzJJL9SJBYIv7WlfQ==", + "dev": true, "hasInstallScript": true, "funding": { "type": "opencollective", @@ -8690,14 +8680,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/deep-extend": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz", - "integrity": "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==", - "engines": { - "node": ">=4.0.0" - } - }, "node_modules/deep-is": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz", @@ -10706,11 +10688,6 @@ "node": ">=8" } }, - "node_modules/fast-json-patch": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/fast-json-patch/-/fast-json-patch-3.1.0.tgz", - "integrity": "sha512-IhpytlsVTRndz0hU5t0/MGzS/etxLlfrpG5V5M9mVbuj9TrJLWaMfsox9REM5rkuGX0T+5qjpe8XA1o0gZ42nA==" - }, "node_modules/fast-json-stable-stringify": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", @@ -11116,23 +11093,6 @@ "node": ">= 0.12" } }, - "node_modules/form-data-encoder": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/form-data-encoder/-/form-data-encoder-1.7.0.tgz", - "integrity": "sha512-zGhcpAhxoq7ut+sldaXVwmQHvvrlUHm6jLJoqCMuhf4vjMe+Vn+PAjIB6OrqSFoIk4c3/oK6M69RXJYrYl0zWg==" - }, - "node_modules/formdata-node": { - "version": "4.3.1", - "resolved": "https://registry.npmjs.org/formdata-node/-/formdata-node-4.3.1.tgz", - "integrity": "sha512-8xKSa9et4zb+yziWsD/bI+EYjdg1z2p9EpKr+o+Yk12F/wP66bmDdvjj2ZXd2K/MJlR3HBzWnuV7f82jzHRqCA==", - "dependencies": { - "node-domexception": "1.0.0", - "web-streams-polyfill": "4.0.0-beta.1" - }, - "engines": { - "node": ">= 12.20" - } - }, "node_modules/forwarded": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", @@ -17474,24 +17434,6 @@ "node": ">= 0.10.5" } }, - "node_modules/node-domexception": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", - "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/jimmywarting" - }, - { - "type": "github", - "url": "https://paypal.me/jimmywarting" - } - ], - "engines": { - "node": ">=10.5.0" - } - }, "node_modules/node-environment-flags": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/node-environment-flags/-/node-environment-flags-1.0.6.tgz", @@ -17743,6 +17685,7 @@ "version": "1.11.0", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.11.0.tgz", "integrity": "sha512-jp7ikS6Sd3GxQfZJPyH3cjcbJF6GZPClgdV+EFygjFLQ5FmW/dRUnTd9PQ9k0JhoNDabWFbpF1yCdSWCC6gexg==", + "dev": true, "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -20735,6 +20678,7 @@ "version": "1.0.4", "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz", "integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==", + "dev": true, "dependencies": { "call-bind": "^1.0.0", "get-intrinsic": "^1.0.2", @@ -21583,64 +21527,6 @@ "node": ">=8" } }, - "node_modules/swagger-client": { - "version": "3.17.0", - "resolved": "https://registry.npmjs.org/swagger-client/-/swagger-client-3.17.0.tgz", - "integrity": "sha512-d8DOEME49wTXm+uT+lBAjJ5D6IDjEHdbkqa7MbcslR2c+oHIhi13ObwleVWGfr89MPkWgBl6RBq9VUHmrBJRbg==", - "dependencies": { - "@babel/runtime-corejs3": "^7.11.2", - "btoa": "^1.2.1", - "cookie": "~0.4.1", - "cross-fetch": "^3.1.4", - "deep-extend": "~0.6.0", - "fast-json-patch": "^3.0.0-1", - "form-data-encoder": "^1.4.3", - "formdata-node": "^4.0.0", - "js-yaml": "^4.1.0", - "lodash": "^4.17.21", - "qs": "^6.9.4", - "traverse": "~0.6.6", - "url": "~0.11.0" - } - }, - "node_modules/swagger-client/node_modules/argparse": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", - "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==" - }, - "node_modules/swagger-client/node_modules/cookie": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.1.tgz", - "integrity": "sha512-ZwrFkGJxUR3EIoXtO+yVE69Eb7KlixbaeAWfBQB9vVsNn/o+Yw69gBWSSDK825hQNdN+wF8zELf3dFNl/kxkUA==", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/swagger-client/node_modules/js-yaml": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", - "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", - "dependencies": { - "argparse": "^2.0.1" - }, - "bin": { - "js-yaml": "bin/js-yaml.js" - } - }, - "node_modules/swagger-client/node_modules/qs": { - "version": "6.10.1", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.10.1.tgz", - "integrity": "sha512-M528Hph6wsSVOBiYUnGf+K/7w0hNshs/duGsNXPUCLH5XAqjEtiPGwNONLV0tBH8NoGb0mvD5JubnUTrujKDTg==", - "dependencies": { - "side-channel": "^1.0.4" - }, - "engines": { - "node": ">=0.6" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/symbol-tree": { "version": "3.2.4", "resolved": "https://registry.npmjs.org/symbol-tree/-/symbol-tree-3.2.4.tgz", @@ -22077,11 +21963,6 @@ "punycode": "^2.1.0" } }, - "node_modules/traverse": { - "version": "0.6.6", - "resolved": "https://registry.npmjs.org/traverse/-/traverse-0.6.6.tgz", - "integrity": "sha1-y99WD9e5r2MlAv7UD5GMFX6pcTc=" - }, "node_modules/ts-essentials": { "version": "2.0.12", "resolved": "https://registry.npmjs.org/ts-essentials/-/ts-essentials-2.0.12.tgz", @@ -22666,14 +22547,6 @@ "defaults": "^1.0.3" } }, - "node_modules/web-streams-polyfill": { - "version": "4.0.0-beta.1", - "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-4.0.0-beta.1.tgz", - "integrity": "sha512-3ux37gEX670UUphBF9AMCq8XM6iQ8Ac6A+DSRRjDoRBm1ufCkaCDdNVbaqq60PsEkdNlLKrGtv/YBP4EJXqNtQ==", - "engines": { - "node": ">= 12" - } - }, "node_modules/webidl-conversions": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-6.1.0.tgz", @@ -25706,6 +25579,7 @@ "version": "7.16.0", "resolved": "https://registry.npmjs.org/@babel/runtime-corejs3/-/runtime-corejs3-7.16.0.tgz", "integrity": "sha512-Oi2qwQ21X7/d9gn3WiwkDTJmq3TQtYNz89lRnoFy8VeZpWlsyXvzSwiRrRZ8cXluvSwqKxqHJ6dBd9Rv+p0ZGQ==", + "dev": true, "requires": { "core-js-pure": "^3.19.0", "regenerator-runtime": "^0.13.4" @@ -28917,11 +28791,6 @@ "node-int64": "^0.4.0" } }, - "btoa": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/btoa/-/btoa-1.2.1.tgz", - "integrity": "sha512-SB4/MIGlsiVkMcHmT+pSmIPoNDoHg+7cMzmt3Uxt628MTz2487DKSqK/fuhFBrkuqrYv5UCEnACpF4dTFNKc/g==" - }, "buffer": { "version": "6.0.3", "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", @@ -29605,7 +29474,8 @@ "core-js-pure": { "version": "3.19.1", "resolved": "https://registry.npmjs.org/core-js-pure/-/core-js-pure-3.19.1.tgz", - "integrity": "sha512-Q0Knr8Es84vtv62ei6/6jXH/7izKmOrtrxH9WJTHLCMAVeU+8TF8z8Nr08CsH4Ot0oJKzBzJJL9SJBYIv7WlfQ==" + "integrity": "sha512-Q0Knr8Es84vtv62ei6/6jXH/7izKmOrtrxH9WJTHLCMAVeU+8TF8z8Nr08CsH4Ot0oJKzBzJJL9SJBYIv7WlfQ==", + "dev": true }, "core-util-is": { "version": "1.0.2", @@ -30058,11 +29928,6 @@ "regexp.prototype.flags": "^1.2.0" } }, - "deep-extend": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz", - "integrity": "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==" - }, "deep-is": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz", @@ -31631,11 +31496,6 @@ "micromatch": "^4.0.4" } }, - "fast-json-patch": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/fast-json-patch/-/fast-json-patch-3.1.0.tgz", - "integrity": "sha512-IhpytlsVTRndz0hU5t0/MGzS/etxLlfrpG5V5M9mVbuj9TrJLWaMfsox9REM5rkuGX0T+5qjpe8XA1o0gZ42nA==" - }, "fast-json-stable-stringify": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", @@ -31948,20 +31808,6 @@ "mime-types": "^2.1.12" } }, - "form-data-encoder": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/form-data-encoder/-/form-data-encoder-1.7.0.tgz", - "integrity": "sha512-zGhcpAhxoq7ut+sldaXVwmQHvvrlUHm6jLJoqCMuhf4vjMe+Vn+PAjIB6OrqSFoIk4c3/oK6M69RXJYrYl0zWg==" - }, - "formdata-node": { - "version": "4.3.1", - "resolved": "https://registry.npmjs.org/formdata-node/-/formdata-node-4.3.1.tgz", - "integrity": "sha512-8xKSa9et4zb+yziWsD/bI+EYjdg1z2p9EpKr+o+Yk12F/wP66bmDdvjj2ZXd2K/MJlR3HBzWnuV7f82jzHRqCA==", - "requires": { - "node-domexception": "1.0.0", - "web-streams-polyfill": "4.0.0-beta.1" - } - }, "forwarded": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", @@ -36872,11 +36718,6 @@ "minimatch": "^3.0.2" } }, - "node-domexception": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", - "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==" - }, "node-environment-flags": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/node-environment-flags/-/node-environment-flags-1.0.6.tgz", @@ -37077,7 +36918,8 @@ "object-inspect": { "version": "1.11.0", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.11.0.tgz", - "integrity": "sha512-jp7ikS6Sd3GxQfZJPyH3cjcbJF6GZPClgdV+EFygjFLQ5FmW/dRUnTd9PQ9k0JhoNDabWFbpF1yCdSWCC6gexg==" + "integrity": "sha512-jp7ikS6Sd3GxQfZJPyH3cjcbJF6GZPClgdV+EFygjFLQ5FmW/dRUnTd9PQ9k0JhoNDabWFbpF1yCdSWCC6gexg==", + "dev": true }, "object-is": { "version": "1.1.5", @@ -39383,6 +39225,7 @@ "version": "1.0.4", "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz", "integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==", + "dev": true, "requires": { "call-bind": "^1.0.0", "get-intrinsic": "^1.0.2", @@ -40060,54 +39903,6 @@ } } }, - "swagger-client": { - "version": "3.17.0", - "resolved": "https://registry.npmjs.org/swagger-client/-/swagger-client-3.17.0.tgz", - "integrity": "sha512-d8DOEME49wTXm+uT+lBAjJ5D6IDjEHdbkqa7MbcslR2c+oHIhi13ObwleVWGfr89MPkWgBl6RBq9VUHmrBJRbg==", - "requires": { - "@babel/runtime-corejs3": "^7.11.2", - "btoa": "^1.2.1", - "cookie": "~0.4.1", - "cross-fetch": "^3.1.4", - "deep-extend": "~0.6.0", - "fast-json-patch": "^3.0.0-1", - "form-data-encoder": "^1.4.3", - "formdata-node": "^4.0.0", - "js-yaml": "^4.1.0", - "lodash": "^4.17.21", - "qs": "^6.9.4", - "traverse": "~0.6.6", - "url": "~0.11.0" - }, - "dependencies": { - "argparse": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", - "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==" - }, - "cookie": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.1.tgz", - "integrity": "sha512-ZwrFkGJxUR3EIoXtO+yVE69Eb7KlixbaeAWfBQB9vVsNn/o+Yw69gBWSSDK825hQNdN+wF8zELf3dFNl/kxkUA==" - }, - "js-yaml": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", - "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", - "requires": { - "argparse": "^2.0.1" - } - }, - "qs": { - "version": "6.10.1", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.10.1.tgz", - "integrity": "sha512-M528Hph6wsSVOBiYUnGf+K/7w0hNshs/duGsNXPUCLH5XAqjEtiPGwNONLV0tBH8NoGb0mvD5JubnUTrujKDTg==", - "requires": { - "side-channel": "^1.0.4" - } - } - } - }, "symbol-tree": { "version": "3.2.4", "resolved": "https://registry.npmjs.org/symbol-tree/-/symbol-tree-3.2.4.tgz", @@ -40446,11 +40241,6 @@ "punycode": "^2.1.0" } }, - "traverse": { - "version": "0.6.6", - "resolved": "https://registry.npmjs.org/traverse/-/traverse-0.6.6.tgz", - "integrity": "sha1-y99WD9e5r2MlAv7UD5GMFX6pcTc=" - }, "ts-essentials": { "version": "2.0.12", "resolved": "https://registry.npmjs.org/ts-essentials/-/ts-essentials-2.0.12.tgz", @@ -40912,11 +40702,6 @@ "defaults": "^1.0.3" } }, - "web-streams-polyfill": { - "version": "4.0.0-beta.1", - "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-4.0.0-beta.1.tgz", - "integrity": "sha512-3ux37gEX670UUphBF9AMCq8XM6iQ8Ac6A+DSRRjDoRBm1ufCkaCDdNVbaqq60PsEkdNlLKrGtv/YBP4EJXqNtQ==" - }, "webidl-conversions": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-6.1.0.tgz", diff --git a/package.json b/package.json index 14dd8d0a9..c3672c8b2 100644 --- a/package.json +++ b/package.json @@ -99,7 +99,6 @@ "redux-thunk": "^2.3.0", "reselect": "^4.0.0", "stream-browserify": "^3.0.0", - "swagger-client": "^3.16.0", "uuid": "^8.3.1" }, "devDependencies": { diff --git a/src/lib/apidoc.json b/src/lib/apidoc.json deleted file mode 100644 index 72bf8b244..000000000 --- a/src/lib/apidoc.json +++ /dev/null @@ -1,1855 +0,0 @@ -{ - "openapi": "3.0.1", - "info": { - "title": "QA 2.2 Linked Data API", - "version": "2.2", - "license": { - "name": "Apache 2.0", - "url": "http://www.apache.org/licenses/LICENSE-2.0.html" - } - }, - "servers": [ - { - "url": "https://lookup.ld4l.org/authorities", - "description": "LD4L Lookup - QA v2.2 API Server" - }, - { - "url": "http://localhost:3000/authorities", - "description": "QA v2.2 API Server" - }, - { - "url": "{http_protocol}://{site_host}/{qa_engine_mount}", - "description": "QA v2.2 API Server", - "variables": { - "http_protocol": { - "default": "https", - "description": "" - }, - "site_host": { - "default": "ld4l-qa-int.pge2e2mdhm.us-east-1.elasticbeanstalk.com", - "description": "" - }, - "qa_engine_mount": { - "default": "authorities" - } - } - } - ], - "paths": { - "/list/linked_data/authorities": { - "get": { - "summary": "List currently loaded linked data authorities", - "operationId": "GET_listAuthorities", - "tags": ["AuthorityManagement"], - "responses": { - "200": { - "description": "Successfully accessed authority and received results.", - "headers": { - "Access-Control-Allow-Origin": { - "description": "CORS header will be * if cors_headers_enabled", - "schema": { - "type": "string" - } - } - }, - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/linked_data_authorities_list_result" - } - } - } - } - } - } - }, - "/reload/linked_data/authorities": { - "get": { - "summary": "Reload linked data authorities. Using this command avoids having to restart the rails server.", - "operationId": "GET_reloadAuthorities", - "tags": ["AuthorityManagement"], - "parameters": [ - { - "description": "Security token which must be included for this command to execute.", - "in": "query", - "name": "auth_token", - "required": true, - "schema": { - "default": "", - "type": "string" - } - } - ], - "responses": { - "200": { - "description": "Successfully reloaded authorities.", - "headers": { - "Access-Control-Allow-Origin": { - "description": "CORS header will be * if cors_headers_enabled", - "schema": { - "type": "string" - } - } - }, - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/linked_data_authorities_list_result" - } - } - } - }, - "401": { - "description": "Unauthorized", - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - } - } - } - }, - "/search/linked_data/{vocab}": { - "get": { - "summary": "Send a query string to an authority and return search results. Parameters are typical examples. Actual parameters are driven by the authority's config file.", - "operationId": "GET_searchAuthority", - "tags": ["SearchQuery"], - "parameters": [ - { - "description": "Name of the authority's configuration file.", - "in": "path", - "name": "vocab", - "required": true, - "schema": { - "default": "agrovoc_ld4l_cache", - "type": "string" - } - }, - { - "description": "The query string", - "in": "query", - "name": "q", - "required": true, - "schema": { - "default": "milk", - "type": "string" - } - }, - { - "description": "Limit number of returned results. NOTE: Most authorities use maxRecords, but a few use maximumRecords for this parameter.", - "in": "query", - "name": "maxRecords", - "required": false, - "schema": { - "default": 4, - "type": "integer" - } - }, - { - "description": "Limit string values to this language when multiple languages are provided.", - "in": "query", - "name": "lang", - "required": false, - "schema": { - "default": "en", - "type": "string" - } - }, - { - "description": "Return context provided by QA", - "in": "query", - "name": "context", - "required": false, - "schema": { - "default": "en", - "type": "string" - } - }, - { - "description": "Include response header", - "in": "query", - "name": "response_header", - "required": true, - "schema": { - "default": "true", - "type": "string" - } - }, - { - "description": "First record offset (1 based)", - "in": "query", - "name": "startRecord", - "required": false, - "schema": { - "default": 1, - "type": "integer" - } - } - ], - "responses": { - "200": { - "description": "Successfully accessed authority and received results.", - "headers": { - "Access-Control-Allow-Origin": { - "description": "CORS header will be * if cors_headers_enabled", - "schema": { - "type": "string" - } - } - }, - "content": { - "application/json": { - "schema": { - "type": "object", - "items": { - "required": ["results", "response_header"], - "properties": { - "results": { - "$ref": "#/components/schemas/linked_data_query_results" - }, - "response_header": { - "$ref": "#/components/schemas/response_header" - } - } - } - } - } - } - }, - "400": { - "description": "Bad Request - occurs when required params are missing (e.g. q)", - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - }, - "500": { - "description": "Internal Server Error - can be raised while attempting to access the external authority OR during processing of results when results are not a valid RDF Format", - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - }, - "503": { - "description": "Service Unavailable - can be raised while attempting to access the external authority", - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - } - } - }, - "options": { - "summary": "CORS preflight request", - "operationId": "OPTIONS_searchAuthority", - "tags": ["SearchQuery"], - "parameters": [ - { - "description": "Name of the authority's configuration file.", - "in": "path", - "name": "vocab", - "required": true, - "schema": { - "default": "oclc_fast", - "type": "string" - } - } - ], - "responses": { - "204": { - "description": "When CORS is enabled, perform CORS preflight for searching an authority", - "headers": { - "Access-Control-Allow-Origin": { - "description": "CORS header will be * if CORS headers are enabled", - "schema": { - "type": "string" - } - }, - "Access-Control-Allow-Headers": { - "description": "Indicates which headers a future CORS request to the same resource might use.", - "schema": { - "type": "string" - } - }, - "Access-Control-Allow-Methods": { - "description": "Indicates which method a future CORS request to the same resource might use.", - "schema": { - "type": "string" - } - } - }, - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - }, - "501": { - "description": "OPTIONS action is not implement when CORS headers are not enabled", - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - } - } - } - }, - "/search/linked_data/{vocab}/{subauthority}": { - "get": { - "summary": "Send a query string to a subauthority in an authority and return search results.", - "operationId": "GET_searchSubauthority", - "tags": ["SearchQuery"], - "parameters": [ - { - "description": "Name of the authority's configuration file.", - "in": "path", - "name": "vocab", - "required": true, - "schema": { - "default": "geonames_ld4l_cache", - "type": "string" - } - }, - { - "description": "Name of the subauthority.", - "in": "path", - "name": "subauthority", - "required": true, - "schema": { - "default": "place", - "type": "string" - } - }, - { - "description": "The query string", - "in": "query", - "name": "q", - "required": true, - "schema": { - "default": "Ithaca", - "type": "string" - } - }, - { - "description": "Limit number of returned results. NOTE: Most authorities use maxRecords, but a few use maximumRecords for this parameter.", - "in": "query", - "name": "maxRecords", - "required": false, - "schema": { - "default": 4, - "type": "integer" - } - }, - { - "description": "Limit string values to this language when multiple languages are provided.", - "in": "query", - "name": "lang", - "required": false, - "schema": { - "default": "en", - "type": "string" - } - }, - { - "description": "Return context provided by QA", - "in": "query", - "name": "context", - "required": false, - "schema": { - "default": "en", - "type": "string" - } - }, - { - "description": "Include response header", - "in": "query", - "name": "response_header", - "required": true, - "schema": { - "default": "true", - "type": "string" - } - }, - { - "description": "First record offset (1 based)", - "in": "query", - "name": "startRecord", - "required": false, - "schema": { - "default": 1, - "type": "integer" - } - } - ], - "responses": { - "200": { - "description": "Successfully accessed subauthority in an authority and received results.", - "headers": { - "Access-Control-Allow-Origin": { - "description": "CORS header will be * if CORS headers are enabled", - "schema": { - "type": "string" - } - } - }, - "content": { - "application/json": { - "schema": { - "type": "object", - "items": { - "required": ["results", "response_header"], - "properties": { - "results": { - "$ref": "#/components/schemas/linked_data_query_results" - }, - "response_header": { - "$ref": "#/components/schemas/response_header" - } - } - } - } - } - } - }, - "400": { - "description": "Bad Request - occurs when required params are missing (e.g. q)", - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - }, - "500": { - "description": "Internal Server Error - can be raised while attempting to access the external authority OR during processing of results when results are not a valid RDF Format", - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - }, - "503": { - "description": "Service Unavailable - can be raised while attempting to access the external authority", - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - } - } - }, - "options": { - "summary": "CORS preflight request", - "operationId": "OPTIONS_searchSubauthority", - "tags": ["SearchQuery"], - "parameters": [ - { - "description": "Name of the authority's configuration file.", - "in": "path", - "name": "vocab", - "required": true, - "schema": { - "default": "oclc_fast", - "type": "string" - } - }, - { - "description": "Name of the subauthority.", - "in": "path", - "name": "subauthority", - "required": true, - "schema": { - "default": "personal_name", - "type": "string" - } - } - ], - "responses": { - "204": { - "description": "Perform CORS preflight for searching a subauthoroity in an authority", - "headers": { - "Access-Control-Allow-Origin": { - "description": "CORS header will be * if CORS headers are enabled", - "schema": { - "type": "string" - } - }, - "Access-Control-Allow-Headers": { - "description": "Indicates which headers a future CORS request to the same resource might use.", - "schema": { - "type": "string" - } - }, - "Access-Control-Allow-Methods": { - "description": "Indicates which method a future CORS request to the same resource might use.", - "schema": { - "type": "string" - } - } - }, - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - }, - "501": { - "description": "OPTIONS action is not implement when CORS headers are not enabled", - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - } - } - } - }, - "/show/linked_data/{vocab}/{id}": { - "get": { - "operationId": "GET_fetchByIDFromAuthority", - "summary": "Get a single term from an authority. Generally there are no additional parameters. See the authority's configuration file to be sure. Some authorities support `lang` which can be used to filter the language of returned strings.", - "tags": ["FetchTerm"], - "parameters": [ - { - "description": "Name of the authority's configuration file.", - "in": "path", - "name": "vocab", - "required": true, - "schema": { - "default": "oclc_fast", - "type": "string" - } - }, - { - "description": "The ID or URI for the term being retrieved.", - "in": "path", - "name": "id", - "required": true, - "schema": { - "default": "1914919", - "type": "string" - } - }, - { - "description": "The format of the returned result.", - "in": "query", - "name": "format", - "required": false, - "schema": { - "default": "json", - "type": "string", - "enum": ["json", "jsonld"] - } - } - ], - "responses": { - "200": { - "description": "Successfully accessed authority and received term.", - "headers": { - "Access-Control-Allow-Origin": { - "description": "CORS header will be * if CORS headers are enabled", - "schema": { - "type": "string" - } - } - }, - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/linked_data_term_json_result" - } - }, - "application/ld+json": { - "schema": { - "$ref": "#/components/schemas/linked_data_term_jsonld_result" - } - } - } - }, - "400": { - "description": "Bad Request - occurs when required params are missing (e.g. id)", - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - }, - "404": { - "description": "Not Found", - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - }, - "500": { - "description": "Internal Server Error - can be raised while attempting to access the external authority OR during processing of results when results are not a valid RDF Format", - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - }, - "503": { - "description": "Service Unavailable - can be raised while attempting to access the external authority", - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - } - } - }, - "options": { - "summary": "CORS preflight request", - "operationId": "OPTIONS_fetchByIDFromAuthority", - "tags": ["FetchTerm"], - "parameters": [ - { - "description": "Name of the authority's configuration file.", - "in": "path", - "name": "vocab", - "required": true, - "schema": { - "default": "oclc_fast", - "type": "string" - } - }, - { - "description": "The ID or URI for the term being retrieved.", - "in": "path", - "name": "id", - "required": true, - "schema": { - "default": "1914919", - "type": "string" - } - } - ], - "responses": { - "204": { - "description": "Perform CORS preflight for fetching a term from an authority", - "headers": { - "Access-Control-Allow-Origin": { - "description": "CORS header will be * if CORS headers are enabled", - "schema": { - "type": "string" - } - }, - "Access-Control-Allow-Headers": { - "description": "Indicates which headers a future CORS request to the same resource might use.", - "schema": { - "type": "string" - } - }, - "Access-Control-Allow-Methods": { - "description": "Indicates which method a future CORS request to the same resource might use.", - "schema": { - "type": "string" - } - } - }, - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - }, - "501": { - "description": "OPTIONS action is not implement when CORS headers are not enabled", - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - } - } - } - }, - "/show/linked_data/{vocab}/{subauthority}/{id}": { - "get": { - "operationId": "GET_fetchByIDFromSubauthority", - "summary": "Get a single term from a subauthority in an authority. Generally there are no additional parameters. See the authority's configuration file to be sure. Some authorities support `lang` which can be used to filter the language of returned strings.", - "tags": ["FetchTerm"], - "parameters": [ - { - "description": "Name of the authority's configuration file.", - "in": "path", - "name": "vocab", - "required": true, - "schema": { - "default": "loc", - "type": "string" - } - }, - { - "description": "Name of the subauthority.", - "in": "path", - "name": "subauthority", - "required": true, - "schema": { - "default": "names", - "type": "string" - } - }, - { - "description": "The ID or URI for the term being retrieved.", - "in": "path", - "name": "id", - "required": true, - "schema": { - "default": "n92016188", - "type": "string" - } - }, - { - "description": "The format of the returned result.", - "in": "query", - "name": "format", - "required": false, - "schema": { - "default": "json", - "type": "string", - "enum": ["json", "jsonld"] - } - } - ], - "responses": { - "200": { - "description": "Successfully accessed subauthority in the authority and received term.", - "headers": { - "Access-Control-Allow-Origin": { - "description": "CORS header will be * if CORS headers are enabled", - "schema": { - "type": "string" - } - } - }, - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/linked_data_term_json_result" - } - }, - "application/ld+json": { - "schema": { - "$ref": "#/components/schemas/linked_data_term_jsonld_result" - } - } - } - }, - "400": { - "description": "Bad Request - occurs when required params are missing (e.g. id)", - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - }, - "404": { - "description": "Not Found", - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - }, - "500": { - "description": "Internal Server Error - can be raised while attempting to access the external authority OR during processing of results when results are not a valid RDF Format", - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - }, - "503": { - "description": "Service Unavailable - can be raised while attempting to access the external authority", - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - } - } - }, - "options": { - "summary": "CORS preflight request", - "operationId": "OPTIONS_fetchByIDFromSubauthority", - "tags": ["FetchTerm"], - "parameters": [ - { - "description": "Name of the authority's configuration file.", - "in": "path", - "name": "vocab", - "required": true, - "schema": { - "default": "loc", - "type": "string" - } - }, - { - "description": "Name of the subauthority.", - "in": "path", - "name": "subauthority", - "required": true, - "schema": { - "default": "names", - "type": "string" - } - }, - { - "description": "The ID or URI for the term being retrieved.", - "in": "path", - "name": "id", - "required": true, - "schema": { - "default": "n92016188", - "type": "string" - } - } - ], - "responses": { - "204": { - "description": "Perform CORS preflight for fetching a term from a subauthority in an authority", - "headers": { - "Access-Control-Allow-Origin": { - "description": "CORS header will be * if CORS headers are enabled", - "schema": { - "type": "string" - } - }, - "Access-Control-Allow-Headers": { - "description": "Indicates which headers a future CORS request to the same resource might use.", - "schema": { - "type": "string" - } - }, - "Access-Control-Allow-Methods": { - "description": "Indicates which method a future CORS request to the same resource might use.", - "schema": { - "type": "string" - } - } - }, - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - }, - "501": { - "description": "OPTIONS action is not implement when CORS headers are not enabled", - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - } - } - } - }, - "/fetch/linked_data/{vocab}": { - "get": { - "operationId": "GET_fetchURIFromAuthority", - "summary": "Get a single term from an authority given the term's URI. Generally there are no additional parameters. See the authority's configuration file to be sure. Some authorities support `lang` which can be used to filter the language of returned strings.", - "tags": ["FetchTerm"], - "parameters": [ - { - "description": "Name of the authority's configuration file.", - "in": "path", - "name": "vocab", - "required": true, - "schema": { - "default": "locgenres_ld4l_cache", - "type": "string" - } - }, - { - "description": "The URI for the term being retrieved.", - "in": "query", - "name": "uri", - "required": true, - "schema": { - "default": "http://id.loc.gov/authorities/genreForms/gf2011026141", - "type": "string" - } - }, - { - "description": "The format of the returned result.", - "in": "query", - "name": "format", - "required": false, - "schema": { - "default": "json", - "type": "string", - "enum": ["json", "jsonld"] - } - } - ], - "responses": { - "200": { - "description": "Successfully accessed authority and received term.", - "headers": { - "Access-Control-Allow-Origin": { - "description": "CORS header will be * if CORS headers are enabled", - "schema": { - "type": "string" - } - } - }, - "content": { - "application/json": { - "schema": { - "type": "object", - "items": { - "required": ["results", "response_header"], - "properties": { - "results": { - "$ref": "#/components/schemas/linked_data_query_results" - }, - "response_header": { - "$ref": "#/components/schemas/response_header" - } - } - } - } - }, - "application/ld+json": { - "schema": { - "$ref": "#/components/schemas/linked_data_term_jsonld_result" - } - } - } - }, - "400": { - "description": "Bad Request - occurs when required params are missing (e.g. uri)", - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - }, - "404": { - "description": "Not Found", - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - }, - "500": { - "description": "Internal Server Error - can be raised while attempting to access the external authority OR during processing of results when results are not a valid RDF Format", - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - }, - "503": { - "description": "Service Unavailable - can be raised while attempting to access the external authority", - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - } - } - }, - "options": { - "summary": "CORS preflight request", - "operationId": "OPTIONS_fetchURIFromAuthority", - "tags": ["FetchTerm"], - "parameters": [ - { - "description": "Name of the authority's configuration file.", - "in": "path", - "name": "vocab", - "required": true, - "schema": { - "default": "locgenres_ld4l_cache", - "type": "string" - } - }, - { - "description": "The URI for the term being retrieved.", - "in": "query", - "name": "uri", - "required": true, - "schema": { - "default": "http://id.loc.gov/authorities/genreForms/gf2011026141", - "type": "string" - } - } - ], - "responses": { - "204": { - "description": "Perform CORS preflight for fetching a term from an authority", - "headers": { - "Access-Control-Allow-Origin": { - "description": "CORS header will be * if CORS headers are enabled", - "schema": { - "type": "string" - } - }, - "Access-Control-Allow-Headers": { - "description": "Indicates which headers a future CORS request to the same resource might use.", - "schema": { - "type": "string" - } - }, - "Access-Control-Allow-Methods": { - "description": "Indicates which method a future CORS request to the same resource might use.", - "schema": { - "type": "string" - } - } - }, - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - }, - "501": { - "description": "OPTIONS action is not implement when CORS headers are not enabled", - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - } - } - } - }, - "/search/{vocab}": { - "get": { - "summary": "Send a query string to an authority and return search results. Parameters are typical examples. Actual parameters are driven by the authority's config file.", - "operationId": "GET_nonldSearchAuthority", - "tags": ["SearchQuery"], - "parameters": [ - { - "description": "Name of the authority's configuration file.", - "in": "path", - "name": "vocab", - "required": true, - "schema": { - "default": "discogs", - "type": "string" - } - }, - { - "description": "The query string", - "in": "query", - "name": "q", - "required": true, - "schema": { - "default": "sinatra", - "type": "string" - } - }, - { - "description": "Limit number of returned results. NOTE: Most authorities use maxRecords, but a few use maximumRecords for this parameter.", - "in": "query", - "name": "maxRecords", - "required": false, - "schema": { - "default": 4, - "type": "integer" - } - }, - { - "description": "Limit string values to this language when multiple languages are provided.", - "in": "query", - "name": "lang", - "required": false, - "schema": { - "default": "en", - "type": "string" - } - }, - { - "description": "Return context provided by QA", - "in": "query", - "name": "context", - "required": false, - "schema": { - "default": "en", - "type": "string" - } - }, - { - "description": "Include response header", - "in": "query", - "name": "response_header", - "required": true, - "schema": { - "default": "true", - "type": "string" - } - }, - { - "description": "First record offset (1 based)", - "in": "query", - "name": "startRecord", - "required": false, - "schema": { - "default": 1, - "type": "integer" - } - } - ], - "responses": { - "200": { - "description": "Successfully accessed authority and received results.", - "headers": { - "Access-Control-Allow-Origin": { - "description": "CORS header will be * if cors_headers_enabled", - "schema": { - "type": "string" - } - } - }, - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/linked_data_query_results" - } - } - } - }, - "400": { - "description": "Bad Request - occurs when required params are missing (e.g. q)", - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - }, - "500": { - "description": "Internal Server Error - can be raised while attempting to access the external authority OR during processing of results when results are not a valid RDF Format", - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - }, - "503": { - "description": "Service Unavailable - can be raised while attempting to access the external authority", - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - } - } - }, - "options": { - "summary": "CORS preflight request", - "operationId": "OPTIONS_nonldsearchAuthority", - "tags": ["SearchQuery"], - "parameters": [ - { - "description": "Name of the authority's configuration file.", - "in": "path", - "name": "vocab", - "required": true, - "schema": { - "default": "discogs", - "type": "string" - } - } - ], - "responses": { - "204": { - "description": "When CORS is enabled, perform CORS preflight for searching an authority", - "headers": { - "Access-Control-Allow-Origin": { - "description": "CORS header will be * if CORS headers are enabled", - "schema": { - "type": "string" - } - }, - "Access-Control-Allow-Headers": { - "description": "Indicates which headers a future CORS request to the same resource might use.", - "schema": { - "type": "string" - } - }, - "Access-Control-Allow-Methods": { - "description": "Indicates which method a future CORS request to the same resource might use.", - "schema": { - "type": "string" - } - } - }, - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - }, - "501": { - "description": "OPTIONS action is not implement when CORS headers are not enabled", - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - } - } - } - }, - "/search/{vocab}/{subauthority}": { - "get": { - "summary": "Send a query string to an authority and return search results. Parameters are typical examples. Actual parameters are driven by the authority's config file.", - "operationId": "GET_nonldSearchWithSubauthority", - "tags": ["SearchQuery"], - "parameters": [ - { - "description": "Name of the authority's configuration file.", - "in": "path", - "name": "vocab", - "required": true, - "schema": { - "default": "discogs", - "type": "string" - } - }, - { - "description": "Name of the subauthority.", - "in": "path", - "name": "subauthority", - "required": true, - "schema": { - "default": "all", - "type": "string" - } - }, - { - "description": "The query string", - "in": "query", - "name": "q", - "required": true, - "schema": { - "default": "sinatra", - "type": "string" - } - }, - { - "description": "Limit number of returned results. NOTE: Most authorities use maxRecords, but a few use maximumRecords for this parameter.", - "in": "query", - "name": "maxRecords", - "required": false, - "schema": { - "default": 4, - "type": "integer" - } - }, - { - "description": "Limit string values to this language when multiple languages are provided.", - "in": "query", - "name": "lang", - "required": false, - "schema": { - "default": "en", - "type": "string" - } - }, - { - "description": "Return context provided by QA", - "in": "query", - "name": "context", - "required": false, - "schema": { - "default": "en", - "type": "string" - } - }, - { - "description": "Include response header", - "in": "query", - "name": "response_header", - "required": true, - "schema": { - "default": "true", - "type": "string" - } - }, - { - "description": "First record offset (1 based)", - "in": "query", - "name": "startRecord", - "required": false, - "schema": { - "default": 1, - "type": "integer" - } - } - ], - "responses": { - "200": { - "description": "Successfully accessed authority and received results.", - "headers": { - "Access-Control-Allow-Origin": { - "description": "CORS header will be * if cors_headers_enabled", - "schema": { - "type": "string" - } - } - }, - "content": { - "application/json": { - "schema": { - "type": "object", - "items": { - "required": ["results", "response_header"], - "properties": { - "results": { - "$ref": "#/components/schemas/linked_data_query_results" - }, - "response_header": { - "$ref": "#/components/schemas/response_header" - } - } - } - } - } - } - }, - "400": { - "description": "Bad Request - occurs when required params are missing (e.g. q)", - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - }, - "500": { - "description": "Internal Server Error - can be raised while attempting to access the external authority OR during processing of results when results are not a valid RDF Format", - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - }, - "503": { - "description": "Service Unavailable - can be raised while attempting to access the external authority", - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - } - } - }, - "options": { - "summary": "CORS preflight request", - "operationId": "OPTIONS_nonldsearchWithSubauthority", - "tags": ["SearchQuery"], - "parameters": [ - { - "description": "Name of the authority's configuration file.", - "in": "path", - "name": "vocab", - "required": true, - "schema": { - "default": "discogs", - "type": "string" - } - } - ], - "responses": { - "204": { - "description": "When CORS is enabled, perform CORS preflight for searching an authority", - "headers": { - "Access-Control-Allow-Origin": { - "description": "CORS header will be * if CORS headers are enabled", - "schema": { - "type": "string" - } - }, - "Access-Control-Allow-Headers": { - "description": "Indicates which headers a future CORS request to the same resource might use.", - "schema": { - "type": "string" - } - }, - "Access-Control-Allow-Methods": { - "description": "Indicates which method a future CORS request to the same resource might use.", - "schema": { - "type": "string" - } - } - }, - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - }, - "501": { - "description": "OPTIONS action is not implement when CORS headers are not enabled", - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - } - } - } - }, - "/show/{vocab}/{subauthority}/{id}": { - "get": { - "operationId": "GET_nonldfetchByIDWithSubauthority", - "summary": "Get a single term from a subauthority in an authority. Generally there are no additional parameters. See the authority's configuration file to be sure. Some authorities support `lang` which can be used to filter the language of returned strings.", - "tags": ["FetchTerm"], - "parameters": [ - { - "description": "Name of the authority's configuration file.", - "in": "path", - "name": "vocab", - "required": true, - "schema": { - "default": "discogs", - "type": "string" - } - }, - { - "description": "Name of the subauthority.", - "in": "path", - "name": "subauthority", - "required": true, - "schema": { - "default": "all", - "type": "string" - } - }, - { - "description": "The ID of the term being retrieved.", - "in": "path", - "name": "id", - "required": true, - "schema": { - "default": "12345", - "type": "string" - } - }, - { - "description": "The format of the returned result.", - "in": "query", - "name": "format", - "required": false, - "schema": { - "default": "json", - "type": "string", - "enum": ["json", "jsonld"] - } - } - ], - "responses": { - "200": { - "description": "Successfully accessed subauthority in the authority and received term.", - "headers": { - "Access-Control-Allow-Origin": { - "description": "CORS header will be * if CORS headers are enabled", - "schema": { - "type": "string" - } - } - }, - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/linked_data_term_json_result" - } - }, - "application/ld+json": { - "schema": { - "$ref": "#/components/schemas/linked_data_term_jsonld_result" - } - } - } - }, - "400": { - "description": "Bad Request - occurs when required params are missing (e.g. id)", - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - }, - "404": { - "description": "Not Found", - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - }, - "500": { - "description": "Internal Server Error - can be raised while attempting to access the external authority OR during processing of results when results are not a valid RDF Format", - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - }, - "503": { - "description": "Service Unavailable - can be raised while attempting to access the external authority", - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - } - } - }, - "options": { - "summary": "CORS preflight request", - "operationId": "OPTIONS_nonldfetchByIDWithSubauthority", - "tags": ["FetchTerm"], - "parameters": [ - { - "description": "Name of the authority's configuration file.", - "in": "path", - "name": "vocab", - "required": true, - "schema": { - "default": "discogs", - "type": "string" - } - }, - { - "description": "Name of the subauthority.", - "in": "path", - "name": "subauthority", - "required": true, - "schema": { - "default": "all", - "type": "string" - } - }, - { - "description": "The ID or URI for the term being retrieved.", - "in": "path", - "name": "id", - "required": true, - "schema": { - "default": "12345", - "type": "string" - } - }, - { - "description": "The format of the returned result.", - "in": "query", - "name": "format", - "required": false, - "schema": { - "default": "json", - "type": "string", - "enum": ["json", "jsonld"] - } - } - ], - "responses": { - "204": { - "description": "Perform CORS preflight for fetching a term from a subauthority in an authority", - "headers": { - "Access-Control-Allow-Origin": { - "description": "CORS header will be * if CORS headers are enabled", - "schema": { - "type": "string" - } - }, - "Access-Control-Allow-Headers": { - "description": "Indicates which headers a future CORS request to the same resource might use.", - "schema": { - "type": "string" - } - }, - "Access-Control-Allow-Methods": { - "description": "Indicates which method a future CORS request to the same resource might use.", - "schema": { - "type": "string" - } - } - }, - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - }, - "501": { - "description": "OPTIONS action is not implement when CORS headers are not enabled", - "content": { - "text/plain": { - "schema": { - "type": "string", - "example": "" - } - } - } - } - } - } - } - }, - "components": { - "schemas": { - "linked_data_authorities_list_result": { - "type": "array", - "items": { - "type": "string" - } - }, - "response_header": { - "type": "object", - "items": { - "required": [ - "start_record", - "requested_records", - "retrieved_records", - "total_records" - ], - "properties": { - "start_record": { - "type": "integer" - }, - "requested_records": { - "type": "integer" - }, - "retrieved_records": { - "type": "integer" - }, - "total_records": { - "type": "integer" - } - } - } - }, - "linked_data_query_results": { - "type": "array", - "items": { - "required": ["id", "uri", "label"], - "properties": { - "id": { - "type": "string" - }, - "uri": { - "type": "string" - }, - "label": { - "type": "string" - }, - "context": { - "type": "object" - } - } - } - }, - "linked_data_term_json_result": { - "required": ["id", "uri", "label"], - "properties": { - "id": { - "type": "string" - }, - "uri": { - "type": "string" - }, - "label": { - "type": "string" - }, - "altlabel": { - "type": "array", - "items": { - "type": "string" - } - }, - "broader": { - "type": "array", - "items": { - "type": "string" - } - }, - "narrower": { - "type": "array", - "items": { - "type": "string" - } - }, - "sameas": { - "type": "array", - "items": { - "type": "string" - } - }, - "predicates": { - "type": "object" - } - } - }, - "linked_data_term_jsonld_result": { - "required": ["@context", "@graph"], - "properties": { - "@context": { - "type": "object" - }, - "@graph": { - "type": "object" - } - } - } - } - }, - "tags": [ - { - "name": "AuthorityManagement", - "description": "Services managing all authorities." - }, - { - "name": "SearchQuery", - "description": "Services sending a search query to an authority to retrieve multiple results." - }, - { - "name": "FetchTerm", - "description": "Services to fetch a single term from an authority." - } - ] -} diff --git a/src/utilities/QuestioningAuthority.js b/src/utilities/QuestioningAuthority.js index 1099b5bfe..60acb6b30 100644 --- a/src/utilities/QuestioningAuthority.js +++ b/src/utilities/QuestioningAuthority.js @@ -1,62 +1,59 @@ // Copyright 2019 Stanford University see LICENSE for license /* eslint max-params: ["warn", 4] */ -import Swagger from "swagger-client" -import swaggerSpec from "lib/apidoc.json" import Config from "Config" import { findAuthorityConfig } from "utilities/authorityConfig" import _ from "lodash" +import { URLSearchParams } from "url" export const isContext = (propertyTemplate) => propertyTemplate?.subtype === "context" -export const createLookupPromise = (query, lookupConfig, options = {}) => { - const authority = lookupConfig.authority - const subauthority = lookupConfig.subauthority - const language = lookupConfig.language - +const baseUrlFromConfig = (nonldLookup, authority, subauthority) => { /* - * There are two types of lookup: linked data and non-linked data. The API calls - * for each type are different, so check the nonldLookup field in the lookup config. - * If the field is not set, assume false. + * There are four types of lookup: linked data and non-linked data, authority + * andsubauthority. The API calls for each type are different, so construct + * the URL depending on the options passed. */ + const urlSegments = [Config.qaUrl, "search"] - // default the API calls to their linked data values - let subAuthCall = "GET_searchSubauthority" - let authorityCall = "GET_searchAuthority" + if (nonldLookup) urlSegments.push("linked_data") - // Change the API calls if this is a non-linked data lookup - if (lookupConfig.nonldLookup) { - subAuthCall = "GET_nonldSearchWithSubauthority" - authorityCall = "GET_nonldSearchAuthority" - } + urlSegments.push(authority) + + if (subauthority) urlSegments.push(subauthority) + + return urlSegments.join("/") +} + +export const createLookupPromise = ( + query, + { authority, subauthority, language, nonldLookup }, + options = {} +) => { + const baseUrl = baseUrlFromConfig(nonldLookup, authority, subauthority) + const urlParams = new URLSearchParams({ + q: query, + maxRecords: options.resultsPerPage || Config.maxRecordsForQALookups, + lang: language, + context: true, // Always search to see if context is available + response_header: true, + startRecord: options.startOfRange ? options.startOfRange + 1 : 1, + }) /* * Return the promise * Since we don't want promise.all to fail if * one of the lookups fails, we want a catch statement * at this level which will then return the error. Subauthorities require a different API call than authorities so need to check if subauthority is available - * The only difference between this call and the next one is the call to Get_searchSubauthority instead of - * Get_searchauthority. Passing API call in a variable name/dynamically, thanks @mjgiarlo */ - const actionFunction = subauthority ? subAuthCall : authorityCall - - return Swagger({ spec: swaggerSpec }).then((client) => - client.apis.SearchQuery?.[actionFunction]({ - q: query, - vocab: authority, - subauthority, - maxRecords: options.resultsPerPage || Config.maxRecordsForQALookups, - lang: language, - context: true, // Always search to see if context is available - response_header: true, - startRecord: options.startOfRange ? options.startOfRange + 1 : 1, - }).catch((err) => { + return fetch(`${baseUrl}?${urlParams}`) + .then((resp) => resp) + .catch((err) => { console.error("Error in executing lookup against source", err.toString()) // Return information along with the error in its own object return { isError: true, errorObject: err } }) - ) } /**