UNPKG

odp-sdk

Version:

Ocean Data Platform JavaScript SDK

115 lines 5.48 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const constants_1 = require("../constants"); class DataMeshApiClient { constructor(options) { var _a, _b; this.autocompleteCatalog = (searchWord) => __awaiter(this, void 0, void 0, function* () { try { const token = yield this._auth.getToken(this._tokenScope); const response = yield fetch(`${this._dataMeshApiBaseUrl}/autocomplete?q=${searchWord}`, { headers: { Authorization: `Bearer ${token}`, }, }); return response.json(); } catch (error) { throw new Error(`Autocompleting the catalog failed with the following error: ${error}`); } }); this.autocompleteDataLayers = (searchWord) => __awaiter(this, void 0, void 0, function* () { try { const token = yield this._auth.getToken(this._tokenScope); const response = yield fetch(`${this._dataMeshApiBaseUrl}/autocompletelayers?q=${searchWord}`, { headers: { Authorization: `Bearer ${token}`, }, }); return response.json(); } catch (error) { throw new Error(`Autocompleting the data layers failed with the following error: ${error}`); } }); this.getLayerById = (id) => __awaiter(this, void 0, void 0, function* () { try { const token = yield this._auth.getToken(this._tokenScope); const result = yield (yield fetch(`${this._dataMeshApiBaseUrl}/layer?id=${id}`, { headers: { Authorization: `Bearer ${token}`, }, })).json(); return Object.assign(Object.assign({}, result), { explorerStyling: JSON.parse(result.explorerStyling) }); } catch (error) { throw new Error(`Fetching the data layer with id ${id} has failed with the following error: ${error}`); } }); this.getDataProductByUuid = (uuid) => __awaiter(this, void 0, void 0, function* () { try { const token = yield this._auth.getToken(this._tokenScope); const dataProduct = yield (yield fetch(`${this._dataMeshApiBaseUrl}/dataproduct?uuid=${uuid}`, { headers: { Authorization: `Bearer ${token}`, }, })).json(); return dataProduct; } catch (error) { throw new Error(`Fetching the data product with uuid ${uuid} has failed with the following error: ${error}`); } }); this.getAllDataProducts = () => __awaiter(this, void 0, void 0, function* () { try { const token = yield this._auth.getToken(this._tokenScope); const dataProducts = yield (yield fetch(`${this._dataMeshApiBaseUrl}/dataproducts`, { headers: { Authorization: `Bearer ${token}`, }, })).json(); return dataProducts; } catch (error) { throw new Error(`Fetching all data products has failed with the following error: ${error}`); } }); this._auth = options.auth; this._dataMeshApiBaseUrl = (_a = options.datahMeshApiBaseUrl) !== null && _a !== void 0 ? _a : constants_1.ODP_DATAMESH_BASE_URL; this._tokenScope = (_b = options.backendTokenScope) !== null && _b !== void 0 ? _b : constants_1.ODP_BACKEND_TOKEN_SCOPE; } static getDataMeshApiClient(options) { if (this._dataMeshApiClient) { return this._dataMeshApiClient; } this._dataMeshApiClient = new DataMeshApiClient(options); return this._dataMeshApiClient; } searchCatalog(searchWord) { return __awaiter(this, void 0, void 0, function* () { try { const token = yield this._auth.getToken(this._tokenScope); const response = yield fetch(`${this._dataMeshApiBaseUrl}/search?q=${searchWord}`, { headers: { Authorization: `Bearer ${token}`, }, }); return response.json(); } catch (error) { throw new Error(`Searching the catalog failed with the following error: ${error}`); } }); } } exports.default = DataMeshApiClient; //# sourceMappingURL=DataMeshApiClient.js.map