odp-sdk
Version:
Ocean Data Platform JavaScript SDK
105 lines • 4.38 kB
JavaScript
"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());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const loglevel_1 = __importDefault(require("loglevel"));
const auth_1 = require("./auth");
const Catalog_1 = __importDefault(require("./Catalog/Catalog"));
class ODPClient {
constructor(options, authConfig) {
var _a;
this.listeners = [];
this.listenToAuthChanges = (listenerFn) => {
if (!(typeof listenerFn === "function")) {
throw new Error(`Listener function is not of type function, got ${typeof listenerFn}`);
}
this.listeners.push(listenerFn);
return () => {
this.listeners = this.listeners.filter(fn => fn === listenerFn);
};
};
this.notifyListeners = () => {
for (const listenerFn of this.listeners) {
try {
listenerFn(this.authTokens);
}
catch (error) {
loglevel_1.default.warn("Listener function threw uncaught error", listenerFn);
}
}
};
this.authStateUpdated = (token) => {
this.authResult = token;
this.notifyListeners();
};
loglevel_1.default.setLevel((_a = options.logLevel) !== null && _a !== void 0 ? _a : loglevel_1.default.levels.SILENT);
this.auth = new auth_1.Auth(Object.assign({ redirectUri: "http://localhost:3000/", knownAuthorities: ["oceandataplatform.b2clogin.com"], authority: "https://oceandataplatform.b2clogin.com/oceandataplatform.onmicrosoft.com/B2C_1A_signup_signin_custom" }, authConfig));
this._catalog = new Catalog_1.default({ auth: this.auth });
}
get authTokens() {
if (!this.authResult) {
return undefined;
}
return {
accessToken: this.authResult.accessToken,
idToken: this.authResult.idToken,
idTokenClaims: this.authResult.idTokenClaims,
authority: this.authResult.authority,
scopes: this.authResult.scopes,
};
}
authenticate() {
return __awaiter(this, void 0, void 0, function* () {
if (!this.authResult) {
this.authResult = yield this.auth.handleRedirectAuth();
return this.authTokens;
}
return this.authTokens;
});
}
unauthorizeUser() {
return this.auth.logout();
}
searchCatalog(keyword) {
return __awaiter(this, void 0, void 0, function* () {
return this._catalog.searchCatalog(keyword);
});
}
autocompleteCatalog(keyword) {
return __awaiter(this, void 0, void 0, function* () {
return this._catalog.autocompleteCatalog(keyword);
});
}
autocompleteDataLayers(keyword) {
return __awaiter(this, void 0, void 0, function* () {
return this._catalog.autocompleteDataLayers(keyword);
});
}
getDataLayerById(id) {
return __awaiter(this, void 0, void 0, function* () {
return this._catalog.getDataLayerById(id);
});
}
getDataProductByUuid(dataProductUuid) {
return __awaiter(this, void 0, void 0, function* () {
return this._catalog.getDataProductByUuid(dataProductUuid);
});
}
getAllDataProducts() {
return __awaiter(this, void 0, void 0, function* () {
return this._catalog.getAllDataProducts();
});
}
}
exports.default = ODPClient;
//# sourceMappingURL=ODPClient.js.map