atlas-app-services-admin-api
Version:
OpenAPI client for Atlas App Services Admin API
161 lines (160 loc) • 10.3 kB
JavaScript
;
/* tslint:disable */
/* eslint-disable */
/**
* MongoDB Atlas App Services Admin API
* The App Services Admin API lets you programmatically perform administrative tasks over HTTPS. This includes defining & configuring things like: - App Deployment & Security - APIs & Endpoints - Authentication & User Management - Data Sources - Device Sync - Environments - Functions - Logs - Rules - Schemas - Static Hosting - Triggers - Usage & Billing Metrics - Values & Secrets The Admin API is for application development, configuration, and deployment. To actually use the features you configure with the Admin API, client applications connect with a [Realm SDK](https://mongodb.com/docs/realm/) or over an HTTPS API specific to your App. ## Project & Application IDs **Note**: The terms _Project ID_ and _Group ID_ are interchangeable. Atlas App Services Admin API endpoints frequently require you to include two parameters in the URL: - Your Atlas _Project ID_ (also sometimes called a _Group ID_) - Your App Services _Application ID_ ### Project ID You can find your Project ID from the MongoDB Atlas dashboard or with the MongoDB Atlas CLI. ### Application ID To find an Application ID, make a request to the [List Apps](#operation/adminListApplications) endpoint for your project. You\'ll need an `access_token` to make this request. To learn how to get one, see [Get an Admin API Session Access Token](#get-an-admin-api-session-access-token). ```sh curl --request GET \\ --header \'Authorization: Bearer <access_token>\' \\ https://realm.mongodb.com/api/admin/v3.0/groups/{groupId}/apps ``` This will return a list of objects describing each App Services App in the provided project/group. For Admin API requests, your Application ID is the ObjectId value in the `_id` field, _not_ the `client_app_id`. ```json [ { \"_id\": \"5997529e46224c6e42gb6dd9\", \"group_id\": \"57879f6cc4b32dbe440bb8c5\", \"domain_id\": \"5886619e46124e4c42fb5dd8\", \"client_app_id\": \"myapp-abcde\", \"name\": \"myapp\", \"location\": \"US-VA\", \"deployment_model\": \"GLOBAL\", \"last_used\": 1615153544, \"last_modified\": 0, \"product\": \"standard\", \"environment\": \"\" } ] ``` ## Get an Admin API Session Access Token Every request to the App Services Admin API must include a valid, unexpired access token issued by the MongoDB Cloud API. You include this token in the `Authorization` header of each request using the bearer auth scheme. You need a valid [MongoDB Atlas programmatic API key](https://docs.atlas.mongodb.com/configure-api-access) for MongoDB Atlas to get a token. Once you have an API key pair, call the authentication endpoint: ```shell curl --request POST \\ --header \'Content-Type: application/json\' \\ --header \'Accept: application/json\' \\ --data \'{\"username\": \"<Public API Key>\", \"apiKey\": \"<Private API Key>\"}\' \\ https://realm.mongodb.com/api/admin/v3.0/auth/providers/mongodb-cloud/login ``` If authentication succeeds, App Services returns an access token as part of the JSON response document: ```json { \"access_token\": \"<access_token>\", \"refresh_token\": \"<refresh_token>\", \"user_id\": \"<user_id>\", \"device_id\": \"<device_id>\" } ``` The `access_token` represents a limited-time authorization to interact with the Admin API. To authenticate a request, include the token in a [Bearer token](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication) `Authorization` header. ```http Authorization: Bearer <access_token> ``` ## Refresh an Admin API Session Access Token Session access tokens expire 30 minutes after they are issued. When you login, the response also includes a `refresh_token` that you can use to get a new access token. This is useful because you only need to log in with credentials one time. After that you can use the refresh token to re-authenticate for as long as its valid. Refresh tokens expire 60 days after being issued. To refresh your authentication and get a new `access_token`, call the auth session endpoint with your `refresh_token` in the `Authorization` header: ```shell curl --request POST \\ --header \'Authorization: Bearer <refresh_token>\' \\ https://realm.mongodb.com/api/admin/v3.0/auth/session ``` If the refresh token is valid, the response body includes a new `access_token` that\'s valid for the next 30 minutes: ```json { \"access_token\": \"<access_token>\" } ```
*
* The version of the OpenAPI document: 3.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
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 });
exports.createRequestFunction = exports.toPathString = exports.serializeDataIfNeeded = exports.setSearchParams = exports.setOAuthToObject = exports.setBearerAuthToObject = exports.setBasicAuthToObject = exports.setApiKeyToObject = exports.assertParamExists = exports.DUMMY_BASE_URL = void 0;
const base_1 = require("./base");
/**
*
* @export
*/
exports.DUMMY_BASE_URL = 'https://example.com';
/**
*
* @throws {RequiredError}
* @export
*/
const assertParamExists = function (functionName, paramName, paramValue) {
if (paramValue === null || paramValue === undefined) {
throw new base_1.RequiredError(paramName, `Required parameter ${paramName} was null or undefined when calling ${functionName}.`);
}
};
exports.assertParamExists = assertParamExists;
/**
*
* @export
*/
const setApiKeyToObject = function (object, keyParamName, configuration) {
return __awaiter(this, void 0, void 0, function* () {
if (configuration && configuration.apiKey) {
const localVarApiKeyValue = typeof configuration.apiKey === 'function'
? yield configuration.apiKey(keyParamName)
: yield configuration.apiKey;
object[keyParamName] = localVarApiKeyValue;
}
});
};
exports.setApiKeyToObject = setApiKeyToObject;
/**
*
* @export
*/
const setBasicAuthToObject = function (object, configuration) {
if (configuration && (configuration.username || configuration.password)) {
object["auth"] = { username: configuration.username, password: configuration.password };
}
};
exports.setBasicAuthToObject = setBasicAuthToObject;
/**
*
* @export
*/
const setBearerAuthToObject = function (object, configuration) {
return __awaiter(this, void 0, void 0, function* () {
if (configuration && configuration.accessToken) {
const accessToken = typeof configuration.accessToken === 'function'
? yield configuration.accessToken()
: yield configuration.accessToken;
object["Authorization"] = "Bearer " + accessToken;
}
});
};
exports.setBearerAuthToObject = setBearerAuthToObject;
/**
*
* @export
*/
const setOAuthToObject = function (object, name, scopes, configuration) {
return __awaiter(this, void 0, void 0, function* () {
if (configuration && configuration.accessToken) {
const localVarAccessTokenValue = typeof configuration.accessToken === 'function'
? yield configuration.accessToken(name, scopes)
: yield configuration.accessToken;
object["Authorization"] = "Bearer " + localVarAccessTokenValue;
}
});
};
exports.setOAuthToObject = setOAuthToObject;
function setFlattenedQueryParams(urlSearchParams, parameter, key = "") {
if (parameter == null)
return;
if (typeof parameter === "object") {
if (Array.isArray(parameter)) {
parameter.forEach(item => setFlattenedQueryParams(urlSearchParams, item, key));
}
else {
Object.keys(parameter).forEach(currentKey => setFlattenedQueryParams(urlSearchParams, parameter[currentKey], `${key}${key !== '' ? '.' : ''}${currentKey}`));
}
}
else {
if (urlSearchParams.has(key)) {
urlSearchParams.append(key, parameter);
}
else {
urlSearchParams.set(key, parameter);
}
}
}
/**
*
* @export
*/
const setSearchParams = function (url, ...objects) {
const searchParams = new URLSearchParams(url.search);
setFlattenedQueryParams(searchParams, objects);
url.search = searchParams.toString();
};
exports.setSearchParams = setSearchParams;
/**
*
* @export
*/
const serializeDataIfNeeded = function (value, requestOptions, configuration) {
const nonString = typeof value !== 'string';
const needsSerialization = nonString && configuration && configuration.isJsonMime
? configuration.isJsonMime(requestOptions.headers['Content-Type'])
: nonString;
return needsSerialization
? JSON.stringify(value !== undefined ? value : {})
: (value || "");
};
exports.serializeDataIfNeeded = serializeDataIfNeeded;
/**
*
* @export
*/
const toPathString = function (url) {
return url.pathname + url.search + url.hash;
};
exports.toPathString = toPathString;
/**
*
* @export
*/
const createRequestFunction = function (axiosArgs, globalAxios, BASE_PATH, configuration) {
return (axios = globalAxios, basePath = BASE_PATH) => {
const axiosRequestArgs = Object.assign(Object.assign({}, axiosArgs.options), { url: ((configuration === null || configuration === void 0 ? void 0 : configuration.basePath) || axios.defaults.baseURL || basePath) + axiosArgs.url });
return axios.request(axiosRequestArgs);
};
};
exports.createRequestFunction = createRequestFunction;