UNPKG

@jupyterlab/services

Version:

Client APIs for the Jupyter services REST APIs

52 lines 1.84 kB
"use strict"; // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. Object.defineProperty(exports, "__esModule", { value: true }); exports.UserAPIClient = void 0; const serverconnection_1 = require("../serverconnection"); const coreutils_1 = require("@jupyterlab/coreutils"); /** * The url for the user service. */ const SERVICE_USER_URL = 'api/me'; /** * The User API client. * * #### Notes * Use this class to interact with the Jupyter Server User API. * This class adheres to the Jupyter Server API endpoints. */ class UserAPIClient { /** * Create a new User API client. * * @param options - The options used to create the client. */ constructor(options = {}) { var _a; this.serverSettings = (_a = options.serverSettings) !== null && _a !== void 0 ? _a : serverconnection_1.ServerConnection.makeSettings(); } /** * Fetch the user data. * * @returns A promise that resolves with the user data. * * #### Notes * Uses the [Jupyter Server API](https://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter-server/jupyter_server/main/jupyter_server/services/api/api.yaml#/identity). */ async get() { const { baseUrl } = this.serverSettings; const { makeRequest, ResponseError } = serverconnection_1.ServerConnection; const url = coreutils_1.URLExt.join(baseUrl, SERVICE_USER_URL); const response = await makeRequest(url, {}, this.serverSettings); if (response.status !== 200) { const err = await ResponseError.create(response); throw err; } // TODO: add validation return await response.json(); } } exports.UserAPIClient = UserAPIClient; //# sourceMappingURL=restapi.js.map